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);