浏览代码

Make distance fog calculation overflow less in mediump

Gregg (Greggman/GMan) Tavares 7 年之前
父节点
当前提交
33f69d778e
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      src/renderers/shaders/ShaderChunk/fog_fragment.glsl

+ 4 - 1
src/renderers/shaders/ShaderChunk/fog_fragment.glsl

@@ -1,6 +1,9 @@
 #ifdef USE_FOG
 #ifdef USE_FOG
 
 
-	float fogDepth = length( vFogPosition );
+	// divide then multiply by max component to try to avoid saturating mediump precision
+	vec3 fogPositionAbs = abs( vFogPosition );
+	float fogMaxComponent = max( fogPositionAbs.x, max( fogPositionAbs.y, fogPositionAbs.z ) );
+	float fogDepth = length( vFogPosition / fogMaxComponent ) * fogMaxComponent;
 
 
 	#ifdef FOG_EXP2
 	#ifdef FOG_EXP2