ShiroSmith 6 gadi atpakaļ
vecāks
revīzija
a4f83dac6f
2 mainītis faili ar 35 papildinājumiem un 22 dzēšanām
  1. 23 12
      h3d/pass/PointShadowMap.hx
  2. 12 10
      h3d/pass/SpotShadowMap.hx

+ 23 - 12
h3d/pass/PointShadowMap.hx

@@ -115,10 +115,15 @@ class PointShadowMap extends Shadows {
 			switch( mode ) {
 			case None:
 				return passes;
-			case Dynamic:	// nothing
-			case Mixed:		// nothing
+			case Dynamic:
+				// nothing
+			case Mixed:
+				if( staticTexture == null || staticTexture.isDisposed() )
+					staticTexture = createDefaultShadowMap();
 			case Static:
-				if( staticTexture == null || staticTexture.isDisposed() ) staticTexture = createDefaultShadowMap();
+				if( staticTexture == null || staticTexture.isDisposed() )
+					staticTexture = createDefaultShadowMap();
+				updateCamera();
 				syncShader(staticTexture);
 				return passes;
 			}
@@ -133,12 +138,12 @@ class PointShadowMap extends Shadows {
 		}
 		texture.depthBuffer = depth;
 
+		var validBakedTexture = (staticTexture != null && staticTexture.width == texture.width);
 		var merge : h3d.mat.Texture = null;
-		if( mode == Mixed && !ctx.computingStatic )
+		if( mode == Mixed && !ctx.computingStatic && validBakedTexture)
 			merge = ctx.textures.allocTarget("pointShadowMap", size, size, false, format, [Target, Cube]);
 
 		for(i in 0 ... 6){
-
 			var pointLight = cast(light, h3d.scene.pbr.PointLight);
 
 			var absPos = light.getAbsPos();
@@ -150,8 +155,13 @@ class PointShadowMap extends Shadows {
 			ctx.engine.clear(0xFFFFFF, 1);
 			passes = super.draw(passes);
 			ctx.engine.popTarget();
+		}
+
+		if( blur.radius > 0 )
+			blur.apply(ctx, texture);
 
-			if( mode == Mixed && !ctx.computingStatic ) {
+		if( mode == Mixed && !ctx.computingStatic && merge != null ) {
+			for(i in 0 ... 6){
 				mergePass.shader.texA = texture;
 				mergePass.shader.texB = staticTexture;
 				mergePass.shader.mat = cubeDir[i];
@@ -159,18 +169,19 @@ class PointShadowMap extends Shadows {
 				mergePass.render();
 				ctx.engine.popTarget();
 			}
-		}
-
-		if( blur.radius > 0 && (mode != Mixed || !ctx.computingStatic) )
-				blur.apply(ctx, texture);
-
-		if( mode == Mixed && !ctx.computingStatic )
 			texture = merge;
+		}
 
 		syncShader(texture);
 		return passes;
 	}
 
+	function updateCamera(){
+		var absPos = light.getAbsPos();
+		lightCamera.pos.set(absPos.tx, absPos.ty, absPos.tz);
+		lightCamera.update();
+	}
+
 	override function computeStatic( passes : h3d.pass.Object ) {
 		if( mode != Static && mode != Mixed )
 			return;

+ 12 - 10
h3d/pass/SpotShadowMap.hx

@@ -96,14 +96,15 @@ class SpotShadowMap extends Shadows {
 				return passes;
 			case Dynamic:
 				// nothing
-			case Static, Mixed:
+			case Mixed:
 				if( staticTexture == null || staticTexture.isDisposed() )
 					staticTexture = h3d.mat.Texture.fromColor(0xFFFFFF);
-				if( mode == Static ) {
-					updateCamera();
-					syncShader(staticTexture);
-					return passes;
-				}
+			case Static:
+				if( staticTexture == null || staticTexture.isDisposed() )
+					staticTexture = h3d.mat.Texture.fromColor(0xFFFFFF);
+				updateCamera();
+				syncShader(staticTexture);
+				return passes;
 			}
 
 		passes = filterPasses(passes);
@@ -122,7 +123,11 @@ class SpotShadowMap extends Shadows {
 		if( border != null ) border.render();
 		ctx.engine.popTarget();
 
-		if( mode == Mixed && !ctx.computingStatic ) {
+		if( blur.radius > 0 )
+			blur.apply(ctx, texture);
+
+		var validBakedTexture = (staticTexture != null && staticTexture.width == texture.width);
+		if( mode == Mixed && !ctx.computingStatic && validBakedTexture ) {
 			var merge = ctx.textures.allocTarget("shadowMap", size, size, false, format);
 			mergePass.shader.texA = texture;
 			mergePass.shader.texB = staticTexture;
@@ -132,9 +137,6 @@ class SpotShadowMap extends Shadows {
 			texture = merge;
 		}
 
-		if( blur.radius > 0 && (mode != Mixed || !ctx.computingStatic) )
-			blur.apply(ctx, texture);
-
 		syncShader(texture);
 		return passes;
 	}