Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions examples/webgl2_rendertarget_texture2darray.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

void main()
{
float voxel = texture( uTexture, vec3( vUv, uDepth ) ).r;
float voxel = texture(uTexture, vec3( vUv, uDepth )).r;
gl_FragColor.r = (voxel - uSampleLeft) / uSampleWidth;
}

Expand Down Expand Up @@ -75,7 +75,6 @@

// lighten a bit
gl_FragColor = vec4( color.rrr * 1.5, 1.0 );

}
</script>
<body>
Expand Down Expand Up @@ -103,7 +102,7 @@
import * as THREE from '../build/three.module.js';

import Stats from './jsm/libs/stats.module.js';
import { JSZip } from './jsm/libs/jszip.module.min.js';
import { unzipSync } from './jsm/libs/fflate.module.min.js';

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

Expand All @@ -126,7 +125,7 @@
/** Post-processing objects */

const postProcessScene = new THREE.Scene();
const postProcessCamera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
const postProcessCamera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );

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

var zip = new JSZip( data );
var array = zip.files[ 'head256x256x109' ].asUint8Array();
var zip = unzipSync( new Uint8Array( data ) );
const array = new Uint8Array( zip[ 'head256x256x109' ].buffer );

const texture = new THREE.DataTexture2DArray( array, DIMENSIONS.width, DIMENSIONS.height, DIMENSIONS.depth );
texture.format = THREE.RedFormat;
Expand Down Expand Up @@ -248,7 +247,7 @@
postProcessMaterial.uniforms.uSampleLeft.value += deltaX;
postProcessMaterial.uniforms.uSampleWidth.value += deltaY;

App.mousePrevious.set(x, y);
App.mousePrevious.set( x, y );

}

Expand All @@ -265,7 +264,7 @@

requestAnimationFrame( animate );

var value = mesh.material.uniforms[ "depth" ].value;
var value = mesh.material.uniforms[ 'depth' ].value;

value += depthStep;

Expand All @@ -278,15 +277,18 @@

}

mesh.material.uniforms[ "depth" ].value = value;
mesh.material.uniforms[ 'depth' ].value = value;

render();

}

/**
* Renders the 2D array into the render target `renderTarget`.
*/
function renderTo2DArray() {

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

function render() {

// Step 1 - Render the input DataTexture2DArray into a
// DataTexture2DArray render target.
renderTo2DArray();

// Step 2 - Renders the scene containing the plane with a material
// sampling the render target texture.
renderer.render( scene, camera );

}
Expand Down