浏览代码

Fix parallax shader with mix NaN.

clementlandrin 10 月之前
父节点
当前提交
18b1f3c19b
共有 1 个文件被更改,包括 2 次插入4 次删除
  1. 2 4
      h3d/shader/Parallax.hx

+ 2 - 4
h3d/shader/Parallax.hx

@@ -33,15 +33,13 @@ class Parallax extends hxsl.Shader {
 			if( maxLayers == 0 )
 				calculatedUV += viewNS.xy * heightMap.get(calculatedUV) * amount;
 			else {
-				var numLayers = int(mix(float(maxLayers), float(minLayers), abs(viewNS.z)));
+				var numLayers = mix(float(maxLayers), float(minLayers), saturate(abs(viewNS.z)));
 				var layerDepth = 1 / numLayers;
 				var curLayerDepth = 0.;
 				var delta = (viewNS.xy / viewNS.z) * amount / numLayers;
 				var curUV = calculatedUV;
 				var curDepth = heightMap.getLod(curUV,0.);
-			    for (i in 0...numLayers) {
-					if (curLayerDepth < curDepth)
-						break;
+			    while( curLayerDepth < curDepth ) {
 			        curUV += delta;
 			        curDepth = heightMap.getLod(curUV,0.);
 			        curLayerDepth += layerDepth;