Skip to content

Commit e9bdf76

Browse files
authored
Examples: Simplify webgl2_rendertarget_texture2darray. (#21520)
1 parent 8bb4b0a commit e9bdf76

File tree

1 file changed

+12
-40
lines changed

1 file changed

+12
-40
lines changed

examples/webgl2_rendertarget_texture2darray.html

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@
3333

3434
uniform sampler2DArray uTexture;
3535
uniform int uDepth;
36-
uniform float uSampleLeft;
37-
uniform float uSampleWidth;
36+
uniform float uIntensity;
3837

3938
void main()
4039
{
4140
float voxel = texture(uTexture, vec3( vUv, uDepth )).r;
42-
gl_FragColor.r = (voxel - uSampleLeft) / uSampleWidth;
41+
gl_FragColor.r = voxel * uIntensity;
4342
}
4443

4544
</script>
@@ -87,8 +86,7 @@
8786

8887
<p>
8988
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.
9290
</p>
9391

9492
Scanned head data by
@@ -103,6 +101,7 @@
103101

104102
import Stats from './jsm/libs/stats.module.js';
105103
import { unzipSync } from './jsm/libs/fflate.module.min.js';
104+
import { GUI } from './jsm/libs/dat.gui.module.js';
106105

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

@@ -118,8 +117,8 @@
118117
depth: 109
119118
};
120119

121-
const App = {
122-
mousePrevious: new THREE.Vector2()
120+
const params = {
121+
intensity: 1
123122
};
124123

125124
/** Post-processing objects */
@@ -139,8 +138,7 @@
139138
uniforms: {
140139
uTexture: { value: null },
141140
uDepth: { value: 55 },
142-
uSampleLeft: { value: 0 },
143-
uSampleWidth: { value: 1.0 },
141+
uIntensity: { value: 1.0 }
144142
},
145143
vertexShader: document.getElementById( 'vertex-postprocess' ).textContent.trim(),
146144
fragmentShader: document.getElementById( 'fragment-postprocess' ).textContent.trim()
@@ -178,13 +176,16 @@
178176
renderer.setSize( window.innerWidth, window.innerHeight );
179177
container.appendChild( renderer.domElement );
180178

181-
renderer.domElement.addEventListener( 'mousedown', onMouseDown );
182-
183179
stats = new Stats();
184180
container.appendChild( stats.dom );
185181

186182
window.addEventListener( 'resize', onWindowResize, false );
187183

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+
188189
// width 256, height 256, depth 109, 8-bit, zip archived raw data
189190

190191
new THREE.FileLoader()
@@ -222,35 +223,6 @@
222223

223224
}
224225

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-
254226
function onWindowResize() {
255227

256228
camera.aspect = window.innerWidth / window.innerHeight;

0 commit comments

Comments
 (0)