1 /*************************************************************************/ 2 /* light_2d.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ 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 #ifndef LIGHT_2D_H 31 #define LIGHT_2D_H 32 33 #include "scene/2d/node_2d.h" 34 35 class Light2D : public Node2D { 36 37 OBJ_TYPE(Light2D, Node2D); 38 39 public: 40 enum Mode { 41 MODE_ADD, 42 MODE_SUB, 43 MODE_MIX, 44 MODE_MASK, 45 }; 46 47 private: 48 RID canvas_light; 49 bool enabled; 50 bool editor_only; 51 bool shadow; 52 Color color; 53 Color shadow_color; 54 float height; 55 float _scale; 56 float energy; 57 int z_min; 58 int z_max; 59 int layer_min; 60 int layer_max; 61 int item_mask; 62 int item_shadow_mask; 63 int shadow_buffer_size; 64 float shadow_esm_multiplier; 65 Mode mode; 66 Ref<Texture> texture; 67 Vector2 texture_offset; 68 69 void _update_light_visibility(); 70 71 protected: 72 void _notification(int p_what); 73 static void _bind_methods(); 74 75 public: 76 virtual void edit_set_pivot(const Point2 &p_pivot); 77 virtual Point2 edit_get_pivot() const; 78 virtual bool edit_has_pivot() const; 79 80 void set_enabled(bool p_enabled); 81 bool is_enabled() const; 82 83 void set_editor_only(bool p_editor_only); 84 bool is_editor_only() const; 85 86 void set_texture(const Ref<Texture> &p_texture); 87 Ref<Texture> get_texture() const; 88 89 void set_texture_offset(const Vector2 &p_offset); 90 Vector2 get_texture_offset() const; 91 92 void set_color(const Color &p_color); 93 Color get_color() const; 94 95 void set_height(float p_height); 96 float get_height() const; 97 98 void set_energy(float p_energy); 99 float get_energy() const; 100 101 void set_texture_scale(float p_scale); 102 float get_texture_scale() const; 103 104 void set_z_range_min(int p_min_z); 105 int get_z_range_min() const; 106 107 void set_z_range_max(int p_max_z); 108 int get_z_range_max() const; 109 110 void set_layer_range_min(int p_min_layer); 111 int get_layer_range_min() const; 112 113 void set_layer_range_max(int p_max_layer); 114 int get_layer_range_max() const; 115 116 void set_item_mask(int p_mask); 117 int get_item_mask() const; 118 119 void set_item_shadow_mask(int p_mask); 120 int get_item_shadow_mask() const; 121 122 void set_mode(Mode p_mode); 123 Mode get_mode() const; 124 125 void set_shadow_enabled(bool p_enabled); 126 bool is_shadow_enabled() const; 127 128 void set_shadow_buffer_size(int p_size); 129 int get_shadow_buffer_size() const; 130 131 void set_shadow_esm_multiplier(float p_multiplier); 132 float get_shadow_esm_multiplier() const; 133 134 void set_shadow_color(const Color &p_shadow_color); 135 Color get_shadow_color() const; 136 137 virtual Rect2 get_item_rect() const; 138 139 String get_configuration_warning() const; 140 141 Light2D(); 142 ~Light2D(); 143 }; 144 145 VARIANT_ENUM_CAST(Light2D::Mode); 146 147 #endif // LIGHT_2D_H 148