Răsfoiți Sursa

Add zNear for pointlights

ShiroSmith 6 ani în urmă
părinte
comite
0af13f5731
3 a modificat fișierele cu 15 adăugiri și 9 ștergeri
  1. 7 4
      h3d/pass/DirShadowMap.hx
  2. 7 5
      h3d/pass/PointShadowMap.hx
  3. 1 0
      h3d/scene/pbr/PointLight.hx

+ 7 - 4
h3d/pass/DirShadowMap.hx

@@ -90,7 +90,7 @@ class DirShadowMap extends Shadows {
 			var cameraBounds = new h3d.col.Bounds();
 			for( pt in ctx.camera.getFrustumCorners() ) {
 				pt.transform(camera.mcam);
-				cameraBounds.addPos(pt.x, pt.y, pt.z);				
+				cameraBounds.addPos(pt.x, pt.y, pt.z);
 			}
 			cameraBounds.zMin = bounds.zMin;
 			bounds.intersection(bounds, cameraBounds);
@@ -167,6 +167,7 @@ class DirShadowMap extends Shadows {
 		if( staticTexture != null ) staticTexture.dispose();
 		staticTexture = new h3d.mat.Texture(size, size, [Target], format);
 		staticTexture.uploadPixels(pixels);
+		staticTexture.name = "defaultDirShadowMap";
 		syncShader(staticTexture);
 		return true;
 	}
@@ -180,8 +181,10 @@ class DirShadowMap extends Shadows {
 			case Dynamic:
 				// nothing
 			case Static, Mixed:
-				if( staticTexture == null || staticTexture.isDisposed() )
+				if( staticTexture == null || staticTexture.isDisposed() ){
 					staticTexture = h3d.mat.Texture.fromColor(0xFFFFFF);
+					staticTexture.name = "defaultDirShadowMap";
+				}
 				if( mode == Static ) {
 					syncShader(staticTexture);
 					return passes;
@@ -190,7 +193,7 @@ class DirShadowMap extends Shadows {
 
 		passes = filterPasses(passes);
 
-		var texture = ctx.textures.allocTarget("shadowMap", size, size, false, format);
+		var texture = ctx.textures.allocTarget("dirShadowMap", 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);
@@ -221,7 +224,7 @@ class DirShadowMap extends Shadows {
 		ctx.engine.popTarget();
 
 		if( mode == Mixed && !ctx.computingStatic ) {
-			var merge = ctx.textures.allocTarget("shadowMap", size, size, false, format);
+			var merge = ctx.textures.allocTarget("mergedDirShadowMap", size, size, false, format);
 			mergePass.shader.texA = texture;
 			mergePass.shader.texB = staticTexture;
 			ctx.engine.pushTarget(merge);

+ 7 - 5
h3d/pass/PointShadowMap.hx

@@ -90,7 +90,8 @@ class PointShadowMap extends Shadows {
 			return false;
 
 		if( staticTexture != null ) staticTexture.dispose();
-			staticTexture = new h3d.mat.Texture(size, size, [Target, Cube], format);
+		staticTexture = new h3d.mat.Texture(size, size, [Target, Cube], format);
+		staticTexture.name = "staticTexture";
 
 		for(i in 0 ... 6){
 			var len = buffer.readInt32();
@@ -102,10 +103,10 @@ class PointShadowMap extends Shadows {
 	}
 
 	function createDefaultShadowMap(){
-		var tex = new h3d.mat.Texture(1,1, [Cube,Target], format);
-		for(i in 0 ... 6){
+		var tex = new h3d.mat.Texture(1,1, [Target,Cube], format);
+		tex.name = "defaultStaticTexture";
+		for(i in 0 ... 6)
 			tex.clear(0xFFFFFF, i);
-		}
 		return tex;
 	}
 
@@ -141,7 +142,7 @@ class PointShadowMap extends Shadows {
 		var validBakedTexture = (staticTexture != null && staticTexture.width == texture.width);
 		var merge : h3d.mat.Texture = null;
 		if( mode == Mixed && !ctx.computingStatic && validBakedTexture)
-			merge = ctx.textures.allocTarget("pointShadowMap", size, size, false, format, [Target, Cube]);
+			merge = ctx.textures.allocTarget("mergedPointShadowMap", size, size, false, format, [Target, Cube]);
 
 		for(i in 0 ... 6){
 			var pointLight = cast(light, h3d.scene.pbr.PointLight);
@@ -149,6 +150,7 @@ class PointShadowMap extends Shadows {
 			var absPos = light.getAbsPos();
 			lightCamera.setCubeMap(i, new h3d.Vector(absPos.tx, absPos.ty, absPos.tz));
 			lightCamera.zFar = pointLight.range;
+			lightCamera.zNear = pointLight.zNear;
 			lightCamera.update();
 
 			ctx.engine.pushTarget(texture, i);

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

@@ -4,6 +4,7 @@ class PointLight extends Light {
 
 	var pbr : h3d.shader.pbr.Light.PointLight;
 	public var size : Float;
+	public var zNear : Float = 0.02;
 	/**
 		Alias for uniform scale.
 	**/