From cd762c4cb494abe5181797280911ad239f8f6297 Mon Sep 17 00:00:00 2001 From: Renaud Rohlinger Date: Sat, 10 Aug 2024 23:28:27 +0900 Subject: [PATCH] WebGPURenderer: Support needsUpdate on shadows --- examples/webgpu_shadowmap_opacity.html | 4 ++++ src/nodes/lighting/AnalyticLightNode.js | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/examples/webgpu_shadowmap_opacity.html b/examples/webgpu_shadowmap_opacity.html index 03c3aac663ee8b..fac456f26b27c1 100644 --- a/examples/webgpu_shadowmap_opacity.html +++ b/examples/webgpu_shadowmap_opacity.html @@ -71,6 +71,10 @@ dirLight.shadow.mapSize.height = 2048; dirLight.shadow.radius = 4; dirLight.shadow.bias = - 0.0005; + + dirLight.shadow.autoUpdate = false; + dirLight.shadow.needsUpdate = true; + scene.add( dirLight ); // diff --git a/src/nodes/lighting/AnalyticLightNode.js b/src/nodes/lighting/AnalyticLightNode.js index 1a043253b8614a..110b5084f7678e 100644 --- a/src/nodes/lighting/AnalyticLightNode.js +++ b/src/nodes/lighting/AnalyticLightNode.js @@ -267,6 +267,10 @@ class AnalyticLightNode extends LightingNode { const { shadowMap, light } = this; const { renderer, scene, camera } = frame; + + const depthVersion = shadowMap.depthTexture.version; + this._depthVersionCached = depthVersion; + const currentOverrideMaterial = scene.overrideMaterial; scene.overrideMaterial = overrideMaterial; @@ -315,7 +319,21 @@ class AnalyticLightNode extends LightingNode { updateBefore( frame ) { - this.updateShadow( frame ); + const shadow = this.light.shadow; + + const needsUpdate = shadow.needsUpdate || shadow.autoUpdate; + + if ( needsUpdate ) { + + this.updateShadow( frame ); + + if ( this.shadowMap.depthTexture.version === this._depthVersionCached ) { + + shadow.needsUpdate = false; + + } + + } }