Skip to content

Commit a5cbfc6

Browse files
authored
Examples: Improved WebGPU SSR example. (#31539)
* Examples: Improved WebGPU SSR example. * Pack metalness and roughness. * Updated screenshot. * Rename function.
1 parent 95febf4 commit a5cbfc6

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed
-290 Bytes
Loading

examples/webgpu_postprocessing_ssr.html

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<script type="module">
3333

3434
import * as THREE from 'three/webgpu';
35-
import { pass, mrt, output, normalView, metalness, blendColor, screenUV, color, sample, directionToColor, colorToDirection } from 'three/tsl';
35+
import { pass, mrt, output, normalView, metalness, roughness, blendColor, screenUV, color, sample, directionToColor, colorToDirection, vec2 } from 'three/tsl';
3636
import { ssr } from 'three/addons/tsl/display/SSRNode.js';
3737
import { smaa } from 'three/addons/tsl/display/SMAANode.js';
3838

@@ -75,6 +75,12 @@
7575

7676
if ( object.material ) {
7777

78+
if ( object.material.name === 'Lense_Casing' ) {
79+
80+
object.material.transparent = true;
81+
82+
}
83+
7884
// Avoid overdrawing
7985
object.material.side = THREE.FrontSide;
8086

@@ -113,36 +119,42 @@
113119
scenePass.setMRT( mrt( {
114120
output: output,
115121
normal: directionToColor( normalView ),
116-
metalness: metalness
122+
metalrough: vec2( metalness, roughness )
117123
} ) );
118124

119125
const scenePassColor = scenePass.getTextureNode( 'output' );
120126
const scenePassNormal = scenePass.getTextureNode( 'normal' );
121127
const scenePassDepth = scenePass.getTextureNode( 'depth' );
122-
const scenePassMetalness = scenePass.getTextureNode( 'metalness' );
128+
const scenePassMetalRough = scenePass.getTextureNode( 'metalrough' );
123129

124130
// optimization bandwidth packing the normals and reducing the texture precision if possible
125131

126-
const metalnessTexture = scenePass.getTexture( 'metalness' );
127-
metalnessTexture.type = THREE.UnsignedByteType;
128-
129132
const normalTexture = scenePass.getTexture( 'normal' );
130133
normalTexture.type = THREE.UnsignedByteType;
131134

135+
const metalRoughTexture = scenePass.getTexture( 'metalrough' );
136+
metalRoughTexture.type = THREE.UnsignedByteType;
137+
132138
const customNormal = sample( ( uv ) => {
133139

134140
return colorToDirection( scenePassNormal.sample( uv ) );
135141

136142
} );
137143

144+
const customMetalness = sample( ( uv ) => {
145+
146+
return scenePassMetalRough.sample( uv ).r;
147+
148+
} );
149+
138150
//
139151

140-
ssrPass = ssr( scenePassColor, scenePassDepth, customNormal, scenePassMetalness, camera );
152+
ssrPass = ssr( scenePassColor, scenePassDepth, customNormal, customMetalness, camera );
141153
ssrPass.resolutionScale = 1.0;
142154

143155
// blend SSR over beauty
144-
145-
const outputNode = smaa( blendColor( scenePassColor, ssrPass ) );
156+
157+
const outputNode = smaa( blendColor( scenePassColor, ssrPass.mul( scenePassMetalRough.g.oneMinus() ) ) );
146158

147159
postProcessing.outputNode = outputNode;
148160

0 commit comments

Comments
 (0)