Explorar el Código

-Fix cubemap copy

ShiroSmith hace 7 años
padre
commit
497b06022a
Se han modificado 4 ficheros con 22 adiciones y 32 borrados
  1. 11 10
      h3d/pass/CubeCopy.hx
  2. 7 17
      h3d/pass/PointShadowMap.hx
  3. 1 1
      h3d/scene/pbr/PointLight.hx
  4. 3 4
      h3d/shader/MinMaxShader.hx

+ 11 - 10
h3d/pass/CubeCopy.hx

@@ -4,31 +4,32 @@ private class CubeCopyShader extends h3d.shader.ScreenShader {
 
 	static var SRC = {
 		@param var texture : SamplerCube;
-		@param var mat : Mat3x4;
+		@param var mat : Mat3;
 		function fragment() {
-			pixelColor = texture.get(vec3(calculatedUV, 1) * mat);
+			var uv = calculatedUV * 2.0 - 1.0;
+			pixelColor = texture.get(normalize(vec3(uv, 1) * mat));
 		}
 	}
 }
 
 class CubeCopy extends ScreenFx<CubeCopyShader> {
 
-	var cubeDir = [ h3d.Matrix.L([0,0,-1,0, 0,1,0,0, -1,-1,1,0]),
-					h3d.Matrix.L([0,0,1,0, 0,1,0,0, 1,-1,-1,0]),
-	 				h3d.Matrix.L([-1,0,0,0, 0,0,1,0, 1,-1,-1,0]),
-	 				h3d.Matrix.L([-1,0,0,0, 0,0,-1,0, 1,1,1,0]),
-				 	h3d.Matrix.L([-1,0,0,0, 0,1,0,0, 1,-1,1,0]),
-				 	h3d.Matrix.L([1,0,0,0, 0,1,0,0, -1,-1,-1,0]) ];
+	var cubeDir = [ h3d.Matrix.L([0,0,-1,0, 0,-1,0,0, 1,0,0,0]),
+					h3d.Matrix.L([0,0,1,0, 0,-1,0,0, -1,0,0,0]),
+	 				h3d.Matrix.L([1,0,0,0, 0,0,1,0, 0,1,0,0]),
+	 				h3d.Matrix.L([1,0,0,0, 0,0,-1,0, 0,-1,0,0]),
+				 	h3d.Matrix.L([1,0,0,0, 0,-1,0,0, 0,1,0,0]),
+				 	h3d.Matrix.L([-1,0,0,0, 0,-1,0,0, 0,0,-1,0]) ];
 
 	public function new() {
 		super(new CubeCopyShader());
 	}
 
 	public function apply( from, to, ?blend : h3d.mat.BlendMode, ?customPass : h3d.mat.Pass ) {
+		shader.texture = from;
 		for(i in 0 ... 6){
 			if( to != null )
 				engine.pushTarget(to, i);
-			shader.texture = from;
 			shader.mat = cubeDir[i];
 			if( customPass != null ) {
 				var old = pass;
@@ -45,10 +46,10 @@ class CubeCopy extends ScreenFx<CubeCopyShader> {
 				pass.setBlendMode(blend == null ? None : blend);
 				render();
 			}
-			shader.texture = null;
 			if( to != null )
 				engine.popTarget();
 		}
+		shader.texture = null;
 	}
 
 	public static function run( from : h3d.mat.Texture, to : h3d.mat.Texture, ?blend : h3d.mat.BlendMode, ?pass : h3d.mat.Pass ) {

+ 7 - 17
h3d/pass/PointShadowMap.hx

@@ -8,12 +8,12 @@ class PointShadowMap extends Shadows {
 	var pshader : h3d.shader.PointShadow;
 	var mergePass = new h3d.pass.ScreenFx(new h3d.shader.MinMaxShader.CubeMinMaxShader());
 
-	var cubeDir = [ h3d.Matrix.L([0,0,-1,0, 0,1,0,0, -1,-1,1,0]),
-					h3d.Matrix.L([0,0,1,0, 0,1,0,0, 1,-1,-1,0]),
-	 				h3d.Matrix.L([-1,0,0,0, 0,0,1,0, 1,-1,-1,0]),
-	 				h3d.Matrix.L([-1,0,0,0, 0,0,-1,0, 1,1,1,0]),
-				 	h3d.Matrix.L([-1,0,0,0, 0,1,0,0, 1,-1,1,0]),
-				 	h3d.Matrix.L([1,0,0,0, 0,1,0,0, -1,-1,-1,0]) ];
+	var cubeDir = [ h3d.Matrix.L([0,0,-1,0, 0,-1,0,0, 1,0,0,0]),
+					h3d.Matrix.L([0,0,1,0, 0,-1,0,0, -1,0,0,0]),
+	 				h3d.Matrix.L([1,0,0,0, 0,0,1,0, 0,1,0,0]),
+	 				h3d.Matrix.L([1,0,0,0, 0,0,-1,0, 0,-1,0,0]),
+				 	h3d.Matrix.L([1,0,0,0, 0,-1,0,0, 0,1,0,0]),
+				 	h3d.Matrix.L([-1,0,0,0, 0,-1,0,0, 0,0,-1,0]) ];
 
 	public function new( light : h3d.scene.Light, useWorldDist : Bool ) {
 		super(light);
@@ -47,13 +47,6 @@ class PointShadowMap extends Shadows {
 		return lightCamera.m;
 	}
 
-	public dynamic function calcShadowBounds( camera : h3d.Camera ) {
-		var pt : Array<h3d.Vector> = camera.getFrustumCorners();
-		for( p in pt) {
-			camera.orthoBounds.addPos(p.x, p.y, p.z);
-		}
-	}
-
 	override function setGlobals() {
 		super.setGlobals();
 		cameraViewProj = getShadowProj();
@@ -138,7 +131,7 @@ class PointShadowMap extends Shadows {
 			}
 		}
 
-		passes = filterPasses(passes);
+		var passes = filterPasses(passes);
 
 		var texture = ctx.textures.allocTarget("pointShadowMap", size, size, false, format, [Target, Cube]);
 		if(depth == null || depth.width != size || depth.height != size || depth.isDisposed() ) {
@@ -147,9 +140,6 @@ class PointShadowMap extends Shadows {
 		}
 		texture.depthBuffer = depth;
 
-		var textureTest = ctx.textures.allocTarget("pointShadowMap", size, size, false, format);
-		textureTest.depthBuffer = depth;
-
 		var merge : h3d.mat.Texture = null;
 		if( mode == Mixed && !ctx.computingStatic )
 			merge = ctx.textures.allocTarget("pointShadowMap", size, size, false, format, [Target, Cube]);

+ 1 - 1
h3d/scene/pbr/PointLight.hx

@@ -11,9 +11,9 @@ class PointLight extends Light {
 
 	public function new(?parent) {
 		pbr = new h3d.shader.pbr.Light.PointLight();
+		shadows = new h3d.pass.PointShadowMap(this, true);
 		super(pbr,parent);
 		range = 10;
-		shadows = new h3d.pass.PointShadowMap(this, true);
 		primitive = h3d.prim.Sphere.defaultUnitSphere();
 	}
 

+ 3 - 4
h3d/shader/MinMaxShader.hx

@@ -13,7 +13,6 @@ class MinMaxShader extends ScreenShader {
 			var b = texB.get(calculatedUV);
 			pixelColor = isMax ? max(a,b) : min(a,b);
 		}
-
 	};
 }
 
@@ -24,14 +23,14 @@ class CubeMinMaxShader extends ScreenShader {
 		@param var texA : SamplerCube;
 		@param var texB : SamplerCube;
 		@const var isMax : Bool;
-		@param var mat : Mat3x4;
+		@param var mat : Mat3;
 
 		function fragment() {
-			var dir = vec3(calculatedUV , 1) * mat;
+			var uv = calculatedUV * 2.0 - 1.0;
+			var dir = vec3(uv , 1) * mat;
 			var a = texA.get(dir);
 			var b = texB.get(dir);
 			pixelColor = isMax ? max(a,b) : min(a,b);
 		}
-
 	};
 }