1/**************************************************************************/
2/* light_2d.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#ifndef LIGHT_2D_H
32#define LIGHT_2D_H
33
34#include "scene/2d/node_2d.h"
35
36class Light2D : public Node2D {
37 GDCLASS(Light2D, Node2D);
38
39public:
40 enum ShadowFilter {
41 SHADOW_FILTER_NONE,
42 SHADOW_FILTER_PCF5,
43 SHADOW_FILTER_PCF13,
44 SHADOW_FILTER_MAX
45 };
46
47 enum BlendMode {
48 BLEND_MODE_ADD,
49 BLEND_MODE_SUB,
50 BLEND_MODE_MIX,
51 };
52
53private:
54 RID canvas_light;
55 bool enabled = true;
56 bool editor_only = false;
57 bool shadow = false;
58 Color color = Color(1, 1, 1);
59 Color shadow_color = Color(0, 0, 0, 0);
60 real_t height = 0.0;
61 real_t energy = 1.0;
62 int z_min = -1024;
63 int z_max = 1024;
64 int layer_min = 0;
65 int layer_max = 0;
66 int item_mask = 1;
67 int item_shadow_mask = 1;
68 real_t shadow_smooth = 0.0;
69 Ref<Texture2D> texture;
70 Vector2 texture_offset;
71 ShadowFilter shadow_filter = SHADOW_FILTER_NONE;
72 BlendMode blend_mode = BLEND_MODE_ADD;
73
74 void _update_light_visibility();
75
76 virtual void owner_changed_notify() override;
77
78protected:
79 _FORCE_INLINE_ RID _get_light() const { return canvas_light; }
80 void _notification(int p_what);
81 static void _bind_methods();
82 void _validate_property(PropertyInfo &p_property) const;
83
84public:
85 void set_enabled(bool p_enabled);
86 bool is_enabled() const;
87
88 void set_editor_only(bool p_editor_only);
89 bool is_editor_only() const;
90
91 void set_color(const Color &p_color);
92 Color get_color() const;
93
94 void set_height(real_t p_height);
95 real_t get_height() const;
96
97 void set_energy(real_t p_energy);
98 real_t get_energy() const;
99
100 void set_z_range_min(int p_min_z);
101 int get_z_range_min() const;
102
103 void set_z_range_max(int p_max_z);
104 int get_z_range_max() const;
105
106 void set_layer_range_min(int p_min_layer);
107 int get_layer_range_min() const;
108
109 void set_layer_range_max(int p_max_layer);
110 int get_layer_range_max() const;
111
112 void set_item_cull_mask(int p_mask);
113 int get_item_cull_mask() const;
114
115 void set_item_shadow_cull_mask(int p_mask);
116 int get_item_shadow_cull_mask() const;
117
118 void set_shadow_enabled(bool p_enabled);
119 bool is_shadow_enabled() const;
120
121 void set_shadow_filter(ShadowFilter p_filter);
122 ShadowFilter get_shadow_filter() const;
123
124 void set_shadow_color(const Color &p_shadow_color);
125 Color get_shadow_color() const;
126
127 void set_shadow_smooth(real_t p_amount);
128 real_t get_shadow_smooth() const;
129
130 void set_blend_mode(BlendMode p_mode);
131 BlendMode get_blend_mode() const;
132
133 Light2D();
134 ~Light2D();
135};
136
137VARIANT_ENUM_CAST(Light2D::ShadowFilter);
138VARIANT_ENUM_CAST(Light2D::BlendMode);
139
140class PointLight2D : public Light2D {
141 GDCLASS(PointLight2D, Light2D);
142
143private:
144 real_t _scale = 1.0;
145 Ref<Texture2D> texture;
146 Vector2 texture_offset;
147
148protected:
149 static void _bind_methods();
150
151public:
152#ifdef TOOLS_ENABLED
153 virtual Dictionary _edit_get_state() const override;
154 virtual void _edit_set_state(const Dictionary &p_state) override;
155
156 virtual void _edit_set_pivot(const Point2 &p_pivot) override;
157 virtual Point2 _edit_get_pivot() const override;
158 virtual bool _edit_use_pivot() const override;
159 virtual Rect2 _edit_get_rect() const override;
160 virtual bool _edit_use_rect() const override;
161#endif
162
163 virtual Rect2 get_anchorable_rect() const override;
164
165 void set_texture(const Ref<Texture2D> &p_texture);
166 Ref<Texture2D> get_texture() const;
167
168 void set_texture_offset(const Vector2 &p_offset);
169 Vector2 get_texture_offset() const;
170
171 void set_texture_scale(real_t p_scale);
172 real_t get_texture_scale() const;
173
174 PackedStringArray get_configuration_warnings() const override;
175
176 PointLight2D();
177};
178
179class DirectionalLight2D : public Light2D {
180 GDCLASS(DirectionalLight2D, Light2D);
181
182 real_t max_distance = 10000.0;
183
184protected:
185 static void _bind_methods();
186
187public:
188 void set_max_distance(real_t p_distance);
189 real_t get_max_distance() const;
190
191 DirectionalLight2D();
192};
193
194#endif // LIGHT_2D_H
195