Преглед изворни кода

Add clamp for distance fog

ShiroSmith пре 6 година
родитељ
комит
8be1a01e1b
1 измењених фајлова са 2 додато и 2 уклоњено
  1. 2 2
      h3d/shader/DistanceFog.hx

+ 2 - 2
h3d/shader/DistanceFog.hx

@@ -32,8 +32,8 @@ class DistanceFog extends ScreenShader {
 			var origin = getPosition(calculatedUV);
 			var distance = (origin - cameraPos).length();
 			if( startDistance > distance ) discard;
-			var opacityFactor = (distance - startDistance) / (endDistance - startDistance);
-			var colorFactor = (distance - startColorDistance) / (endColorDistance - startColorDistance);
+			var opacityFactor = clamp((distance - startDistance) / (endDistance - startDistance), 0, 1);
+			var colorFactor = clamp((distance - startColorDistance) / (endColorDistance - startColorDistance), 0, 1);
 			var fogColor = mix(startColor, endColor, colorFactor);
 			var fogOpacity = mix(startOpacity, endOpacity, opacityFactor);
 			if( fogOpacity <= 0 ) discard;