| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/2d/node_2d.h" |
| 34 |
|
| 35 |
class Light2D : public Node2D { |
| 36 |
GDCLASS(Light2D, Node2D); |
| 37 |
|
| 38 |
public: |
| 39 |
enum ShadowFilter { |
| 40 |
SHADOW_FILTER_NONE, |
| 41 |
SHADOW_FILTER_PCF5, |
| 42 |
SHADOW_FILTER_PCF13, |
| 43 |
SHADOW_FILTER_MAX |
| 44 |
}; |
| 45 |
|
| 46 |
enum BlendMode { |
| 47 |
BLEND_MODE_ADD, |
| 48 |
BLEND_MODE_SUB, |
| 49 |
BLEND_MODE_MIX, |
| 50 |
}; |
| 51 |
|
| 52 |
private: |
| 53 |
RID canvas_light; |
| 54 |
bool enabled = true; |
| 55 |
bool editor_only = false; |
| 56 |
bool shadow = false; |
| 57 |
Color color = Color(1, 1, 1); |
| 58 |
Color shadow_color = Color(0, 0, 0, 0); |
| 59 |
real_t height = 0.0; |
| 60 |
real_t energy = 1.0; |
| 61 |
int z_min = -1024; |
| 62 |
int z_max = 1024; |
| 63 |
int layer_min = 0; |
| 64 |
int layer_max = 0; |
| 65 |
int item_mask = 1; |
| 66 |
int item_shadow_mask = 1; |
| 67 |
real_t shadow_smooth = 0.0; |
| 68 |
Ref<Texture2D> texture; |
| 69 |
Vector2 texture_offset; |
| 70 |
ShadowFilter shadow_filter = SHADOW_FILTER_NONE; |
| 71 |
BlendMode blend_mode = BLEND_MODE_ADD; |
| 72 |
|
| 73 |
void _update_light_visibility(); |
| 74 |
|
| 75 |
virtual void owner_changed_notify() override; |
| 76 |
virtual void _physics_interpolated_changed() override; |
| 77 |
|
| 78 |
protected: |
| 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 |
|
| 84 |
public: |
| 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 |
|
| 137 |
VARIANT_ENUM_CAST(Light2D::ShadowFilter); |
| 138 |
VARIANT_ENUM_CAST(Light2D::BlendMode); |
| 139 |
|
| 140 |
class PointLight2D : public Light2D { |
| 141 |
GDCLASS(PointLight2D, Light2D); |
| 142 |
|
| 143 |
private: |
| 144 |
real_t _scale = 1.0; |
| 145 |
Ref<Texture2D> texture; |
| 146 |
Vector2 texture_offset; |
| 147 |
|
| 148 |
protected: |
| 149 |
#ifndef DISABLE_DEPRECATED |
| 150 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 151 |
#endif |
| 152 |
static void _bind_methods(); |
| 153 |
|
| 154 |
public: |
| 155 |
#ifdef TOOLS_ENABLED |
| 156 |
virtual Dictionary _edit_get_state() const override; |
| 157 |
virtual void _edit_set_state(const Dictionary &p_state) override; |
| 158 |
|
| 159 |
virtual void _edit_set_pivot(const Point2 &p_pivot) override; |
| 160 |
virtual Point2 _edit_get_pivot() const override; |
| 161 |
virtual bool _edit_use_pivot() const override; |
| 162 |
#endif |
| 163 |
|
| 164 |
#ifdef DEBUG_ENABLED |
| 165 |
virtual Rect2 _edit_get_rect() const override; |
| 166 |
virtual bool _edit_use_rect() const override; |
| 167 |
#endif |
| 168 |
|
| 169 |
virtual Rect2 get_anchorable_rect() const override; |
| 170 |
|
| 171 |
void set_texture(const Ref<Texture2D> &p_texture); |
| 172 |
Ref<Texture2D> get_texture() const; |
| 173 |
|
| 174 |
void set_texture_offset(const Vector2 &p_offset); |
| 175 |
Vector2 get_texture_offset() const; |
| 176 |
|
| 177 |
void set_texture_scale(real_t p_scale); |
| 178 |
real_t get_texture_scale() const; |
| 179 |
|
| 180 |
PackedStringArray get_configuration_warnings() const override; |
| 181 |
|
| 182 |
PointLight2D(); |
| 183 |
}; |
| 184 |
|
| 185 |
class DirectionalLight2D : public Light2D { |
| 186 |
GDCLASS(DirectionalLight2D, Light2D); |
| 187 |
|
| 188 |
real_t max_distance = 10000.0; |
| 189 |
|
| 190 |
protected: |
| 191 |
static void _bind_methods(); |
| 192 |
|
| 193 |
public: |
| 194 |
void set_max_distance(real_t p_distance); |
| 195 |
real_t get_max_distance() const; |
| 196 |
|
| 197 |
DirectionalLight2D(); |
| 198 |
}; |