1 /*************************************************************************/
2 /*  light.cpp                                                            */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */
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 #include "light.h"
32 
33 #include "core/engine.h"
34 #include "core/project_settings.h"
35 #include "scene/resources/surface_tool.h"
36 
_can_gizmo_scale() const37 bool Light::_can_gizmo_scale() const {
38 
39 	return false;
40 }
41 
set_param(Param p_param,float p_value)42 void Light::set_param(Param p_param, float p_value) {
43 
44 	ERR_FAIL_INDEX(p_param, PARAM_MAX);
45 	param[p_param] = p_value;
46 
47 	VS::get_singleton()->light_set_param(light, VS::LightParam(p_param), p_value);
48 
49 	if (p_param == PARAM_SPOT_ANGLE || p_param == PARAM_RANGE) {
50 		update_gizmo();
51 
52 		if (p_param == PARAM_SPOT_ANGLE) {
53 			_change_notify("spot_angle");
54 			update_configuration_warning();
55 		} else if (p_param == PARAM_RANGE) {
56 			_change_notify("omni_range");
57 			_change_notify("spot_range");
58 		}
59 	}
60 }
61 
get_param(Param p_param) const62 float Light::get_param(Param p_param) const {
63 
64 	ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
65 	return param[p_param];
66 }
67 
set_shadow(bool p_enable)68 void Light::set_shadow(bool p_enable) {
69 
70 	shadow = p_enable;
71 	VS::get_singleton()->light_set_shadow(light, p_enable);
72 
73 	if (type == VisualServer::LIGHT_SPOT) {
74 		update_configuration_warning();
75 	}
76 }
has_shadow() const77 bool Light::has_shadow() const {
78 
79 	return shadow;
80 }
81 
set_negative(bool p_enable)82 void Light::set_negative(bool p_enable) {
83 
84 	negative = p_enable;
85 	VS::get_singleton()->light_set_negative(light, p_enable);
86 }
is_negative() const87 bool Light::is_negative() const {
88 
89 	return negative;
90 }
91 
set_cull_mask(uint32_t p_cull_mask)92 void Light::set_cull_mask(uint32_t p_cull_mask) {
93 
94 	cull_mask = p_cull_mask;
95 	VS::get_singleton()->light_set_cull_mask(light, p_cull_mask);
96 }
get_cull_mask() const97 uint32_t Light::get_cull_mask() const {
98 
99 	return cull_mask;
100 }
101 
set_color(const Color & p_color)102 void Light::set_color(const Color &p_color) {
103 
104 	color = p_color;
105 	VS::get_singleton()->light_set_color(light, p_color);
106 	// The gizmo color depends on the light color, so update it.
107 	update_gizmo();
108 }
get_color() const109 Color Light::get_color() const {
110 
111 	return color;
112 }
113 
set_shadow_color(const Color & p_shadow_color)114 void Light::set_shadow_color(const Color &p_shadow_color) {
115 
116 	shadow_color = p_shadow_color;
117 	VS::get_singleton()->light_set_shadow_color(light, p_shadow_color);
118 }
119 
get_shadow_color() const120 Color Light::get_shadow_color() const {
121 
122 	return shadow_color;
123 }
124 
set_shadow_reverse_cull_face(bool p_enable)125 void Light::set_shadow_reverse_cull_face(bool p_enable) {
126 	reverse_cull = p_enable;
127 	VS::get_singleton()->light_set_reverse_cull_face_mode(light, reverse_cull);
128 }
129 
get_shadow_reverse_cull_face() const130 bool Light::get_shadow_reverse_cull_face() const {
131 
132 	return reverse_cull;
133 }
134 
get_aabb() const135 AABB Light::get_aabb() const {
136 
137 	if (type == VisualServer::LIGHT_DIRECTIONAL) {
138 
139 		return AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));
140 
141 	} else if (type == VisualServer::LIGHT_OMNI) {
142 
143 		return AABB(Vector3(-1, -1, -1) * param[PARAM_RANGE], Vector3(2, 2, 2) * param[PARAM_RANGE]);
144 
145 	} else if (type == VisualServer::LIGHT_SPOT) {
146 
147 		float len = param[PARAM_RANGE];
148 		float size = Math::tan(Math::deg2rad(param[PARAM_SPOT_ANGLE])) * len;
149 		return AABB(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len));
150 	}
151 
152 	return AABB();
153 }
154 
get_faces(uint32_t p_usage_flags) const155 PoolVector<Face3> Light::get_faces(uint32_t p_usage_flags) const {
156 
157 	return PoolVector<Face3>();
158 }
159 
set_bake_mode(BakeMode p_mode)160 void Light::set_bake_mode(BakeMode p_mode) {
161 	bake_mode = p_mode;
162 	VS::get_singleton()->light_set_use_gi(light, p_mode != BAKE_DISABLED);
163 }
164 
get_bake_mode() const165 Light::BakeMode Light::get_bake_mode() const {
166 	return bake_mode;
167 }
168 
_update_visibility()169 void Light::_update_visibility() {
170 
171 	if (!is_inside_tree())
172 		return;
173 
174 	bool editor_ok = true;
175 
176 #ifdef TOOLS_ENABLED
177 	if (editor_only) {
178 		if (!Engine::get_singleton()->is_editor_hint()) {
179 			editor_ok = false;
180 		} else {
181 			editor_ok = (get_tree()->get_edited_scene_root() && (this == get_tree()->get_edited_scene_root() || get_owner() == get_tree()->get_edited_scene_root()));
182 		}
183 	}
184 #else
185 	if (editor_only) {
186 		editor_ok = false;
187 	}
188 #endif
189 
190 	VS::get_singleton()->instance_set_visible(get_instance(), is_visible_in_tree() && editor_ok);
191 
192 	_change_notify("geometry/visible");
193 }
194 
_notification(int p_what)195 void Light::_notification(int p_what) {
196 
197 	if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
198 
199 		_update_visibility();
200 	}
201 
202 	if (p_what == NOTIFICATION_ENTER_TREE) {
203 		_update_visibility();
204 	}
205 }
206 
set_editor_only(bool p_editor_only)207 void Light::set_editor_only(bool p_editor_only) {
208 
209 	editor_only = p_editor_only;
210 	_update_visibility();
211 }
212 
is_editor_only() const213 bool Light::is_editor_only() const {
214 
215 	return editor_only;
216 }
217 
_validate_property(PropertyInfo & property) const218 void Light::_validate_property(PropertyInfo &property) const {
219 
220 	if (VisualServer::get_singleton()->is_low_end() && property.name == "shadow_contact") {
221 		property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL;
222 	}
223 }
224 
_bind_methods()225 void Light::_bind_methods() {
226 
227 	ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light::set_editor_only);
228 	ClassDB::bind_method(D_METHOD("is_editor_only"), &Light::is_editor_only);
229 
230 	ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &Light::set_param);
231 	ClassDB::bind_method(D_METHOD("get_param", "param"), &Light::get_param);
232 
233 	ClassDB::bind_method(D_METHOD("set_shadow", "enabled"), &Light::set_shadow);
234 	ClassDB::bind_method(D_METHOD("has_shadow"), &Light::has_shadow);
235 
236 	ClassDB::bind_method(D_METHOD("set_negative", "enabled"), &Light::set_negative);
237 	ClassDB::bind_method(D_METHOD("is_negative"), &Light::is_negative);
238 
239 	ClassDB::bind_method(D_METHOD("set_cull_mask", "cull_mask"), &Light::set_cull_mask);
240 	ClassDB::bind_method(D_METHOD("get_cull_mask"), &Light::get_cull_mask);
241 
242 	ClassDB::bind_method(D_METHOD("set_color", "color"), &Light::set_color);
243 	ClassDB::bind_method(D_METHOD("get_color"), &Light::get_color);
244 
245 	ClassDB::bind_method(D_METHOD("set_shadow_reverse_cull_face", "enable"), &Light::set_shadow_reverse_cull_face);
246 	ClassDB::bind_method(D_METHOD("get_shadow_reverse_cull_face"), &Light::get_shadow_reverse_cull_face);
247 
248 	ClassDB::bind_method(D_METHOD("set_shadow_color", "shadow_color"), &Light::set_shadow_color);
249 	ClassDB::bind_method(D_METHOD("get_shadow_color"), &Light::get_shadow_color);
250 
251 	ClassDB::bind_method(D_METHOD("set_bake_mode", "bake_mode"), &Light::set_bake_mode);
252 	ClassDB::bind_method(D_METHOD("get_bake_mode"), &Light::get_bake_mode);
253 
254 	ADD_GROUP("Light", "light_");
255 	ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_color", "get_color");
256 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "light_energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_param", "get_param", PARAM_ENERGY);
257 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "light_indirect_energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_param", "get_param", PARAM_INDIRECT_ENERGY);
258 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_negative"), "set_negative", "is_negative");
259 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "light_specular", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SPECULAR);
260 	ADD_PROPERTY(PropertyInfo(Variant::INT, "light_bake_mode", PROPERTY_HINT_ENUM, "Disable,Indirect,All"), "set_bake_mode", "get_bake_mode");
261 	ADD_PROPERTY(PropertyInfo(Variant::INT, "light_cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask");
262 	ADD_GROUP("Shadow", "shadow_");
263 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_enabled"), "set_shadow", "has_shadow");
264 	ADD_PROPERTY(PropertyInfo(Variant::COLOR, "shadow_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_shadow_color", "get_shadow_color");
265 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "shadow_bias", PROPERTY_HINT_RANGE, "-16,16,0.01"), "set_param", "get_param", PARAM_SHADOW_BIAS);
266 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "shadow_contact", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_param", "get_param", PARAM_CONTACT_SHADOW_SIZE);
267 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_reverse_cull_face"), "set_shadow_reverse_cull_face", "get_shadow_reverse_cull_face");
268 	ADD_GROUP("Editor", "");
269 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "is_editor_only");
270 	ADD_GROUP("", "");
271 
272 	BIND_ENUM_CONSTANT(PARAM_ENERGY);
273 	BIND_ENUM_CONSTANT(PARAM_INDIRECT_ENERGY);
274 	BIND_ENUM_CONSTANT(PARAM_SPECULAR);
275 	BIND_ENUM_CONSTANT(PARAM_RANGE);
276 	BIND_ENUM_CONSTANT(PARAM_ATTENUATION);
277 	BIND_ENUM_CONSTANT(PARAM_SPOT_ANGLE);
278 	BIND_ENUM_CONSTANT(PARAM_SPOT_ATTENUATION);
279 	BIND_ENUM_CONSTANT(PARAM_CONTACT_SHADOW_SIZE);
280 	BIND_ENUM_CONSTANT(PARAM_SHADOW_MAX_DISTANCE);
281 	BIND_ENUM_CONSTANT(PARAM_SHADOW_SPLIT_1_OFFSET);
282 	BIND_ENUM_CONSTANT(PARAM_SHADOW_SPLIT_2_OFFSET);
283 	BIND_ENUM_CONSTANT(PARAM_SHADOW_SPLIT_3_OFFSET);
284 	BIND_ENUM_CONSTANT(PARAM_SHADOW_NORMAL_BIAS);
285 	BIND_ENUM_CONSTANT(PARAM_SHADOW_BIAS);
286 	BIND_ENUM_CONSTANT(PARAM_SHADOW_BIAS_SPLIT_SCALE);
287 	BIND_ENUM_CONSTANT(PARAM_MAX);
288 
289 	BIND_ENUM_CONSTANT(BAKE_DISABLED);
290 	BIND_ENUM_CONSTANT(BAKE_INDIRECT);
291 	BIND_ENUM_CONSTANT(BAKE_ALL);
292 }
293 
Light(VisualServer::LightType p_type)294 Light::Light(VisualServer::LightType p_type) {
295 
296 	type = p_type;
297 	switch (p_type) {
298 		case VS::LIGHT_DIRECTIONAL: light = VisualServer::get_singleton()->directional_light_create(); break;
299 		case VS::LIGHT_OMNI: light = VisualServer::get_singleton()->omni_light_create(); break;
300 		case VS::LIGHT_SPOT: light = VisualServer::get_singleton()->spot_light_create(); break;
301 		default: {
302 		};
303 	}
304 
305 	VS::get_singleton()->instance_set_base(get_instance(), light);
306 
307 	reverse_cull = false;
308 	bake_mode = BAKE_INDIRECT;
309 
310 	editor_only = false;
311 	set_color(Color(1, 1, 1, 1));
312 	set_shadow(false);
313 	set_negative(false);
314 	set_cull_mask(0xFFFFFFFF);
315 
316 	set_param(PARAM_ENERGY, 1);
317 	set_param(PARAM_INDIRECT_ENERGY, 1);
318 	set_param(PARAM_SPECULAR, 0.5);
319 	set_param(PARAM_RANGE, 5);
320 	set_param(PARAM_ATTENUATION, 1);
321 	set_param(PARAM_SPOT_ANGLE, 45);
322 	set_param(PARAM_SPOT_ATTENUATION, 1);
323 	set_param(PARAM_CONTACT_SHADOW_SIZE, 0);
324 	set_param(PARAM_SHADOW_MAX_DISTANCE, 0);
325 	set_param(PARAM_SHADOW_SPLIT_1_OFFSET, 0.1);
326 	set_param(PARAM_SHADOW_SPLIT_2_OFFSET, 0.2);
327 	set_param(PARAM_SHADOW_SPLIT_3_OFFSET, 0.5);
328 	set_param(PARAM_SHADOW_NORMAL_BIAS, 0.0);
329 	set_param(PARAM_SHADOW_BIAS, 0.15);
330 	set_disable_scale(true);
331 }
332 
Light()333 Light::Light() {
334 
335 	type = VisualServer::LIGHT_DIRECTIONAL;
336 	ERR_PRINT("Light should not be instanced directly; use the DirectionalLight, OmniLight or SpotLight subtypes instead.");
337 }
338 
~Light()339 Light::~Light() {
340 
341 	VS::get_singleton()->instance_set_base(get_instance(), RID());
342 
343 	if (light.is_valid())
344 		VisualServer::get_singleton()->free(light);
345 }
346 /////////////////////////////////////////
347 
set_shadow_mode(ShadowMode p_mode)348 void DirectionalLight::set_shadow_mode(ShadowMode p_mode) {
349 
350 	shadow_mode = p_mode;
351 	VS::get_singleton()->light_directional_set_shadow_mode(light, VS::LightDirectionalShadowMode(p_mode));
352 }
353 
get_shadow_mode() const354 DirectionalLight::ShadowMode DirectionalLight::get_shadow_mode() const {
355 
356 	return shadow_mode;
357 }
358 
set_shadow_depth_range(ShadowDepthRange p_range)359 void DirectionalLight::set_shadow_depth_range(ShadowDepthRange p_range) {
360 	shadow_depth_range = p_range;
361 	VS::get_singleton()->light_directional_set_shadow_depth_range_mode(light, VS::LightDirectionalShadowDepthRangeMode(p_range));
362 }
363 
get_shadow_depth_range() const364 DirectionalLight::ShadowDepthRange DirectionalLight::get_shadow_depth_range() const {
365 
366 	return shadow_depth_range;
367 }
368 
set_blend_splits(bool p_enable)369 void DirectionalLight::set_blend_splits(bool p_enable) {
370 
371 	blend_splits = p_enable;
372 	VS::get_singleton()->light_directional_set_blend_splits(light, p_enable);
373 }
374 
is_blend_splits_enabled() const375 bool DirectionalLight::is_blend_splits_enabled() const {
376 
377 	return blend_splits;
378 }
379 
_bind_methods()380 void DirectionalLight::_bind_methods() {
381 
382 	ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &DirectionalLight::set_shadow_mode);
383 	ClassDB::bind_method(D_METHOD("get_shadow_mode"), &DirectionalLight::get_shadow_mode);
384 
385 	ClassDB::bind_method(D_METHOD("set_shadow_depth_range", "mode"), &DirectionalLight::set_shadow_depth_range);
386 	ClassDB::bind_method(D_METHOD("get_shadow_depth_range"), &DirectionalLight::get_shadow_depth_range);
387 
388 	ClassDB::bind_method(D_METHOD("set_blend_splits", "enabled"), &DirectionalLight::set_blend_splits);
389 	ClassDB::bind_method(D_METHOD("is_blend_splits_enabled"), &DirectionalLight::is_blend_splits_enabled);
390 
391 	ADD_GROUP("Directional Shadow", "directional_shadow_");
392 	ADD_PROPERTY(PropertyInfo(Variant::INT, "directional_shadow_mode", PROPERTY_HINT_ENUM, "Orthogonal (Fast),PSSM 2 Splits (Average),PSSM 4 Splits (Slow)"), "set_shadow_mode", "get_shadow_mode");
393 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "directional_shadow_split_1", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_1_OFFSET);
394 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "directional_shadow_split_2", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_2_OFFSET);
395 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "directional_shadow_split_3", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_3_OFFSET);
396 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "directional_shadow_blend_splits"), "set_blend_splits", "is_blend_splits_enabled");
397 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "directional_shadow_normal_bias", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_param", "get_param", PARAM_SHADOW_NORMAL_BIAS);
398 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "directional_shadow_bias_split_scale", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SHADOW_BIAS_SPLIT_SCALE);
399 	ADD_PROPERTY(PropertyInfo(Variant::INT, "directional_shadow_depth_range", PROPERTY_HINT_ENUM, "Stable,Optimized"), "set_shadow_depth_range", "get_shadow_depth_range");
400 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "directional_shadow_max_distance", PROPERTY_HINT_EXP_RANGE, "0,8192,0.1,or_greater"), "set_param", "get_param", PARAM_SHADOW_MAX_DISTANCE);
401 
402 	BIND_ENUM_CONSTANT(SHADOW_ORTHOGONAL);
403 	BIND_ENUM_CONSTANT(SHADOW_PARALLEL_2_SPLITS);
404 	BIND_ENUM_CONSTANT(SHADOW_PARALLEL_4_SPLITS);
405 
406 	BIND_ENUM_CONSTANT(SHADOW_DEPTH_RANGE_STABLE);
407 	BIND_ENUM_CONSTANT(SHADOW_DEPTH_RANGE_OPTIMIZED);
408 }
409 
DirectionalLight()410 DirectionalLight::DirectionalLight() :
411 		Light(VisualServer::LIGHT_DIRECTIONAL) {
412 
413 	set_param(PARAM_SHADOW_NORMAL_BIAS, 0.8);
414 	set_param(PARAM_SHADOW_BIAS, 0.1);
415 	set_param(PARAM_SHADOW_MAX_DISTANCE, 100);
416 	set_param(PARAM_SHADOW_BIAS_SPLIT_SCALE, 0.25);
417 	set_shadow_mode(SHADOW_PARALLEL_4_SPLITS);
418 	set_shadow_depth_range(SHADOW_DEPTH_RANGE_STABLE);
419 
420 	blend_splits = false;
421 }
422 
set_shadow_mode(ShadowMode p_mode)423 void OmniLight::set_shadow_mode(ShadowMode p_mode) {
424 
425 	shadow_mode = p_mode;
426 	VS::get_singleton()->light_omni_set_shadow_mode(light, VS::LightOmniShadowMode(p_mode));
427 }
428 
get_shadow_mode() const429 OmniLight::ShadowMode OmniLight::get_shadow_mode() const {
430 
431 	return shadow_mode;
432 }
433 
set_shadow_detail(ShadowDetail p_detail)434 void OmniLight::set_shadow_detail(ShadowDetail p_detail) {
435 
436 	shadow_detail = p_detail;
437 	VS::get_singleton()->light_omni_set_shadow_detail(light, VS::LightOmniShadowDetail(p_detail));
438 }
get_shadow_detail() const439 OmniLight::ShadowDetail OmniLight::get_shadow_detail() const {
440 
441 	return shadow_detail;
442 }
443 
_bind_methods()444 void OmniLight::_bind_methods() {
445 
446 	ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &OmniLight::set_shadow_mode);
447 	ClassDB::bind_method(D_METHOD("get_shadow_mode"), &OmniLight::get_shadow_mode);
448 
449 	ClassDB::bind_method(D_METHOD("set_shadow_detail", "detail"), &OmniLight::set_shadow_detail);
450 	ClassDB::bind_method(D_METHOD("get_shadow_detail"), &OmniLight::get_shadow_detail);
451 
452 	ADD_GROUP("Omni", "omni_");
453 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "omni_range", PROPERTY_HINT_EXP_RANGE, "0,4096,0.1,or_greater"), "set_param", "get_param", PARAM_RANGE);
454 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "omni_attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_param", "get_param", PARAM_ATTENUATION);
455 	ADD_PROPERTY(PropertyInfo(Variant::INT, "omni_shadow_mode", PROPERTY_HINT_ENUM, "Dual Paraboloid,Cube"), "set_shadow_mode", "get_shadow_mode");
456 	ADD_PROPERTY(PropertyInfo(Variant::INT, "omni_shadow_detail", PROPERTY_HINT_ENUM, "Vertical,Horizontal"), "set_shadow_detail", "get_shadow_detail");
457 
458 	BIND_ENUM_CONSTANT(SHADOW_DUAL_PARABOLOID);
459 	BIND_ENUM_CONSTANT(SHADOW_CUBE);
460 
461 	BIND_ENUM_CONSTANT(SHADOW_DETAIL_VERTICAL);
462 	BIND_ENUM_CONSTANT(SHADOW_DETAIL_HORIZONTAL);
463 }
464 
OmniLight()465 OmniLight::OmniLight() :
466 		Light(VisualServer::LIGHT_OMNI) {
467 
468 	set_shadow_mode(SHADOW_CUBE);
469 	set_shadow_detail(SHADOW_DETAIL_HORIZONTAL);
470 }
471 
get_configuration_warning() const472 String SpotLight::get_configuration_warning() const {
473 	String warning = Light::get_configuration_warning();
474 
475 	if (has_shadow() && get_param(PARAM_SPOT_ANGLE) >= 90.0) {
476 		if (warning != String()) {
477 			warning += "\n\n";
478 		}
479 
480 		warning += TTR("A SpotLight with an angle wider than 90 degrees cannot cast shadows.");
481 	}
482 
483 	return warning;
484 }
485 
_bind_methods()486 void SpotLight::_bind_methods() {
487 
488 	ADD_GROUP("Spot", "spot_");
489 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "spot_range", PROPERTY_HINT_EXP_RANGE, "0,4096,0.1,or_greater"), "set_param", "get_param", PARAM_RANGE);
490 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "spot_attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_param", "get_param", PARAM_ATTENUATION);
491 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "spot_angle", PROPERTY_HINT_RANGE, "0,180,0.1"), "set_param", "get_param", PARAM_SPOT_ANGLE);
492 	ADD_PROPERTYI(PropertyInfo(Variant::REAL, "spot_angle_attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_param", "get_param", PARAM_SPOT_ATTENUATION);
493 }
494