@@ -1373,7 +1373,7 @@ AtmosphericEffects(const ShaderProperties& props)
1373
1373
// Compute the intersection of the view direction and the cloud layer (currently assumed to be a sphere)
1374
1374
source += " float rq = dot(eyePosition, eyeDir);\n " ;
1375
1375
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 " ;
1377
1377
source += " vec3 atmEnter = eyePosition + min(0.0, (-rq + d)) * eyeDir;\n " ;
1378
1378
source += " vec3 atmLeave = in_Position.xyz;\n " ;
1379
1379
@@ -1384,7 +1384,7 @@ AtmosphericEffects(const ShaderProperties& props)
1384
1384
source += " vec3 atmSamplePointSun = atmEnter * 0.5 + atmLeave * 0.5;\n " ;
1385
1385
source += " rq = dot(atmSamplePointSun, " + LightProperty (0 , " direction" ) + " );\n " ;
1386
1386
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 " ;
1388
1388
source += " float distSun = -rq + d;\n " ;
1389
1389
source += " float distAtm = length(atmEnter - atmLeave);\n " ;
1390
1390
@@ -1465,7 +1465,7 @@ AtmosphericEffects(const ShaderProperties& props, unsigned int nSamples)
1465
1465
// Compute the intersection of the view direction and the cloud layer (currently assumed to be a sphere)
1466
1466
source += " float rq = dot(eyePosition, eyeDir);\n";
1467
1467
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";
1469
1469
source += " vec3 atmEnter = eyePosition + min(0.0, (-rq + d)) * eyeDir;\n";
1470
1470
source += " vec3 atmLeave = in_Position.xyz;\n";
1471
1471
@@ -1480,7 +1480,7 @@ AtmosphericEffects(const ShaderProperties& props, unsigned int nSamples)
1480
1480
// Compute the distance through the atmosphere from the sample point to the sun
1481
1481
source += " rq = dot(atmSamplePoint, " + LightProperty(0, "direction") + ");\n";
1482
1482
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";
1484
1484
source += " float distSun = -rq + d;\n";
1485
1485
1486
1486
// Compute the density of the atmosphere at the sample point; it falls off exponentially
@@ -1987,7 +1987,7 @@ ShaderManager::buildVertexShader(const ShaderProperties& props)
1987
1987
// Compute the intersection of the sun direction and the cloud layer (currently assumed to be a sphere)
1988
1988
source += " float rq = dot(" + LightProperty(j, "direction") + ", in_Position.xyz);\n";
1989
1989
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";
1991
1991
source += " vec3 cloudSpherePos = (in_Position.xyz + (-rq + d) * " + LightProperty(j, "direction") + ");\n";
1992
1992
//source += " vec3 cloudSpherePos = in_Position.xyz;\n";
1993
1993
0 commit comments