light_2d.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*************************************************************************/
  2. /* light_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 void edit_set_pivot(const Point2 &p_pivot);
  79. virtual Point2 edit_get_pivot() const;
  80. virtual bool edit_has_pivot() const;
  81. void set_enabled(bool p_enabled);
  82. bool is_enabled() const;
  83. void set_editor_only(bool p_editor_only);
  84. bool is_editor_only() const;
  85. void set_texture(const Ref<Texture> &p_texture);
  86. Ref<Texture> get_texture() const;
  87. void set_texture_offset(const Vector2 &p_offset);
  88. Vector2 get_texture_offset() const;
  89. void set_color(const Color &p_color);
  90. Color get_color() const;
  91. void set_height(float p_height);
  92. float get_height() const;
  93. void set_energy(float p_energy);
  94. float get_energy() const;
  95. void set_texture_scale(float p_scale);
  96. float get_texture_scale() const;
  97. void set_z_range_min(int p_min_z);
  98. int get_z_range_min() const;
  99. void set_z_range_max(int p_max_z);
  100. int get_z_range_max() const;
  101. void set_layer_range_min(int p_min_layer);
  102. int get_layer_range_min() const;
  103. void set_layer_range_max(int p_max_layer);
  104. int get_layer_range_max() const;
  105. void set_item_cull_mask(int p_mask);
  106. int get_item_cull_mask() const;
  107. void set_item_shadow_cull_mask(int p_mask);
  108. int get_item_shadow_cull_mask() const;
  109. void set_mode(Mode p_mode);
  110. Mode get_mode() const;
  111. void set_shadow_enabled(bool p_enabled);
  112. bool is_shadow_enabled() const;
  113. void set_shadow_buffer_size(int p_size);
  114. int get_shadow_buffer_size() const;
  115. void set_shadow_gradient_length(float p_multiplier);
  116. float get_shadow_gradient_length() const;
  117. void set_shadow_filter(ShadowFilter p_filter);
  118. ShadowFilter get_shadow_filter() const;
  119. void set_shadow_color(const Color &p_shadow_color);
  120. Color get_shadow_color() const;
  121. void set_shadow_smooth(float p_amount);
  122. float get_shadow_smooth() const;
  123. virtual Rect2 get_item_rect() const;
  124. String get_configuration_warning() const;
  125. Light2D();
  126. ~Light2D();
  127. };
  128. VARIANT_ENUM_CAST(Light2D::Mode);
  129. VARIANT_ENUM_CAST(Light2D::ShadowFilter);
  130. #endif // LIGHT_2D_H