Skip to content

Commit 6d979a4

Browse files
authored
Merge pull request #21243 from DavidPeicho/feature/layered-framebuffer
Remove JSZip from example 'webgl2_rendertarget_texture2darray'
2 parents ddc530d + 2a851ff commit 6d979a4

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

examples/webgl2_rendertarget_texture2darray.html

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
void main()
4040
{
41-
float voxel = texture( uTexture, vec3( vUv, uDepth ) ).r;
41+
float voxel = texture(uTexture, vec3( vUv, uDepth )).r;
4242
gl_FragColor.r = (voxel - uSampleLeft) / uSampleWidth;
4343
}
4444

@@ -75,7 +75,6 @@
7575

7676
// lighten a bit
7777
gl_FragColor = vec4( color.rrr * 1.5, 1.0 );
78-
7978
}
8079
</script>
8180
<body>
@@ -103,7 +102,7 @@
103102
import * as THREE from '../build/three.module.js';
104103

105104
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';
107106

108107
import { WEBGL } from './jsm/WebGL.js';
109108

@@ -126,7 +125,7 @@
126125
/** Post-processing objects */
127126

128127
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 );
130129

131130
const renderTargetTexture = new THREE.DataTexture2DArray();
132131
renderTargetTexture.format = THREE.RedFormat;
@@ -192,8 +191,8 @@
192191
.setResponseType( 'arraybuffer' )
193192
.load( 'textures/3d/head256x256x109.zip', function ( data ) {
194193

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 );
197196

198197
const texture = new THREE.DataTexture2DArray( array, DIMENSIONS.width, DIMENSIONS.height, DIMENSIONS.depth );
199198
texture.format = THREE.RedFormat;
@@ -248,7 +247,7 @@
248247
postProcessMaterial.uniforms.uSampleLeft.value += deltaX;
249248
postProcessMaterial.uniforms.uSampleWidth.value += deltaY;
250249

251-
App.mousePrevious.set(x, y);
250+
App.mousePrevious.set( x, y );
252251

253252
}
254253

@@ -265,7 +264,7 @@
265264

266265
requestAnimationFrame( animate );
267266

268-
var value = mesh.material.uniforms[ "depth" ].value;
267+
var value = mesh.material.uniforms[ 'depth' ].value;
269268

270269
value += depthStep;
271270

@@ -278,15 +277,18 @@
278277

279278
}
280279

281-
mesh.material.uniforms[ "depth" ].value = value;
280+
mesh.material.uniforms[ 'depth' ].value = value;
282281

283282
render();
284283

285284
}
286285

286+
/**
287+
* Renders the 2D array into the render target `renderTarget`.
288+
*/
287289
function renderTo2DArray() {
288290

289-
const layer = Math.floor( mesh.material.uniforms[ "depth" ].value );
291+
const layer = Math.floor( mesh.material.uniforms[ 'depth' ].value );
290292
postProcessMaterial.uniforms.uDepth.value = layer;
291293
renderer.setRenderTarget( renderTarget, layer );
292294
renderer.render( postProcessScene, postProcessCamera );
@@ -296,7 +298,12 @@
296298

297299
function render() {
298300

301+
// Step 1 - Render the input DataTexture2DArray into a
302+
// DataTexture2DArray render target.
299303
renderTo2DArray();
304+
305+
// Step 2 - Renders the scene containing the plane with a material
306+
// sampling the render target texture.
300307
renderer.render( scene, camera );
301308

302309
}

0 commit comments

Comments
 (0)