Skip to content

Commit 8bd8cac

Browse files
committed
Add a workaround for Intel's garbage GLSL sin & cos
The imprecision of the hardward implementation of sin leads to broken geometry of the Moon every 0.9° of elevation.
1 parent 917e860 commit 8bd8cac

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/core/RefractionExtinction.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ QByteArray Refraction::getForwardTransformShader() const
282282
{
283283
return QByteArray(1+R"(
284284
uniform float REFRACTION_press_temp_corr;
285+
// Workaround for Intel's unusable implementation of sin & cos, which leads to broken geometry of the Moon every 0.9° of elevation.
286+
float REFRACTION_sin(float x)
287+
{
288+
const float PI = 3.14159265;
289+
x = mod(x+PI, 2*PI)-PI;
290+
return x*(0.999999599920672 + x*x*(-0.166665526354071 + x*x*(0.00833240298869917 + x*x*(-0.0001980863334175 + x*x*(2.69971463693744e-6 - 2.03622449118901e-8*x*x)))));
291+
}
285292
vec3 innerRefractionForward(vec3 altAzPos)
286293
{
287294
const float PI = 3.14159265;
@@ -321,7 +328,7 @@ vec3 innerRefractionForward(vec3 altAzPos)
321328
// We have to shorten X,Y components of the vector as well by the change in cosines of altitude, or (sqrt(1-sin(alt))
322329
323330
float refr_alt_rad=geom_alt_deg*M_PI_180;
324-
float sinRef=sin(refr_alt_rad);
331+
float sinRef = REFRACTION_sin(refr_alt_rad);
325332
326333
// FIXME: do we really need double's mantissa length here as a comment in the C++ code says?
327334
float shortenxy = abs(sinGeo)>=1.0 ? 1.0 : sqrt((1.-sinRef*sinRef)/(1.-sinGeo*sinGeo));

0 commit comments

Comments
 (0)