2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* light_2d.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
2022-01-03 20:27:34 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2016-06-18 12:46:12 +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
|
|
|
|
2015-02-16 17:45:11 +00:00
|
|
|
#ifndef LIGHT_2D_H
|
|
|
|
#define LIGHT_2D_H
|
|
|
|
|
|
|
|
#include "scene/2d/node_2d.h"
|
|
|
|
|
|
|
|
class Light2D : public Node2D {
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(Light2D, Node2D);
|
|
|
|
|
2015-04-03 04:43:37 +00:00
|
|
|
public:
|
2016-10-03 19:33:42 +00:00
|
|
|
enum ShadowFilter {
|
|
|
|
SHADOW_FILTER_NONE,
|
|
|
|
SHADOW_FILTER_PCF5,
|
|
|
|
SHADOW_FILTER_PCF13,
|
2019-07-07 04:49:40 +00:00
|
|
|
SHADOW_FILTER_MAX
|
2016-10-03 19:33:42 +00:00
|
|
|
};
|
|
|
|
|
2020-11-03 19:51:53 +00:00
|
|
|
enum BlendMode {
|
|
|
|
BLEND_MODE_ADD,
|
|
|
|
BLEND_MODE_SUB,
|
|
|
|
BLEND_MODE_MIX,
|
|
|
|
};
|
|
|
|
|
2015-02-16 17:45:11 +00:00
|
|
|
private:
|
|
|
|
RID canvas_light;
|
2021-02-07 21:29:31 +00:00
|
|
|
bool enabled = true;
|
|
|
|
bool editor_only = false;
|
|
|
|
bool shadow = false;
|
|
|
|
Color color = Color(1, 1, 1);
|
|
|
|
Color shadow_color = Color(0, 0, 0, 0);
|
2021-01-30 04:10:32 +00:00
|
|
|
real_t height = 0.0;
|
|
|
|
real_t energy = 1.0;
|
2021-02-07 21:29:31 +00:00
|
|
|
int z_min = -1024;
|
|
|
|
int z_max = 1024;
|
|
|
|
int layer_min = 0;
|
|
|
|
int layer_max = 0;
|
|
|
|
int item_mask = 1;
|
|
|
|
int item_shadow_mask = 1;
|
2021-01-30 04:10:32 +00:00
|
|
|
real_t shadow_smooth = 0.0;
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> texture;
|
2015-02-16 17:45:11 +00:00
|
|
|
Vector2 texture_offset;
|
2021-02-07 21:29:31 +00:00
|
|
|
ShadowFilter shadow_filter = SHADOW_FILTER_NONE;
|
|
|
|
BlendMode blend_mode = BLEND_MODE_ADD;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2016-01-01 13:45:24 +00:00
|
|
|
void _update_light_visibility();
|
2015-02-16 17:45:11 +00:00
|
|
|
|
2022-06-23 06:19:18 +00:00
|
|
|
virtual void owner_changed_notify() override;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
protected:
|
2020-11-03 19:51:53 +00:00
|
|
|
_FORCE_INLINE_ RID _get_light() const { return canvas_light; }
|
2015-02-18 22:39:44 +00:00
|
|
|
void _notification(int p_what);
|
2015-02-16 17:45:11 +00:00
|
|
|
static void _bind_methods();
|
2022-08-12 20:57:11 +00:00
|
|
|
void _validate_property(PropertyInfo &p_property) const;
|
2015-02-16 17:45:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
|
|
|
void set_enabled(bool p_enabled);
|
2015-02-16 17:45:11 +00:00
|
|
|
bool is_enabled() const;
|
|
|
|
|
2016-10-04 14:44:59 +00:00
|
|
|
void set_editor_only(bool p_editor_only);
|
|
|
|
bool is_editor_only() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_color(const Color &p_color);
|
2015-02-16 17:45:11 +00:00
|
|
|
Color get_color() const;
|
|
|
|
|
2021-01-30 04:10:32 +00:00
|
|
|
void set_height(real_t p_height);
|
|
|
|
real_t get_height() const;
|
2015-02-16 17:45:11 +00:00
|
|
|
|
2021-01-30 04:10:32 +00:00
|
|
|
void set_energy(real_t p_energy);
|
|
|
|
real_t get_energy() const;
|
2015-04-03 04:43:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_z_range_min(int p_min_z);
|
2015-02-16 17:45:11 +00:00
|
|
|
int get_z_range_min() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_z_range_max(int p_max_z);
|
2015-02-16 17:45:11 +00:00
|
|
|
int get_z_range_max() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_layer_range_min(int p_min_layer);
|
2015-02-18 22:39:44 +00:00
|
|
|
int get_layer_range_min() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_layer_range_max(int p_max_layer);
|
2015-02-18 22:39:44 +00:00
|
|
|
int get_layer_range_max() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_item_cull_mask(int p_mask);
|
2016-10-03 19:33:42 +00:00
|
|
|
int get_item_cull_mask() const;
|
2015-02-16 17:45:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_item_shadow_cull_mask(int p_mask);
|
2016-10-03 19:33:42 +00:00
|
|
|
int get_item_shadow_cull_mask() const;
|
2015-03-09 05:34:56 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_shadow_enabled(bool p_enabled);
|
2015-02-16 17:45:11 +00:00
|
|
|
bool is_shadow_enabled() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_shadow_filter(ShadowFilter p_filter);
|
2016-10-03 19:33:42 +00:00
|
|
|
ShadowFilter get_shadow_filter() const;
|
2015-03-02 03:54:10 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_shadow_color(const Color &p_shadow_color);
|
2015-06-24 21:15:43 +00:00
|
|
|
Color get_shadow_color() const;
|
|
|
|
|
2021-01-30 04:10:32 +00:00
|
|
|
void set_shadow_smooth(real_t p_amount);
|
|
|
|
real_t get_shadow_smooth() const;
|
2017-06-13 04:23:04 +00:00
|
|
|
|
2020-11-03 19:51:53 +00:00
|
|
|
void set_blend_mode(BlendMode p_mode);
|
|
|
|
BlendMode get_blend_mode() const;
|
2016-05-17 21:27:15 +00:00
|
|
|
|
2015-02-16 17:45:11 +00:00
|
|
|
Light2D();
|
|
|
|
~Light2D();
|
|
|
|
};
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
VARIANT_ENUM_CAST(Light2D::ShadowFilter);
|
2020-11-03 19:51:53 +00:00
|
|
|
VARIANT_ENUM_CAST(Light2D::BlendMode);
|
|
|
|
|
|
|
|
class PointLight2D : public Light2D {
|
|
|
|
GDCLASS(PointLight2D, Light2D);
|
|
|
|
|
|
|
|
private:
|
2021-01-30 04:10:32 +00:00
|
|
|
real_t _scale = 1.0;
|
2020-11-03 19:51:53 +00:00
|
|
|
Ref<Texture2D> texture;
|
|
|
|
Vector2 texture_offset;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
virtual Dictionary _edit_get_state() const override;
|
|
|
|
virtual void _edit_set_state(const Dictionary &p_state) override;
|
|
|
|
|
|
|
|
virtual void _edit_set_pivot(const Point2 &p_pivot) override;
|
|
|
|
virtual Point2 _edit_get_pivot() const override;
|
|
|
|
virtual bool _edit_use_pivot() const override;
|
|
|
|
virtual Rect2 _edit_get_rect() const override;
|
|
|
|
virtual bool _edit_use_rect() const override;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual Rect2 get_anchorable_rect() const override;
|
|
|
|
|
|
|
|
void set_texture(const Ref<Texture2D> &p_texture);
|
|
|
|
Ref<Texture2D> get_texture() const;
|
|
|
|
|
|
|
|
void set_texture_offset(const Vector2 &p_offset);
|
|
|
|
Vector2 get_texture_offset() const;
|
|
|
|
|
2021-01-30 04:10:32 +00:00
|
|
|
void set_texture_scale(real_t p_scale);
|
|
|
|
real_t get_texture_scale() const;
|
2020-11-03 19:51:53 +00:00
|
|
|
|
2020-10-29 10:01:28 +00:00
|
|
|
TypedArray<String> get_configuration_warnings() const override;
|
2020-11-03 19:51:53 +00:00
|
|
|
|
|
|
|
PointLight2D();
|
|
|
|
};
|
|
|
|
|
|
|
|
class DirectionalLight2D : public Light2D {
|
|
|
|
GDCLASS(DirectionalLight2D, Light2D);
|
|
|
|
|
2021-01-30 04:10:32 +00:00
|
|
|
real_t max_distance = 10000.0;
|
2020-11-03 19:51:53 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2021-01-30 04:10:32 +00:00
|
|
|
void set_max_distance(real_t p_distance);
|
|
|
|
real_t get_max_distance() const;
|
2020-11-03 19:51:53 +00:00
|
|
|
|
|
|
|
DirectionalLight2D();
|
|
|
|
};
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2015-02-16 17:45:11 +00:00
|
|
|
#endif // LIGHT_2D_H
|