Skylight.hpp   Skylight.hpp
skipping to change at line 28 skipping to change at line 28
// Class which computes the daylight sky color // Class which computes the daylight sky color
// Fast implementation of the algorithm from the article // Fast implementation of the algorithm from the article
// "A Practical Analytic Model for Daylight" by A. J. Preetham, Peter Shirl ey and Brian Smits. // "A Practical Analytic Model for Daylight" by A. J. Preetham, Peter Shirl ey and Brian Smits.
#ifndef _SKYLIGHT_HPP_ #ifndef _SKYLIGHT_HPP_
#define _SKYLIGHT_HPP_ #define _SKYLIGHT_HPP_
#include <cmath> #include <cmath>
#include <QDebug> #include <QDebug>
#include "StelUtils.hpp"
typedef struct { typedef struct {
float zenithAngle; // zenithAngle : angular distance to the zenith in radian float zenithAngle; // zenithAngle : angular distance to the zenith in radian
float distSun; // distSun : angular distance to the sun in radian float distSun; // distSun : angular distance to the sun in radian
float color[3]; // 3 component color, can be RGB or CIE color sy stem float color[3]; // 3 component color, can be RGB or CIE color sy stem
} skylightStruct; } skylightStruct;
typedef struct { typedef struct {
float pos[3]; // Vector to the position (vertical = pos[2]) float pos[3]; // Vector to the position (vertical = pos[2])
float color[3]; // 3 component color, can be RGB or CIE color sy stem float color[3]; // 3 component color, can be RGB or CIE color sy stem
} skylightStruct2; } skylightStruct2;
class Skylight class Skylight
{ {
public: public:
Skylight(); Skylight();
virtual ~Skylight(); virtual ~Skylight();
// Set the fixed parameters and precompute what can be // Set the fixed parameters and precompute what can be
// This fun() // This function has to be called once before any call to get_*_valu e()
void setParams(float sunZenithAngle, float turbidity); void setParams(float sunZenithAngle, float turbidity);
// Compute the sky color at the given position in the xyY color syst em and store it in position.color // Compute the sky color at the given position in the xyY color syst em and store it in position.color
// void getxyYValue(skylightStruct * position); // void getxyYValue(skylightStruct * position);
// Return the current zenith color // Return the current zenith color
inline void getZenithColor(float * v) const; inline void getZenithColor(float * v) const;
// Same functions but in vector mode : faster because prevents extra cosine calculations // Same functions but in vector mode : faster because prevents extra cosine calculations
// The position vectors MUST be normalized, and the vertical z compo nent is the third one // The position vectors MUST be normalized, and the vertical z compo nent is the third one
void setParamsv(const float * sunPos, float turbidity); void setParamsv(const float * sunPos, float turbidity);
// Compute the sky color at the given position in the CIE color syst em and store it in p.color // Compute the sky color at the given position in the CIE color syst em and store it in p.color
// p.color[0] is CIE x color component // p.color[0] is CIE x color component
// p.color[1] is CIE y color component // p.color[1] is CIE y color component
// p.color[2] is ) // p.color[2] is undefined (CIE Y color component (luminance) if unc ommented)
void getxyYValuev(skylightStruct2& p) const void getxyYValuev(skylightStruct2& p) const
{ {
const float cosDistSun = sunPos[0]*p.pos[0] + sunPos[1]*p.po s[1] + sunPos[2]*p.pos[2]; const float cosDistSun = sunPos[0]*p.pos[0] + sunPos[1]*p.po s[1] + sunPos[2]*p.pos[2];
const float distSun = fastAcos(cosDistSun); const float distSun = StelUtils::fastAcos(cosDistSun);
const float cosDistSun_q = cosDistSun*cosDistSun; const float cosDistSun_q = cosDistSun*cosDistSun;
Q_ASSERT(p.pos[2] >= 0.f); Q_ASSERT(p.pos[2] >= 0.f);
const float oneOverCosZenithAngle = (p.pos[2]==0.) ? 1e99 : 1.f / p.pos[2]; const float oneOverCosZenithAngle = (p.pos[2]==0.) ? 1e99 : 1.f / p.pos[2];
p.color[0] = term_x * (1.f + Ax * std::exp(Bx*oneOverCosZeni thAngle)) p.color[0] = term_x * (1.f + Ax * std::exp(Bx*oneOverCosZeni thAngle))
* (1.f + Cx * std::exp(Dx*distSun) + Ex * co sDistSun_q); * (1.f + Cx * std::exp(Dx*distSun) + Ex * co sDistSun_q);
p.color[1] = term_y * (1.f + Ay * std::exp(By*oneOverCosZeni thAngle)) p.color[1] = term_y * (1.f + Ay * std::exp(By*oneOverCosZeni thAngle))
* (1.f + Cy * std::exp(Dy*distSun) + Ey * co sDistSun_q); * (1.f + Cy * std::exp(Dy*distSun) + Ey * co sDistSun_q);
p.color[2] = term_Y * (1.f + AY * std::exp(BY*oneOverCosZeni // p.color[2] = term_Y * (1.f + AY * std::exp(BY*oneOverCosZeni
thAngle)) thAngle))
* (1.f + CY * std::exp(DY*distSun) + EY * co // * (1.f + CY * std::exp(DY*distSun) + EY * co
sDistSun_q); sDistSun_q);
if (.) if (/*p.color[2] < 0. || */p.color[0] < 0. || p.color[1] < 0 .)
{ {
p.color[0] = 0.25; p.color[0] = 0.25;
p.color[1] = 0.25; p.color[1] = 0.25;
p.color[2] = 0.; p.color[2] = 0.;
} }
} }
void getShadersParams(Vec3f& asunPos, float& aterm_x, float& aAx, fl
oat& aBx, float& aCx, float& aDx, float& aEx,
float& aterm_y, float& aAy, float& aBy, float& aCy, float& a
Dy, float& aEy) const
{
asunPos=sunPos;
}
private: private:
float thetas; // angular distance between the zenith and the sun in radian float thetas; // angular distance between the zenith and the sun in radian
float T; // Turbidity : i.e. sky "clarity" float T; // Turbidity : i.e. sky "clarity"
// 1 : pure air // 1 : pure air
// 2 : exceptionnally clear // 2 : exceptionnally clear
// 4 : clear // 4 : clear
// 8 : light haze // 8 : light haze
// 25 : haze // 25 : haze
// 64 : thin fog // 64 : thin fog
skipping to change at line 122 skipping to change at line 131
float sunPos[3]; float sunPos[3];
// Compute CIE Y (luminance) for zenith in cd/m^2 // Compute CIE Y (luminance) for zenith in cd/m^2
inline void computeZenithLuminance(void); inline void computeZenithLuminance(void);
// Compute CIE x and y color components // Compute CIE x and y color components
inline void computeZenithColor(void); inline void computeZenithColor(void);
// Compute the luminance distribution coefficients // Compute the luminance distribution coefficients
inline void computeLuminanceDistributionCoefs(void); inline void computeLuminanceDistributionCoefs(void);
// Compute the color distribution coefficients // Compute the color distribution coefficients
inline void computeColorDistributionCoefs(void); inline void computeColorDistributionCoefs(void);
}; };
// Return the current zenith color in xyY color system // Return the current zenith color in xyY color system
inline void Skylight::getZenithColor(float * v) const inline void Skylight::getZenithColor(float * v) const
{ {
v[0] = zenithColorX; v[0] = zenithColorX;
v[1] = zenithColorY; v[1] = zenithColorY;
v[2] = zenithLuminance; v[2] = zenithLuminance;
} }
End of changes. 8 change blocks.
16 lines changed or deleted 19 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/