浏览代码

Update Terrain

ShiroSmith 7 年之前
父节点
当前提交
fc3ec07ed4
共有 2 个文件被更改,包括 6 次插入3 次删除
  1. 3 0
      h3d/scene/pbr/terrain/Tile.hx
  2. 3 3
      h3d/shader/pbr/Terrain.hx

+ 3 - 0
h3d/scene/pbr/terrain/Tile.hx

@@ -93,6 +93,7 @@ class Tile extends h3d.scene.Mesh {
 			heightMap.wrap = Clamp;
 			heightMap.filter = Linear;
 			heightMap.preventAutoDispose();
+			heightMap.realloc = null;
 			if(oldHeightMap != null){
 				getTerrain().copyPass.apply(oldHeightMap, heightMap);
 				oldHeightMap.dispose();
@@ -105,6 +106,7 @@ class Tile extends h3d.scene.Mesh {
 			surfaceIndexMap = new h3d.mat.Texture(getTerrain().weightMapResolution, getTerrain().weightMapResolution, [Target], RGBA);
 			surfaceIndexMap.filter = Nearest;
 			surfaceIndexMap.preventAutoDispose();
+			surfaceIndexMap.realloc = null;
 			if(oldSurfaceIndexMap != null){
 				getTerrain().copyPass.apply(oldSurfaceIndexMap, surfaceIndexMap);
 				oldSurfaceIndexMap.dispose();
@@ -119,6 +121,7 @@ class Tile extends h3d.scene.Mesh {
 				surfaceWeights[i] = new h3d.mat.Texture(getTerrain().weightMapResolution, getTerrain().weightMapResolution, [Target], R8);
 				surfaceWeights[i].wrap = Clamp;
 				surfaceWeights[i].preventAutoDispose();
+				surfaceWeights[i].realloc = null;
 				if(i < oldArray.length && oldArray[i] != null)
 					getTerrain().copyPass.apply(oldArray[i], surfaceWeights[i]);
 			}

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

@@ -43,7 +43,7 @@ class Terrain extends hxsl.Shader {
 			calculatedUV = input.position.xy / primSize;
 			var terrainUV = (calculatedUV * (heightMapSize - 1)) / heightMapSize;
 			terrainUV += 0.5 / heightMapSize;
-			transformedPosition += (vec3(0,0, heightMap.get(terrainUV).r) * global.modelView.mat3());
+			transformedPosition += (vec3(0,0, textureLod(heightMap, terrainUV, 0).r) * global.modelView.mat3());
 			TBN = mat3(normalize(cross(transformedNormal, vec3(0,1,0))), normalize(cross(transformedNormal,vec3(-1,0,0))), transformedNormal);
 		}
 
@@ -61,12 +61,12 @@ class Terrain extends hxsl.Shader {
 			var numLayers = mix(float(maxStep), float(minStep), abs(viewNS.z));
 			var layerDepth = 1 / numLayers;
 			var curLayerDepth = 0.;
-			var delta = (viewNS.xy / viewNS.z) * parallaxAmount / numLayers * 1.0/surfaceParams[surfaceIndex].x;
+			var delta = (viewNS.xy / viewNS.z) * parallaxAmount / numLayers * 1.0 / surfaceParams[surfaceIndex].x;
 			var curUV = uv;
 			var curDepth = 1 - pbrTextures.get(getsurfaceUV(surfaceIndex, curUV)).a;
 			while( curLayerDepth < curDepth ) {
 				curUV += delta;
-				curDepth =  1 - pbrTextures.get(getsurfaceUV(surfaceIndex, curUV)).a;
+				curDepth =  1 - pbrTextures.getLod( getsurfaceUV(surfaceIndex, curUV), 0).a;
 				curLayerDepth += layerDepth;
 			}
 			var prevUV = curUV - delta;