light.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /**************************************************************************/
  2. /* light.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. #ifndef LIGHT_H
  31. #define LIGHT_H
  32. #include "scene/3d/visual_instance.h"
  33. #include "scene/resources/texture.h"
  34. #include "servers/visual_server.h"
  35. class Light : public VisualInstance {
  36. GDCLASS(Light, VisualInstance);
  37. OBJ_CATEGORY("3D Light Nodes");
  38. public:
  39. enum Param {
  40. PARAM_ENERGY = VS::LIGHT_PARAM_ENERGY,
  41. PARAM_INDIRECT_ENERGY = VS::LIGHT_PARAM_INDIRECT_ENERGY,
  42. PARAM_SIZE = VS::LIGHT_PARAM_SIZE,
  43. PARAM_SPECULAR = VS::LIGHT_PARAM_SPECULAR,
  44. PARAM_RANGE = VS::LIGHT_PARAM_RANGE,
  45. PARAM_ATTENUATION = VS::LIGHT_PARAM_ATTENUATION,
  46. PARAM_SPOT_ANGLE = VS::LIGHT_PARAM_SPOT_ANGLE,
  47. PARAM_SPOT_ATTENUATION = VS::LIGHT_PARAM_SPOT_ATTENUATION,
  48. PARAM_CONTACT_SHADOW_SIZE = VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE,
  49. PARAM_SHADOW_MAX_DISTANCE = VS::LIGHT_PARAM_SHADOW_MAX_DISTANCE,
  50. PARAM_SHADOW_SPLIT_1_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET,
  51. PARAM_SHADOW_SPLIT_2_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET,
  52. PARAM_SHADOW_SPLIT_3_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET,
  53. PARAM_SHADOW_NORMAL_BIAS = VS::LIGHT_PARAM_SHADOW_NORMAL_BIAS,
  54. PARAM_SHADOW_BIAS = VS::LIGHT_PARAM_SHADOW_BIAS,
  55. PARAM_SHADOW_BIAS_SPLIT_SCALE = VS::LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE,
  56. PARAM_MAX = VS::LIGHT_PARAM_MAX
  57. };
  58. enum BakeMode {
  59. BAKE_DISABLED,
  60. BAKE_INDIRECT,
  61. BAKE_ALL
  62. };
  63. private:
  64. Color color;
  65. float param[PARAM_MAX];
  66. Color shadow_color;
  67. bool shadow;
  68. bool negative;
  69. bool reverse_cull;
  70. uint32_t cull_mask;
  71. VS::LightType type;
  72. bool editor_only;
  73. void _update_visibility();
  74. BakeMode bake_mode;
  75. // bind helpers
  76. virtual void owner_changed_notify();
  77. protected:
  78. RID light;
  79. static void _bind_methods();
  80. void _notification(int p_what);
  81. virtual void _validate_property(PropertyInfo &property) const;
  82. Light(VisualServer::LightType p_type);
  83. public:
  84. VS::LightType get_light_type() const { return type; }
  85. void set_editor_only(bool p_editor_only);
  86. bool is_editor_only() const;
  87. void set_param(Param p_param, float p_value);
  88. float get_param(Param p_param) const;
  89. void set_shadow(bool p_enable);
  90. bool has_shadow() const;
  91. void set_negative(bool p_enable);
  92. bool is_negative() const;
  93. void set_cull_mask(uint32_t p_cull_mask);
  94. uint32_t get_cull_mask() const;
  95. void set_color(const Color &p_color);
  96. Color get_color() const;
  97. void set_shadow_color(const Color &p_shadow_color);
  98. Color get_shadow_color() const;
  99. void set_shadow_reverse_cull_face(bool p_enable);
  100. bool get_shadow_reverse_cull_face() const;
  101. void set_bake_mode(BakeMode p_mode);
  102. BakeMode get_bake_mode() const;
  103. virtual AABB get_aabb() const;
  104. virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
  105. Light();
  106. ~Light();
  107. };
  108. VARIANT_ENUM_CAST(Light::Param);
  109. VARIANT_ENUM_CAST(Light::BakeMode);
  110. class DirectionalLight : public Light {
  111. GDCLASS(DirectionalLight, Light);
  112. public:
  113. enum ShadowMode {
  114. SHADOW_ORTHOGONAL,
  115. SHADOW_PARALLEL_2_SPLITS,
  116. SHADOW_PARALLEL_4_SPLITS
  117. };
  118. enum ShadowDepthRange {
  119. SHADOW_DEPTH_RANGE_STABLE = VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE,
  120. SHADOW_DEPTH_RANGE_OPTIMIZED = VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED,
  121. };
  122. private:
  123. bool blend_splits;
  124. ShadowMode shadow_mode;
  125. ShadowDepthRange shadow_depth_range;
  126. protected:
  127. static void _bind_methods();
  128. virtual void _validate_property(PropertyInfo &property) const;
  129. public:
  130. void set_shadow_mode(ShadowMode p_mode);
  131. ShadowMode get_shadow_mode() const;
  132. void set_shadow_depth_range(ShadowDepthRange p_range);
  133. ShadowDepthRange get_shadow_depth_range() const;
  134. void set_blend_splits(bool p_enable);
  135. bool is_blend_splits_enabled() const;
  136. DirectionalLight();
  137. };
  138. VARIANT_ENUM_CAST(DirectionalLight::ShadowMode)
  139. VARIANT_ENUM_CAST(DirectionalLight::ShadowDepthRange)
  140. class OmniLight : public Light {
  141. GDCLASS(OmniLight, Light);
  142. public:
  143. // omni light
  144. enum ShadowMode {
  145. SHADOW_DUAL_PARABOLOID,
  146. SHADOW_CUBE,
  147. };
  148. // omni light
  149. enum ShadowDetail {
  150. SHADOW_DETAIL_VERTICAL,
  151. SHADOW_DETAIL_HORIZONTAL
  152. };
  153. private:
  154. ShadowMode shadow_mode;
  155. ShadowDetail shadow_detail;
  156. protected:
  157. static void _bind_methods();
  158. public:
  159. void set_shadow_mode(ShadowMode p_mode);
  160. ShadowMode get_shadow_mode() const;
  161. void set_shadow_detail(ShadowDetail p_detail);
  162. ShadowDetail get_shadow_detail() const;
  163. OmniLight();
  164. };
  165. VARIANT_ENUM_CAST(OmniLight::ShadowMode)
  166. VARIANT_ENUM_CAST(OmniLight::ShadowDetail)
  167. class SpotLight : public Light {
  168. GDCLASS(SpotLight, Light);
  169. protected:
  170. static void _bind_methods();
  171. public:
  172. virtual String get_configuration_warning() const;
  173. SpotLight() :
  174. Light(VisualServer::LIGHT_SPOT) {}
  175. };
  176. #endif // LIGHT_H