light_2d.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. #include "scene/2d/node_2d.h"
  33. class Light2D : public Node2D {
  34. GDCLASS(Light2D, Node2D);
  35. public:
  36. enum Mode {
  37. MODE_ADD,
  38. MODE_SUB,
  39. MODE_MIX,
  40. MODE_MASK,
  41. };
  42. enum ShadowFilter {
  43. SHADOW_FILTER_NONE,
  44. SHADOW_FILTER_PCF3,
  45. SHADOW_FILTER_PCF5,
  46. SHADOW_FILTER_PCF7,
  47. SHADOW_FILTER_PCF9,
  48. SHADOW_FILTER_PCF13,
  49. };
  50. private:
  51. RID canvas_light;
  52. bool enabled;
  53. bool editor_only;
  54. bool shadow;
  55. Color color;
  56. Color shadow_color;
  57. float height;
  58. float _scale;
  59. float energy;
  60. int z_min;
  61. int z_max;
  62. int layer_min;
  63. int layer_max;
  64. int item_mask;
  65. int item_shadow_mask;
  66. int shadow_buffer_size;
  67. float shadow_smooth;
  68. float shadow_gradient_length;
  69. Mode mode;
  70. Ref<Texture> texture;
  71. Vector2 texture_offset;
  72. ShadowFilter shadow_filter;
  73. void _update_light_visibility();
  74. protected:
  75. void _notification(int p_what);
  76. static void _bind_methods();
  77. public:
  78. virtual Dictionary _edit_get_state() const;
  79. virtual void _edit_set_state(const Dictionary &p_state);
  80. virtual void _edit_set_pivot(const Point2 &p_pivot);
  81. virtual Point2 _edit_get_pivot() const;
  82. virtual bool _edit_use_pivot() const;
  83. virtual Rect2 _edit_get_rect() const;
  84. virtual bool _edit_use_rect() const;
  85. virtual Rect2 get_anchorable_rect() const;
  86. void set_enabled(bool p_enabled);
  87. bool is_enabled() const;
  88. void set_editor_only(bool p_editor_only);
  89. bool is_editor_only() const;
  90. void set_texture(const Ref<Texture> &p_texture);
  91. Ref<Texture> get_texture() const;
  92. void set_texture_offset(const Vector2 &p_offset);
  93. Vector2 get_texture_offset() const;
  94. void set_color(const Color &p_color);
  95. Color get_color() const;
  96. void set_height(float p_height);
  97. float get_height() const;
  98. void set_energy(float p_energy);
  99. float get_energy() const;
  100. void set_texture_scale(float p_scale);
  101. float get_texture_scale() const;
  102. void set_z_range_min(int p_min_z);
  103. int get_z_range_min() const;
  104. void set_z_range_max(int p_max_z);
  105. int get_z_range_max() const;
  106. void set_layer_range_min(int p_min_layer);
  107. int get_layer_range_min() const;
  108. void set_layer_range_max(int p_max_layer);
  109. int get_layer_range_max() const;
  110. void set_item_cull_mask(int p_mask);
  111. int get_item_cull_mask() const;
  112. void set_item_shadow_cull_mask(int p_mask);
  113. int get_item_shadow_cull_mask() const;
  114. void set_mode(Mode p_mode);
  115. Mode get_mode() const;
  116. void set_shadow_enabled(bool p_enabled);
  117. bool is_shadow_enabled() const;
  118. void set_shadow_buffer_size(int p_size);
  119. int get_shadow_buffer_size() const;
  120. void set_shadow_gradient_length(float p_multiplier);
  121. float get_shadow_gradient_length() const;
  122. void set_shadow_filter(ShadowFilter p_filter);
  123. ShadowFilter get_shadow_filter() const;
  124. void set_shadow_color(const Color &p_shadow_color);
  125. Color get_shadow_color() const;
  126. void set_shadow_smooth(float p_amount);
  127. float get_shadow_smooth() const;
  128. String get_configuration_warning() const;
  129. Light2D();
  130. ~Light2D();
  131. };
  132. VARIANT_ENUM_CAST(Light2D::Mode);
  133. VARIANT_ENUM_CAST(Light2D::ShadowFilter);
  134. #endif // LIGHT_2D_H