11// Configurable parameters
2+ struct SkySettings {
3+ float sunElevationDeg;
4+ int month;
5+ float altitude;
6+ int aerosol;
7+
8+ vec4 groundAlbedo;
9+
10+ float aerosolTurbidity;
11+ int resolution;
12+ bool useForIBL;
13+ int updateType;
14+ };
215
316#define ANIMATE_SUN 0
4- // 0=equirectangular, 1=fisheye, 2=projection
5- #define CAMERA_TYPE 2
17+
618// 0=Background, 1=Desert Dust, 2=Maritime Clean, 3=Maritime Mineral,
719// 4=Polar Antarctic, 5=Polar Artic, 6=Remote Continental, 7=Rural, 8=Urban
820#define AEROSOL_TYPE 8
921
10- const float SUN_ELEVATION_DEGREES = 0.0 ; // 0=horizon, 90=zenith
11- const float EYE_ALTITUDE = 0.5 ; // km
12- const int MONTH = 0 ; // 0-11, January to December
1322const float AEROSOL_TURBIDITY = 1.0 ;
14- const vec4 GROUND_ALBEDO = vec4 (0.3 );
1523
1624// Ray marching steps. More steps mean better accuracy but worse performance
1725const int TRANSMITTANCE_STEPS = 32 ;
@@ -49,9 +57,8 @@ const float gg = g*g;
4957const float EARTH_RADIUS = 6371.0 ; // km
5058const float ATMOSPHERE_THICKNESS = 100.0 ; // km
5159const float ATMOSPHERE_RADIUS = EARTH_RADIUS + ATMOSPHERE_THICKNESS;
52- const float EYE_DISTANCE_TO_EARTH_CENTER = EARTH_RADIUS + EYE_ALTITUDE;
53- const float SUN_ZENITH_COS_ANGLE = cos (radians (90.0 - SUN_ELEVATION_DEGREES));
54- const vec3 SUN_DIR = vec3 (- sqrt (1.0 - SUN_ZENITH_COS_ANGLE* SUN_ZENITH_COS_ANGLE), 0.0 , SUN_ZENITH_COS_ANGLE);
60+
61+
5562
5663#if ENABLE_SPECTRAL == 1
5764// Extraterrestial Solar Irradiance Spectra, units W * m^-2 * nm^-1
@@ -162,14 +169,10 @@ const float aerosol_background_divided_by_base_density = aerosol_background_dens
162169
163170// -----------------------------------------------------------------------------
164171
165- vec3 get_sun_direction(float time )
172+ vec3 get_sun_direction(float sunElevationDeg )
166173{
167- #if ANIMATE_SUN == 0
168- return SUN_DIR;
169- #else
170- float a = sin (time* 0.5 - 1.5 ) * 0.55 + 0.45 ;
171- return vec3 (- sqrt (1.0 - a* a), 0.0 , a);
172- #endif
174+ float sunZenithCosAngle = cos (radians (90.0 - sunElevationDeg));
175+ return vec3 (- sqrt (1.0 - sunZenithCosAngle* sunZenithCosAngle), 0.0 , sunZenithCosAngle);
173176}
174177
175178/*
@@ -216,7 +219,7 @@ float aerosol_phase_function(float cos_theta)
216219 return INV_4PI * (1.0 - gg) / (den * sqrt (den));
217220}
218221
219- vec4 get_multiple_scattering(sampler2D transmittance_lut, float cos_theta, float normalized_height, float d)
222+ vec4 get_multiple_scattering(sampler2D transmittance_lut, vec4 groundAlbedo, float cos_theta, float normalized_height, float d)
220223{
221224#if ENABLE_MULTIPLE_SCATTERING == 1
222225 // Solid angle subtended by the planet from a point at d distance
@@ -230,7 +233,7 @@ vec4 get_multiple_scattering(sampler2D transmittance_lut, float cos_theta, float
230233 transmittance_from_lut(transmittance_lut, 1.0 , normalized_height);
231234
232235 // 2nd order scattering from the ground
233- vec4 L_ground = PHASE_ISOTROPIC * omega * (GROUND_ALBEDO / PI) * T_to_ground * T_ground_to_sample * cos_theta;
236+ vec4 L_ground = PHASE_ISOTROPIC * omega * (groundAlbedo / PI) * T_to_ground * T_ground_to_sample * cos_theta;
234237
235238 // Fit of Earth's multiple scattering coming from other points in the atmosphere
236239 vec4 L_ms = 0.02 * vec4 (0.217 , 0.347 , 0.594 , 1.0 ) * (1.0 / (1.0 + 5.0 * exp (- 17.92 * cos_theta)));
@@ -254,12 +257,12 @@ vec4 get_molecular_scattering_coefficient(float h)
254257 * Return the molecular volume absorption coefficient (km^-1) for a given altitude
255258 * in kilometers.
256259 */
257- vec4 get_molecular_absorption_coefficient(float h)
260+ vec4 get_molecular_absorption_coefficient(float h, int month )
258261{
259262 h += 1e-4 ; // Avoid division by 0
260263 float t = log (h) - 3.22261 ;
261264 float density = 3.78547397e20 * (1.0 / h) * exp (- t * t * 5.55555555 );
262- return ozone_absorption_cross_section * ozone_mean_monthly_dobson[MONTH ] * density;
265+ return ozone_absorption_cross_section * ozone_mean_monthly_dobson[month ] * density;
263266}
264267
265268float get_aerosol_density(float h)
@@ -277,6 +280,8 @@ float get_aerosol_density(float h)
277280 * atmospheric medium for a given point at an altitude h.
278281 */
279282void get_atmosphere_collision_coefficients(in float h,
283+ in int month,
284+ in float turbidity,
280285 out vec4 aerosol_absorption,
281286 out vec4 aerosol_scattering,
282287 out vec4 molecular_absorption,
@@ -289,10 +294,10 @@ void get_atmosphere_collision_coefficients(in float h,
289294 aerosol_scattering = vec4 (0.0 );
290295#else
291296 float aerosol_density = get_aerosol_density(h);
292- aerosol_absorption = aerosol_absorption_cross_section * aerosol_density * AEROSOL_TURBIDITY ;
293- aerosol_scattering = aerosol_scattering_cross_section * aerosol_density * AEROSOL_TURBIDITY ;
297+ aerosol_absorption = aerosol_absorption_cross_section * aerosol_density * turbidity ;
298+ aerosol_scattering = aerosol_scattering_cross_section * aerosol_density * turbidity ;
294299#endif
295- molecular_absorption = get_molecular_absorption_coefficient(h);
300+ molecular_absorption = get_molecular_absorption_coefficient(h, month );
296301 molecular_scattering = get_molecular_scattering_coefficient(h);
297302 extinction = aerosol_absorption + aerosol_scattering + molecular_absorption + molecular_scattering;
298303}
0 commit comments