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
15 changes: 2 additions & 13 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, screenUV, velocity, context } from 'three/tsl';
import { pass, vec3, vec4, mrt, screenUV, velocity, builtinShadowContext } 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 @@ -158,18 +158,7 @@
// scene context

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

const sssContext = context( {

getShadow: ( light ) => {

if ( light === dirLight ) return sssSample;

return null;

}

} );
const sssContext = builtinShadowContext( sssSample, dirLight );

scenePass.contextNode = sssContext;

Expand Down
1 change: 1 addition & 0 deletions src/Three.TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const bufferAttribute = TSL.bufferAttribute;
export const bumpMap = TSL.bumpMap;
export const burn = TSL.burn;
export const builtin = TSL.builtin;
export const builtinShadowContext = TSL.builtinShadowContext;
export const bvec2 = TSL.bvec2;
export const bvec3 = TSL.bvec3;
export const bvec4 = TSL.bvec4;
Expand Down
31 changes: 31 additions & 0 deletions src/nodes/core/ContextNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,36 @@ export const uniformFlow = ( node ) => context( node, { uniformFlow: true } );
*/
export const setName = ( node, name ) => context( node, { nodeName: name } );

/**
* TSL function for defining a built-in shadow context for a given node.
*
* @tsl
* @function
* @param {ShadowNode} shadowNode - The shadow node representing the light's shadow.
* @param {Light} light - The light associated with the shadow.
* @param {Node} [node=null] - The node whose context should be modified.
* @returns {ContextNode}
*/
export function builtinShadowContext( shadowNode, light, node = null ) {

return context( node, {

getShadow: ( { light: shadowLight, shadowColorNode } ) => {

if ( light === shadowLight ) {

return shadowColorNode.mul( shadowNode );

}

return shadowColorNode;

}

} );

}

/**
* TSL function for defining a label context value for a given node.
*
Expand All @@ -224,3 +254,4 @@ addMethodChaining( 'context', context );
addMethodChaining( 'label', label );
addMethodChaining( 'uniformFlow', uniformFlow );
addMethodChaining( 'setName', setName );
addMethodChaining( 'builtinShadowContext', ( node, shadowNode, light ) => builtinShadowContext( shadowNode, light, node ) );
8 changes: 1 addition & 7 deletions src/nodes/lighting/AnalyticLightNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,7 @@ class AnalyticLightNode extends LightingNode {

if ( builder.context.getShadow ) {

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

if ( shadow ) {

shadowColorNode = shadowColorNode.mul( shadow );

}
shadowColorNode = builder.context.getShadow( this, builder );

}

Expand Down