From 33f69d778e5d4d2ac7be4a613a409c0a7ad59b43 Mon Sep 17 00:00:00 2001 From: "Gregg (Greggman/GMan) Tavares" Date: Tue, 21 Aug 2018 15:11:17 +0900 Subject: [PATCH] Make distance fog calculation overflow less in mediump --- src/renderers/shaders/ShaderChunk/fog_fragment.glsl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/renderers/shaders/ShaderChunk/fog_fragment.glsl b/src/renderers/shaders/ShaderChunk/fog_fragment.glsl index 46cc3788640aff..ad12ba20f7c7ca 100644 --- a/src/renderers/shaders/ShaderChunk/fog_fragment.glsl +++ b/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