Blender V4.3
sky_model.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012-2013 Lukas Hosek and Alexander Wilkie. All rights reserved.
2 *
3 * SPDX-License-Identifier: BSD-3-Clause */
4
5/* ============================================================================
6
7This file is part of a sample implementation of the analytical skylight and
8solar radiance models presented in the SIGGRAPH 2012 paper
9
10
11 "An Analytic Model for Full Spectral Sky-Dome Radiance"
12
13and the 2013 IEEE CG&A paper
14
15 "Adding a Solar Radiance Function to the Hosek Skylight Model"
16
17 both by
18
19 Lukas Hosek and Alexander Wilkie
20 Charles University in Prague, Czech Republic
21
22
23 Version: 1.4a, February 22nd, 2013
24
25Version history:
26
271.4a February 22nd, 2013
28 Removed unnecessary and counter-intuitive solar radius parameters
29 from the interface of the colourspace sky dome initialization functions.
30
311.4 February 11th, 2013
32 Fixed a bug which caused the relative brightness of the solar disc
33 and the sky dome to be off by a factor of about 6. The sun was too
34 bright: this affected both normal and alien sun scenarios. The
35 coefficients of the solar radiance function were changed to fix this.
36
371.3 January 21st, 2013 (not released to the public)
38 Added support for solar discs that are not exactly the same size as
39 the terrestrial sun. Also added support for suns with a different
40 emission spectrum ("Alien World" functionality).
41
421.2a December 18th, 2012
43 Fixed a mistake and some inaccuracies in the solar radiance function
44 explanations found in ArHosekSkyModel.h. The actual source code is
45 unchanged compared to version 1.2.
46
471.2 December 17th, 2012
48 Native RGB data and a solar radiance function that matches the turbidity
49 conditions were added.
50
511.1 September 2012
52 The coefficients of the spectral model are now scaled so that the output
53 is given in physical units: W / (m^-2 * sr * nm). Also, the output of the
54 XYZ model is now no longer scaled to the range [0...1]. Instead, it is
55 the result of a simple conversion from spectral data via the CIE 2 degree
56 standard observer matching functions. Therefore, after multiplication
57 with 683 lm / W, the Y channel now corresponds to luminance in lm.
58
591.0 May 11th, 2012
60 Initial release.
61
62
63Please visit http://cgg.mff.cuni.cz/projects/SkylightModelling/ to check if
64an updated version of this code has been published!
65
66============================================================================ */
67
68/*
69
70This code is taken from ART, a rendering research system written in a
71mix of C99 / Objective C. Since ART is not a small system and is intended to
72be inter-operable with other libraries, and since C does not have namespaces,
73the structures and functions in ART all have to have somewhat wordy
74canonical names that begin with Ar.../ar..., like those seen in this example.
75
76Usage information:
77==================
78
79
80Model initialization
81--------------------
82
83A separate ArHosekSkyModelState has to be maintained for each spectral
84band you want to use the model for. So in a renderer with 'num_channels'
85bands, you would need something like
86
87 ArHosekSkyModelState * skymodel_state[num_channels];
88
89You then have to allocate and initialize these states. In the following code
90snippet, we assume that 'albedo' is defined as
91
92 double albedo[num_channels];
93
94with a ground albedo value between [0,1] for each channel. The solar elevation
95is given in radians.
96
97 for ( unsigned int i = 0; i < num_channels; i++ )
98 skymodel_state[i] =
99 arhosekskymodelstate_alloc_init(
100 turbidity,
101 albedo[i],
102 solarElevation
103 );
104
105Note that starting with version 1.3, there is also a second initialization
106function which generates skydome states for different solar emission spectra
107and solar radii: 'arhosekskymodelstate_alienworld_alloc_init()'.
108
109See the notes about the "Alien World" functionality provided further down for a
110discussion of the usefulness and limits of that second initialization function.
111Sky model states that have been initialized with either function behave in a
112completely identical fashion during use and cleanup.
113
114Using the model to generate skydome samples
115-------------------------------------------
116
117Generating a skydome radiance spectrum "skydome_result" for a given location
118on the skydome determined via the angles theta and gamma works as follows:
119
120 double skydome_result[num_channels];
121
122 for ( unsigned int i = 0; i < num_channels; i++ )
123 skydome_result[i] =
124 arhosekskymodel_radiance(
125 skymodel_state[i],
126 theta,
127 gamma,
128 channel_center[i]
129 );
130
131The variable "channel_center" is assumed to hold the channel center wavelengths
132for each of the num_channels samples of the spectrum we are building.
133
134
135Cleanup after use
136-----------------
137
138After rendering is complete, the content of the sky model states should be
139disposed of via
140
141 for ( unsigned int i = 0; i < num_channels; i++ )
142 arhosekskymodelstate_free( skymodel_state[i] );
143
144
145CIE XYZ Version of the Model
146----------------------------
147
148Usage of the CIE XYZ version of the model is exactly the same, except that
149num_channels is of course always 3, and that ArHosekTristimSkyModelState and
150arhosek_tristim_skymodel_radiance() have to be used instead of their spectral
151counterparts.
152
153RGB Version of the Model
154------------------------
155
156The RGB version uses sRGB primaries with a linear gamma ramp. The same set of
157functions as with the XYZ data is used, except the model is initialized
158by calling arhosek_rgb_skymodelstate_alloc_init.
159
160Solar Radiance Function
161-----------------------
162
163For each position on the solar disc, this function returns the entire radiance
164one sees - direct emission, as well as in-scattered light in the area of the
165solar disc. The latter is important for low solar elevations - nice images of
166the setting sun would not be possible without this. This is also the reason why
167this function, just like the regular sky dome model evaluation function, needs
168access to the sky dome data structures, as these provide information on
169in-scattered radiance.
170
171CAVEAT #1: in this release, this function is only provided in spectral form!
172 RGB/XYZ versions to follow at a later date.
173
174CAVEAT #2: (fixed from release 1.3 onwards)
175
176CAVEAT #3: limb darkening renders the brightness of the solar disc
177 inhomogeneous even for high solar elevations - only taking a single
178 sample at the centre of the sun will yield an incorrect power
179 estimate for the solar disc! Always take multiple random samples
180 across the entire solar disc to estimate its power!
181
182CAVEAT #4: in this version, the limb darkening calculations still use a fairly
183 computationally expensive 5th order polynomial that was directly
184 taken from astronomical literature. For the purposes of Computer
185 Graphics, this is needlessly accurate, though, and will be replaced
186 by a cheaper approximation in a future release.
187
188"Alien World" functionality
189---------------------------
190
191The Hosek sky model can be used to roughly (!) predict the appearance of
192outdoor scenes on earth-like planets, i.e. planets of a similar size and
193atmospheric make-up. Since the spectral version of our model predicts sky dome
194luminance patterns and solar radiance independently for each waveband, and
195since the intensity of each waveband is solely dependent on the input radiance
196from the star that the world in question is orbiting, it is trivial to re-scale
197the wavebands to match a different star radiance.
198
199At least in theory, the spectral version of the model has always been capable
200of this sort of thing, and the actual sky dome and solar radiance models were
201actually not altered at all in this release. All we did was to add some support
202functionality for doing this more easily with the existing data and functions,
203and to add some explanations.
204
205Just use 'arhosekskymodelstate_alienworld_alloc_init()' to initialize the sky
206model states (you will have to provide values for star temperature and solar
207intensity compared to the terrestrial sun), and do everything else as you
208did before.
209
210CAVEAT #1: we assume the emission of the star that illuminates the alien world
211 to be a perfect blackbody emission spectrum. This is never entirely
212 realistic - real star emission spectra are considerably more complex
213 than this, mainly due to absorption effects in the outer layers of
214 stars. However, blackbody spectra are a reasonable first assumption
215 in a usage scenario like this, where 100% accuracy is simply not
216 necessary: for rendering purposes, there are likely no visible
217 differences between a highly accurate solution based on a more
218 involved simulation, and this approximation.
219
220CAVEAT #2: we always use limb darkening data from our own sun to provide this
221 "appearance feature", even for suns of strongly different
222 temperature. Which is presumably not very realistic, but (as with
223 the unaltered blackbody spectrum from caveat #1) probably not a bad
224 first guess, either. If you need more accuracy than we provide here,
225 please make inquiries with a friendly astro-physicst of your choice.
226
227CAVEAT #3: you have to provide a value for the solar intensity of the star
228 which illuminates the alien world. For this, please bear in mind
229 that there is very likely a comparatively tight range of absolute
230 solar irradiance values for which an earth-like planet with an
231 atmosphere like the one we assume in our model can exist in the
232 first place!
233
234 Too much irradiance, and the atmosphere probably boils off into
235 space, too little, it freezes. Which means that stars of
236 considerably different emission colour than our sun will have to be
237 fairly different in size from it, to still provide a reasonable and
238 inhabitable amount of irradiance. Red stars will need to be much
239 larger than our sun, while white or blue stars will have to be
240 comparatively tiny. The initialization function handles this and
241 computes a plausible solar radius for a given emission spectrum. In
242 terms of absolute radiometric values, you should probably not stray
243 all too far from a solar intensity value of 1.0.
244
245CAVEAT #4: although we now support different solar radii for the actual solar
246 disc, the sky dome luminance patterns are *not* parameterised by
247 this value - i.e. the patterns stay exactly the same for different
248 solar radii! Which is of course not correct. But in our experience,
249 solar discs up to several degrees in diameter (! - our own sun is
250 half a degree across) do not cause the luminance patterns on the sky
251 to change perceptibly. The reason we know this is that we initially
252 used unrealistically large suns in our brute force path tracer, in
253 order to improve convergence speeds (which in the beginning were
254 abysmal). Later, we managed to do the reference renderings much
255 faster even with realistically small suns, and found that there was
256 no real difference in skydome appearance anyway.
257 Conclusion: changing the solar radius should not be over-done, so
258 close orbits around red supergiants are a no-no. But for the
259 purposes of getting a fairly credible first impression of what an
260 alien world with a reasonably sized sun would look like, what we are
261 doing here is probably still o.k.
262
263HINT #1: if you want to model the sky of an earth-like planet that orbits
264 a binary star, just super-impose two of these models with solar
265 intensity of ~0.5 each, and closely spaced solar positions. Light is
266 additive, after all. Tattooine, here we come... :-)
267
268 P.S. according to Star Wars canon, Tattooine orbits a binary
269 that is made up of a G and K class star, respectively.
270 So ~5500K and ~4200K should be good first guesses for their
271 temperature. Just in case you were wondering, after reading the
272 previous paragraph.
273*/
274
279#ifndef __SKY_MODEL_H__
280#define __SKY_MODEL_H__
281
282#ifdef __cplusplus
283extern "C" {
284#endif
285
287
288// Spectral version of the model
289
290/* ----------------------------------------------------------------------------
291
292 ArHosekSkyModelState struct
293 ---------------------------
294
295 This struct holds the pre-computation data for one particular albedo value.
296 Most fields are self-explanatory, but users should never directly
297 manipulate any of them anyway. The only consistent way to manipulate such
298 structs is via the functions 'arhosekskymodelstate_alloc_init' and
299 'arhosekskymodelstate_free'.
300
301 'emission_correction_factor_sky'
302 'emission_correction_factor_sun'
303
304 The original model coefficients were fitted against the emission of
305 our local sun. If a different solar emission is desired (i.e. if the
306 model is being used to predict skydome appearance for an earth-like
307 planet that orbits a different star), these correction factors, which
308 are determined during the alloc_init step, are applied to each waveband
309 separately (they default to 1.0 in normal usage). This is the simplest
310 way to retrofit this sort of capability to the existing model. The
311 different factors for sky and sun are needed since the solar disc may
312 be of a different size compared to the terrestrial sun.
313
314---------------------------------------------------------------------------- */
315
326
327/* ----------------------------------------------------------------------------
328
329 arhosekskymodelstate_alloc_init() function
330 ------------------------------------------
331
332 Initializes an #ArHosekSkyModelState struct for a terrestrial setting.
333
334---------------------------------------------------------------------------- */
335
337 const double atmospheric_turbidity,
338 const double ground_albedo);
339
340/* ----------------------------------------------------------------------------
341
342 arhosekskymodelstate_alienworld_alloc_init() function
343 -----------------------------------------------------
344
345 Initializes an ArHosekSkyModelState struct for an "alien world" setting
346 with a sun of a surface temperature given in 'kelvin'. The parameter
347 'solar_intensity' controls the overall brightness of the sky, relative
348 to the solar irradiance on Earth. A value of 1.0 yields a sky dome that
349 is, on average over the wavelengths covered in the model (!), as bright
350 as the terrestrial sky in radiometric terms.
351
352 Which means that the solar radius has to be adjusted, since the
353 emissivity of a solar surface with a given temperature is more or less
354 fixed. So hotter suns have to be smaller to be equally bright as the
355 terrestrial sun, while cooler suns have to be larger. Note that there are
356 limits to the validity of the luminance patterns of the underlying model:
357 see the discussion above for more on this. In particular, an alien sun with
358 a surface temperature of only 2000 Kelvin has to be very large if it is
359 to be as bright as the terrestrial sun - so large that the luminance
360 patterns are no longer a really good fit in that case.
361
362 If you need information about the solar radius that the model computes
363 for a given temperature (say, for light source sampling purposes), you
364 have to query the 'solar_radius' variable of the sky model state returned
365 *after* running this function.
366
367---------------------------------------------------------------------------- */
368
370 const double solar_elevation,
371 const double solar_intensity,
372 const double solar_surface_temperature_kelvin,
373 const double atmospheric_turbidity,
374 const double ground_albedo);
375
377
379 double theta,
380 double gamma,
381 double wavelength);
382
383// CIE XYZ and RGB versions
384
386 const double albedo,
387 const double elevation);
388
390 const double albedo,
391 const double elevation);
392
394 double theta,
395 double gamma,
396 int channel);
397
398// Delivers the complete function: sky + sun, including limb darkening.
399// Please read the above description before using this - there are several
400// caveats!
401
403 double theta,
404 double gamma,
405 double wavelength);
406
407/* Nishita improved sky model */
408
410 int stride,
411 int start_y,
412 int end_y,
413 int width,
414 int height,
415 float sun_elevation,
416 float altitude,
417 float air_density,
418 float dust_density,
419 float ozone_density);
420
421void SKY_nishita_skymodel_precompute_sun(float sun_elevation,
422 float angular_diameter,
423 float altitude,
424 float air_density,
425 float dust_density,
426 float *r_pixel_bottom,
427 float *r_pixel_top);
428
429#ifdef __cplusplus
430}
431#endif
432
433#endif // __SKY_MODEL_H__
static ulong state[N]
void SKY_arhosekskymodelstate_free(SKY_ArHosekSkyModelState *state)
SKY_ArHosekSkyModelState * SKY_arhosekskymodelstate_alienworld_alloc_init(const double solar_elevation, const double solar_intensity, const double solar_surface_temperature_kelvin, const double atmospheric_turbidity, const double ground_albedo)
SKY_ArHosekSkyModelState * SKY_arhosek_rgb_skymodelstate_alloc_init(const double turbidity, const double albedo, const double elevation)
SKY_ArHosekSkyModelState * SKY_arhosek_xyz_skymodelstate_alloc_init(const double turbidity, const double albedo, const double elevation)
double SKY_arhosekskymodel_solar_radiance(SKY_ArHosekSkyModelState *state, double theta, double gamma, double wavelength)
void SKY_nishita_skymodel_precompute_sun(float sun_elevation, float angular_diameter, float altitude, float air_density, float dust_density, float *r_pixel_bottom, float *r_pixel_top)
struct SKY_ArHosekSkyModelState SKY_ArHosekSkyModelState
double SKY_arhosek_tristim_skymodel_radiance(SKY_ArHosekSkyModelState *state, double theta, double gamma, int channel)
double SKY_arhosekskymodel_radiance(SKY_ArHosekSkyModelState *state, double theta, double gamma, double wavelength)
double SKY_ArHosekSkyModelConfiguration[9]
Definition sky_model.h:286
SKY_ArHosekSkyModelState * SKY_arhosekskymodelstate_alloc_init(const double solar_elevation, const double atmospheric_turbidity, const double ground_albedo)
void SKY_nishita_skymodel_precompute_texture(float *pixels, int stride, int start_y, int end_y, int width, int height, float sun_elevation, float altitude, float air_density, float dust_density, float ozone_density)
double emission_correction_factor_sky[11]
Definition sky_model.h:321
SKY_ArHosekSkyModelConfiguration configs[11]
Definition sky_model.h:317
double emission_correction_factor_sun[11]
Definition sky_model.h:322