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

WebGPURenderer: Enable dynamic shadowMap type switching. (#32105)

* Add shadowMap type to cache key values

* TSL: recreate shadowmap resources if its type is changed

* Update ShadowNode.js

Clean up.

* Update ShadowNode.js

Simplify check.

---------

Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
Kirill Osipov 2 месяцев назад
Родитель
Сommit
d043955c6f
2 измененных файлов с 48 добавлено и 4 удалено
  1. 47 4
      src/nodes/lighting/ShadowNode.js
  2. 1 0
      src/renderers/common/nodes/Nodes.js

+ 47 - 4
src/nodes/lighting/ShadowNode.js

@@ -273,6 +273,22 @@ class ShadowNode extends ShadowBaseNode {
 		 */
 		this._node = null;
 
+		/**
+		 * The current shadow map type of this shadow node.
+		 *
+		 * @type {?number}
+		 * @private
+		 * @default null
+		 */
+		this._currentShadowType = null;
+
+		/**
+		 * A Weak Map holding the current frame ID per camera. Used
+		 * to control the update of shadow maps.
+		 *
+		 * @type {WeakMap<Camera,number>}
+		 * @private
+		 */
 		this._cameraFrameId = new WeakMap();
 
 		/**
@@ -549,6 +565,15 @@ class ShadowNode extends ShadowBaseNode {
 
 		return Fn( () => {
 
+			const currentShadowType = builder.renderer.shadowMap.type;
+
+			if ( this._currentShadowType !== currentShadowType ) {
+
+				this._reset();
+				this._node = null;
+
+			}
+
 			let node = this._node;
 
 			this.setupShadowPosition( builder );
@@ -556,6 +581,7 @@ class ShadowNode extends ShadowBaseNode {
 			if ( node === null ) {
 
 				this._node = node = this.setupShadow( builder );
+				this._currentShadowType = currentShadowType;
 
 			}
 
@@ -688,8 +714,27 @@ class ShadowNode extends ShadowBaseNode {
 	 */
 	dispose() {
 
-		this.shadowMap.dispose();
-		this.shadowMap = null;
+		this._reset();
+
+		super.dispose();
+
+	}
+
+	/**
+	 * Resets the resouce state of this shadow node.
+	 *
+	 * @private
+	 */
+	_reset() {
+
+		this._currentShadowType = null;
+
+		if ( this.shadowMap ) {
+
+			this.shadowMap.dispose();
+			this.shadowMap = null;
+
+		}
 
 		if ( this.vsmShadowMapVertical !== null ) {
 
@@ -711,8 +756,6 @@ class ShadowNode extends ShadowBaseNode {
 
 		}
 
-		super.dispose();
-
 	}
 
 	/**

+ 1 - 0
src/renderers/common/nodes/Nodes.js

@@ -413,6 +413,7 @@ class Nodes extends DataMap {
 
 			_cacheKeyValues.push( this.renderer.getOutputRenderTarget() && this.renderer.getOutputRenderTarget().multiview ? 1 : 0 );
 			_cacheKeyValues.push( this.renderer.shadowMap.enabled ? 1 : 0 );
+			_cacheKeyValues.push( this.renderer.shadowMap.type );
 
 			cacheKeyData.callId = callId;
 			cacheKeyData.cacheKey = hashArray( _cacheKeyValues );

粤ICP备19079148号