Browse Source

switching filters on switching shadow types fixed (#25847)

Co-authored-by: unknown <[email protected]>
digitalArt3DTobias 2 years ago
parent
commit
b1c731288a
1 changed files with 13 additions and 1 deletions
  1. 13 1
      src/renderers/webgl/WebGLShadowMap.js

+ 13 - 1
src/renderers/webgl/WebGLShadowMap.js

@@ -67,6 +67,7 @@ function WebGLShadowMap( _renderer, _objects, _capabilities ) {
 	this.needsUpdate = false;
 
 	this.type = PCFShadowMap;
+	let _previousType = this.type;
 
 	this.render = function ( lights, scene, camera ) {
 
@@ -131,10 +132,19 @@ function WebGLShadowMap( _renderer, _objects, _capabilities ) {
 
 			}
 
-			if ( shadow.map === null ) {
+			const switchedToVSM = _previousType !== VSMShadowMap && this.type === VSMShadowMap;
+			const switchedFromVSM = _previousType === VSMShadowMap && this.type !== VSMShadowMap;
+
+			if ( shadow.map === null || switchedToVSM || switchedFromVSM ) {
 
 				const pars = ( this.type !== VSMShadowMap ) ? { minFilter: NearestFilter, magFilter: NearestFilter } : {};
 
+				if ( shadow.map !== null ) {
+
+					shadow.map.dispose();
+
+				}
+
 				shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
 				shadow.map.texture.name = light.name + '.shadowMap';
 
@@ -142,6 +152,8 @@ function WebGLShadowMap( _renderer, _objects, _capabilities ) {
 
 			}
 
+			_previousType = this.type;
+
 			_renderer.setRenderTarget( shadow.map );
 			_renderer.clear();