Browse Source

Update Terrain

ShiroSmith 6 years ago
parent
commit
f9e7f6aeea
3 changed files with 8 additions and 8 deletions
  1. 2 2
      h3d/scene/pbr/terrain/Surface.hx
  2. 1 1
      h3d/scene/pbr/terrain/Terrain.hx
  3. 5 5
      h3d/shader/pbr/Terrain.hx

+ 2 - 2
h3d/scene/pbr/terrain/Surface.hx

@@ -7,7 +7,7 @@ class Surface {
 	public var tilling = 1.0;
 	public var offset : h3d.Vector;
 	public var angle = 0.0;
-	public var heightScale = 1.0;
+	public var heightBias = 0.0;
 
 	public function new(?albedo : h3d.mat.Texture, ?normal : h3d.mat.Texture, ?pbr : h3d.mat.Texture){
 		this.albedo = albedo;
@@ -21,7 +21,7 @@ class Surface {
 		o.tilling = tilling;
 		o.offset.load(offset);
 		o.angle = angle;
-		o.heightScale = heightScale;
+		o.heightBias = heightBias;
 		return o;
 	}
 

+ 1 - 1
h3d/scene/pbr/terrain/Terrain.hx

@@ -113,7 +113,7 @@ class Terrain extends Object {
 	public function updateSurfaceParams(){
 		for(i in 0 ... surfaces.length){
 			surfaceArray.params[i] = new h3d.Vector(surfaces[i].tilling, surfaces[i].offset.x, surfaces[i].offset.y, hxd.Math.degToRad(surfaces[i].angle));
-			surfaceArray.secondParams[i] = new h3d.Vector(surfaces[i].heightScale, 0, 0, 0);
+			surfaceArray.secondParams[i] = new h3d.Vector(surfaces[i].heightBias, 0, 0, 0);
 		}
 	}
 

+ 5 - 5
h3d/shader/pbr/Terrain.hx

@@ -64,9 +64,9 @@ class Terrain extends hxsl.Shader {
 
 		function getDepth( i : Vec3,  uv : Vec2 ) : Vec3 {
 			var depth = vec3(0);
-			if( w.x > 0 ) depth.x = pbrTextures.getLod(getsurfaceUV(i.x, uv), 0).a * secondSurfaceParams[i.x].x;
-			if( w.y > 0 ) depth.y = pbrTextures.getLod(getsurfaceUV(i.y, uv), 0).a * secondSurfaceParams[i.y].x;
-			if( w.z > 0 ) depth.z = pbrTextures.getLod(getsurfaceUV(i.z, uv), 0).a * secondSurfaceParams[i.z].x;
+			if( w.x > 0 ) depth.x = pbrTextures.getLod(getsurfaceUV(i.x, uv), 0).a - secondSurfaceParams[i.x].x;
+			if( w.y > 0 ) depth.y = pbrTextures.getLod(getsurfaceUV(i.y, uv), 0).a - secondSurfaceParams[i.y].x;
+			if( w.z > 0 ) depth.z = pbrTextures.getLod(getsurfaceUV(i.z, uv), 0).a - secondSurfaceParams[i.z].x;
 			return 1 - depth;
 		}
 
@@ -88,7 +88,7 @@ class Terrain extends hxsl.Shader {
 					curUV += delta;
 					prevDepth = curDepth;
 					depth = getDepth(i, curUV);
-					curDepth = curDepth = depth.dot(w);
+					curDepth = depth.dot(w);
 					curLayerDepth += layerDepth;
 				}
 				var prevUV = curUV - delta;
@@ -147,7 +147,7 @@ class Terrain extends hxsl.Shader {
 				var pbr3 = pbrTextures.get(surfaceUV3).rgba;
 
 				// Height Blend
-				var h = vec3(pbr1.a * secondSurfaceParams[i.x].x, pbr2.a *secondSurfaceParams[i.y].x, pbr3.a * secondSurfaceParams[i.z].x );
+				var h = vec3(pbr1.a - secondSurfaceParams[i.x].x, pbr2.a - secondSurfaceParams[i.y].x, pbr3.a - secondSurfaceParams[i.z].x );
 				w = mix(w, vec3(w.x*h.x, w.y*h.y, w.z*h.z), heightBlendStrength);
 
 				// Sharpness