|
33 | 33 |
|
34 | 34 | uniform sampler2DArray uTexture; |
35 | 35 | uniform int uDepth; |
36 | | - uniform float uSampleLeft; |
37 | | - uniform float uSampleWidth; |
| 36 | + uniform float uIntensity; |
38 | 37 |
|
39 | 38 | void main() |
40 | 39 | { |
41 | 40 | float voxel = texture(uTexture, vec3( vUv, uDepth )).r; |
42 | | - gl_FragColor.r = (voxel - uSampleLeft) / uSampleWidth; |
| 41 | + gl_FragColor.r = voxel * uIntensity; |
43 | 42 | } |
44 | 43 |
|
45 | 44 | </script> |
|
87 | 86 |
|
88 | 87 | <p> |
89 | 88 | This example shows how to render to an array of 2D texture.</br> |
90 | | - WebGL2 allows to render to specific "layers" in 3D texture and array of textures.</br> |
91 | | - You can use the mouse left click to change the intensity of the render target. |
| 89 | + WebGL2 allows to render to specific "layers" in 3D texture and array of textures. |
92 | 90 | </p> |
93 | 91 |
|
94 | 92 | Scanned head data by |
|
103 | 101 |
|
104 | 102 | import Stats from './jsm/libs/stats.module.js'; |
105 | 103 | import { unzipSync } from './jsm/libs/fflate.module.min.js'; |
| 104 | + import { GUI } from './jsm/libs/dat.gui.module.js'; |
106 | 105 |
|
107 | 106 | import { WEBGL } from './jsm/WebGL.js'; |
108 | 107 |
|
|
118 | 117 | depth: 109 |
119 | 118 | }; |
120 | 119 |
|
121 | | - const App = { |
122 | | - mousePrevious: new THREE.Vector2() |
| 120 | + const params = { |
| 121 | + intensity: 1 |
123 | 122 | }; |
124 | 123 |
|
125 | 124 | /** Post-processing objects */ |
|
139 | 138 | uniforms: { |
140 | 139 | uTexture: { value: null }, |
141 | 140 | uDepth: { value: 55 }, |
142 | | - uSampleLeft: { value: 0 }, |
143 | | - uSampleWidth: { value: 1.0 }, |
| 141 | + uIntensity: { value: 1.0 } |
144 | 142 | }, |
145 | 143 | vertexShader: document.getElementById( 'vertex-postprocess' ).textContent.trim(), |
146 | 144 | fragmentShader: document.getElementById( 'fragment-postprocess' ).textContent.trim() |
|
178 | 176 | renderer.setSize( window.innerWidth, window.innerHeight ); |
179 | 177 | container.appendChild( renderer.domElement ); |
180 | 178 |
|
181 | | - renderer.domElement.addEventListener( 'mousedown', onMouseDown ); |
182 | | - |
183 | 179 | stats = new Stats(); |
184 | 180 | container.appendChild( stats.dom ); |
185 | 181 |
|
186 | 182 | window.addEventListener( 'resize', onWindowResize, false ); |
187 | 183 |
|
| 184 | + const gui = new GUI(); |
| 185 | + |
| 186 | + gui.add( params, 'intensity', 0, 1 ).step( 0.01 ).onChange( value => postProcessMaterial.uniforms.uIntensity.value = value ); |
| 187 | + gui.open(); |
| 188 | + |
188 | 189 | // width 256, height 256, depth 109, 8-bit, zip archived raw data |
189 | 190 |
|
190 | 191 | new THREE.FileLoader() |
|
222 | 223 |
|
223 | 224 | } |
224 | 225 |
|
225 | | - function onMouseDown(e) { |
226 | | - |
227 | | - renderer.domElement.addEventListener('mouseup', onMouseUp); |
228 | | - renderer.domElement.addEventListener('mousemove', onMouseMove); |
229 | | - |
230 | | - App.mousePrevious.set(e.clientX, e.clientY); |
231 | | - |
232 | | - } |
233 | | - |
234 | | - function onMouseUp() { |
235 | | - |
236 | | - renderer.domElement.removeEventListener('mousemove', onMouseMove); |
237 | | - renderer.domElement.removeEventListener('mouseup', onMouseUp); |
238 | | - |
239 | | - } |
240 | | - |
241 | | - function onMouseMove(e) { |
242 | | - |
243 | | - const x = e.clientX; |
244 | | - const y = e.clientY; |
245 | | - const deltaX = ( x - App.mousePrevious.x ) * 0.001; |
246 | | - const deltaY = ( y - App.mousePrevious.y ) * 0.001; |
247 | | - postProcessMaterial.uniforms.uSampleLeft.value += deltaX; |
248 | | - postProcessMaterial.uniforms.uSampleWidth.value += deltaY; |
249 | | - |
250 | | - App.mousePrevious.set( x, y ); |
251 | | - |
252 | | - } |
253 | | - |
254 | 226 | function onWindowResize() { |
255 | 227 |
|
256 | 228 | camera.aspect = window.innerWidth / window.innerHeight; |
|
0 commit comments