Skip to content

Commit 6b8a1fe

Browse files
committed
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"
1 parent c588f80 commit 6b8a1fe

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/celengine/shadermanager.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,7 @@ AtmosphericEffects(const ShaderProperties& props)
13731373
// Compute the intersection of the view direction and the cloud layer (currently assumed to be a sphere)
13741374
source += " float rq = dot(eyePosition, eyeDir);\n";
13751375
source += " float qq = dot(eyePosition, eyePosition) - atmosphereRadius.y;\n";
1376-
source += " float d = sqrt(rq * rq - qq);\n";
1376+
source += " float d = sqrt(max(rq * rq - qq, 0.0));\n";
13771377
source += " vec3 atmEnter = eyePosition + min(0.0, (-rq + d)) * eyeDir;\n";
13781378
source += " vec3 atmLeave = in_Position.xyz;\n";
13791379

@@ -1384,7 +1384,7 @@ AtmosphericEffects(const ShaderProperties& props)
13841384
source += " vec3 atmSamplePointSun = atmEnter * 0.5 + atmLeave * 0.5;\n";
13851385
source += " rq = dot(atmSamplePointSun, " + LightProperty(0, "direction") + ");\n";
13861386
source += " qq = dot(atmSamplePointSun, atmSamplePointSun) - atmosphereRadius.y;\n";
1387-
source += " d = sqrt(rq * rq - qq);\n";
1387+
source += " d = sqrt(max(rq * rq - qq, 0.0));\n";
13881388
source += " float distSun = -rq + d;\n";
13891389
source += " float distAtm = length(atmEnter - atmLeave);\n";
13901390

@@ -1465,7 +1465,7 @@ AtmosphericEffects(const ShaderProperties& props, unsigned int nSamples)
14651465
// Compute the intersection of the view direction and the cloud layer (currently assumed to be a sphere)
14661466
source += " float rq = dot(eyePosition, eyeDir);\n";
14671467
source += " float qq = dot(eyePosition, eyePosition) - atmosphereRadius.y;\n";
1468-
source += " float d = sqrt(rq * rq - qq);\n";
1468+
source += " float d = sqrt(max(rq * rq - qq, 0.0));\n";
14691469
source += " vec3 atmEnter = eyePosition + min(0.0, (-rq + d)) * eyeDir;\n";
14701470
source += " vec3 atmLeave = in_Position.xyz;\n";
14711471

@@ -1480,7 +1480,7 @@ AtmosphericEffects(const ShaderProperties& props, unsigned int nSamples)
14801480
// Compute the distance through the atmosphere from the sample point to the sun
14811481
source += " rq = dot(atmSamplePoint, " + LightProperty(0, "direction") + ");\n";
14821482
source += " qq = dot(atmSamplePoint, atmSamplePoint) - atmosphereRadius.y;\n";
1483-
source += " d = sqrt(rq * rq - qq);\n";
1483+
source += " d = sqrt(max(rq * rq - qq, 0.0));\n";
14841484
source += " float distSun = -rq + d;\n";
14851485

14861486
// Compute the density of the atmosphere at the sample point; it falls off exponentially
@@ -1987,7 +1987,7 @@ ShaderManager::buildVertexShader(const ShaderProperties& props)
19871987
// Compute the intersection of the sun direction and the cloud layer (currently assumed to be a sphere)
19881988
source += " float rq = dot(" + LightProperty(j, "direction") + ", in_Position.xyz);\n";
19891989
source += " float qq = dot(in_Position.xyz, in_Position.xyz) - cloudHeight * cloudHeight;\n";
1990-
source += " float d = sqrt(rq * rq - qq);\n";
1990+
source += " float d = sqrt(max(rq * rq - qq, 0.0));\n";
19911991
source += " vec3 cloudSpherePos = (in_Position.xyz + (-rq + d) * " + LightProperty(j, "direction") + ");\n";
19921992
//source += " vec3 cloudSpherePos = in_Position.xyz;\n";
19931993

0 commit comments

Comments
 (0)