Browse Source

Opti Terrain

ShiroSmith 6 years ago
parent
commit
8d5bc38f9d
2 changed files with 15 additions and 30 deletions
  1. 3 25
      h3d/scene/pbr/terrain/Surface.hx
  2. 12 5
      h3d/scene/pbr/terrain/Tile.hx

+ 3 - 25
h3d/scene/pbr/terrain/Surface.hx

@@ -1,9 +1,9 @@
 package h3d.scene.pbr.terrain;
 
 class Surface {
-	public var albedo (default, set) : h3d.mat.Texture;
-	public var normal (default, set) : h3d.mat.Texture;
-	public var pbr (default, set) : h3d.mat.Texture;
+	public var albedo : h3d.mat.Texture;
+	public var normal : h3d.mat.Texture;
+	public var pbr : h3d.mat.Texture;
 	public var tilling = 1.0;
 	public var offset : h3d.Vector;
 	public var angle = 0.0;
@@ -20,28 +20,6 @@ class Surface {
 		if(normal != null) normal.dispose();
 		if(pbr != null) pbr.dispose();
 	}
-
-	function set_albedo(t : h3d.mat.Texture){
-		return albedo = swap(albedo, t);
-	}
-
-	function set_normal(t : h3d.mat.Texture){
-		return normal = swap(normal, t);
-	}
-
-	function set_pbr(t : h3d.mat.Texture){
-		return pbr = swap(pbr, t);
-	}
-
-	function swap(a : h3d.mat.Texture, b : h3d.mat.Texture) : h3d.mat.Texture {
-		if(a != null) a.dispose();
-		if(b != null){
-			var r = b.clone();
-			r.wrap = Repeat;
-			return r;
-		}
-		return null;
-	}
 }
 
 class SurfaceArray {

+ 12 - 5
h3d/scene/pbr/terrain/Tile.hx

@@ -18,7 +18,7 @@ class Tile extends h3d.scene.Mesh {
 	var heightmapPixels : hxd.Pixels.PixelsFloat;
 	var shader : h3d.shader.pbr.Terrain;
 
-	public function new(x : Int, y : Int , ?parent){
+	public function new( x : Int, y : Int , ?parent ){
 		super(null, null, parent);
 		this.tileX = x;
 		this.tileY = y;
@@ -27,7 +27,6 @@ class Tile extends h3d.scene.Mesh {
 		material.mainPass.culling = None;
 		this.x = x * getTerrain().tileSize;
 		this.y = y * getTerrain().tileSize;
-		refreshMesh();
 		name = "tile_" + x + "_" + y;
 	}
 
@@ -435,9 +434,9 @@ class Tile extends h3d.scene.Mesh {
 				t2.z += getHeight(t2.x / getTerrain().tileSize, t2.y / getTerrain().tileSize);
 			}
 			var n1 = t1.sub(t0);
-			n1.normalize();
+			n1.normalizeFast();
 			var n2 = t2.sub(t0);
-			n2.normalize();
+			n2.normalizeFast();
 			var n = n1.cross(n2);
 			grid.normals[i0].x += n.x; grid.normals[i0].y += n.y; grid.normals[i0].z += n.z;
 			grid.normals[i1].x += n.x; grid.normals[i1].y += n.y; grid.normals[i1].z += n.z;
@@ -491,7 +490,15 @@ class Tile extends h3d.scene.Mesh {
 			cachedBounds = getBounds();
 			cachedBounds.zMax = 10000;  // TODO: Use real low/high Z values
 			cachedBounds.zMin = -10000;
-		}		
+
+			var maxZ : Float;
+			var minZ : Float;
+			var vertexCount = grid.width + 1;
+
+			/*for( p in grid.points ){
+				var h = getHeight(p.)
+			}*/
+		}
 		if(ctx.camera.frustum.hasBounds(cachedBounds))
 			super.emit(ctx);
 	}