Browse Source

Improved CSM.

clandrin 2 years ago
parent
commit
6afaf3d0f0
1 changed files with 9 additions and 13 deletions
  1. 9 13
      h3d/pass/CascadeShadowMap.hx

+ 9 - 13
h3d/pass/CascadeShadowMap.hx

@@ -198,12 +198,10 @@ class CascadeShadowMap extends DirShadowMap {
 				far = shadowFar;
 			addCorners(near);
 			addCorners(hxd.Math.min(far, shadowFar));
-			lightCameras[i].orthoBounds = bounds.clone();
-			lightCameras[i].orthoBounds.intersection(lightCameras[i].orthoBounds, cascadeBounds);
+			lightCameras[i].orthoBounds = cascadeBounds;
 			var limits = lightCameras[i].orthoBounds.clone();
 			lightCameras[i].orthoBounds.empty();
 			calcBounds(lightCameras[i], limits);
-			lightCameras[i].orthoBounds.intersection(lightCameras[i].orthoBounds, limits);
 
 			near += firstCascadeSize * hxd.Math.pow(pow, i);
 			far += firstCascadeSize * hxd.Math.pow(pow, i+1);
@@ -259,16 +257,6 @@ class CascadeShadowMap extends DirShadowMap {
 		if( !filterPasses(passes) )
 			return;
 
-		if( mode != Mixed || ctx.computingStatic ) {
-			lightCamera.orthoBounds.empty();
-			for ( lC in lightCameras ) lC.orthoBounds.empty();
-			if( !passes.isEmpty() ) calcCascadeShadowBounds(lightCamera);
-			lightCamera.update();
-			for ( lC in lightCameras ) lC.update();
-		}
-
-		cullPasses(passes,function(col) return col.inFrustum(lightCamera.frustum));
-
 		if( mode != Mixed || ctx.computingStatic ) {
 			var ct = ctx.camera.target;
 			var slight = light == null ? ctx.lightSystem.shadowLight : light;
@@ -297,8 +285,16 @@ class CascadeShadowMap extends DirShadowMap {
 				lightCameras[i].pos.load(ct);
 				lightCameras[i].update();
 			}
+
+			lightCamera.orthoBounds.empty();
+			for ( lC in lightCameras ) lC.orthoBounds.empty();
+			if( !passes.isEmpty() ) calcCascadeShadowBounds(lightCamera);
+			lightCamera.update();
+			for ( lC in lightCameras ) lC.update();
 		}
 
+		cullPasses(passes,function(col) return col.inFrustum(lightCamera.frustum));
+
 		var textures = [];
 		if ( g != null )
 			g.clear();