Toast Engine
Loading...
Searching...
No Matches
light.hpp
Go to the documentation of this file.
1
8
9#pragma once
10#include "node_3d.hpp"
11
12#include <toast/export.hpp>
13
14namespace toast {
15
17enum class LightType : uint8_t {
18 none,
19 point,
20 directional,
21 spot,
22 ambient,
23};
24
25class [[ToastNode, Hidden, Icon("PointLight")]] TOAST_API Light : public Node3D {
26public:
27 Light() = default;
28
29 [[nodiscard]]
30 auto lightType() const -> LightType {
31 return m_light_type;
32 }
33
34 [[nodiscard]]
35 auto color() const -> const glm::vec3& {
36 return m_light_color;
37 }
38
39 [[nodiscard]]
40 auto intensity() const -> float {
41 return m_intensity;
42 }
43
45 [[nodiscard]]
46 auto castsShadows() const -> bool {
47 return m_cast_shadows;
48 }
49
51 [[nodiscard]]
52 auto shadowResolutionScale() const -> float {
53 return m_shadow_resolution_scale;
54 }
55
57 [[nodiscard]]
58 auto shadowDistance() const -> float {
59 return m_shadow_distance;
60 }
61
63 [[nodiscard]]
64 auto cullDistance() const -> float {
65 return m_cull_distance;
66 }
67
68protected:
70 void setLightType(LightType type) { m_light_type = type; }
71
72private:
73 void init();
74 void end();
75 void destroy();
76
77 [[Reflect, Color]]
78 glm::vec3 m_light_color = glm::vec3(1.0f, 1.0f, 1.0f);
79
80 [[Reflect, Unit("lm")]]
81 float m_intensity = 1.0f;
82
83 [[Reflect, Name("Cast Shadows"), Group("Optimization")]]
84 bool m_cast_shadows = true;
85
90 [[Reflect, Name("Shadow Resolution Scale"), Range(0.1, 1.0), Group("Optimization")]]
91 float m_shadow_resolution_scale = 1.0f;
92
96 [[Reflect, Name("Shadow Distance"), Unit("m"), Group("Optimization")]]
97 float m_shadow_distance = 60.0f;
98
102 [[Reflect, Name("Cull Distance"), Unit("m"), Group("Optimization")]]
103 float m_cull_distance = 0.0f;
104
105 // Deliberately not [[Reflect]] - applyFields() only ever touches reflected fields during prefab
106 // deserialization, so this constructor-set value can never be clobbered
107 LightType m_light_type = LightType::none;
108
109 bool m_registered_proxy = false;
110};
111}
auto shadowResolutionScale() const -> float
Multiplier on the shadow-map resolution this light is granted, see m_shadow_resolution_scale.
Definition light.hpp:52
void setLightType(LightType type)
Tags the concrete light kind; called once from each subclass's own constructor body.
Definition light.hpp:70
auto castsShadows() const -> bool
Whether this light should be rendered into a shadow map.
Definition light.hpp:46
auto shadowDistance() const -> float
Camera distance past which this light stops casting shadows; 0 disables the limit.
Definition light.hpp:58
auto cullDistance() const -> float
Camera distance past which this light stops being submitted at all; 0 disables the limit.
Definition light.hpp:64
Definition node_3d.hpp:25
auto type() const noexcept -> NodeType
Definition node.hpp:192
Definition reflect.hpp:244
LightType
Concrete light kind, tagged once by each subclass's constructor - not RTTI, not reflected.
Definition light.hpp:17
Node with 3D spatial transforms.