23 #ifndef _SKYLIGHT_HPP_
24 #define _SKYLIGHT_HPP_
28 #include "StelUtils.hpp"
48 void setParams(
float sunZenithAngle,
float turbidity);
52 inline void getZenithColor(
float * v)
const;
56 void setParamsv(
const float * sunPos,
float turbidity);
64 const float cosDistSun = sunPos[0]*p.pos[0] + sunPos[
1]*p.pos[
1] + sunPos[2]*p.pos[2];
66 const float cosDistSun_q = cosDistSun*cosDistSun;
68 Q_ASSERT(p.pos[2] >= 0.f);
69 const float oneOverCosZenithAngle = (p.pos[2]==0.) ? 1e99 :
1.f / p.pos[2];
70 p.color[0] = term_x * (
1.f + Ax * std::exp(Bx*oneOverCosZenithAngle))
71 * (
1.f + Cx * std::exp(Dx*distSun) + Ex * cosDistSun_q);
73 p.color[
1] = term_y * (
1.f + Ay * std::exp(By*oneOverCosZenithAngle))
74 * (
1.f + Cy * std::exp(Dy*distSun) + Ey * cosDistSun_q);
80 if (p.color[0] < 0. || p.color[
1] < 0.)
88 void getShadersParams(
Vec3f& asunPos,
float& aterm_x,
float& aAx,
float& aBx,
float& aCx,
float& aDx,
float& aEx,
89 float& aterm_y,
float& aAy,
float& aBy,
float& aCy,
float& aDy,
float& aEy)
const
92 aterm_x=term_x;aAx=Ax;aBx=Bx;aCx=Cx;aDx=Dx;aEx=Ex;
93 aterm_y=term_y;aAy=Ay;aBy=By;aCy=Cy;aDy=Dy;aEy=Ey;
109 float zenithLuminance;
113 float eyeLumConversion;
116 float AY, BY, CY, DY, EY;
117 float Ax, Bx, Cx, Dx, Ex;
118 float Ay, By, Cy, Dy, Ey;
127 inline void computeZenithLuminance(
void);
129 inline void computeZenithColor(
void);
131 inline void computeLuminanceDistributionCoefs(
void);
133 inline void computeColorDistributionCoefs(
void);
137 inline void Skylight::getZenithColor(
float * v)
const
141 v[2] = zenithLuminance;
145 inline void Skylight::computeZenithLuminance(
void)
147 zenithLuminance = 1000.f * ((4.0453f*T - 4.9710f) * std::tan( (0.4444f - T/120.f) * (M_PI-2.f*thetas) ) -
148 0.2155f*T + 2.4192f);
149 if (zenithLuminance<=0.f) zenithLuminance=0.00000000001;
154 inline void Skylight::computeZenithColor(
void)
156 static float thetas2;
157 static float thetas3;
160 thetas2 = thetas * thetas;
161 thetas3 = thetas2 * thetas;
164 zenithColorX = ( 0.00216f*thetas3 - 0.00375f*thetas2 + 0.00209f*thetas) * T2 +
165 (-0.02903f*thetas3 + 0.06377f*thetas2 - 0.03202f*thetas + 0.00394f) * T +
166 ( 0.10169f*thetas3 - 0.21196f*thetas2 + 0.06052f*thetas + 0.25886f);
168 zenithColorY = ( 0.00275f*thetas3 - 0.00610f*thetas2 + 0.00317f*thetas) * T2 +
169 (-0.04214f*thetas3 + 0.08970f*thetas2 - 0.04153f*thetas + 0.00516f) * T +
170 ( 0.14535f*thetas3 - 0.26756f*thetas2 + 0.06670f*thetas + 0.26688f);
176 inline void Skylight::computeLuminanceDistributionCoefs(
void)
178 AY = 0.2787f*T -
1.0630f;
179 BY =-0.3554f*T + 0.4275f;
180 CY =-0.0227f*T + 6.3251f;
181 DY = 0.1206f*T - 2.5771f;
182 EY =-0.0670f*T + 0.3703f;
189 inline void Skylight::computeColorDistributionCoefs(
void)
191 Ax =-0.0148f*T - 0.1703f;
192 Bx =-0.0664f*T + 0.0011f;
193 Cx =-0.0005f*T + 0.2127f;
194 Dx =-0.0641f*T - 0.8992f;
195 Ex =-0.0035f*T + 0.0453f;
197 Ay =-0.0131f*T - 0.2498f;
198 By =-0.0951f*T + 0.0092f;
199 Cy =-0.0082f*T + 0.2404f;
200 Dy =-0.0438f*T -
1.0539f;
201 Ey =-0.0109f*T + 0.0531f;
208 #endif // _SKYLIGHT_H_