23 #ifndef _SKYLIGHT_HPP_ 24 #define _SKYLIGHT_HPP_ 26 #include "StelUtils.hpp" 49 void setParams(
float sunZenithAngle,
float turbidity);
53 inline void getZenithColor(
float * v)
const;
57 void setParamsv(
const float * sunPos,
float turbidity);
65 const float cosDistSun = sunPos[0]*p.pos[0] + sunPos[1]*p.pos[1] + sunPos[2]*p.pos[2];
67 const float cosDistSun_q = cosDistSun*cosDistSun;
69 Q_ASSERT(p.pos[2] >= 0.f);
70 const float oneOverCosZenithAngle = (p.pos[2]==0.) ? 1e99 : 1.f / p.pos[2];
71 p.color[0] = term_x * (1.f + Ax * std::exp(Bx*oneOverCosZenithAngle))
72 * (1.f + Cx * std::exp(Dx*distSun) + Ex * cosDistSun_q);
74 p.color[1] = term_y * (1.f + Ay * std::exp(By*oneOverCosZenithAngle))
75 * (1.f + Cy * std::exp(Dy*distSun) + Ey * cosDistSun_q);
81 if (p.color[0] < 0. || p.color[1] < 0.)
89 void getShadersParams(
Vec3f& asunPos,
float& aterm_x,
float& aAx,
float& aBx,
float& aCx,
float& aDx,
float& aEx,
90 float& aterm_y,
float& aAy,
float& aBy,
float& aCy,
float& aDy,
float& aEy)
const 93 aterm_x=term_x;aAx=Ax;aBx=Bx;aCx=Cx;aDx=Dx;aEx=Ex;
94 aterm_y=term_y;aAy=Ay;aBy=By;aCy=Cy;aDy=Dy;aEy=Ey;
110 float zenithLuminance;
114 float eyeLumConversion;
117 float AY, BY, CY, DY, EY;
118 float Ax, Bx, Cx, Dx, Ex;
119 float Ay, By, Cy, Dy, Ey;
128 inline void computeZenithLuminance(
void);
130 inline void computeZenithColor(
void);
132 inline void computeLuminanceDistributionCoefs(
void);
134 inline void computeColorDistributionCoefs(
void);
138 inline void Skylight::getZenithColor(
float * v)
const 142 v[2] = zenithLuminance;
146 inline void Skylight::computeZenithLuminance(
void)
148 zenithLuminance = 1000.f * ((4.0453f*T - 4.9710f) * std::tan( (0.4444f - T/120.f) * (M_PI-2.f*thetas) ) -
149 0.2155f*T + 2.4192f);
150 if (zenithLuminance<=0.f) zenithLuminance=0.00000000001;
155 inline void Skylight::computeZenithColor(
void)
157 static float thetas2;
158 static float thetas3;
161 thetas2 = thetas * thetas;
162 thetas3 = thetas2 * thetas;
165 zenithColorX = ( 0.00216f*thetas3 - 0.00375f*thetas2 + 0.00209f*thetas) * T2 +
166 (-0.02903f*thetas3 + 0.06377f*thetas2 - 0.03202f*thetas + 0.00394f) * T +
167 ( 0.10169f*thetas3 - 0.21196f*thetas2 + 0.06052f*thetas + 0.25886f);
169 zenithColorY = ( 0.00275f*thetas3 - 0.00610f*thetas2 + 0.00317f*thetas) * T2 +
170 (-0.04214f*thetas3 + 0.08970f*thetas2 - 0.04153f*thetas + 0.00516f) * T +
171 ( 0.14535f*thetas3 - 0.26756f*thetas2 + 0.06670f*thetas + 0.26688f);
177 inline void Skylight::computeLuminanceDistributionCoefs(
void)
179 AY = 0.2787f*T - 1.0630f;
180 BY =-0.3554f*T + 0.4275f;
181 CY =-0.0227f*T + 6.3251f;
182 DY = 0.1206f*T - 2.5771f;
183 EY =-0.0670f*T + 0.3703f;
190 inline void Skylight::computeColorDistributionCoefs(
void)
192 Ax =-0.0148f*T - 0.1703f;
193 Bx =-0.0664f*T + 0.0011f;
194 Cx =-0.0005f*T + 0.2127f;
195 Dx =-0.0641f*T - 0.8992f;
196 Ex =-0.0035f*T + 0.0453f;
198 Ay =-0.0131f*T - 0.2498f;
199 By =-0.0951f*T + 0.0092f;
200 Cy =-0.0082f*T + 0.2404f;
201 Dy =-0.0438f*T - 1.0539f;
202 Ey =-0.0109f*T + 0.0531f;
209 #endif // _SKYLIGHT_H_
float fastAcos(const float x)
Compute acos(x) The taylor serie is not accurate around x=1 and x=-1.