Browse Source

Merge pull request #14752 from greggman/non-overflowing-fog

Make distance fog calculation overflow less in mediump
Mr.doob 7 years ago
parent
commit
508b82def9
1 changed files with 4 additions and 1 deletions
  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
 
-	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