-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Examples: Update webgpu_postprocessing_sss using pre-pass
#32345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
98d720b
f6daf1a
c27b5da
cea08d3
5f1b881
8750224
e683710
beded1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,7 @@ | |
| <script type="module"> | ||
|
|
||
| import * as THREE from 'three/webgpu'; | ||
| import { pass, vec3, vec4, mrt, output, velocity } from 'three/tsl'; | ||
| import { pass, vec3, vec4, mrt, screenUV, velocity, context } from 'three/tsl'; | ||
| import { sss } from 'three/addons/tsl/display/SSSNode.js'; | ||
| import { traa } from 'three/addons/tsl/display/TRAANode.js'; | ||
|
|
||
|
|
@@ -128,33 +128,60 @@ | |
| renderer.inspector = new Inspector(); | ||
| document.body.appendChild( renderer.domElement ); | ||
|
|
||
| // post-processing | ||
|
|
||
| postProcessing = new THREE.PostProcessing( renderer ); | ||
|
|
||
| const scenePass = pass( scene, camera ); | ||
| scenePass.setMRT( mrt( { | ||
| output: output, | ||
| velocity: velocity | ||
| // pre-pass | ||
|
|
||
| const prePass = pass( scene, camera ); | ||
| prePass.name = 'Pre-Pass'; | ||
| prePass.transparent = false; | ||
|
|
||
| prePass.setMRT( mrt( { | ||
| output: velocity | ||
| } ) ); | ||
|
|
||
| const scenePassColor = scenePass.getTextureNode( 'output' ); | ||
| const scenePassVelocity = scenePass.getTextureNode( 'velocity' ); | ||
| const scenePassDepth = scenePass.getTextureNode( 'depth' ); | ||
| const prePassDepth = prePass.getTextureNode( 'depth' ).toInspector( 'Depth', () => prePass.getLinearDepthNode() ); | ||
| const prePassVelocity = prePass.getTextureNode( 'output' ).toInspector( 'Velocity' ); | ||
|
|
||
| // pre-pass - bandwidth optimization | ||
|
|
||
| const normalTexture = prePass.getTexture( 'output' ); | ||
| normalTexture.type = THREE.UnsignedByteType; | ||
|
|
||
| // scene pass | ||
|
|
||
| const scenePass = pass( scene, camera ).toInspector( 'Color' ); | ||
|
|
||
| // sss | ||
|
|
||
| const sssPass = sss( scenePassDepth, camera, dirLight ); | ||
| sssPass.shadowIntensity.value = 0.3; | ||
| const sssPass = sss( prePassDepth, camera, dirLight ); | ||
| sssPass.shadowIntensity.value = 1; | ||
| sssPass.maxDistance.value = 0.2; | ||
| sssPass.useTemporalFiltering = true; | ||
|
|
||
| // composite | ||
| // scene context | ||
|
|
||
| const sssSample = sssPass.getTextureNode().sample( screenUV ).r; | ||
|
|
||
| const sssContext = context( { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the future, do you think we could simplify this bit somehow? Maybe: scenePass.contextNode = context( {
sss: sssPass.getTextureNode().sample( screenUV ).r
} );The instance of
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I still have to think of a way to simplify this utilization. |
||
|
|
||
| getSSS: ( light ) => { | ||
|
|
||
| if ( light === dirLight ) return sssSample; | ||
|
|
||
| return null; | ||
|
|
||
| } | ||
|
|
||
| } ); | ||
|
|
||
| scenePass.contextNode = sssContext; | ||
|
|
||
| const compositePass = vec4( scenePassColor.rgb.mul( sssPass.r ), scenePassColor.a ); | ||
| compositePass.name = 'Composite'; | ||
|
|
||
| // traa | ||
|
|
||
| const traaPass = traa( compositePass, scenePassDepth, scenePassVelocity, camera ); | ||
| const traaPass = traa( scenePass, prePassDepth, prePassVelocity, camera ); | ||
| postProcessing.outputNode = traaPass; | ||
|
|
||
| // | ||
|
|
@@ -184,17 +211,15 @@ | |
|
|
||
| function updatePostprocessing() { | ||
|
|
||
| if ( params.output === 1 ) { | ||
|
|
||
| postProcessing.outputNode = scenePassColor; | ||
| scenePass.contextNode = params.output !== 1 ? sssContext : null; | ||
|
|
||
| } else if ( params.output === 2 ) { | ||
| if ( params.output === 2 ) { | ||
|
|
||
| postProcessing.outputNode = vec4( vec3( sssPass.r ), 1 ); | ||
|
|
||
| } else { | ||
|
|
||
| postProcessing.outputNode = sssPass.useTemporalFiltering ? traaPass : compositePass; | ||
| postProcessing.outputNode = sssPass.useTemporalFiltering ? traaPass : scenePass; | ||
|
|
||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.