2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* light.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "light.h"
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/engine.h"
|
|
|
|
#include "core/project_settings.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/resources/surface_tool.h"
|
|
|
|
|
|
|
|
bool Light::_can_gizmo_scale() const {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-27 14:50:26 +00:00
|
|
|
void Light::set_param(Param p_param, float p_value) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_param, PARAM_MAX);
|
|
|
|
param[p_param] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VS::get_singleton()->light_set_param(light, VS::LightParam(p_param), p_value);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_param == PARAM_SPOT_ANGLE || p_param == PARAM_RANGE) {
|
2017-01-14 17:03:38 +00:00
|
|
|
update_gizmo();
|
2018-09-07 20:59:55 +00:00
|
|
|
|
|
|
|
if (p_param == PARAM_SPOT_ANGLE) {
|
|
|
|
_change_notify("spot_angle");
|
2019-07-07 14:22:09 +00:00
|
|
|
update_configuration_warning();
|
2018-09-07 20:59:55 +00:00
|
|
|
} else if (p_param == PARAM_RANGE) {
|
|
|
|
_change_notify("omni_range");
|
|
|
|
_change_notify("spot_range");
|
|
|
|
}
|
2016-10-27 14:50:26 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float Light::get_param(Param p_param) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
|
2016-10-27 14:50:26 +00:00
|
|
|
return param[p_param];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Light::set_shadow(bool p_enable) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
shadow = p_enable;
|
|
|
|
VS::get_singleton()->light_set_shadow(light, p_enable);
|
2019-07-07 14:22:09 +00:00
|
|
|
|
|
|
|
if (type == VisualServer::LIGHT_SPOT) {
|
|
|
|
update_configuration_warning();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bool Light::has_shadow() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-27 14:50:26 +00:00
|
|
|
return shadow;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Light::set_negative(bool p_enable) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
negative = p_enable;
|
|
|
|
VS::get_singleton()->light_set_negative(light, p_enable);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bool Light::is_negative() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-27 14:50:26 +00:00
|
|
|
return negative;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Light::set_cull_mask(uint32_t p_cull_mask) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
cull_mask = p_cull_mask;
|
|
|
|
VS::get_singleton()->light_set_cull_mask(light, p_cull_mask);
|
2016-10-27 14:50:26 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
uint32_t Light::get_cull_mask() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-27 14:50:26 +00:00
|
|
|
return cull_mask;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Light::set_color(const Color &p_color) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
color = p_color;
|
|
|
|
VS::get_singleton()->light_set_color(light, p_color);
|
2019-12-31 23:52:20 +00:00
|
|
|
// The gizmo color depends on the light color, so update it.
|
|
|
|
update_gizmo();
|
2016-10-27 14:50:26 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
Color Light::get_color() const {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2016-10-27 14:50:26 +00:00
|
|
|
return color;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Light::set_shadow_color(const Color &p_shadow_color) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
shadow_color = p_shadow_color;
|
|
|
|
VS::get_singleton()->light_set_shadow_color(light, p_shadow_color);
|
2016-11-11 15:27:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Color Light::get_shadow_color() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-11-11 15:27:52 +00:00
|
|
|
return shadow_color;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-19 23:06:40 +00:00
|
|
|
void Light::set_shadow_reverse_cull_face(bool p_enable) {
|
|
|
|
reverse_cull = p_enable;
|
|
|
|
VS::get_singleton()->light_set_reverse_cull_face_mode(light, reverse_cull);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Light::get_shadow_reverse_cull_face() const {
|
|
|
|
|
|
|
|
return reverse_cull;
|
|
|
|
}
|
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
AABB Light::get_aabb() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (type == VisualServer::LIGHT_DIRECTIONAL) {
|
2016-10-27 14:50:26 +00:00
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
return AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (type == VisualServer::LIGHT_OMNI) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
return AABB(Vector3(-1, -1, -1) * param[PARAM_RANGE], Vector3(2, 2, 2) * param[PARAM_RANGE]);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (type == VisualServer::LIGHT_SPOT) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float len = param[PARAM_RANGE];
|
|
|
|
float size = Math::tan(Math::deg2rad(param[PARAM_SPOT_ANGLE])) * len;
|
2017-11-17 02:09:00 +00:00
|
|
|
return AABB(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
return AABB();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
PoolVector<Face3> Light::get_faces(uint32_t p_usage_flags) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
return PoolVector<Face3>();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 11:59:46 +00:00
|
|
|
void Light::set_bake_mode(BakeMode p_mode) {
|
|
|
|
bake_mode = p_mode;
|
2019-04-23 09:36:36 +00:00
|
|
|
VS::get_singleton()->light_set_use_gi(light, p_mode != BAKE_DISABLED);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Light::BakeMode Light::get_bake_mode() const {
|
|
|
|
return bake_mode;
|
|
|
|
}
|
|
|
|
|
2014-10-12 05:13:22 +00:00
|
|
|
void Light::_update_visibility() {
|
|
|
|
|
2014-11-06 00:20:42 +00:00
|
|
|
if (!is_inside_tree())
|
2014-10-12 05:13:22 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool editor_ok = true;
|
2014-10-14 04:01:25 +00:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
2014-10-12 05:13:22 +00:00
|
|
|
if (editor_only) {
|
2017-08-18 23:02:56 +00:00
|
|
|
if (!Engine::get_singleton()->is_editor_hint()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
editor_ok = false;
|
2014-10-12 05:13:22 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
editor_ok = (get_tree()->get_edited_scene_root() && (this == get_tree()->get_edited_scene_root() || get_owner() == get_tree()->get_edited_scene_root()));
|
2014-10-12 05:13:22 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-03 14:23:43 +00:00
|
|
|
#else
|
|
|
|
if (editor_only) {
|
2017-03-05 15:44:50 +00:00
|
|
|
editor_ok = false;
|
2016-10-03 14:23:43 +00:00
|
|
|
}
|
2014-10-14 04:01:25 +00:00
|
|
|
#endif
|
2014-10-12 05:13:22 +00:00
|
|
|
|
2018-10-24 14:47:32 +00:00
|
|
|
VS::get_singleton()->instance_set_visible(get_instance(), is_visible_in_tree() && editor_ok);
|
|
|
|
|
2014-10-12 05:13:22 +00:00
|
|
|
_change_notify("geometry/visible");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Light::_notification(int p_what) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
|
2016-12-20 03:21:07 +00:00
|
|
|
|
2014-10-12 05:13:22 +00:00
|
|
|
_update_visibility();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
2016-12-20 03:21:07 +00:00
|
|
|
_update_visibility();
|
2014-10-12 05:13:22 +00:00
|
|
|
}
|
2014-06-11 13:41:03 +00:00
|
|
|
}
|
|
|
|
|
2014-10-12 05:13:22 +00:00
|
|
|
void Light::set_editor_only(bool p_editor_only) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
editor_only = p_editor_only;
|
2014-10-12 05:13:22 +00:00
|
|
|
_update_visibility();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool Light::is_editor_only() const {
|
2014-10-12 05:13:22 +00:00
|
|
|
|
|
|
|
return editor_only;
|
|
|
|
}
|
|
|
|
|
2019-03-03 01:12:01 +00:00
|
|
|
void Light::_validate_property(PropertyInfo &property) const {
|
|
|
|
|
|
|
|
if (VisualServer::get_singleton()->is_low_end() && property.name == "shadow_contact") {
|
|
|
|
property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void Light::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light::set_editor_only);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_editor_only"), &Light::is_editor_only);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &Light::set_param);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_param", "param"), &Light::get_param);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow", "enabled"), &Light::set_shadow);
|
|
|
|
ClassDB::bind_method(D_METHOD("has_shadow"), &Light::has_shadow);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_negative", "enabled"), &Light::set_negative);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_negative"), &Light::is_negative);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_cull_mask", "cull_mask"), &Light::set_cull_mask);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_cull_mask"), &Light::get_cull_mask);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_color", "color"), &Light::set_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color"), &Light::get_color);
|
|
|
|
|
2017-08-19 23:06:40 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_reverse_cull_face", "enable"), &Light::set_shadow_reverse_cull_face);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_reverse_cull_face"), &Light::get_shadow_reverse_cull_face);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_color", "shadow_color"), &Light::set_shadow_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_color"), &Light::get_shadow_color);
|
|
|
|
|
2017-12-14 11:59:46 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bake_mode", "bake_mode"), &Light::set_bake_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bake_mode"), &Light::get_bake_mode);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_GROUP("Light", "light_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_color", "get_color");
|
2019-06-16 21:47:50 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "light_energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_param", "get_param", PARAM_ENERGY);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "light_indirect_energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_param", "get_param", PARAM_INDIRECT_ENERGY);
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_negative"), "set_negative", "is_negative");
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "light_specular", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SPECULAR);
|
2017-12-14 11:59:46 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "light_bake_mode", PROPERTY_HINT_ENUM, "Disable,Indirect,All"), "set_bake_mode", "get_bake_mode");
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "light_cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask");
|
|
|
|
ADD_GROUP("Shadow", "shadow_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_enabled"), "set_shadow", "has_shadow");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "shadow_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_shadow_color", "get_shadow_color");
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "shadow_bias", PROPERTY_HINT_RANGE, "-16,16,0.01"), "set_param", "get_param", PARAM_SHADOW_BIAS);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "shadow_contact", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_param", "get_param", PARAM_CONTACT_SHADOW_SIZE);
|
2017-08-19 23:06:40 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_reverse_cull_face"), "set_shadow_reverse_cull_face", "get_shadow_reverse_cull_face");
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_GROUP("Editor", "");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "is_editor_only");
|
|
|
|
ADD_GROUP("", "");
|
|
|
|
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(PARAM_ENERGY);
|
2017-11-20 00:45:42 +00:00
|
|
|
BIND_ENUM_CONSTANT(PARAM_INDIRECT_ENERGY);
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(PARAM_SPECULAR);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_RANGE);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_ATTENUATION);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_SPOT_ANGLE);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_SPOT_ATTENUATION);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_CONTACT_SHADOW_SIZE);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_SHADOW_MAX_DISTANCE);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_SHADOW_SPLIT_1_OFFSET);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_SHADOW_SPLIT_2_OFFSET);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_SHADOW_SPLIT_3_OFFSET);
|
2019-09-07 17:38:17 +00:00
|
|
|
BIND_ENUM_CONSTANT(PARAM_SHADOW_FADE_START);
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(PARAM_SHADOW_NORMAL_BIAS);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_SHADOW_BIAS);
|
2017-10-21 18:58:02 +00:00
|
|
|
BIND_ENUM_CONSTANT(PARAM_SHADOW_BIAS_SPLIT_SCALE);
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(PARAM_MAX);
|
2017-12-14 11:59:46 +00:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_DISABLED);
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_INDIRECT);
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_ALL);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Light::Light(VisualServer::LightType p_type) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
type = p_type;
|
2017-11-10 02:34:01 +00:00
|
|
|
switch (p_type) {
|
|
|
|
case VS::LIGHT_DIRECTIONAL: light = VisualServer::get_singleton()->directional_light_create(); break;
|
|
|
|
case VS::LIGHT_OMNI: light = VisualServer::get_singleton()->omni_light_create(); break;
|
|
|
|
case VS::LIGHT_SPOT: light = VisualServer::get_singleton()->spot_light_create(); break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
};
|
2017-11-10 02:34:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VS::get_singleton()->instance_set_base(get_instance(), light);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-08-19 23:06:40 +00:00
|
|
|
reverse_cull = false;
|
2017-12-14 11:59:46 +00:00
|
|
|
bake_mode = BAKE_INDIRECT;
|
2017-08-19 23:06:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
editor_only = false;
|
|
|
|
set_color(Color(1, 1, 1, 1));
|
2016-10-27 14:50:26 +00:00
|
|
|
set_shadow(false);
|
|
|
|
set_negative(false);
|
|
|
|
set_cull_mask(0xFFFFFFFF);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
set_param(PARAM_ENERGY, 1);
|
2017-11-20 00:45:42 +00:00
|
|
|
set_param(PARAM_INDIRECT_ENERGY, 1);
|
2017-03-05 15:44:50 +00:00
|
|
|
set_param(PARAM_SPECULAR, 0.5);
|
|
|
|
set_param(PARAM_RANGE, 5);
|
|
|
|
set_param(PARAM_ATTENUATION, 1);
|
|
|
|
set_param(PARAM_SPOT_ANGLE, 45);
|
|
|
|
set_param(PARAM_SPOT_ATTENUATION, 1);
|
|
|
|
set_param(PARAM_CONTACT_SHADOW_SIZE, 0);
|
|
|
|
set_param(PARAM_SHADOW_MAX_DISTANCE, 0);
|
|
|
|
set_param(PARAM_SHADOW_SPLIT_1_OFFSET, 0.1);
|
|
|
|
set_param(PARAM_SHADOW_SPLIT_2_OFFSET, 0.2);
|
|
|
|
set_param(PARAM_SHADOW_SPLIT_3_OFFSET, 0.5);
|
2019-09-07 17:38:17 +00:00
|
|
|
set_param(PARAM_SHADOW_FADE_START, 0.8);
|
2017-06-13 03:07:05 +00:00
|
|
|
set_param(PARAM_SHADOW_NORMAL_BIAS, 0.0);
|
2017-06-14 19:56:47 +00:00
|
|
|
set_param(PARAM_SHADOW_BIAS, 0.15);
|
2019-09-07 17:38:17 +00:00
|
|
|
set_param(PARAM_SHADOW_FADE_START, 1);
|
2018-07-18 16:47:42 +00:00
|
|
|
set_disable_scale(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Light::Light() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
type = VisualServer::LIGHT_DIRECTIONAL;
|
2018-09-07 20:36:39 +00:00
|
|
|
ERR_PRINT("Light should not be instanced directly; use the DirectionalLight, OmniLight or SpotLight subtypes instead.");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Light::~Light() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VS::get_singleton()->instance_set_base(get_instance(), RID());
|
2016-10-27 14:50:26 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (light.is_valid())
|
|
|
|
VisualServer::get_singleton()->free(light);
|
|
|
|
}
|
|
|
|
/////////////////////////////////////////
|
|
|
|
|
|
|
|
void DirectionalLight::set_shadow_mode(ShadowMode p_mode) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
shadow_mode = p_mode;
|
|
|
|
VS::get_singleton()->light_directional_set_shadow_mode(light, VS::LightDirectionalShadowMode(p_mode));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 02:55:06 +00:00
|
|
|
DirectionalLight::ShadowMode DirectionalLight::get_shadow_mode() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return shadow_mode;
|
|
|
|
}
|
|
|
|
|
2017-09-07 21:00:47 +00:00
|
|
|
void DirectionalLight::set_shadow_depth_range(ShadowDepthRange p_range) {
|
2017-09-07 06:57:09 +00:00
|
|
|
shadow_depth_range = p_range;
|
2017-09-07 21:00:47 +00:00
|
|
|
VS::get_singleton()->light_directional_set_shadow_depth_range_mode(light, VS::LightDirectionalShadowDepthRangeMode(p_range));
|
|
|
|
}
|
|
|
|
|
|
|
|
DirectionalLight::ShadowDepthRange DirectionalLight::get_shadow_depth_range() const {
|
|
|
|
|
|
|
|
return shadow_depth_range;
|
|
|
|
}
|
|
|
|
|
2016-11-10 02:55:06 +00:00
|
|
|
void DirectionalLight::set_blend_splits(bool p_enable) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
blend_splits = p_enable;
|
|
|
|
VS::get_singleton()->light_directional_set_blend_splits(light, p_enable);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 02:55:06 +00:00
|
|
|
bool DirectionalLight::is_blend_splits_enabled() const {
|
|
|
|
|
|
|
|
return blend_splits;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DirectionalLight::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &DirectionalLight::set_shadow_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_mode"), &DirectionalLight::get_shadow_mode);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-07 21:00:47 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_depth_range", "mode"), &DirectionalLight::set_shadow_depth_range);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_depth_range"), &DirectionalLight::get_shadow_depth_range);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_blend_splits", "enabled"), &DirectionalLight::set_blend_splits);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_blend_splits_enabled"), &DirectionalLight::is_blend_splits_enabled);
|
2016-11-10 02:55:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_GROUP("Directional Shadow", "directional_shadow_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "directional_shadow_mode", PROPERTY_HINT_ENUM, "Orthogonal,PSSM 2 Splits,PSSM 4 Splits"), "set_shadow_mode", "get_shadow_mode");
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
2019-09-07 17:38:17 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "directional_shadow_fade_start", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SHADOW_FADE_START);
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "directional_shadow_blend_splits"), "set_blend_splits", "is_blend_splits_enabled");
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "directional_shadow_normal_bias", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_param", "get_param", PARAM_SHADOW_NORMAL_BIAS);
|
2017-08-30 11:07:25 +00:00
|
|
|
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);
|
2017-09-07 21:00:47 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "directional_shadow_depth_range", PROPERTY_HINT_ENUM, "Stable,Optimized"), "set_shadow_depth_range", "get_shadow_depth_range");
|
2018-05-16 12:13:41 +00:00
|
|
|
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);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(SHADOW_ORTHOGONAL);
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_PARALLEL_2_SPLITS);
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_PARALLEL_4_SPLITS);
|
2017-09-07 21:00:47 +00:00
|
|
|
|
2017-09-07 06:57:09 +00:00
|
|
|
BIND_ENUM_CONSTANT(SHADOW_DEPTH_RANGE_STABLE);
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_DEPTH_RANGE_OPTIMIZED);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 20:36:34 +00:00
|
|
|
DirectionalLight::DirectionalLight() :
|
|
|
|
Light(VisualServer::LIGHT_DIRECTIONAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-30 11:07:25 +00:00
|
|
|
set_param(PARAM_SHADOW_NORMAL_BIAS, 0.8);
|
|
|
|
set_param(PARAM_SHADOW_BIAS, 0.1);
|
2019-07-17 17:44:00 +00:00
|
|
|
set_param(PARAM_SHADOW_MAX_DISTANCE, 100);
|
2019-09-07 17:38:17 +00:00
|
|
|
set_param(PARAM_SHADOW_FADE_START, 0.8);
|
2017-08-30 11:07:25 +00:00
|
|
|
set_param(PARAM_SHADOW_BIAS_SPLIT_SCALE, 0.25);
|
2016-11-10 02:55:06 +00:00
|
|
|
set_shadow_mode(SHADOW_PARALLEL_4_SPLITS);
|
2017-09-07 21:00:47 +00:00
|
|
|
set_shadow_depth_range(SHADOW_DEPTH_RANGE_STABLE);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
blend_splits = false;
|
2016-11-10 02:55:06 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-11-10 02:55:06 +00:00
|
|
|
void OmniLight::set_shadow_mode(ShadowMode p_mode) {
|
2014-06-11 13:41:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
shadow_mode = p_mode;
|
|
|
|
VS::get_singleton()->light_omni_set_shadow_mode(light, VS::LightOmniShadowMode(p_mode));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OmniLight::ShadowMode OmniLight::get_shadow_mode() const {
|
2016-11-10 02:55:06 +00:00
|
|
|
|
|
|
|
return shadow_mode;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OmniLight::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &OmniLight::set_shadow_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_mode"), &OmniLight::get_shadow_mode);
|
2016-11-10 02:55:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_GROUP("Omni", "omni_");
|
2018-05-16 12:13:41 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "omni_range", PROPERTY_HINT_EXP_RANGE, "0,4096,0.1,or_greater"), "set_param", "get_param", PARAM_RANGE);
|
2018-05-15 20:12:35 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "omni_attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_param", "get_param", PARAM_ATTENUATION);
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "omni_shadow_mode", PROPERTY_HINT_ENUM, "Dual Paraboloid,Cube"), "set_shadow_mode", "get_shadow_mode");
|
2017-09-12 19:09:06 +00:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_DUAL_PARABOLOID);
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_CUBE);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 20:36:34 +00:00
|
|
|
OmniLight::OmniLight() :
|
|
|
|
Light(VisualServer::LIGHT_OMNI) {
|
2016-11-10 02:55:06 +00:00
|
|
|
|
2017-06-13 02:36:33 +00:00
|
|
|
set_shadow_mode(SHADOW_CUBE);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-07 14:22:09 +00:00
|
|
|
String SpotLight::get_configuration_warning() const {
|
|
|
|
String warning = Light::get_configuration_warning();
|
|
|
|
|
|
|
|
if (has_shadow() && get_param(PARAM_SPOT_ANGLE) >= 90.0) {
|
|
|
|
if (warning != String()) {
|
|
|
|
warning += "\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
warning += TTR("A SpotLight with an angle wider than 90 degrees cannot cast shadows.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return warning;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void SpotLight::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_GROUP("Spot", "spot_");
|
2018-05-16 12:13:41 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "spot_range", PROPERTY_HINT_EXP_RANGE, "0,4096,0.1,or_greater"), "set_param", "get_param", PARAM_RANGE);
|
2018-05-15 20:12:35 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "spot_attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_param", "get_param", PARAM_ATTENUATION);
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "spot_angle", PROPERTY_HINT_RANGE, "0,180,0.1"), "set_param", "get_param", PARAM_SPOT_ANGLE);
|
2018-05-15 20:12:35 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "spot_angle_attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_param", "get_param", PARAM_SPOT_ATTENUATION);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|