2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2020-03-26 21:49:16 +00:00
|
|
|
/* light_3d.cpp */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* 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
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 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
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
#include "light_3d.h"
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/config/engine.h"
|
|
|
|
#include "core/config/project_settings.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/resources/surface_tool.h"
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
bool Light3D::_can_gizmo_scale() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-30 00:55:54 +00:00
|
|
|
void Light3D::set_param(Param p_param, real_t p_value) {
|
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
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->light_set_param(light, RS::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) {
|
2021-06-23 14:49:50 +00:00
|
|
|
update_gizmos();
|
2018-09-07 20:59:55 +00:00
|
|
|
|
|
|
|
if (p_param == PARAM_SPOT_ANGLE) {
|
2020-10-29 10:01:28 +00:00
|
|
|
update_configuration_warnings();
|
2018-09-07 20:59:55 +00:00
|
|
|
}
|
2016-10-27 14:50:26 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 00:55:54 +00:00
|
|
|
real_t Light3D::get_param(Param p_param) const {
|
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
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void Light3D::set_shadow(bool p_enable) {
|
2017-03-05 15:44:50 +00:00
|
|
|
shadow = p_enable;
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->light_set_shadow(light, p_enable);
|
2019-07-07 14:22:09 +00:00
|
|
|
|
2020-04-14 20:05:45 +00:00
|
|
|
if (type == RenderingServer::LIGHT_SPOT || type == RenderingServer::LIGHT_OMNI) {
|
2020-10-29 10:01:28 +00:00
|
|
|
update_configuration_warnings();
|
2019-07-07 14:22:09 +00:00
|
|
|
}
|
2020-02-14 02:34:59 +00:00
|
|
|
|
|
|
|
notify_property_list_changed();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
bool Light3D::has_shadow() const {
|
2016-10-27 14:50:26 +00:00
|
|
|
return shadow;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void Light3D::set_negative(bool p_enable) {
|
2017-03-05 15:44:50 +00:00
|
|
|
negative = p_enable;
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->light_set_negative(light, p_enable);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
bool Light3D::is_negative() const {
|
2016-10-27 14:50:26 +00:00
|
|
|
return negative;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void Light3D::set_cull_mask(uint32_t p_cull_mask) {
|
2017-03-05 15:44:50 +00:00
|
|
|
cull_mask = p_cull_mask;
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->light_set_cull_mask(light, p_cull_mask);
|
2016-10-27 14:50:26 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
uint32_t Light3D::get_cull_mask() const {
|
2016-10-27 14:50:26 +00:00
|
|
|
return cull_mask;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void Light3D::set_color(const Color &p_color) {
|
2017-03-05 15:44:50 +00:00
|
|
|
color = p_color;
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::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.
|
2021-06-23 14:49:50 +00:00
|
|
|
update_gizmos();
|
2016-10-27 14:50:26 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Color Light3D::get_color() const {
|
2016-10-27 14:50:26 +00:00
|
|
|
return color;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void Light3D::set_shadow_color(const Color &p_shadow_color) {
|
2017-03-05 15:44:50 +00:00
|
|
|
shadow_color = p_shadow_color;
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::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
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Color Light3D::get_shadow_color() const {
|
2016-11-11 15:27:52 +00:00
|
|
|
return shadow_color;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void Light3D::set_shadow_reverse_cull_face(bool p_enable) {
|
2017-08-19 23:06:40 +00:00
|
|
|
reverse_cull = p_enable;
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->light_set_reverse_cull_face_mode(light, reverse_cull);
|
2017-08-19 23:06:40 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
bool Light3D::get_shadow_reverse_cull_face() const {
|
2017-08-19 23:06:40 +00:00
|
|
|
return reverse_cull;
|
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
AABB Light3D::get_aabb() const {
|
2020-03-27 18:21:27 +00:00
|
|
|
if (type == RenderingServer::LIGHT_DIRECTIONAL) {
|
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
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
} else if (type == RenderingServer::LIGHT_OMNI) {
|
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
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
} else if (type == RenderingServer::LIGHT_SPOT) {
|
2021-01-30 00:55:54 +00:00
|
|
|
real_t len = param[PARAM_RANGE];
|
|
|
|
real_t 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
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Vector<Face3> Light3D::get_faces(uint32_t p_usage_flags) const {
|
2020-02-17 21:06:54 +00:00
|
|
|
return Vector<Face3>();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void Light3D::set_bake_mode(BakeMode p_mode) {
|
2017-12-14 11:59:46 +00:00
|
|
|
bake_mode = p_mode;
|
2020-06-25 13:33:28 +00:00
|
|
|
RS::get_singleton()->light_set_bake_mode(light, RS::LightBakeMode(p_mode));
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Light3D::BakeMode Light3D::get_bake_mode() const {
|
2017-12-14 11:59:46 +00:00
|
|
|
return bake_mode;
|
|
|
|
}
|
|
|
|
|
2020-04-15 07:09:48 +00:00
|
|
|
void Light3D::set_projector(const Ref<Texture2D> &p_texture) {
|
2020-04-14 20:05:45 +00:00
|
|
|
projector = p_texture;
|
|
|
|
RID tex_id = projector.is_valid() ? projector->get_rid() : RID();
|
|
|
|
RS::get_singleton()->light_set_projector(light, tex_id);
|
2020-10-29 10:01:28 +00:00
|
|
|
update_configuration_warnings();
|
2020-04-14 20:05:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Texture2D> Light3D::get_projector() const {
|
|
|
|
return projector;
|
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void Light3D::_update_visibility() {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!is_inside_tree()) {
|
2014-10-12 05:13:22 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-10-12 05:13:22 +00:00
|
|
|
|
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
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->instance_set_visible(get_instance(), is_visible_in_tree() && editor_ok);
|
2014-10-12 05:13:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void Light3D::_notification(int p_what) {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
|
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
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void Light3D::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();
|
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
bool Light3D::is_editor_only() const {
|
2014-10-12 05:13:22 +00:00
|
|
|
return editor_only;
|
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void Light3D::_validate_property(PropertyInfo &property) const {
|
2021-03-03 23:51:35 +00:00
|
|
|
if (!shadow && (property.name == "shadow_color" || property.name == "shadow_bias" || property.name == "shadow_normal_bias" || property.name == "shadow_reverse_cull_face" || property.name == "shadow_transmittance_bias" || property.name == "shadow_fog_fade" || property.name == "shadow_blur")) {
|
2020-02-14 02:34:59 +00:00
|
|
|
property.usage = PROPERTY_USAGE_NOEDITOR;
|
|
|
|
}
|
|
|
|
|
2020-04-09 18:11:15 +00:00
|
|
|
if (get_light_type() == RS::LIGHT_DIRECTIONAL && property.name == "light_size") {
|
2021-07-01 01:24:34 +00:00
|
|
|
property.usage = PROPERTY_USAGE_NONE;
|
2020-04-09 18:11:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-17 16:25:38 +00:00
|
|
|
if (get_light_type() == RS::LIGHT_DIRECTIONAL && property.name == "light_specular") {
|
2021-07-01 01:24:34 +00:00
|
|
|
property.usage = PROPERTY_USAGE_NONE;
|
2021-01-17 16:25:38 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 20:05:45 +00:00
|
|
|
if (get_light_type() == RS::LIGHT_DIRECTIONAL && property.name == "light_projector") {
|
2021-07-01 01:24:34 +00:00
|
|
|
property.usage = PROPERTY_USAGE_NONE;
|
2020-04-14 20:05:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 18:11:15 +00:00
|
|
|
if (get_light_type() != RS::LIGHT_DIRECTIONAL && property.name == "light_angular_distance") {
|
2021-07-01 01:24:34 +00:00
|
|
|
property.usage = PROPERTY_USAGE_NONE;
|
2020-04-09 18:11:15 +00:00
|
|
|
}
|
2019-03-03 01:12:01 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void Light3D::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light3D::set_editor_only);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_editor_only"), &Light3D::is_editor_only);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &Light3D::set_param);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_param", "param"), &Light3D::get_param);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow", "enabled"), &Light3D::set_shadow);
|
|
|
|
ClassDB::bind_method(D_METHOD("has_shadow"), &Light3D::has_shadow);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_negative", "enabled"), &Light3D::set_negative);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_negative"), &Light3D::is_negative);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_cull_mask", "cull_mask"), &Light3D::set_cull_mask);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_cull_mask"), &Light3D::get_cull_mask);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_color", "color"), &Light3D::set_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color"), &Light3D::get_color);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_reverse_cull_face", "enable"), &Light3D::set_shadow_reverse_cull_face);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_reverse_cull_face"), &Light3D::get_shadow_reverse_cull_face);
|
2017-08-19 23:06:40 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_color", "shadow_color"), &Light3D::set_shadow_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_color"), &Light3D::get_shadow_color);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bake_mode", "bake_mode"), &Light3D::set_bake_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bake_mode"), &Light3D::get_bake_mode);
|
2017-12-14 11:59:46 +00:00
|
|
|
|
2020-04-14 20:05:45 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_projector", "projector"), &Light3D::set_projector);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_projector"), &Light3D::get_projector);
|
|
|
|
|
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");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_param", "get_param", PARAM_ENERGY);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_indirect_energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_param", "get_param", PARAM_INDIRECT_ENERGY);
|
2020-04-14 20:05:45 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "light_projector", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_projector", "get_projector");
|
2020-05-08 09:22:41 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_size", PROPERTY_HINT_RANGE, "0,1,0.01,or_greater"), "set_param", "get_param", PARAM_SIZE);
|
2020-04-09 18:11:15 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_angular_distance", PROPERTY_HINT_RANGE, "0,90,0.01"), "set_param", "get_param", PARAM_SIZE);
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_negative"), "set_negative", "is_negative");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_specular", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SPECULAR);
|
2020-06-25 13:33:28 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "light_bake_mode", PROPERTY_HINT_ENUM, "Disabled,Dynamic,Static"), "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");
|
2020-04-08 01:51:52 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_bias", PROPERTY_HINT_RANGE, "0,10,0.001"), "set_param", "get_param", PARAM_SHADOW_BIAS);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_normal_bias", PROPERTY_HINT_RANGE, "0,10,0.001"), "set_param", "get_param", PARAM_SHADOW_NORMAL_BIAS);
|
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");
|
2020-04-08 01:51:52 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_transmittance_bias", PROPERTY_HINT_RANGE, "-16,16,0.01"), "set_param", "get_param", PARAM_TRANSMITTANCE_BIAS);
|
2020-08-13 01:21:01 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_fog_fade", PROPERTY_HINT_RANGE, "0.01,10,0.01"), "set_param", "get_param", PARAM_SHADOW_VOLUMETRIC_FOG_FADE);
|
2020-04-10 09:30:36 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_blur", PROPERTY_HINT_RANGE, "0.1,8,0.01"), "set_param", "get_param", PARAM_SHADOW_BLUR);
|
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);
|
2020-04-20 09:48:00 +00:00
|
|
|
BIND_ENUM_CONSTANT(PARAM_SIZE);
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(PARAM_ATTENUATION);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_SPOT_ANGLE);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_SPOT_ATTENUATION);
|
|
|
|
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);
|
2020-04-08 01:51:52 +00:00
|
|
|
BIND_ENUM_CONSTANT(PARAM_SHADOW_PANCAKE_SIZE);
|
2020-04-10 09:30:36 +00:00
|
|
|
BIND_ENUM_CONSTANT(PARAM_SHADOW_BLUR);
|
2020-08-13 01:21:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(PARAM_SHADOW_VOLUMETRIC_FOG_FADE);
|
2020-04-08 01:51:52 +00:00
|
|
|
BIND_ENUM_CONSTANT(PARAM_TRANSMITTANCE_BIAS);
|
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);
|
2020-06-25 13:33:28 +00:00
|
|
|
BIND_ENUM_CONSTANT(BAKE_DYNAMIC);
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_STATIC);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
Light3D::Light3D(RenderingServer::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) {
|
2020-05-10 11:00:47 +00:00
|
|
|
case RS::LIGHT_DIRECTIONAL:
|
|
|
|
light = RenderingServer::get_singleton()->directional_light_create();
|
|
|
|
break;
|
|
|
|
case RS::LIGHT_OMNI:
|
|
|
|
light = RenderingServer::get_singleton()->omni_light_create();
|
|
|
|
break;
|
|
|
|
case RS::LIGHT_SPOT:
|
|
|
|
light = RenderingServer::get_singleton()->spot_light_create();
|
|
|
|
break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
};
|
2017-11-10 02:34:01 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->instance_set_base(get_instance(), light);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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);
|
2020-04-09 18:11:15 +00:00
|
|
|
set_param(PARAM_SIZE, 0);
|
2017-03-05 15:44:50 +00:00
|
|
|
set_param(PARAM_ATTENUATION, 1);
|
|
|
|
set_param(PARAM_SPOT_ANGLE, 45);
|
|
|
|
set_param(PARAM_SPOT_ATTENUATION, 1);
|
|
|
|
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);
|
2020-04-08 01:51:52 +00:00
|
|
|
set_param(PARAM_SHADOW_PANCAKE_SIZE, 20.0);
|
2020-04-10 09:30:36 +00:00
|
|
|
set_param(PARAM_SHADOW_BLUR, 1.0);
|
2020-04-08 01:51:52 +00:00
|
|
|
set_param(PARAM_SHADOW_BIAS, 0.02);
|
|
|
|
set_param(PARAM_SHADOW_NORMAL_BIAS, 1.0);
|
|
|
|
set_param(PARAM_TRANSMITTANCE_BIAS, 0.05);
|
2021-02-06 14:51:56 +00:00
|
|
|
set_param(PARAM_SHADOW_VOLUMETRIC_FOG_FADE, 0.1);
|
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
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Light3D::Light3D() {
|
2021-06-17 22:03:09 +00:00
|
|
|
ERR_PRINT("Light3D should not be instantiated directly; use the DirectionalLight3D, OmniLight3D or SpotLight3D subtypes instead.");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Light3D::~Light3D() {
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->instance_set_base(get_instance(), RID());
|
2016-10-27 14:50:26 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (light.is_valid()) {
|
2020-03-27 18:21:27 +00:00
|
|
|
RenderingServer::get_singleton()->free(light);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/////////////////////////////////////////
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void DirectionalLight3D::set_shadow_mode(ShadowMode p_mode) {
|
2017-03-05 15:44:50 +00:00
|
|
|
shadow_mode = p_mode;
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->light_directional_set_shadow_mode(light, RS::LightDirectionalShadowMode(p_mode));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
DirectionalLight3D::ShadowMode DirectionalLight3D::get_shadow_mode() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return shadow_mode;
|
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void DirectionalLight3D::set_blend_splits(bool p_enable) {
|
2017-03-05 15:44:50 +00:00
|
|
|
blend_splits = p_enable;
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->light_directional_set_blend_splits(light, p_enable);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
bool DirectionalLight3D::is_blend_splits_enabled() const {
|
2016-11-10 02:55:06 +00:00
|
|
|
return blend_splits;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-10-22 06:22:53 +00:00
|
|
|
void DirectionalLight3D::set_sky_only(bool p_sky_only) {
|
|
|
|
sky_only = p_sky_only;
|
|
|
|
RS::get_singleton()->light_directional_set_sky_only(light, p_sky_only);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DirectionalLight3D::is_sky_only() const {
|
|
|
|
return sky_only;
|
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void DirectionalLight3D::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &DirectionalLight3D::set_shadow_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_mode"), &DirectionalLight3D::get_shadow_mode);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_blend_splits", "enabled"), &DirectionalLight3D::set_blend_splits);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_blend_splits_enabled"), &DirectionalLight3D::is_blend_splits_enabled);
|
2016-11-10 02:55:06 +00:00
|
|
|
|
2020-10-22 06:22:53 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_sky_only", "priority"), &DirectionalLight3D::set_sky_only);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_sky_only"), &DirectionalLight3D::is_sky_only);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_GROUP("Directional Shadow", "directional_shadow_");
|
2020-05-31 23:20:35 +00:00
|
|
|
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");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_split_1", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_1_OFFSET);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_split_2", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_2_OFFSET);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_split_3", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_3_OFFSET);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "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");
|
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 19:42:12 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_max_distance", PROPERTY_HINT_RANGE, "0,8192,0.1,or_greater,exp"), "set_param", "get_param", PARAM_SHADOW_MAX_DISTANCE);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_pancake_size", PROPERTY_HINT_RANGE, "0,1024,0.1,or_greater,exp"), "set_param", "get_param", PARAM_SHADOW_PANCAKE_SIZE);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-10-22 06:22:53 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_in_sky_only"), "set_sky_only", "is_sky_only");
|
|
|
|
|
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);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
DirectionalLight3D::DirectionalLight3D() :
|
2020-03-27 18:21:27 +00:00
|
|
|
Light3D(RenderingServer::LIGHT_DIRECTIONAL) {
|
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);
|
2020-05-21 18:16:23 +00:00
|
|
|
// Increase the default shadow bias to better suit most scenes.
|
|
|
|
// Leave normal bias untouched as it doesn't benefit DirectionalLight3D as much as OmniLight3D.
|
|
|
|
set_param(PARAM_SHADOW_BIAS, 0.05);
|
2016-11-10 02:55:06 +00:00
|
|
|
set_shadow_mode(SHADOW_PARALLEL_4_SPLITS);
|
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
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void OmniLight3D::set_shadow_mode(ShadowMode p_mode) {
|
2017-03-05 15:44:50 +00:00
|
|
|
shadow_mode = p_mode;
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->light_omni_set_shadow_mode(light, RS::LightOmniShadowMode(p_mode));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
OmniLight3D::ShadowMode OmniLight3D::get_shadow_mode() const {
|
2016-11-10 02:55:06 +00:00
|
|
|
return shadow_mode;
|
|
|
|
}
|
|
|
|
|
2020-10-29 10:01:28 +00:00
|
|
|
TypedArray<String> OmniLight3D::get_configuration_warnings() const {
|
|
|
|
TypedArray<String> warnings = Node::get_configuration_warnings();
|
2020-04-14 20:05:45 +00:00
|
|
|
|
|
|
|
if (!has_shadow() && get_projector().is_valid()) {
|
2020-10-29 10:01:28 +00:00
|
|
|
warnings.push_back(TTR("Projector texture only works with shadows active."));
|
2020-04-14 20:05:45 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 10:01:28 +00:00
|
|
|
return warnings;
|
2020-04-14 20:05:45 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void OmniLight3D::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &OmniLight3D::set_shadow_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_mode"), &OmniLight3D::get_shadow_mode);
|
2016-11-10 02:55:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_GROUP("Omni", "omni_");
|
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 19:42:12 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "omni_range", PROPERTY_HINT_RANGE, "0,4096,0.1,or_greater,exp"), "set_param", "get_param", PARAM_RANGE);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "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
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
OmniLight3D::OmniLight3D() :
|
2020-03-27 18:21:27 +00:00
|
|
|
Light3D(RenderingServer::LIGHT_OMNI) {
|
2017-06-13 02:36:33 +00:00
|
|
|
set_shadow_mode(SHADOW_CUBE);
|
2020-05-21 18:16:23 +00:00
|
|
|
// Increase the default shadow biases to better suit most scenes.
|
|
|
|
set_param(PARAM_SHADOW_BIAS, 0.1);
|
|
|
|
set_param(PARAM_SHADOW_NORMAL_BIAS, 2.0);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 10:01:28 +00:00
|
|
|
TypedArray<String> SpotLight3D::get_configuration_warnings() const {
|
|
|
|
TypedArray<String> warnings = Node::get_configuration_warnings();
|
2019-07-07 14:22:09 +00:00
|
|
|
|
|
|
|
if (has_shadow() && get_param(PARAM_SPOT_ANGLE) >= 90.0) {
|
2020-10-29 10:01:28 +00:00
|
|
|
warnings.push_back(TTR("A SpotLight3D with an angle wider than 90 degrees cannot cast shadows."));
|
2019-07-07 14:22:09 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 20:05:45 +00:00
|
|
|
if (!has_shadow() && get_projector().is_valid()) {
|
2020-10-29 10:01:28 +00:00
|
|
|
warnings.push_back(TTR("Projector texture only works with shadows active."));
|
2020-04-14 20:05:45 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 10:01:28 +00:00
|
|
|
return warnings;
|
2019-07-07 14:22:09 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void SpotLight3D::_bind_methods() {
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_GROUP("Spot", "spot_");
|
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 19:42:12 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "spot_range", PROPERTY_HINT_RANGE, "0,4096,0.1,or_greater,exp"), "set_param", "get_param", PARAM_RANGE);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "spot_attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_param", "get_param", PARAM_ATTENUATION);
|
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-29 19:42:12 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "spot_angle", PROPERTY_HINT_RANGE, "0,180,0.1,degrees"), "set_param", "get_param", PARAM_SPOT_ANGLE);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "spot_angle_attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_param", "get_param", PARAM_SPOT_ATTENUATION);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|