Просмотр исходного кода

WebGPURenderer: Support needsUpdate on shadows (#29110)

Renaud Rohlinger 1 год назад
Родитель
Сommit
350d1c5777
2 измененных файлов с 23 добавлено и 1 удалено
  1. 4 0
      examples/webgpu_shadowmap_opacity.html
  2. 19 1
      src/nodes/lighting/AnalyticLightNode.js

+ 4 - 0
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 );
 
 				//

+ 19 - 1
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;
+
+			}
+
+		}
 
 	}
 

粤ICP备19079148号