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
4 changes: 2 additions & 2 deletions examples/jsm/tsl/display/SSSNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class SSSNode extends TempNode {
* Shadow intensity. Must be in the range `[0, 1]`.
*
* @type {UniformNode<float>}
* @default 0.5
* @default 1.0
*/
this.shadowIntensity = uniform( 0.5, 'float' );
this.shadowIntensity = uniform( 1.0, 'float' );

/**
* This parameter controls how detailed the raymarching process works.
Expand Down
59 changes: 39 additions & 20 deletions examples/webgpu_postprocessing_sss.html
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -128,33 +128,54 @@
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' );

// 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.maxDistance.value = 0.2;
sssPass.useTemporalFiltering = true;

// composite
// scene context

const sssSample = sssPass.getTextureNode().sample( screenUV ).r;

const sssContext = context( {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 SSSNode has a reference to the directional main light so maybe you could hide some of this code in AnalyticLightNode.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.


getShadow: ( 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;

//
Expand Down Expand Up @@ -184,17 +205,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;

}

Expand Down
2 changes: 1 addition & 1 deletion src/materials/nodes/manager/NodeMaterialObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class NodeMaterialObserver {

}

if ( builder.context.modelViewMatrix || builder.context.modelNormalViewMatrix || builder.context.ao )
if ( builder.context.modelViewMatrix || builder.context.modelNormalViewMatrix || builder.context.ao || builder.context.getShadow )
return true;

return false;
Expand Down
12 changes: 12 additions & 0 deletions src/nodes/lighting/AnalyticLightNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ class AnalyticLightNode extends LightingNode {

//

if ( builder.context.getShadow ) {

const shadow = builder.context.getShadow( this.light, builder );

if ( shadow ) {

shadowColorNode = shadowColorNode.mul( shadow );

}

}

this.colorNode = shadowColorNode;

}
Expand Down