2
* Copyright (C) 2003 Fabien Chereau
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
// Class which computes the daylight sky color
20
// Fast implementation of the algorithm from the article
21
// "A Practical Analytic Model for Daylight" by A. J. Preetham, Peter Shirley and Brian Smits.
27
float zenith_angle; // zenith_angle : angular distance to the zenith in radian
28
float dist_sun; // dist_sun : angular distance to the sun in radian
29
float color[3]; // 3 component color, can be RGB or CIE color system
33
float pos[3]; // Vector to the position (vertical = pos[2])
34
float color[3]; // 3 component color, can be RGB or CIE color system
42
// Set the fixed parameters and precompute what can be
43
// This funtion has to be called once before any call to get_*_value()
44
void set_params(float sun_zenith_angle, float turbidity);
45
// Compute the sky color at the given position in the xyY color system and store it in position.color
46
inline void get_xyY_value(skylight_struct * position);
47
// Return the current zenith color
48
inline void get_zenith_color(float * v) const;
50
// Same functions but in vector mode : faster because prevents extra cosine calculations
51
// The position vectors MUST be normalized, and the vertical z component is the third one
52
void set_paramsv(const float * sun_pos, float turbidity);
53
void get_xyY_valuev(skylight_struct2& position);
56
float thetas; // angular distance between the zenith and the sun in radian
57
float T; // Turbidity : i.e. sky "clarity"
59
// 2 : exceptionnally clear
65
// Computed variables depending on the 2 above
66
float zenith_luminance; // Y color component of the CIE color at zenith (luminance)
67
float zenith_color_x; // x color component of the CIE color at zenith
68
float zenith_color_y; // y color component of the CIE color at zenith
70
float eye_lum_conversion; // luminance conversion for an eye adapted to screen luminance (around 40 cd/m^2)
72
float AY, BY, CY, DY, EY; // Distribution coefficients for the luminance distribution function
73
float Ax, Bx, Cx, Dx, Ex; // Distribution coefficients for x distribution function
74
float Ay, By, Cy, Dy, Ey; // Distribution coefficients for y distribution function
76
float term_x; // Precomputed term for x calculation
77
float term_y; // Precomputed term for y calculation
78
float term_Y; // Precomputed term for luminance calculation
82
// Compute CIE Y (luminance) for zenith in cd/m^2
83
inline void compute_zenith_luminance(void);
84
// Compute CIE x and y color components
85
inline void compute_zenith_color(void);
86
// Compute the luminance distribution coefficients
87
inline void compute_luminance_distribution_coefs(void);
88
// Compute the color distribution coefficients
89
inline void compute_color_distribution_coefs(void);
93
#endif // _SKYLIGHT_H_