Skip to content

Commit 0519773

Browse files
committed
fix garbage implementation of asin on Intel and AMD GPUs
1 parent c32519b commit 0519773

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/core/RefractionExtinction.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ float REFRACTION_sin(float x)
289289
x = mod(x+PI, 2.0*PI)-PI;
290290
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)))));
291291
}
292+
// Workaround for Intel's and AMD's unusable implementation of asin, which leads to time-dependent shifts of the Moon from its refracted positions.
293+
float REFRACTION_asin(float x)
294+
{
295+
float sign = x < 0 ? -1 : 1;
296+
if(x < 0) x = -x;
297+
x = 2 * sqrt(1 - x) - 1;
298+
return 0.848061881596496 + x*(-0.755929497461161 + x*(-0.0539853235799928 + x*(-0.025701166121295 + x*(-0.00723634508887381 +
299+
x*(-0.00314276748524976 + x*(-0.00101365621070969 + x*(-0.000411380592372285 + x*(-0.000428167561924693 - 0.000213293541786718*x))))))));
300+
}
292301
vec3 innerRefractionForward(vec3 altAzPos)
293302
{
294303
const float PI = 3.14159265;
@@ -307,7 +316,7 @@ vec3 innerRefractionForward(vec3 altAzPos)
307316
}
308317
309318
float sinGeo = altAzPos[2]/len;
310-
float geom_alt_rad = asin(sinGeo);
319+
float geom_alt_rad = REFRACTION_asin(sinGeo);
311320
float geom_alt_deg = M_180_PI*geom_alt_rad;
312321
if (geom_alt_deg > MIN_GEO_ALTITUDE_DEG)
313322
{

0 commit comments

Comments
 (0)