Skylight.cpp   Skylight.cpp 
skipping to change at line 28 skipping to change at line 28
// Class which compute the daylight sky color // Class which compute 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.
#include "Skylight.hpp" #include "Skylight.hpp"
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
/// Compute acos(x)
inline float fastAcos(float x)
{
return M_PI/2.f - (
x + 1.f/6.f * x*x*x + 3.f/40.f *
x*x*x*x*x +
5.f/112.f * x*x*x*x*x*x*x
);
}
Skylight::Skylight() : thetas(0.f), T(0.f) Skylight::Skylight() : thetas(0.f), T(0.f)
{ {
} }
Skylight::~Skylight() Skylight::~Skylight()
{ {
} }
void Skylight::setParams(float _sunZenithAngle, float _turbidity) void Skylight::setParams(float _sunZenithAngle, float _turbidity)
{ {
skipping to change at line 88 skipping to change at line 79
computeZenithColor(); computeZenithColor();
computeLuminanceDistributionCoefs(); computeLuminanceDistributionCoefs();
computeColorDistributionCoefs(); computeColorDistributionCoefs();
// Precompute everything possible to increase the get_CIE_value() fu nction speed // Precompute everything possible to increase the get_CIE_value() fu nction speed
float cos_thetas = sunPos[2]; float cos_thetas = sunPos[2];
term_x = zenithColorX / ((1.f + Ax * std::exp(Bx)) * (1.f + Cx * s td::exp(Dx*thetas) + Ex * cos_thetas * cos_thetas)); term_x = zenithColorX / ((1.f + Ax * std::exp(Bx)) * (1.f + Cx * s td::exp(Dx*thetas) + Ex * cos_thetas * cos_thetas));
term_y = zenithColorY / ((1.f + Ay * std::exp(By)) * (1.f + Cy * s td::exp(Dy*thetas) + Ey * cos_thetas * cos_thetas)); term_y = zenithColorY / ((1.f + Ay * std::exp(By)) * (1.f + Cy * s td::exp(Dy*thetas) + Ey * cos_thetas * cos_thetas));
term_Y = zenithLuminance / ((1.f + AY * std::exp(BY)) * (1.f + CY * std::exp(DY*thetas) + EY * cos_thetas * cos_thetas)); term_Y = zenithLuminance / ((1.f + AY * std::exp(BY)) * (1.f + CY * std::exp(DY*thetas) + EY * cos_thetas * cos_thetas));
} }
// Compute the sky color at the given position in the CIE color system and
store it in p.color
// p.color[0] is CIE x color component
// p.color[1] is CIE y color component
// p.color[2] is CIE Y color component (luminance)
// void Skylight::getxyYValue(skylightStruct * p)
// {
// float cosDistSun = std::cos(p->distSun);
// float oneOverCosZenithAngle = 1.f/std::cos(p->zenithAngle);
// p->color[0] = term_x * (1.f + Ax * std::exp(Bx * oneOverCosZenithAng
le)) * (1.f + Cx * std::exp(Dx*p->distSun) +
// Ex * cosDistSun * cosDistSun);
// p->color[1] = term_y * (1.f + Ay * std::exp(By * oneOverCosZenithAng
le)) * (1.f + Cy * std::exp(Dy*p->distSun) +
// Ey * cosDistSun * cosDistSun);
// p->color[2] = term_Y * (1.f + AY * std::exp(BY * oneOverCosZenithAng
le)) * (1.f + CY * std::exp(DY*p->distSun) +
// EY * cosDistSun * cosDistSun);
// }
// Compute the sky color at the given position in the CIE color system and
store it in p.color
// p.color[0] is CIE x color component
// p.color[1] is CIE y color component
// p.color[2] is CIE Y color component (luminance)
void Skylight::getxyYValuev(skylightStruct2& p) const
{
float cosDistSun = sunPos[0]*p.pos[0]
+ sunPos[1]*p.pos[1]
+ sunPos[2]*p.pos[2];
float distSun;
if (cosDistSun <= -1.f ) {cosDistSun = -1.f;distSun = M_PI;}
else if (cosDistSun >= 1.f ) {cosDistSun = 1.f;distSun = 0.f;}
else distSun = fastAcos(cosDistSun);
const float cosDistSun_q = cosDistSun*cosDistSun;
float Fx = 0.f;
float Fy = 0.f;
float FY = 0.f;
if (p.pos[2] > 0.f) {
float oneOverCosZenithAngle = 1.f / p.pos[2];
Fx = std::exp(Bx*oneOverCosZenithAngle);
Fy = std::exp(By*oneOverCosZenithAngle);
FY = std::exp(BY*oneOverCosZenithAngle);
}
p.color[0] = term_x * (1.f + Ax * Fx)
* (1.f + Cx * std::exp(Dx*distSun) + Ex * cosDis
tSun_q);
p.color[1] = term_y * (1.f + Ay * Fy)
* (1.f + Cy * std::exp(Dy*distSun) + Ey * cosDis
tSun_q);
p.color[2] = term_Y * (1.f + AY * FY)
* (1.f + CY * std::exp(DY*distSun) + EY * cosDis
tSun_q);
if (p.color[2] < 0 || p.color[0] < 0 || p.color[1] < 0)
{
p.color[0] = 0.25;
p.color[1] = 0.25;
p.color[2] = 0;
}
}
 End of changes. 2 change blocks. 
10 lines changed or deleted 0 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/