|
38 | 38 |
|
39 | 39 | void main() |
40 | 40 | { |
41 | | - float voxel = texture( uTexture, vec3( vUv, uDepth ) ).r; |
| 41 | + float voxel = texture(uTexture, vec3( vUv, uDepth )).r; |
42 | 42 | gl_FragColor.r = (voxel - uSampleLeft) / uSampleWidth; |
43 | 43 | } |
44 | 44 |
|
|
75 | 75 |
|
76 | 76 | // lighten a bit |
77 | 77 | gl_FragColor = vec4( color.rrr * 1.5, 1.0 ); |
78 | | - |
79 | 78 | } |
80 | 79 | </script> |
81 | 80 | <body> |
|
103 | 102 | import * as THREE from '../build/three.module.js'; |
104 | 103 |
|
105 | 104 | import Stats from './jsm/libs/stats.module.js'; |
106 | | - import { JSZip } from './jsm/libs/jszip.module.min.js'; |
| 105 | + import { unzipSync } from './jsm/libs/fflate.module.min.js'; |
107 | 106 |
|
108 | 107 | import { WEBGL } from './jsm/WebGL.js'; |
109 | 108 |
|
|
126 | 125 | /** Post-processing objects */ |
127 | 126 |
|
128 | 127 | const postProcessScene = new THREE.Scene(); |
129 | | - const postProcessCamera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 ); |
| 128 | + const postProcessCamera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 ); |
130 | 129 |
|
131 | 130 | const renderTargetTexture = new THREE.DataTexture2DArray(); |
132 | 131 | renderTargetTexture.format = THREE.RedFormat; |
|
192 | 191 | .setResponseType( 'arraybuffer' ) |
193 | 192 | .load( 'textures/3d/head256x256x109.zip', function ( data ) { |
194 | 193 |
|
195 | | - var zip = new JSZip( data ); |
196 | | - var array = zip.files[ 'head256x256x109' ].asUint8Array(); |
| 194 | + var zip = unzipSync( new Uint8Array( data ) ); |
| 195 | + const array = new Uint8Array( zip[ 'head256x256x109' ].buffer ); |
197 | 196 |
|
198 | 197 | const texture = new THREE.DataTexture2DArray( array, DIMENSIONS.width, DIMENSIONS.height, DIMENSIONS.depth ); |
199 | 198 | texture.format = THREE.RedFormat; |
|
248 | 247 | postProcessMaterial.uniforms.uSampleLeft.value += deltaX; |
249 | 248 | postProcessMaterial.uniforms.uSampleWidth.value += deltaY; |
250 | 249 |
|
251 | | - App.mousePrevious.set(x, y); |
| 250 | + App.mousePrevious.set( x, y ); |
252 | 251 |
|
253 | 252 | } |
254 | 253 |
|
|
265 | 264 |
|
266 | 265 | requestAnimationFrame( animate ); |
267 | 266 |
|
268 | | - var value = mesh.material.uniforms[ "depth" ].value; |
| 267 | + var value = mesh.material.uniforms[ 'depth' ].value; |
269 | 268 |
|
270 | 269 | value += depthStep; |
271 | 270 |
|
|
278 | 277 |
|
279 | 278 | } |
280 | 279 |
|
281 | | - mesh.material.uniforms[ "depth" ].value = value; |
| 280 | + mesh.material.uniforms[ 'depth' ].value = value; |
282 | 281 |
|
283 | 282 | render(); |
284 | 283 |
|
285 | 284 | } |
286 | 285 |
|
| 286 | + /** |
| 287 | + * Renders the 2D array into the render target `renderTarget`. |
| 288 | + */ |
287 | 289 | function renderTo2DArray() { |
288 | 290 |
|
289 | | - const layer = Math.floor( mesh.material.uniforms[ "depth" ].value ); |
| 291 | + const layer = Math.floor( mesh.material.uniforms[ 'depth' ].value ); |
290 | 292 | postProcessMaterial.uniforms.uDepth.value = layer; |
291 | 293 | renderer.setRenderTarget( renderTarget, layer ); |
292 | 294 | renderer.render( postProcessScene, postProcessCamera ); |
|
296 | 298 |
|
297 | 299 | function render() { |
298 | 300 |
|
| 301 | + // Step 1 - Render the input DataTexture2DArray into a |
| 302 | + // DataTexture2DArray render target. |
299 | 303 | renderTo2DArray(); |
| 304 | + |
| 305 | + // Step 2 - Renders the scene containing the plane with a material |
| 306 | + // sampling the render target texture. |
300 | 307 | renderer.render( scene, camera ); |
301 | 308 |
|
302 | 309 | } |
|
0 commit comments