Debian Codegraph @

scene/3d/light_3d.h

raw symbols SCIP
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 #pragma once
32
33 #include "scene/3d/visual_instance_3d.h"
34
35 class Light3D : public VisualInstance3D {
36 GDCLASS(Light3D, VisualInstance3D);
37
38 public:
39 enum Param {
40 PARAM_ENERGY = RS::LIGHT_PARAM_ENERGY,
41 PARAM_INDIRECT_ENERGY = RS::LIGHT_PARAM_INDIRECT_ENERGY,
42 PARAM_VOLUMETRIC_FOG_ENERGY = RS::LIGHT_PARAM_VOLUMETRIC_FOG_ENERGY,
43 PARAM_SPECULAR = RS::LIGHT_PARAM_SPECULAR,
44 PARAM_RANGE = RS::LIGHT_PARAM_RANGE,
45 PARAM_SIZE = RS::LIGHT_PARAM_SIZE,
46 PARAM_ATTENUATION = RS::LIGHT_PARAM_ATTENUATION,
47 PARAM_SPOT_ANGLE = RS::LIGHT_PARAM_SPOT_ANGLE,
48 PARAM_SPOT_ATTENUATION = RS::LIGHT_PARAM_SPOT_ATTENUATION,
49 PARAM_SHADOW_MAX_DISTANCE = RS::LIGHT_PARAM_SHADOW_MAX_DISTANCE,
50 PARAM_SHADOW_SPLIT_1_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET,
51 PARAM_SHADOW_SPLIT_2_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET,
52 PARAM_SHADOW_SPLIT_3_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET,
53 PARAM_SHADOW_FADE_START = RS::LIGHT_PARAM_SHADOW_FADE_START,
54 PARAM_SHADOW_NORMAL_BIAS = RS::LIGHT_PARAM_SHADOW_NORMAL_BIAS,
55 PARAM_SHADOW_BIAS = RS::LIGHT_PARAM_SHADOW_BIAS,
56 PARAM_SHADOW_PANCAKE_SIZE = RS::LIGHT_PARAM_SHADOW_PANCAKE_SIZE,
57 PARAM_SHADOW_OPACITY = RS::LIGHT_PARAM_SHADOW_OPACITY,
58 PARAM_SHADOW_BLUR = RS::LIGHT_PARAM_SHADOW_BLUR,
59 PARAM_TRANSMITTANCE_BIAS = RS::LIGHT_PARAM_TRANSMITTANCE_BIAS,
60 PARAM_INTENSITY = RS::LIGHT_PARAM_INTENSITY,
61 PARAM_MAX = RS::LIGHT_PARAM_MAX
62 };
63
64 enum BakeMode {
65 BAKE_DISABLED,
66 BAKE_STATIC,
67 BAKE_DYNAMIC,
68 };
69
70 private:
71 Color color;
72 real_t param[PARAM_MAX] = {};
73 bool shadow = false;
74 bool negative = false;
75 bool reverse_cull = false;
76 uint32_t cull_mask = 0;
77 uint32_t shadow_caster_mask = 0xFFFFFFFF;
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_shadow_caster_mask(uint32_t p_caster_mask);
140 uint32_t get_shadow_caster_mask() const;
141
142 void set_bake_mode(BakeMode p_mode);
143 BakeMode get_bake_mode() const;
144
145 void set_projector(const Ref<Texture2D> &p_texture);
146 Ref<Texture2D> get_projector() const;
147
148 void set_temperature(const float p_temperature);
149 float get_temperature() const;
150 Color get_correlated_color() const;
151
152 virtual AABB get_aabb() const override;
153 virtual PackedStringArray get_configuration_warnings() const override;
154
155 Light3D();
156 ~Light3D();
157 };
158
159 VARIANT_ENUM_CAST(Light3D::Param);
160 VARIANT_ENUM_CAST(Light3D::BakeMode);
161
162 class DirectionalLight3D : public Light3D {
163 GDCLASS(DirectionalLight3D, Light3D);
164
165 public:
166 enum ShadowMode {
167 SHADOW_ORTHOGONAL,
168 SHADOW_PARALLEL_2_SPLITS,
169 SHADOW_PARALLEL_4_SPLITS,
170 };
171
172 enum SkyMode {
173 SKY_MODE_LIGHT_AND_SKY,
174 SKY_MODE_LIGHT_ONLY,
175 SKY_MODE_SKY_ONLY,
176 };
177
178 private:
179 bool blend_splits;
180 ShadowMode shadow_mode;
181 SkyMode sky_mode = SKY_MODE_LIGHT_AND_SKY;
182
183 protected:
184 static void _bind_methods();
185 void _validate_property(PropertyInfo &p_property) const;
186
187 public:
188 void set_shadow_mode(ShadowMode p_mode);
189 ShadowMode get_shadow_mode() const;
190
191 void set_blend_splits(bool p_enable);
192 bool is_blend_splits_enabled() const;
193
194 void set_sky_mode(SkyMode p_mode);
195 SkyMode get_sky_mode() const;
196
197 DirectionalLight3D();
198 };
199
200 VARIANT_ENUM_CAST(DirectionalLight3D::ShadowMode)
201 VARIANT_ENUM_CAST(DirectionalLight3D::SkyMode)
202
203 class OmniLight3D : public Light3D {
204 GDCLASS(OmniLight3D, Light3D);
205
206 public:
207 // omni light
208 enum ShadowMode {
209 SHADOW_DUAL_PARABOLOID,
210 SHADOW_CUBE,
211 };
212
213 private:
214 ShadowMode shadow_mode;
215
216 protected:
217 static void _bind_methods();
218
219 public:
220 void set_shadow_mode(ShadowMode p_mode);
221 ShadowMode get_shadow_mode() const;
222
223 PackedStringArray get_configuration_warnings() const override;
224
225 OmniLight3D();
226 };
227
228 VARIANT_ENUM_CAST(OmniLight3D::ShadowMode)
229
230 class SpotLight3D : public Light3D {
231 GDCLASS(SpotLight3D, Light3D);
232
233 protected:
234 static void _bind_methods();
235
236 public:
237 PackedStringArray get_configuration_warnings() const override;
238
239 SpotLight3D();
240 };