Fix flickering edges on iOS

Li: "rq * rq - qq might be negative, and produce nan in this case,
which got translated into the largest float point number to displayed
as white"
pull/771/head
Hleb Valoshka 2020-06-12 15:21:31 +03:00
parent c588f80824
commit 6b8a1fe6b3
1 changed files with 5 additions and 5 deletions

View File

@ -1373,7 +1373,7 @@ AtmosphericEffects(const ShaderProperties& props)
// Compute the intersection of the view direction and the cloud layer (currently assumed to be a sphere)
source += " float rq = dot(eyePosition, eyeDir);\n";
source += " float qq = dot(eyePosition, eyePosition) - atmosphereRadius.y;\n";
source += " float d = sqrt(rq * rq - qq);\n";
source += " float d = sqrt(max(rq * rq - qq, 0.0));\n";
source += " vec3 atmEnter = eyePosition + min(0.0, (-rq + d)) * eyeDir;\n";
source += " vec3 atmLeave = in_Position.xyz;\n";
@ -1384,7 +1384,7 @@ AtmosphericEffects(const ShaderProperties& props)
source += " vec3 atmSamplePointSun = atmEnter * 0.5 + atmLeave * 0.5;\n";
source += " rq = dot(atmSamplePointSun, " + LightProperty(0, "direction") + ");\n";
source += " qq = dot(atmSamplePointSun, atmSamplePointSun) - atmosphereRadius.y;\n";
source += " d = sqrt(rq * rq - qq);\n";
source += " d = sqrt(max(rq * rq - qq, 0.0));\n";
source += " float distSun = -rq + d;\n";
source += " float distAtm = length(atmEnter - atmLeave);\n";
@ -1465,7 +1465,7 @@ AtmosphericEffects(const ShaderProperties& props, unsigned int nSamples)
// Compute the intersection of the view direction and the cloud layer (currently assumed to be a sphere)
source += " float rq = dot(eyePosition, eyeDir);\n";
source += " float qq = dot(eyePosition, eyePosition) - atmosphereRadius.y;\n";
source += " float d = sqrt(rq * rq - qq);\n";
source += " float d = sqrt(max(rq * rq - qq, 0.0));\n";
source += " vec3 atmEnter = eyePosition + min(0.0, (-rq + d)) * eyeDir;\n";
source += " vec3 atmLeave = in_Position.xyz;\n";
@ -1480,7 +1480,7 @@ AtmosphericEffects(const ShaderProperties& props, unsigned int nSamples)
// Compute the distance through the atmosphere from the sample point to the sun
source += " rq = dot(atmSamplePoint, " + LightProperty(0, "direction") + ");\n";
source += " qq = dot(atmSamplePoint, atmSamplePoint) - atmosphereRadius.y;\n";
source += " d = sqrt(rq * rq - qq);\n";
source += " d = sqrt(max(rq * rq - qq, 0.0));\n";
source += " float distSun = -rq + d;\n";
// Compute the density of the atmosphere at the sample point; it falls off exponentially
@ -1987,7 +1987,7 @@ ShaderManager::buildVertexShader(const ShaderProperties& props)
// Compute the intersection of the sun direction and the cloud layer (currently assumed to be a sphere)
source += " float rq = dot(" + LightProperty(j, "direction") + ", in_Position.xyz);\n";
source += " float qq = dot(in_Position.xyz, in_Position.xyz) - cloudHeight * cloudHeight;\n";
source += " float d = sqrt(rq * rq - qq);\n";
source += " float d = sqrt(max(rq * rq - qq, 0.0));\n";
source += " vec3 cloudSpherePos = (in_Position.xyz + (-rq + d) * " + LightProperty(j, "direction") + ");\n";
//source += " vec3 cloudSpherePos = in_Position.xyz;\n";