2016-06-18 20:46:12 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* light_2d.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 20:16:55 +08:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 20:46:12 +08:00
|
|
|
/*************************************************************************/
|
2019-01-01 19:53:14 +08:00
|
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
2016-06-18 20:46:12 +08: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-05 07:50:27 +08:00
|
|
|
|
2015-02-17 01:45:11 +08:00
|
|
|
#include "light_2d.h"
|
2017-08-19 07:02:56 +08:00
|
|
|
|
2018-09-12 00:13:45 +08:00
|
|
|
#include "core/engine.h"
|
2015-02-17 01:45:11 +08:00
|
|
|
#include "servers/visual_server.h"
|
|
|
|
|
2017-11-07 15:58:35 +08:00
|
|
|
Dictionary Light2D::_edit_get_state() const {
|
|
|
|
Dictionary state = Node2D::_edit_get_state();
|
|
|
|
state["offset"] = get_texture_offset();
|
|
|
|
return state;
|
|
|
|
}
|
2015-02-19 06:39:44 +08:00
|
|
|
|
2017-11-07 15:58:35 +08:00
|
|
|
void Light2D::_edit_set_state(const Dictionary &p_state) {
|
|
|
|
Node2D::_edit_set_state(p_state);
|
|
|
|
set_texture_offset(p_state["offset"]);
|
2015-02-19 06:39:44 +08:00
|
|
|
}
|
|
|
|
|
2017-11-07 15:58:35 +08:00
|
|
|
void Light2D::_edit_set_pivot(const Point2 &p_pivot) {
|
|
|
|
set_position(get_transform().xform(p_pivot));
|
|
|
|
set_texture_offset(get_texture_offset() - p_pivot);
|
|
|
|
}
|
2015-02-19 06:39:44 +08:00
|
|
|
|
2017-11-07 15:58:35 +08:00
|
|
|
Point2 Light2D::_edit_get_pivot() const {
|
|
|
|
return Vector2();
|
2015-02-19 06:39:44 +08:00
|
|
|
}
|
|
|
|
|
2017-11-07 15:58:35 +08:00
|
|
|
bool Light2D::_edit_use_pivot() const {
|
2015-02-19 06:39:44 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-16 06:03:25 +08:00
|
|
|
Rect2 Light2D::_edit_get_rect() const {
|
2015-02-19 06:39:44 +08:00
|
|
|
if (texture.is_null())
|
2018-05-05 22:59:00 +08:00
|
|
|
return Rect2();
|
2015-02-19 06:39:44 +08:00
|
|
|
|
2017-11-07 15:58:35 +08:00
|
|
|
Size2 s = texture->get_size() * _scale;
|
|
|
|
return Rect2(texture_offset - s / 2.0, s);
|
2015-02-19 06:39:44 +08:00
|
|
|
}
|
|
|
|
|
2018-03-09 04:35:41 +08:00
|
|
|
bool Light2D::_edit_use_rect() const {
|
2018-05-05 22:59:00 +08:00
|
|
|
return !texture.is_null();
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect2 Light2D::get_anchorable_rect() const {
|
|
|
|
if (texture.is_null())
|
|
|
|
return Rect2();
|
|
|
|
|
|
|
|
Size2 s = texture->get_size() * _scale;
|
|
|
|
return Rect2(texture_offset - s / 2.0, s);
|
2018-03-09 04:35:41 +08:00
|
|
|
}
|
|
|
|
|
2016-01-01 21:45:24 +08:00
|
|
|
void Light2D::_update_light_visibility() {
|
|
|
|
|
|
|
|
if (!is_inside_tree())
|
|
|
|
return;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
bool editor_ok = true;
|
2016-10-04 22:44:59 +08:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (editor_only) {
|
2017-08-19 07:02:56 +08:00
|
|
|
if (!Engine::get_singleton()->is_editor_hint()) {
|
2017-03-05 23:44:50 +08:00
|
|
|
editor_ok = false;
|
2016-10-04 22:44:59 +08:00
|
|
|
} else {
|
2017-03-05 23:44:50 +08:00
|
|
|
editor_ok = (get_tree()->get_edited_scene_root() && (this == get_tree()->get_edited_scene_root() || get_owner() == get_tree()->get_edited_scene_root()));
|
2016-10-04 22:44:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (editor_only) {
|
2017-03-05 23:44:50 +08:00
|
|
|
editor_ok = false;
|
2016-10-04 22:44:59 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->canvas_light_set_enabled(canvas_light, enabled && is_visible_in_tree() && editor_ok);
|
2016-01-01 21:45:24 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_enabled(bool p_enabled) {
|
2016-01-01 21:45:24 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
enabled = p_enabled;
|
2016-01-01 21:45:24 +08:00
|
|
|
_update_light_visibility();
|
2015-02-17 01:45:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Light2D::is_enabled() const {
|
|
|
|
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
2016-10-04 22:44:59 +08:00
|
|
|
void Light2D::set_editor_only(bool p_editor_only) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
editor_only = p_editor_only;
|
2016-10-04 22:44:59 +08:00
|
|
|
_update_light_visibility();
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
bool Light2D::is_editor_only() const {
|
2016-10-04 22:44:59 +08:00
|
|
|
|
|
|
|
return editor_only;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_texture(const Ref<Texture> &p_texture) {
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
texture = p_texture;
|
2015-02-17 01:45:11 +08:00
|
|
|
if (texture.is_valid())
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->canvas_light_set_texture(canvas_light, texture->get_rid());
|
2015-02-17 01:45:11 +08:00
|
|
|
else
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->canvas_light_set_texture(canvas_light, RID());
|
2016-05-18 05:27:15 +08:00
|
|
|
|
|
|
|
update_configuration_warning();
|
2015-02-17 01:45:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Texture> Light2D::get_texture() const {
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_texture_offset(const Vector2 &p_offset) {
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
texture_offset = p_offset;
|
|
|
|
VS::get_singleton()->canvas_light_set_texture_offset(canvas_light, texture_offset);
|
2015-03-11 08:05:49 +08:00
|
|
|
item_rect_changed();
|
2017-11-07 15:58:35 +08:00
|
|
|
_change_notify("offset");
|
2015-02-17 01:45:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 Light2D::get_texture_offset() const {
|
|
|
|
|
|
|
|
return texture_offset;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_color(const Color &p_color) {
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
color = p_color;
|
|
|
|
VS::get_singleton()->canvas_light_set_color(canvas_light, color);
|
2015-02-17 01:45:11 +08:00
|
|
|
}
|
|
|
|
Color Light2D::get_color() const {
|
|
|
|
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_height(float p_height) {
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
height = p_height;
|
|
|
|
VS::get_singleton()->canvas_light_set_height(canvas_light, height);
|
2015-02-17 01:45:11 +08:00
|
|
|
}
|
2015-03-11 08:05:49 +08:00
|
|
|
|
2015-02-17 01:45:11 +08:00
|
|
|
float Light2D::get_height() const {
|
|
|
|
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_energy(float p_energy) {
|
2015-04-03 12:43:37 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
energy = p_energy;
|
|
|
|
VS::get_singleton()->canvas_light_set_energy(canvas_light, energy);
|
2015-04-03 12:43:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
float Light2D::get_energy() const {
|
|
|
|
|
|
|
|
return energy;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_texture_scale(float p_scale) {
|
2015-04-03 12:43:37 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
_scale = p_scale;
|
|
|
|
VS::get_singleton()->canvas_light_set_scale(canvas_light, _scale);
|
2015-03-11 08:05:49 +08:00
|
|
|
item_rect_changed();
|
|
|
|
}
|
|
|
|
|
2015-03-22 21:39:32 +08:00
|
|
|
float Light2D::get_texture_scale() const {
|
2015-03-11 08:05:49 +08:00
|
|
|
|
2015-03-22 21:33:58 +08:00
|
|
|
return _scale;
|
2015-03-11 08:05:49 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_z_range_min(int p_min_z) {
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
z_min = p_min_z;
|
|
|
|
VS::get_singleton()->canvas_light_set_z_range(canvas_light, z_min, z_max);
|
2015-02-17 01:45:11 +08:00
|
|
|
}
|
|
|
|
int Light2D::get_z_range_min() const {
|
|
|
|
|
|
|
|
return z_min;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_z_range_max(int p_max_z) {
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
z_max = p_max_z;
|
|
|
|
VS::get_singleton()->canvas_light_set_z_range(canvas_light, z_min, z_max);
|
2015-02-17 01:45:11 +08:00
|
|
|
}
|
|
|
|
int Light2D::get_z_range_max() const {
|
|
|
|
|
|
|
|
return z_max;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_layer_range_min(int p_min_layer) {
|
2015-02-19 06:39:44 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
layer_min = p_min_layer;
|
|
|
|
VS::get_singleton()->canvas_light_set_layer_range(canvas_light, layer_min, layer_max);
|
2015-02-19 06:39:44 +08:00
|
|
|
}
|
|
|
|
int Light2D::get_layer_range_min() const {
|
|
|
|
|
|
|
|
return layer_min;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_layer_range_max(int p_max_layer) {
|
2015-02-19 06:39:44 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
layer_max = p_max_layer;
|
|
|
|
VS::get_singleton()->canvas_light_set_layer_range(canvas_light, layer_min, layer_max);
|
2015-02-19 06:39:44 +08:00
|
|
|
}
|
|
|
|
int Light2D::get_layer_range_max() const {
|
|
|
|
|
|
|
|
return layer_max;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_item_cull_mask(int p_mask) {
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
item_mask = p_mask;
|
|
|
|
VS::get_singleton()->canvas_light_set_item_cull_mask(canvas_light, item_mask);
|
2015-02-17 01:45:11 +08:00
|
|
|
}
|
|
|
|
|
2016-10-04 03:33:42 +08:00
|
|
|
int Light2D::get_item_cull_mask() const {
|
2015-02-17 01:45:11 +08:00
|
|
|
|
|
|
|
return item_mask;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_item_shadow_cull_mask(int p_mask) {
|
2015-03-09 13:34:56 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
item_shadow_mask = p_mask;
|
|
|
|
VS::get_singleton()->canvas_light_set_item_shadow_cull_mask(canvas_light, item_shadow_mask);
|
2015-03-09 13:34:56 +08:00
|
|
|
}
|
|
|
|
|
2016-10-04 03:33:42 +08:00
|
|
|
int Light2D::get_item_shadow_cull_mask() const {
|
2015-03-09 13:34:56 +08:00
|
|
|
|
|
|
|
return item_shadow_mask;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_mode(Mode p_mode) {
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
mode = p_mode;
|
|
|
|
VS::get_singleton()->canvas_light_set_mode(canvas_light, VS::CanvasLightMode(p_mode));
|
2015-02-17 01:45:11 +08:00
|
|
|
}
|
|
|
|
|
2015-04-03 12:43:37 +08:00
|
|
|
Light2D::Mode Light2D::get_mode() const {
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2015-04-03 12:43:37 +08:00
|
|
|
return mode;
|
2015-02-17 01:45:11 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_shadow_enabled(bool p_enabled) {
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
shadow = p_enabled;
|
|
|
|
VS::get_singleton()->canvas_light_set_shadow_enabled(canvas_light, shadow);
|
2015-02-17 01:45:11 +08:00
|
|
|
}
|
|
|
|
bool Light2D::is_shadow_enabled() const {
|
|
|
|
|
|
|
|
return shadow;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_shadow_buffer_size(int p_size) {
|
2015-03-02 11:54:10 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
shadow_buffer_size = p_size;
|
|
|
|
VS::get_singleton()->canvas_light_set_shadow_buffer_size(canvas_light, shadow_buffer_size);
|
2015-03-02 11:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Light2D::get_shadow_buffer_size() const {
|
|
|
|
|
|
|
|
return shadow_buffer_size;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_shadow_gradient_length(float p_multiplier) {
|
2015-03-02 11:54:10 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
shadow_gradient_length = p_multiplier;
|
|
|
|
VS::get_singleton()->canvas_light_set_shadow_gradient_length(canvas_light, p_multiplier);
|
2015-03-02 11:54:10 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
float Light2D::get_shadow_gradient_length() const {
|
2015-03-02 11:54:10 +08:00
|
|
|
|
2016-10-04 03:33:42 +08:00
|
|
|
return shadow_gradient_length;
|
2015-03-02 11:54:10 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_shadow_filter(ShadowFilter p_filter) {
|
|
|
|
shadow_filter = p_filter;
|
|
|
|
VS::get_singleton()->canvas_light_set_shadow_filter(canvas_light, VS::CanvasLightShadowFilter(p_filter));
|
2016-10-04 03:33:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Light2D::ShadowFilter Light2D::get_shadow_filter() const {
|
|
|
|
|
|
|
|
return shadow_filter;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void Light2D::set_shadow_color(const Color &p_shadow_color) {
|
|
|
|
shadow_color = p_shadow_color;
|
|
|
|
VS::get_singleton()->canvas_light_set_shadow_color(canvas_light, shadow_color);
|
2015-06-25 05:15:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Color Light2D::get_shadow_color() const {
|
|
|
|
return shadow_color;
|
|
|
|
}
|
|
|
|
|
2015-02-19 06:39:44 +08:00
|
|
|
void Light2D::_notification(int p_what) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
2015-02-19 06:39:44 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, get_canvas());
|
2016-01-01 21:45:24 +08:00
|
|
|
_update_light_visibility();
|
2015-02-19 06:39:44 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
|
2015-02-19 06:39:44 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform());
|
2015-02-19 06:39:44 +08:00
|
|
|
}
|
2017-03-05 23:44:50 +08:00
|
|
|
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
|
2016-01-01 21:45:24 +08:00
|
|
|
|
|
|
|
_update_light_visibility();
|
|
|
|
}
|
2015-02-19 06:39:44 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
if (p_what == NOTIFICATION_EXIT_TREE) {
|
2015-02-19 06:39:44 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, RID());
|
2016-01-01 21:45:24 +08:00
|
|
|
_update_light_visibility();
|
2015-02-19 06:39:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 05:27:15 +08:00
|
|
|
String Light2D::get_configuration_warning() const {
|
|
|
|
|
|
|
|
if (!texture.is_valid()) {
|
|
|
|
return TTR("A texture with the shape of the light must be supplied to the 'texture' property.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-06-13 12:23:04 +08:00
|
|
|
void Light2D::set_shadow_smooth(float p_amount) {
|
|
|
|
|
|
|
|
shadow_smooth = p_amount;
|
|
|
|
VS::get_singleton()->canvas_light_set_shadow_smooth(canvas_light, shadow_smooth);
|
|
|
|
}
|
|
|
|
|
|
|
|
float Light2D::get_shadow_smooth() const {
|
|
|
|
|
|
|
|
return shadow_smooth;
|
|
|
|
}
|
|
|
|
|
2015-02-17 01:45:11 +08:00
|
|
|
void Light2D::_bind_methods() {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &Light2D::set_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_enabled"), &Light2D::is_enabled);
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light2D::set_editor_only);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_editor_only"), &Light2D::is_editor_only);
|
2015-04-03 12:43:37 +08:00
|
|
|
|
2017-08-09 19:19:41 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &Light2D::set_texture);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture"), &Light2D::get_texture);
|
2015-03-11 08:05:49 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_texture_offset", "texture_offset"), &Light2D::set_texture_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture_offset"), &Light2D::get_texture_offset);
|
2015-03-11 08:05:49 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_color", "color"), &Light2D::set_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color"), &Light2D::get_color);
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_height", "height"), &Light2D::set_height);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_height"), &Light2D::get_height);
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_energy", "energy"), &Light2D::set_energy);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_energy"), &Light2D::get_energy);
|
2015-02-19 06:39:44 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_texture_scale", "texture_scale"), &Light2D::set_texture_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture_scale"), &Light2D::get_texture_scale);
|
2015-02-19 06:39:44 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_z_range_min", "z"), &Light2D::set_z_range_min);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_z_range_min"), &Light2D::get_z_range_min);
|
2015-02-19 06:39:44 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_z_range_max", "z"), &Light2D::set_z_range_max);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_z_range_max"), &Light2D::get_z_range_max);
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_layer_range_min", "layer"), &Light2D::set_layer_range_min);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_layer_range_min"), &Light2D::get_layer_range_min);
|
2015-03-09 13:34:56 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_layer_range_max", "layer"), &Light2D::set_layer_range_max);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_layer_range_max"), &Light2D::get_layer_range_max);
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_item_cull_mask", "item_cull_mask"), &Light2D::set_item_cull_mask);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_item_cull_mask"), &Light2D::get_item_cull_mask);
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_item_shadow_cull_mask", "item_shadow_cull_mask"), &Light2D::set_item_shadow_cull_mask);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_item_shadow_cull_mask"), &Light2D::get_item_shadow_cull_mask);
|
2015-03-02 11:54:10 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_mode", "mode"), &Light2D::set_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_mode"), &Light2D::get_mode);
|
2016-10-04 03:33:42 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_enabled", "enabled"), &Light2D::set_shadow_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_shadow_enabled"), &Light2D::is_shadow_enabled);
|
2015-03-02 11:54:10 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_buffer_size", "size"), &Light2D::set_shadow_buffer_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_buffer_size"), &Light2D::get_shadow_buffer_size);
|
2015-06-25 05:15:43 +08:00
|
|
|
|
2017-06-13 12:23:04 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_smooth", "smooth"), &Light2D::set_shadow_smooth);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_smooth"), &Light2D::get_shadow_smooth);
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_gradient_length", "multiplier"), &Light2D::set_shadow_gradient_length);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_gradient_length"), &Light2D::get_shadow_gradient_length);
|
2015-06-25 05:15:43 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_filter", "filter"), &Light2D::set_shadow_filter);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_filter"), &Light2D::get_shadow_filter);
|
2017-01-04 12:16:14 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_color", "shadow_color"), &Light2D::set_shadow_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_color"), &Light2D::get_shadow_color);
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "is_editor_only");
|
2019-01-28 03:58:18 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_texture_offset", "get_texture_offset");
|
2017-08-14 23:53:42 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "texture_scale", PROPERTY_HINT_RANGE, "0.01,50,0.01"), "set_texture_scale", "get_texture_scale");
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "energy", PROPERTY_HINT_RANGE, "0.01,100,0.01"), "set_energy", "get_energy");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Add,Sub,Mix,Mask"), "set_mode", "get_mode");
|
|
|
|
ADD_GROUP("Range", "range_");
|
2019-03-27 02:45:08 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "range_height", PROPERTY_HINT_RANGE, "-2048,2048,0.1,or_lesser,or_greater"), "set_height", "get_height");
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "range_z_min", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_range_min", "get_z_range_min");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "range_z_max", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_range_max", "get_z_range_max");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "range_layer_min", PROPERTY_HINT_RANGE, "-512,512,1"), "set_layer_range_min", "get_layer_range_min");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "range_layer_max", PROPERTY_HINT_RANGE, "-512,512,1"), "set_layer_range_max", "get_layer_range_max");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "range_item_cull_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_item_cull_mask", "get_item_cull_mask");
|
2015-04-03 12:43:37 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_GROUP("Shadow", "shadow_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_enabled"), "set_shadow_enabled", "is_shadow_enabled");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "shadow_color"), "set_shadow_color", "get_shadow_color");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_buffer_size", PROPERTY_HINT_RANGE, "32,16384,1"), "set_shadow_buffer_size", "get_shadow_buffer_size");
|
2017-08-25 05:35:19 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "shadow_gradient_length", PROPERTY_HINT_RANGE, "0,4096,0.1"), "set_shadow_gradient_length", "get_shadow_gradient_length");
|
2019-01-17 21:40:36 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_filter", PROPERTY_HINT_ENUM, "None,PCF3,PCF5,PCF7,PCF9,PCF13"), "set_shadow_filter", "get_shadow_filter");
|
2017-06-13 12:23:04 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "shadow_filter_smooth", PROPERTY_HINT_RANGE, "0,64,0.1"), "set_shadow_smooth", "get_shadow_smooth");
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_item_cull_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_item_shadow_cull_mask", "get_item_shadow_cull_mask");
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-08-20 23:45:01 +08:00
|
|
|
BIND_ENUM_CONSTANT(MODE_ADD);
|
|
|
|
BIND_ENUM_CONSTANT(MODE_SUB);
|
|
|
|
BIND_ENUM_CONSTANT(MODE_MIX);
|
|
|
|
BIND_ENUM_CONSTANT(MODE_MASK);
|
2017-09-13 03:09:06 +08:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_FILTER_NONE);
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_FILTER_PCF3);
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_FILTER_PCF5);
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_FILTER_PCF7);
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_FILTER_PCF9);
|
|
|
|
BIND_ENUM_CONSTANT(SHADOW_FILTER_PCF13);
|
2015-02-17 01:45:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Light2D::Light2D() {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
canvas_light = VisualServer::get_singleton()->canvas_light_create();
|
|
|
|
enabled = true;
|
|
|
|
editor_only = false;
|
|
|
|
shadow = false;
|
|
|
|
color = Color(1, 1, 1);
|
|
|
|
height = 0;
|
|
|
|
_scale = 1.0;
|
|
|
|
z_min = -1024;
|
|
|
|
z_max = 1024;
|
|
|
|
layer_min = 0;
|
|
|
|
layer_max = 0;
|
|
|
|
item_mask = 1;
|
|
|
|
item_shadow_mask = 1;
|
|
|
|
mode = MODE_ADD;
|
|
|
|
shadow_buffer_size = 2048;
|
|
|
|
shadow_gradient_length = 0;
|
|
|
|
energy = 1.0;
|
|
|
|
shadow_color = Color(0, 0, 0, 0);
|
|
|
|
shadow_filter = SHADOW_FILTER_NONE;
|
2017-06-13 12:23:04 +08:00
|
|
|
shadow_smooth = 0;
|
2015-02-17 01:45:11 +08:00
|
|
|
|
2017-01-13 07:35:46 +08:00
|
|
|
set_notify_transform(true);
|
2015-02-17 01:45:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Light2D::~Light2D() {
|
|
|
|
|
|
|
|
VisualServer::get_singleton()->free(canvas_light);
|
|
|
|
}
|