Преглед на файлове

Fix shadowmap baking, remove useless copy step

ShiroSmith преди 5 години
родител
ревизия
df5795f466
променени са 3 файла, в които са добавени 36 реда и са изтрити 39 реда
  1. 5 7
      h3d/pass/PointShadowMap.hx
  2. 27 26
      h3d/pass/Shadows.hx
  3. 4 6
      h3d/pass/SpotShadowMap.hx

+ 5 - 7
h3d/pass/PointShadowMap.hx

@@ -114,6 +114,8 @@ class PointShadowMap extends Shadows {
 	}
 
 	function createStaticTexture() : h3d.mat.Texture {
+		if( staticTexture != null && staticTexture.width == size && staticTexture.width == size && staticTexture.format == format )
+			return staticTexture;
 		if( staticTexture != null )
 			staticTexture.dispose();
 		staticTexture = new h3d.mat.Texture(size, size, [Target, Cube], format);
@@ -165,7 +167,7 @@ class PointShadowMap extends Shadows {
 		return tmpTex;
 	}
 
-	override function draw( passes, ?sort ) {
+	override function draw( passes : h3d.pass.PassList, ?sort ) {
 		if( !enabled )
 			return;
 
@@ -187,8 +189,8 @@ class PointShadowMap extends Shadows {
 			return;
 		}
 
-		var texture = ctx.textures.allocTarget("pointShadowMap", size, size, false, format, true);
-		if(depth == null || depth.width != size || depth.height != size || depth.isDisposed() ) {
+		var texture = ctx.computingStatic ? createStaticTexture() : ctx.textures.allocTarget("pointShadowMap", size, size, false, format, true);
+		if( depth == null || depth.width != size || depth.height != size || depth.isDisposed() ) {
 			if( depth != null ) depth.dispose();
 			depth = new h3d.mat.DepthBuffer(size, size);
 		}
@@ -259,9 +261,5 @@ class PointShadowMap extends Shadows {
 		if( mode != Static && mode != Mixed )
 			return;
 		draw(passes);
-		if( staticTexture == null )
-			createStaticTexture();
-		CubeCopy.run(pshader.shadowMap, staticTexture);
-		pshader.shadowMap = staticTexture;
 	}
 }

+ 27 - 26
h3d/pass/Shadows.hx

@@ -108,36 +108,37 @@ class Shadows extends Default {
 	}
 
 	function filterPasses( passes : h3d.pass.PassList ) {
-		if( !ctx.computingStatic ){
+		if( !ctx.computingStatic ) {
 			switch( mode ) {
-			case None:
-				return false;
-			case Dynamic:
-				// nothing
-			case Mixed:
-				if( staticTexture == null || staticTexture.isDisposed() )
-					staticTexture = createDefaultShadowMap();
-			case Static:
-				if( staticTexture == null || staticTexture.isDisposed() )
-					staticTexture = createDefaultShadowMap();
-				syncShader(staticTexture);
-				return false;
+				case None:
+					return false;
+				case Dynamic:
+					return true;
+				case Mixed:
+					if( staticTexture == null || staticTexture.isDisposed() )
+						staticTexture = createDefaultShadowMap();
+					return true;
+				case Static:
+					if( staticTexture == null || staticTexture.isDisposed() )
+						staticTexture = createDefaultShadowMap();
+					syncShader(staticTexture);
+					return false;
 			}
 		}
-		switch( mode ) {
-		case None:
-			passes.clear();
-		case Dynamic:
-			if( ctx.computingStatic ) passes.clear();
-		case Mixed:
-			passes.filter(function(p) return p.pass.isStatic == ctx.computingStatic);
-		case Static:
-			if( ctx.computingStatic )
-				passes.filter(function(p) return p.pass.isStatic == true);
-			else
-				passes.clear();
+		else {
+			switch( mode ) {
+				case None:
+					return false;
+				case Dynamic:
+					return false;
+				case Mixed:
+					passes.filter(function(p) return p.pass.isStatic == true);
+					return true;
+				case Static:
+					passes.filter(function(p) return p.pass.isStatic == true);
+					return true;
+			}
 		}
-		return true;
 	}
 
 	inline function cullPasses( passes : h3d.pass.PassList, f : h3d.col.Collider -> Bool ) {

+ 4 - 6
h3d/pass/SpotShadowMap.hx

@@ -88,6 +88,8 @@ class SpotShadowMap extends Shadows {
 	}
 
 	function createStaticTexture() : h3d.mat.Texture {
+		if( staticTexture != null && staticTexture.width == size && staticTexture.width == size && staticTexture.format == format )
+			return staticTexture;
 		if( staticTexture != null )
 			staticTexture.dispose();
 		staticTexture = new h3d.mat.Texture(size, size, [Target], format);
@@ -120,7 +122,7 @@ class SpotShadowMap extends Shadows {
 		return true;
 	}
 
-	override function draw( passes, ?sort ) {
+	override function draw( passes : h3d.pass.PassList, ?sort ) {
 		if( !enabled )
 			return;
 
@@ -130,7 +132,7 @@ class SpotShadowMap extends Shadows {
 		updateCamera();
 		cullPasses(passes, function(col) return col.inFrustum(lightCamera.frustum));
 
-		var texture = ctx.textures.allocTarget("spotShadowMap", size, size, false, format);
+		var texture = ctx.computingStatic ? createStaticTexture() : ctx.textures.allocTarget("spotShadowMap", size, size, false, format);
 		if( customDepth && (depth == null || depth.width != size || depth.height != size || depth.isDisposed()) ) {
 			if( depth != null ) depth.dispose();
 			depth = new h3d.mat.DepthBuffer(size, size);
@@ -175,9 +177,5 @@ class SpotShadowMap extends Shadows {
 		if( mode != Static && mode != Mixed )
 			return;
 		draw(passes);
-		if( staticTexture == null )
-			createStaticTexture();
-		Copy.run(sshader.shadowMap, staticTexture);
-		sshader.shadowMap = staticTexture;
 	}
 }