Skip to content

Commit 1d4d2a7

Browse files
authored
Examples: Clean up. (#31887)
* Examples: Clean up. * Update E2E screenshot.
1 parent 41e733f commit 1d4d2a7

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed
-2.8 KB
Loading

examples/webgpu_postprocessing_ssgi.html

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<script type="module">
2929

3030
import * as THREE from 'three/webgpu';
31-
import { pass, mrt, output, normalView, diffuseColor, velocity, add, vec3, vec4 } from 'three/tsl';
31+
import { pass, mrt, output, normalView, diffuseColor, velocity, add, vec3, vec4, directionToColor, colorToDirection, sample } from 'three/tsl';
3232
import { ssgi } from 'three/addons/tsl/display/SSGINode.js';
3333
import { traa } from 'three/addons/tsl/display/TRAANode.js';
3434

@@ -79,7 +79,7 @@
7979
scenePass.setMRT( mrt( {
8080
output: output,
8181
diffuseColor: diffuseColor,
82-
normal: normalView,
82+
normal: directionToColor( normalView ),
8383
velocity: velocity
8484
} ) );
8585

@@ -89,9 +89,23 @@
8989
const scenePassNormal = scenePass.getTextureNode( 'normal' );
9090
const scenePassVelocity = scenePass.getTextureNode( 'velocity' );
9191

92+
// bandwidth optimization
93+
94+
const diffuseTexture = scenePass.getTexture( 'diffuseColor' );
95+
diffuseTexture.type = THREE.UnsignedByteType;
96+
97+
const normalTexture = scenePass.getTexture( 'normal' );
98+
normalTexture.type = THREE.UnsignedByteType;
99+
100+
const sceneNormal = sample( ( uv ) => {
101+
102+
return colorToDirection( scenePassNormal.sample( uv ) );
103+
104+
} );
105+
92106
// gi
93107

94-
const giPass = ssgi( scenePassColor, scenePassDepth, scenePassNormal, camera );
108+
const giPass = ssgi( scenePassColor, scenePassDepth, sceneNormal, camera );
95109
giPass.sliceCount.value = 2;
96110
giPass.stepCount.value = 8;
97111

@@ -100,7 +114,7 @@
100114
const gi = giPass.rgb;
101115
const ao = giPass.a;
102116

103-
const compositePass = vec4( add ( scenePassColor.rgb.mul( ao ), ( scenePassDiffuse.rgb.mul( gi ) ) ), scenePassColor.a );
117+
const compositePass = vec4( add( scenePassColor.rgb.mul( ao ), ( scenePassDiffuse.rgb.mul( gi ) ) ), scenePassColor.a );
104118

105119
// traa
106120

@@ -133,9 +147,21 @@
133147

134148
const gui = new GUI();
135149
gui.title( 'SSGI settings' );
136-
let outputDropdown = gui.add( params, 'output', types );
137-
outputDropdown.onChange( value => {
138-
150+
gui.add( params, 'output', types ).onChange( updatePostprocessing );
151+
gui.add( giPass.sliceCount, 'value', 1, 4 ).step( 1 ).name( 'slice count' );
152+
gui.add( giPass.stepCount, 'value', 1, 32 ).step( 1 ).name( 'step count' );
153+
gui.add( giPass.radius, 'value', 1, 25 ).name( 'radius' );
154+
gui.add( giPass.expFactor, 'value', 1, 3 ).name( 'exp factor' );
155+
gui.add( giPass.thickness, 'value', 0.01, 10 ).name( 'thickness' );
156+
gui.add( giPass.backfaceLighting, 'value', 0, 1 ).name( 'backface lighting' );
157+
gui.add( giPass.aoIntensity, 'value', 0, 4 ).name( 'AO intenstiy' );
158+
gui.add( giPass.giIntensity, 'value', 0, 100 ).name( 'GI intenstiy' );
159+
gui.add( giPass.useLinearThickness, 'value' ).name( 'use linear thickness' );
160+
gui.add( giPass.useScreenSpaceSampling, 'value' ).name( 'screen-space sampling' );
161+
gui.add( giPass, 'useTemporalFiltering' ).name( 'temporal filtering' ).onChange( updatePostprocessing );
162+
163+
function updatePostprocessing( value ) {
164+
139165
if ( value === 1 ) {
140166

141167
postProcessing.outputNode = vec4( vec3( ao ), 1 );
@@ -156,18 +182,10 @@
156182

157183
postProcessing.needsUpdate = true;
158184

159-
} );
160-
gui.add( giPass.sliceCount, 'value', 1, 4 ).step( 1 ).name( 'slice count' );
161-
gui.add( giPass.stepCount, 'value', 1, 32 ).step( 1 ).name( 'step count' );
162-
gui.add( giPass.radius, 'value', 1, 25 ).name( 'radius' );
163-
gui.add( giPass.expFactor, 'value', 1, 3 ).name( 'exp factor' );
164-
gui.add( giPass.thickness, 'value', 0.01, 10 ).name( 'thickness' );
165-
gui.add( giPass.backfaceLighting, 'value', 0, 1 ).name( 'backface lighting' );
166-
gui.add( giPass.aoIntensity, 'value', 0, 4 ).name( 'AO intenstiy' );
167-
gui.add( giPass.giIntensity, 'value', 0, 100 ).name( 'GI intenstiy' );
168-
gui.add( giPass.useLinearThickness, 'value' ).name( 'use linear thickness' );
169-
gui.add( giPass.useScreenSpaceSampling, 'value' ).name( 'screen-space sampling' );
170-
gui.add( giPass, 'useTemporalFiltering' ).name( 'temporal filtering' ).onChange( outputDropdown._onChange );
185+
186+
}
187+
188+
171189
}
172190

173191
function onWindowResize() {

0 commit comments

Comments
 (0)