Skip to content

Commit 0434326

Browse files
authored
RenderObject: Improve cache key computation when rendering shadows. (#30316)
* RenderObject: Improve cache key computation when rendering shadows. * ShadowNode: Fix material type conflict.
1 parent 2cf6a5b commit 0434326

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/nodes/lighting/ShadowNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const getShadowMaterial = ( light ) => {
5656
material = new NodeMaterial();
5757
material.colorNode = vec4( 0, 0, 0, 1 );
5858
material.depthNode = depthNode;
59-
material.isShadowNodeMaterial = true; // Use to avoid other overrideMaterial override material.colorNode unintentionally when using material.shadowNode
59+
material.isShadowPassMaterial = true; // Use to avoid other overrideMaterial override material.colorNode unintentionally when using material.shadowNode
6060
material.name = 'ShadowMaterial';
6161
material.fog = false;
6262

src/renderers/common/ClippingContext.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class ClippingContext {
136136
*/
137137
updateGlobal( scene, camera ) {
138138

139-
this.shadowPass = ( scene.overrideMaterial !== null && scene.overrideMaterial.isShadowNodeMaterial );
139+
this.shadowPass = ( scene.overrideMaterial !== null && scene.overrideMaterial.isShadowPassMaterial );
140140
this.viewMatrix = camera.matrixWorldInverse;
141141

142142
this.viewNormalMatrix.getNormalMatrix( this.viewMatrix );

src/renderers/common/RenderObject.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,16 @@ class RenderObject {
739739
*/
740740
getDynamicCacheKey() {
741741

742-
// Environment Nodes Cache Key
742+
let cacheKey = 0;
743743

744-
let cacheKey = this._nodes.getCacheKey( this.scene, this.lightsNode );
744+
// `Nodes.getCacheKey()` returns an environment cache key which is not relevant when
745+
// the renderer is inside a shadow pass.
746+
747+
if ( this.material.isShadowPassMaterial !== true ) {
748+
749+
cacheKey = this._nodes.getCacheKey( this.scene, this.lightsNode );
750+
751+
}
745752

746753
if ( this.object.receiveShadow ) {
747754

src/renderers/common/Renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2680,7 +2680,7 @@ class Renderer {
26802680
overrideMaterial.alphaMap = material.alphaMap;
26812681
overrideMaterial.transparent = material.transparent || material.transmission > 0;
26822682

2683-
if ( overrideMaterial.isShadowNodeMaterial ) {
2683+
if ( overrideMaterial.isShadowPassMaterial ) {
26842684

26852685
overrideMaterial.side = material.shadowSide === null ? material.side : material.shadowSide;
26862686

0 commit comments

Comments
 (0)