Skip to content
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

RenderObject: Improve cache key computation when rendering shadows. #30316

Merged
merged 2 commits into from
Jan 14, 2025
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
2 changes: 1 addition & 1 deletion src/nodes/lighting/ShadowNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const getShadowMaterial = ( light ) => {
material = new NodeMaterial();
material.colorNode = vec4( 0, 0, 0, 1 );
material.depthNode = depthNode;
material.isShadowNodeMaterial = true; // Use to avoid other overrideMaterial override material.colorNode unintentionally when using material.shadowNode
material.isShadowPassMaterial = true; // Use to avoid other overrideMaterial override material.colorNode unintentionally when using material.shadowNode
Copy link
Collaborator Author

@Mugen87 Mugen87 Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR renames the type property to the more generic isShadowPassMaterial since isShadowNodeMaterial is reserved by ShadowNodeMaterial.

material.name = 'ShadowMaterial';
material.fog = false;

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/common/ClippingContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ClippingContext {
*/
updateGlobal( scene, camera ) {

this.shadowPass = ( scene.overrideMaterial !== null && scene.overrideMaterial.isShadowNodeMaterial );
this.shadowPass = ( scene.overrideMaterial !== null && scene.overrideMaterial.isShadowPassMaterial );
this.viewMatrix = camera.matrixWorldInverse;

this.viewNormalMatrix.getNormalMatrix( this.viewMatrix );
Expand Down
11 changes: 9 additions & 2 deletions src/renderers/common/RenderObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,16 @@ class RenderObject {
*/
getDynamicCacheKey() {

// Environment Nodes Cache Key
let cacheKey = 0;

let cacheKey = this._nodes.getCacheKey( this.scene, this.lightsNode );
// `Nodes.getCacheKey()` returns an environment cache key which is not relevant when
// the renderer is inside a shadow pass.

if ( this.material.isShadowPassMaterial !== true ) {

cacheKey = this._nodes.getCacheKey( this.scene, this.lightsNode );

}

if ( this.object.receiveShadow ) {

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2680,7 +2680,7 @@ class Renderer {
overrideMaterial.alphaMap = material.alphaMap;
overrideMaterial.transparent = material.transparent || material.transmission > 0;

if ( overrideMaterial.isShadowNodeMaterial ) {
if ( overrideMaterial.isShadowPassMaterial ) {

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

Expand Down
Loading