Skip to content

Commit daa858f

Browse files
authored
WebGPURenderer: Introduce shadowMap.color (mrdoob#32596)
1 parent ecf6e9c commit daa858f

5 files changed

Lines changed: 47 additions & 14 deletions

File tree

examples/webgpu_caustics.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
renderer.setSize( window.innerWidth, window.innerHeight );
180180
renderer.setAnimationLoop( animate );
181181
renderer.shadowMap.enabled = true;
182+
renderer.shadowMap.color = true;
182183
renderer.inspector = new Inspector();
183184
document.body.appendChild( renderer.domElement );
184185

examples/webgpu_shadowmap_opacity.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
renderer.toneMapping = THREE.AgXToneMapping;
6060
renderer.toneMappingExposure = 1.5;
6161
renderer.shadowMap.enabled = true;
62+
renderer.shadowMap.color = true;
6263
renderer.inspector = new Inspector();
6364
container.appendChild( renderer.domElement );
6465

examples/webgpu_volume_caustics.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165

166166
renderer = new THREE.WebGPURenderer( { antialias: true } );
167167
renderer.shadowMap.enabled = true;
168+
renderer.shadowMap.color = true;
168169
renderer.inspector = new Inspector();
169170
renderer.setPixelRatio( window.devicePixelRatio );
170171
renderer.setSize( window.innerWidth, window.innerHeight );

src/nodes/lighting/ShadowNode.js

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -518,24 +518,40 @@ class ShadowNode extends ShadowBaseNode {
518518

519519
let shadowColor;
520520

521-
if ( shadowMap.texture.isCubeTexture ) {
521+
if ( renderer.shadowMap.color === true ) {
522522

523-
// For cube shadow maps (point lights), use cubeTexture with vec3 coordinates
524-
shadowColor = cubeTexture( shadowMap.texture, shadowCoord.xyz );
523+
if ( shadowMap.texture.isCubeTexture ) {
525524

526-
} else {
525+
// For cube shadow maps (point lights), use cubeTexture with vec3 coordinates
526+
shadowColor = cubeTexture( shadowMap.texture, shadowCoord.xyz );
527527

528-
shadowColor = texture( shadowMap.texture, shadowCoord );
528+
} else {
529529

530-
if ( depthTexture.isArrayTexture ) {
530+
shadowColor = texture( shadowMap.texture, shadowCoord );
531531

532-
shadowColor = shadowColor.depth( this.depthLayer );
532+
if ( depthTexture.isArrayTexture ) {
533+
534+
shadowColor = shadowColor.depth( this.depthLayer );
535+
536+
}
533537

534538
}
535539

536540
}
537541

538-
const shadowOutput = mix( 1, shadowNode.rgb.mix( shadowColor, 1 ), shadowIntensity.mul( shadowColor.a ) ).toVar();
542+
//
543+
544+
let shadowOutput;
545+
546+
if ( shadowColor ) {
547+
548+
shadowOutput = mix( 1, shadowNode.rgb.mix( shadowColor, 1 ), shadowIntensity.mul( shadowColor.a ) ).toVar();
549+
550+
} else {
551+
552+
shadowOutput = mix( 1, shadowNode, shadowIntensity ).toVar();
553+
554+
}
539555

540556
this.shadowMap = shadowMap;
541557
this.shadow.map = shadowMap;
@@ -544,17 +560,23 @@ class ShadowNode extends ShadowBaseNode {
544560

545561
const inspectName = `${ this.light.type } Shadow [ ${ this.light.name || 'ID: ' + this.light.id } ]`;
546562

547-
return shadowOutput.toInspector( `${ inspectName } / Color`, () => {
563+
if ( shadowColor ) {
548564

549-
if ( this.shadowMap.texture.isCubeTexture ) {
565+
shadowOutput.toInspector( `${ inspectName } / Color`, () => {
550566

551-
return cubeTexture( this.shadowMap.texture );
567+
if ( this.shadowMap.texture.isCubeTexture ) {
552568

553-
}
569+
return cubeTexture( this.shadowMap.texture );
554570

555-
return texture( this.shadowMap.texture );
571+
}
572+
573+
return texture( this.shadowMap.texture );
574+
575+
} );
576+
577+
}
556578

557-
} ).toInspector( `${ inspectName } / Depth`, () => {
579+
return shadowOutput.toInspector( `${ inspectName } / Depth`, () => {
558580

559581
// TODO: Use linear depth
560582

src/renderers/common/Renderer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ class Renderer {
658658
* Shadow map configuration
659659
* @typedef {Object} ShadowMapConfig
660660
* @property {boolean} enabled - Whether to globally enable shadows or not.
661+
* @property {boolean} color - Whether to include shadow color or not.
661662
* @property {number} type - The shadow map type.
662663
*/
663664

@@ -668,6 +669,7 @@ class Renderer {
668669
*/
669670
this.shadowMap = {
670671
enabled: false,
672+
color: false,
671673
type: PCFShadowMap
672674
};
673675

@@ -3051,6 +3053,12 @@ class Renderer {
30513053
shadowRGB = material.castShadowNode.rgb;
30523054
shadowAlpha = material.castShadowNode.a;
30533055

3056+
if ( this.shadowMap.color !== true ) {
3057+
3058+
warnOnce( 'Renderer: `shadowMap.color` needs to be enabled when using `material.castShadowNode`.' );
3059+
3060+
}
3061+
30543062
} else {
30553063

30563064
shadowRGB = vec3( 0 );

0 commit comments

Comments
 (0)