Skip to content
Merged
Show file tree
Hide file tree
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
Binary file modified examples/screenshots/webgpu_postprocessing_ssr.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 21 additions & 9 deletions examples/webgpu_postprocessing_ssr.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<script type="module">

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

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

if ( object.material ) {

if ( object.material.name === 'Lense_Casing' ) {
Copy link
Collaborator

@Mugen87 Mugen87 Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe reverting this addition due to #31539 (comment)?

Yes, the previous look was also not physically correct but the missing objects when looking through the lens makes the scene look broken^^.


object.material.transparent = true;

}

// Avoid overdrawing
object.material.side = THREE.FrontSide;

Expand Down Expand Up @@ -113,36 +119,42 @@
scenePass.setMRT( mrt( {
output: output,
normal: directionToColor( normalView ),
metalness: metalness
metalrough: vec2( metalness, roughness )
} ) );

const scenePassColor = scenePass.getTextureNode( 'output' );
const scenePassNormal = scenePass.getTextureNode( 'normal' );
const scenePassDepth = scenePass.getTextureNode( 'depth' );
const scenePassMetalness = scenePass.getTextureNode( 'metalness' );
const scenePassMetalRough = scenePass.getTextureNode( 'metalrough' );

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

const metalnessTexture = scenePass.getTexture( 'metalness' );
metalnessTexture.type = THREE.UnsignedByteType;

const normalTexture = scenePass.getTexture( 'normal' );
normalTexture.type = THREE.UnsignedByteType;

const metalRoughTexture = scenePass.getTexture( 'metalrough' );
metalRoughTexture.type = THREE.UnsignedByteType;

const customNormal = sample( ( uv ) => {

return colorToDirection( scenePassNormal.sample( uv ) );

} );

const customMetalness = sample( ( uv ) => {

return scenePassMetalRough.sample( uv ).r;

} );

//

ssrPass = ssr( scenePassColor, scenePassDepth, customNormal, scenePassMetalness, camera );
ssrPass = ssr( scenePassColor, scenePassDepth, customNormal, customMetalness, camera );
ssrPass.resolutionScale = 1.0;

// blend SSR over beauty
const outputNode = smaa( blendColor( scenePassColor, ssrPass ) );

const outputNode = smaa( blendColor( scenePassColor, ssrPass.mul( scenePassMetalRough.g.oneMinus() ) ) );

postProcessing.outputNode = outputNode;

Expand Down