1 | /**************************************************************************/ |
2 | /* light_3d.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #ifndef LIGHT_3D_H |
32 | #define LIGHT_3D_H |
33 | |
34 | #include "scene/3d/visual_instance_3d.h" |
35 | |
36 | class Light3D : public VisualInstance3D { |
37 | GDCLASS(Light3D, VisualInstance3D); |
38 | |
39 | public: |
40 | enum Param { |
41 | PARAM_ENERGY = RS::LIGHT_PARAM_ENERGY, |
42 | PARAM_INDIRECT_ENERGY = RS::LIGHT_PARAM_INDIRECT_ENERGY, |
43 | PARAM_VOLUMETRIC_FOG_ENERGY = RS::LIGHT_PARAM_VOLUMETRIC_FOG_ENERGY, |
44 | PARAM_SPECULAR = RS::LIGHT_PARAM_SPECULAR, |
45 | PARAM_RANGE = RS::LIGHT_PARAM_RANGE, |
46 | PARAM_SIZE = RS::LIGHT_PARAM_SIZE, |
47 | PARAM_ATTENUATION = RS::LIGHT_PARAM_ATTENUATION, |
48 | PARAM_SPOT_ANGLE = RS::LIGHT_PARAM_SPOT_ANGLE, |
49 | PARAM_SPOT_ATTENUATION = RS::LIGHT_PARAM_SPOT_ATTENUATION, |
50 | PARAM_SHADOW_MAX_DISTANCE = RS::LIGHT_PARAM_SHADOW_MAX_DISTANCE, |
51 | PARAM_SHADOW_SPLIT_1_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET, |
52 | PARAM_SHADOW_SPLIT_2_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET, |
53 | PARAM_SHADOW_SPLIT_3_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET, |
54 | PARAM_SHADOW_FADE_START = RS::LIGHT_PARAM_SHADOW_FADE_START, |
55 | PARAM_SHADOW_NORMAL_BIAS = RS::LIGHT_PARAM_SHADOW_NORMAL_BIAS, |
56 | PARAM_SHADOW_BIAS = RS::LIGHT_PARAM_SHADOW_BIAS, |
57 | PARAM_SHADOW_PANCAKE_SIZE = RS::LIGHT_PARAM_SHADOW_PANCAKE_SIZE, |
58 | PARAM_SHADOW_OPACITY = RS::LIGHT_PARAM_SHADOW_OPACITY, |
59 | PARAM_SHADOW_BLUR = RS::LIGHT_PARAM_SHADOW_BLUR, |
60 | PARAM_TRANSMITTANCE_BIAS = RS::LIGHT_PARAM_TRANSMITTANCE_BIAS, |
61 | PARAM_INTENSITY = RS::LIGHT_PARAM_INTENSITY, |
62 | PARAM_MAX = RS::LIGHT_PARAM_MAX |
63 | }; |
64 | |
65 | enum BakeMode { |
66 | BAKE_DISABLED, |
67 | BAKE_STATIC, |
68 | BAKE_DYNAMIC, |
69 | }; |
70 | |
71 | private: |
72 | Color color; |
73 | real_t param[PARAM_MAX] = {}; |
74 | bool shadow = false; |
75 | bool negative = false; |
76 | bool reverse_cull = false; |
77 | uint32_t cull_mask = 0; |
78 | bool distance_fade_enabled = false; |
79 | real_t distance_fade_begin = 40.0; |
80 | real_t distance_fade_shadow = 50.0; |
81 | real_t distance_fade_length = 10.0; |
82 | RS::LightType type = RenderingServer::LIGHT_DIRECTIONAL; |
83 | bool editor_only = false; |
84 | void _update_visibility(); |
85 | BakeMode bake_mode = BAKE_DYNAMIC; |
86 | Ref<Texture2D> projector; |
87 | Color correlated_color = Color(1.0, 1.0, 1.0); |
88 | float temperature = 6500.0; |
89 | |
90 | // bind helpers |
91 | |
92 | virtual void owner_changed_notify() override; |
93 | |
94 | protected: |
95 | RID light; |
96 | |
97 | static void _bind_methods(); |
98 | void _notification(int p_what); |
99 | void _validate_property(PropertyInfo &p_property) const; |
100 | |
101 | Light3D(RenderingServer::LightType p_type); |
102 | |
103 | public: |
104 | RS::LightType get_light_type() const { return type; } |
105 | |
106 | void set_editor_only(bool p_editor_only); |
107 | bool is_editor_only() const; |
108 | |
109 | void set_param(Param p_param, real_t p_value); |
110 | real_t get_param(Param p_param) const; |
111 | |
112 | void set_shadow(bool p_enable); |
113 | bool has_shadow() const; |
114 | |
115 | void set_negative(bool p_enable); |
116 | bool is_negative() const; |
117 | |
118 | void set_enable_distance_fade(bool p_enable); |
119 | bool is_distance_fade_enabled() const; |
120 | |
121 | void set_distance_fade_begin(real_t p_distance); |
122 | real_t get_distance_fade_begin() const; |
123 | |
124 | void set_distance_fade_shadow(real_t p_distance); |
125 | real_t get_distance_fade_shadow() const; |
126 | |
127 | void set_distance_fade_length(real_t p_length); |
128 | real_t get_distance_fade_length() const; |
129 | |
130 | void set_cull_mask(uint32_t p_cull_mask); |
131 | uint32_t get_cull_mask() const; |
132 | |
133 | void set_color(const Color &p_color); |
134 | Color get_color() const; |
135 | |
136 | void set_shadow_reverse_cull_face(bool p_enable); |
137 | bool get_shadow_reverse_cull_face() const; |
138 | |
139 | void set_bake_mode(BakeMode p_mode); |
140 | BakeMode get_bake_mode() const; |
141 | |
142 | void set_projector(const Ref<Texture2D> &p_texture); |
143 | Ref<Texture2D> get_projector() const; |
144 | |
145 | void set_temperature(const float p_temperature); |
146 | float get_temperature() const; |
147 | Color get_correlated_color() const; |
148 | |
149 | virtual AABB get_aabb() const override; |
150 | virtual PackedStringArray get_configuration_warnings() const override; |
151 | |
152 | Light3D(); |
153 | ~Light3D(); |
154 | }; |
155 | |
156 | VARIANT_ENUM_CAST(Light3D::Param); |
157 | VARIANT_ENUM_CAST(Light3D::BakeMode); |
158 | |
159 | class DirectionalLight3D : public Light3D { |
160 | GDCLASS(DirectionalLight3D, Light3D); |
161 | |
162 | public: |
163 | enum ShadowMode { |
164 | SHADOW_ORTHOGONAL, |
165 | SHADOW_PARALLEL_2_SPLITS, |
166 | SHADOW_PARALLEL_4_SPLITS, |
167 | }; |
168 | |
169 | enum SkyMode { |
170 | SKY_MODE_LIGHT_AND_SKY, |
171 | SKY_MODE_LIGHT_ONLY, |
172 | SKY_MODE_SKY_ONLY, |
173 | }; |
174 | |
175 | private: |
176 | bool blend_splits; |
177 | ShadowMode shadow_mode; |
178 | SkyMode sky_mode = SKY_MODE_LIGHT_AND_SKY; |
179 | |
180 | protected: |
181 | static void _bind_methods(); |
182 | void _validate_property(PropertyInfo &p_property) const; |
183 | |
184 | public: |
185 | void set_shadow_mode(ShadowMode p_mode); |
186 | ShadowMode get_shadow_mode() const; |
187 | |
188 | void set_blend_splits(bool p_enable); |
189 | bool is_blend_splits_enabled() const; |
190 | |
191 | void set_sky_mode(SkyMode p_mode); |
192 | SkyMode get_sky_mode() const; |
193 | |
194 | DirectionalLight3D(); |
195 | }; |
196 | |
197 | VARIANT_ENUM_CAST(DirectionalLight3D::ShadowMode) |
198 | VARIANT_ENUM_CAST(DirectionalLight3D::SkyMode) |
199 | |
200 | class OmniLight3D : public Light3D { |
201 | GDCLASS(OmniLight3D, Light3D); |
202 | |
203 | public: |
204 | // omni light |
205 | enum ShadowMode { |
206 | SHADOW_DUAL_PARABOLOID, |
207 | SHADOW_CUBE, |
208 | }; |
209 | |
210 | private: |
211 | ShadowMode shadow_mode; |
212 | |
213 | protected: |
214 | static void _bind_methods(); |
215 | |
216 | public: |
217 | void set_shadow_mode(ShadowMode p_mode); |
218 | ShadowMode get_shadow_mode() const; |
219 | |
220 | PackedStringArray get_configuration_warnings() const override; |
221 | |
222 | OmniLight3D(); |
223 | }; |
224 | |
225 | VARIANT_ENUM_CAST(OmniLight3D::ShadowMode) |
226 | |
227 | class SpotLight3D : public Light3D { |
228 | GDCLASS(SpotLight3D, Light3D); |
229 | |
230 | protected: |
231 | static void _bind_methods(); |
232 | |
233 | public: |
234 | PackedStringArray get_configuration_warnings() const override; |
235 | |
236 | SpotLight3D(); |
237 | }; |
238 | |
239 | #endif // LIGHT_3D_H |
240 | |