Toast Engine
Loading...
Searching...
No Matches
shadow_constants.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
9#include <algorithm>
10#include <cstdint>
11#include <toast/export.hpp>
12
13namespace renderer::shadows {
14
15inline constexpr uint32_t k_cascade_count = 4;
16
17inline constexpr uint32_t k_cascade_resolution = 1024;
18
19inline constexpr float k_shadow_distance = 150.0f;
20
21inline constexpr float k_cascade_split_lambda = 0.75f;
22
23inline constexpr uint32_t k_max_spot_shadows = 4;
24
25inline constexpr uint32_t k_max_point_shadows = 2;
26
27inline constexpr uint32_t k_cube_faces = 6;
28
29inline constexpr uint32_t k_punctual_resolution = 512;
30
31inline constexpr uint32_t k_min_punctual_resolution = 64;
32
33inline constexpr float k_punctual_full_resolution_distance = 10.0f;
34inline constexpr float k_punctual_min_resolution_distance = 60.0f;
35
37TOAST_API auto cascadeResolution() -> uint32_t;
38TOAST_API auto punctualResolution() -> uint32_t;
39TOAST_API auto shadowDistance() -> float;
40
41TOAST_API void setCascadeResolution(uint32_t resolution);
42TOAST_API void setPunctualResolution(uint32_t resolution);
43TOAST_API void setShadowDistance(float distance);
44
45[[nodiscard]]
46inline auto punctualShadowResolution(float camera_distance, float resolution_scale) -> uint32_t {
47 const uint32_t full_resolution = punctualResolution();
48 const float span = k_punctual_min_resolution_distance - k_punctual_full_resolution_distance;
49 float t = span > 0.0f ? (camera_distance - k_punctual_full_resolution_distance) / span : 1.0f;
50 t = std::clamp(t, 0.0f, 1.0f);
51
52 const auto max_resolution = static_cast<float>(full_resolution);
53 const auto min_resolution = static_cast<float>(k_min_punctual_resolution);
54 const float scale = std::clamp(resolution_scale, 0.0f, 1.0f);
55 const float target = (max_resolution + ((min_resolution - max_resolution) * t)) * scale;
56
57 uint32_t resolution = k_min_punctual_resolution;
58 while ((resolution * 2) <= full_resolution && static_cast<float>(resolution * 2) <= target) {
59 resolution *= 2;
60 }
61 return resolution;
62}
63
65inline constexpr uint32_t k_spot_layer_base = 0;
66inline constexpr uint32_t k_point_layer_base = k_max_spot_shadows;
67inline constexpr uint32_t k_punctual_layer_count = k_max_spot_shadows + (k_max_point_shadows * k_cube_faces);
68
70inline constexpr uint32_t k_max_shadow_views = k_cascade_count + k_punctual_layer_count;
71
72inline constexpr float k_punctual_near = 0.05f;
73
75inline constexpr float k_cube_face_guard_texels = 4.0f;
76
77}
constexpr uint32_t k_spot_layer_base
Spots first then six faces per point light.
Definition shadow_constants.hpp:65
constexpr float k_cube_face_guard_texels
Must exceed the mesh.slang filter radius.
Definition shadow_constants.hpp:75
constexpr uint32_t k_max_shadow_views
Also sizes the shadow_depth.slang matrix array.
Definition shadow_constants.hpp:70