{"action":"created","issue":{"url":"https://api.github.com/repos/mrdoob/three.js/issues/8124","repository_url":"https://api.github.com/repos/mrdoob/three.js","labels_url":"https://api.github.com/repos/mrdoob/three.js/issues/8124/labels{/name}","comments_url":"https://api.github.com/repos/mrdoob/three.js/issues/8124/comments","events_url":"https://api.github.com/repos/mrdoob/three.js/issues/8124/events","html_url":"https://github.com/mrdoob/three.js/pull/8124","id":133361941,"number":8124,"title":"WebGL2 3D Texture Support","user":{"login":"mattdesl","id":1383811,"avatar_url":"https://avatars.githubusercontent.com/u/1383811?v=3","gravatar_id":"","url":"https://api.github.com/users/mattdesl","html_url":"https://github.com/mattdesl","followers_url":"https://api.github.com/users/mattdesl/followers","following_url":"https://api.github.com/users/mattdesl/following{/other_user}","gists_url":"https://api.github.com/users/mattdesl/gists{/gist_id}","starred_url":"https://api.github.com/users/mattdesl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattdesl/subscriptions","organizations_url":"https://api.github.com/users/mattdesl/orgs","repos_url":"https://api.github.com/users/mattdesl/repos","events_url":"https://api.github.com/users/mattdesl/events{/privacy}","received_events_url":"https://api.github.com/users/mattdesl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2016-02-12T22:45:52Z","updated_at":"2016-03-24T10:49:15Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/mrdoob/three.js/pulls/8124","html_url":"https://github.com/mrdoob/three.js/pull/8124","diff_url":"https://github.com/mrdoob/three.js/pull/8124.diff","patch_url":"https://github.com/mrdoob/three.js/pull/8124.patch"},"body":"This is a first draft of 3D texture support, a WebGL2 feature.\r\n\r\n```js\r\nvar tex3d = new THREE.Texture3D( data, width, height, depth, format, type );\r\n```\r\n\r\nIn FF Nightly and Chrome Canary, I'm getting some errors when using `gl.RGB` as an *internalFormat*. So, for now, this only supports RGB32F or RGBA32F as internal format.\r\n\r\nOne application of 3D textures is for lookup-table based color transforms. A 300es shader might look like this. Notice the `sampler3D` precision qualifier is necessary for this to compile, and it needs to be used as a RawShaderMaterial.\r\n\r\n```glsl\r\n#version 300 es\r\nprecision mediump float;\r\nprecision highp sampler3D;\r\n\r\nin vec2 vUv;\r\nout vec4 fragColor;\r\nuniform sampler2D tDiffuse;\r\nuniform sampler3D tLookup;\r\nconst float lutSize = 32.0; // typically better as a uniform...\r\n\r\nvoid main () {\r\n  // Based on \"GPU Gems 2 — Chapter 24. Using Lookup Tables to Accelerate Color Transformations\"\r\n  // More info and credits @ http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html\r\n  vec4 rawColor = texture(tDiffuse, vUv);\r\n\r\n  // Compute the 3D LUT lookup scale/offset factor\r\n  vec3 scale = vec3((lutSize - 1.0) / lutSize);\r\n  vec3 offset = vec3(1.0 / (2.0 * lutSize));\r\n\r\n  // Apply 3D LUT color transform\r\n  fragColor.rgb = texture(tLookup, scale * rawColor.rgb + offset).rgb;\r\n  fragColor.a = rawColor.a;\r\n}\r\n```\r\n\r\nMore reading:\r\nhttp://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html\r\n\r\nRelated parser:\r\nhttps://github.com/thibauts/parse-cube-lut/"},"comment":{"url":"https://api.github.com/repos/mrdoob/three.js/issues/comments/200784919","html_url":"https://github.com/mrdoob/three.js/pull/8124#issuecomment-200784919","issue_url":"https://api.github.com/repos/mrdoob/three.js/issues/8124","id":200784919,"user":{"login":"rc1","id":166915,"avatar_url":"https://avatars.githubusercontent.com/u/166915?v=3","gravatar_id":"","url":"https://api.github.com/users/rc1","html_url":"https://github.com/rc1","followers_url":"https://api.github.com/users/rc1/followers","following_url":"https://api.github.com/users/rc1/following{/other_user}","gists_url":"https://api.github.com/users/rc1/gists{/gist_id}","starred_url":"https://api.github.com/users/rc1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rc1/subscriptions","organizations_url":"https://api.github.com/users/rc1/orgs","repos_url":"https://api.github.com/users/rc1/repos","events_url":"https://api.github.com/users/rc1/events{/privacy}","received_events_url":"https://api.github.com/users/rc1/received_events","type":"User","site_admin":false},"created_at":"2016-03-24T10:49:15Z","updated_at":"2016-03-24T10:49:15Z","body":"Hi just stumbled into this issue...\r\n\r\nExample code [here](https://gist.github.com/rc1/433177bd0c2ce38fcccd#file-lutstringtotexture-js) which loads a `.cube` text file (generated from the free version of DaVinci Resolve) and creates a texture like attached. The fragment shader then [samples it as a 3D texture](https://gist.github.com/rc1/433177bd0c2ce38fcccd#file-lut-frag). \r\n\r\n![screen shot 2016-03-24 at 10 45 05](https://cloud.githubusercontent.com/assets/166915/14014966/c6433ff8-f1ad-11e5-883e-05a9a85bb9dd.png)\r\n "}}