Unravel Engine C++ Reference
Loading...
Searching...
No Matches
light_component.h
Go to the documentation of this file.
1#pragma once
2#include <base/basetypes.hpp>
6
7namespace unravel
8{
9
14class light_component : public component_crtp<light_component>
15{
16public:
21 auto get_light() const -> const light&;
22
27 void set_light(const light& l);
28
32 auto get_bounds() const -> math::bbox;
33 auto get_bounds_sphere() const -> math::bsphere;
34
38 auto get_bounds_precise(const math::vec3& light_direction) const -> math::bbox;
39 auto get_bounds_sphere_precise(const math::vec3& light_direction) const -> math::bsphere;
40
52 const math::vec3& light_position,
53 const math::vec3& light_direction,
54 const math::vec3& view_origin,
55 const math::transform& view,
56 const math::transform& proj) -> int;
57
63
64private:
65 auto get_bounds_sphere_impl(const math::vec3* light_direction) const -> math::bsphere;
66
70 light light_;
71
75 std::shared_ptr<shadow::shadowmap_generator> shadowmap_generator_ = std::make_shared<shadow::shadowmap_generator>();
76};
77
82class skylight_component : public component_crtp<skylight_component>
83{
84public:
89 enum class sky_mode
90 {
92 reserved_0 = 0,
94 perez = 1,
96 skybox = 2,
97 };
98
106 {
108 flat,
111 };
112
113 enum class cloud_mode
114 {
116 none = 0,
118 flat = 1,
120 volumetric = 2,
121 };
122
127 auto get_mode() const noexcept -> const sky_mode&;
128
133 void set_mode(const sky_mode& mode);
134
139 auto get_turbidity() const noexcept -> float;
140
145 void set_turbidity(float turbidity);
146
151 auto get_cloud_mode() const noexcept -> cloud_mode;
152
157 void set_cloud_mode(cloud_mode mode);
158
163 auto get_cloud_coverage() const noexcept -> float;
164
169 void set_cloud_coverage(float coverage);
170
175 auto get_cloud_base_altitude() const noexcept -> float;
176
181 void set_cloud_base_altitude(float altitude);
182
187 auto get_cloud_top_altitude() const noexcept -> float;
188
193 void set_cloud_top_altitude(float altitude);
194
199 auto get_cloud_speed() const noexcept -> float;
200
205 void set_cloud_speed(float speed);
206
211 auto get_cloud_density() const noexcept -> float;
212
217 void set_cloud_density(float density);
218
223 auto get_cloud_absorption() const noexcept -> float;
224
229 void set_cloud_absorption(float absorption);
230
235 auto get_cloud_light_absorption() const noexcept -> float;
236
241 void set_cloud_light_absorption(float absorption);
242
246 auto get_cloud_vol_uv_scale() const noexcept -> float;
247 void set_cloud_vol_uv_scale(float scale);
248
252 auto get_cloud_vol_edge_width() const noexcept -> float;
254
258 auto get_cloud_vol_shape_power() const noexcept -> float;
259 void set_cloud_vol_shape_power(float power);
260
264 auto get_cloud_vol_detail_erode() const noexcept -> float;
265 void set_cloud_vol_detail_erode(float erode);
266
270 auto get_cloud_vol_macro_strength() const noexcept -> float;
271 void set_cloud_vol_macro_strength(float strength);
272
276 auto get_cloud_vol_coarse_scale() const noexcept -> float;
278
282 auto get_cloud_vol_base_mix() const noexcept -> float;
283 void set_cloud_vol_base_mix(float mix);
284
288 auto get_cloud_vol_sun_intensity() const noexcept -> float;
289 void set_cloud_vol_sun_intensity(float intensity);
290
295 auto get_irradiance_intensity() const noexcept -> float;
296
301 void set_irradiance_intensity(float intensity);
302
307 auto get_irradiance_tint() const noexcept -> const math::color&;
308
313 void set_irradiance_tint(const math::color& color);
314
319 auto get_irradiance_quality() const noexcept -> irradiance_quality;
320
326
331 auto get_irradiance_use_sky() const noexcept -> bool;
332
338 void set_irradiance_use_sky(bool use_sky);
339
344 auto get_sky_brightness() const noexcept -> float;
345
350 void set_sky_brightness(float brightness);
351
352 auto get_cubemap() const noexcept -> const asset_handle<gfx::texture>&
353 {
354 return cubemap_;
355 }
357 {
358 cubemap_ = cubemap;
359 }
360
365 auto get_cloud_time() const noexcept -> float
366 {
367 return cloud_time_;
368 }
369
371 {
372 // cloud_speed_ is in km/h. Convert to the noise-UV time scale used by
373 // the shader (cloud_time * 0.5 UV/s). Calibrated so that 10-20 km/h =
374 // gentle natural drift, ~100 km/h = strong visible wind.
375 constexpr float kmh_to_time_scale = 1.0f / 500.0f;
376 cloud_time_ += dt.count() * cloud_speed_ * kmh_to_time_scale;
377 }
378
379private:
384
388 float turbidity_{1.9};
389
392
394 float cloud_coverage_{0.52f};
395
397 float cloud_base_altitude_{27500.0f};
398
400 float cloud_top_altitude_{45000.0f};
401
403 float cloud_speed_{0.0f};
404
406 float cloud_density_{1.5f};
407
409 float cloud_absorption_{0.08f};
410
412 float cloud_light_absorption_{0.10f};
413
415 float cloud_vol_uv_scale_{0.00008f};
416 float cloud_vol_edge_width_{0.20f};
417 float cloud_vol_shape_power_{1.12f};
418 float cloud_vol_detail_erode_{0.48f};
419 float cloud_vol_macro_strength_{0.36f};
420 float cloud_vol_coarse_scale_{0.38f};
421 float cloud_vol_base_mix_{0.45f};
422 float cloud_vol_sun_intensity_{24.0f};
423
425 float cloud_time_{0.0f};
426
430 float irradiance_intensity_{0.05f};
431
435 math::color irradiance_tint_{1.0f, 1.0f, 1.0f, 1.0f};
436
441
445 bool irradiance_use_sky_{true};
446
450 float sky_brightness_{1.0f};
451
453};
454
455} // namespace unravel
uint32_t width
Provides storage for common representation of spherical bounding volume, and wraps up common function...
Definition bsphere.h:18
General purpose transformation class designed to maintain each component of the transformation separa...
Definition transform.hpp:27
Class that contains core light data, used for rendering and other purposes.
auto get_bounds() const -> math::bbox
Gets the bounding box of the light object.
void set_light(const light &l)
Sets the light object.
auto get_bounds_sphere() const -> math::bsphere
auto get_light() const -> const light &
Gets the light object.
auto compute_projected_sphere_rect(irect32_t &rect, const math::vec3 &light_position, const math::vec3 &light_direction, const math::vec3 &view_origin, const math::transform &view, const math::transform &proj) -> int
Computes the projected sphere rectangle.
auto get_shadowmap_generator() -> shadow::shadowmap_generator &
Gets the shadow map generator.
auto get_bounds_precise(const math::vec3 &light_direction) const -> math::bbox
Gets the bounding box of the light object.
auto get_bounds_sphere_precise(const math::vec3 &light_direction) const -> math::bsphere
Shadow mapping generator with improved algorithms for high-altitude cameras.
Definition shadow.h:654
Class that contains sky light data.
void set_mode(const sky_mode &mode)
Sets the sky mode.
auto get_cloud_top_altitude() const noexcept -> float
Gets the cloud top altitude in world units (volumetric slab top).
void set_cloud_vol_shape_power(float power)
auto get_irradiance_intensity() const noexcept -> float
Gets the irradiance intensity (strength of indirect diffuse).
void set_irradiance_tint(const math::color &color)
Sets the irradiance tint override.
void set_irradiance_intensity(float intensity)
Sets the irradiance intensity.
auto get_irradiance_tint() const noexcept -> const math::color &
Gets the optional irradiance tint override (default from sky when white).
void set_cubemap(const asset_handle< gfx::texture > &cubemap)
void set_irradiance_use_sky(bool use_sky)
Sets whether the sky color contributes to the ambient irradiance.
void set_cloud_vol_macro_strength(float strength)
void set_sky_brightness(float brightness)
Sets the sky brightness multiplier.
void set_cloud_light_absorption(float absorption)
Sets the cloud light absorption (self-shadow strength).
auto get_cubemap() const noexcept -> const asset_handle< gfx::texture > &
void set_cloud_vol_edge_width(float width)
auto get_cloud_density() const noexcept -> float
Gets the cloud density multiplier.
void set_cloud_vol_detail_erode(float erode)
auto get_sky_brightness() const noexcept -> float
Gets the sky brightness multiplier (affects atmospheric pass and irradiance).
auto get_cloud_vol_coarse_scale() const noexcept -> float
Volumetric cloud shape: coarse noise sample scale (larger masses).
auto get_irradiance_quality() const noexcept -> irradiance_quality
Gets the irradiance quality for indirect diffuse.
auto get_cloud_absorption() const noexcept -> float
Gets the cloud absorption coefficient (Beer-Lambert extinction).
void set_cloud_mode(cloud_mode mode)
Sets the cloud rendering mode.
auto get_cloud_vol_detail_erode() const noexcept -> float
Volumetric cloud shape: Worley detail erosion strength.
auto get_cloud_vol_edge_width() const noexcept -> float
Volumetric cloud shape: smoothstep edge width for the density mask.
auto get_cloud_coverage() const noexcept -> float
Gets the cloud coverage value.
auto get_cloud_time() const noexcept -> float
Gets the accumulated time for cloud animation.
void set_cloud_vol_uv_scale(float scale)
auto get_cloud_vol_macro_strength() const noexcept -> float
Volumetric cloud shape: macro Worley threshold jitter (clearings vs sheet).
auto get_turbidity() const noexcept -> float
Gets the current turbidity value.
auto get_mode() const noexcept -> const sky_mode &
Gets the current sky mode.
auto get_cloud_vol_shape_power() const noexcept -> float
Volumetric cloud shape: contrast on the density mask (pow exponent).
auto get_cloud_vol_uv_scale() const noexcept -> float
Volumetric cloud shape: world-to-noise UV scale (smaller = larger features).
void set_cloud_absorption(float absorption)
Sets the cloud absorption coefficient.
auto get_irradiance_use_sky() const noexcept -> bool
Gets whether the sky color contributes to the ambient irradiance.
void set_cloud_vol_sun_intensity(float intensity)
auto get_cloud_vol_sun_intensity() const noexcept -> float
Volumetric cloud lighting: sun contribution multiplier in the cloud integrator.
void set_turbidity(float turbidity)
Sets the turbidity value.
@ volumetric
Volumetric raymarched clouds (full scattering, half-res with temporal)
irradiance_quality
Directional variation of the indirect diffuse ambient.
@ flat
Flat ambient: only the constant SH band (L0) is written, same color for every normal.
@ directional
Directional ambient: full L0-L2 spherical harmonics, varies with the surface normal.
auto get_cloud_vol_base_mix() const noexcept -> float
Volumetric cloud shape: blend between coarse and fine base noise.
void set_cloud_coverage(float coverage)
Sets the cloud coverage value.
auto get_cloud_light_absorption() const noexcept -> float
Gets the cloud light absorption (self-shadow strength).
void set_irradiance_quality(irradiance_quality quality)
Sets the irradiance quality.
auto get_cloud_mode() const noexcept -> cloud_mode
Gets the cloud rendering mode.
void set_cloud_vol_coarse_scale(float scale)
void set_cloud_top_altitude(float altitude)
Sets the cloud top altitude. Must be greater than base altitude.
void set_cloud_base_altitude(float altitude)
Sets the cloud base altitude.
sky_mode
Enumeration for sky modes.
auto get_cloud_base_altitude() const noexcept -> float
Gets the cloud base altitude in world units.
void set_cloud_speed(float speed)
Sets the cloud speed multiplier.
auto get_cloud_speed() const noexcept -> float
Gets the cloud speed multiplier.
void set_cloud_density(float density)
Sets the cloud density multiplier.
std::chrono::duration< float > delta_t
uint16_t view
Definition bbox.cpp:5
std::vector< math::color > color
std::vector< float > scale
Thread-safe handle to an asset.
Storage for box vector values and wraps up common functionality.
Definition bbox.h:21
CRTP (Curiously Recurring Template Pattern) base structure for components.
Struct representing a light.
Definition light.h:87