light.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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_SHADOW_FADE_START = VS::LIGHT_PARAM_SHADOW_FADE_START,
  57. PARAM_MAX = VS::LIGHT_PARAM_MAX
  58. };
  59. enum BakeMode {
  60. BAKE_DISABLED,
  61. BAKE_INDIRECT,
  62. BAKE_ALL
  63. };
  64. private:
  65. Color color;
  66. float param[PARAM_MAX];
  67. Color shadow_color;
  68. bool shadow;
  69. bool negative;
  70. bool reverse_cull;
  71. uint32_t cull_mask;
  72. VS::LightType type;
  73. bool editor_only;
  74. void _update_visibility();
  75. BakeMode bake_mode;
  76. // bind helpers
  77. virtual void owner_changed_notify();
  78. protected:
  79. RID light;
  80. static void _bind_methods();
  81. void _notification(int p_what);
  82. virtual void _validate_property(PropertyInfo &property) const;
  83. Light(VisualServer::LightType p_type);
  84. public:
  85. VS::LightType get_light_type() const { return type; }
  86. void set_editor_only(bool p_editor_only);
  87. bool is_editor_only() const;
  88. void set_param(Param p_param, float p_value);
  89. float get_param(Param p_param) const;
  90. void set_shadow(bool p_enable);
  91. bool has_shadow() const;
  92. void set_negative(bool p_enable);
  93. bool is_negative() const;
  94. void set_cull_mask(uint32_t p_cull_mask);
  95. uint32_t get_cull_mask() const;
  96. void set_color(const Color &p_color);
  97. Color get_color() const;
  98. void set_shadow_color(const Color &p_shadow_color);
  99. Color get_shadow_color() const;
  100. void set_shadow_reverse_cull_face(bool p_enable);
  101. bool get_shadow_reverse_cull_face() const;
  102. void set_bake_mode(BakeMode p_mode);
  103. BakeMode get_bake_mode() const;
  104. virtual AABB get_aabb() const;
  105. virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
  106. Light();
  107. ~Light();
  108. };
  109. VARIANT_ENUM_CAST(Light::Param);
  110. VARIANT_ENUM_CAST(Light::BakeMode);
  111. class DirectionalLight : public Light {
  112. GDCLASS(DirectionalLight, Light);
  113. public:
  114. enum ShadowMode {
  115. SHADOW_ORTHOGONAL,
  116. SHADOW_PARALLEL_2_SPLITS,
  117. SHADOW_PARALLEL_3_SPLITS,
  118. SHADOW_PARALLEL_4_SPLITS
  119. };
  120. enum ShadowDepthRange {
  121. SHADOW_DEPTH_RANGE_STABLE = VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE,
  122. SHADOW_DEPTH_RANGE_OPTIMIZED = VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED,
  123. };
  124. private:
  125. bool blend_splits;
  126. ShadowMode shadow_mode;
  127. ShadowDepthRange shadow_depth_range;
  128. protected:
  129. static void _bind_methods();
  130. virtual void _validate_property(PropertyInfo &property) const;
  131. public:
  132. void set_shadow_mode(ShadowMode p_mode);
  133. ShadowMode get_shadow_mode() const;
  134. void set_shadow_depth_range(ShadowDepthRange p_range);
  135. ShadowDepthRange get_shadow_depth_range() const;
  136. void set_blend_splits(bool p_enable);
  137. bool is_blend_splits_enabled() const;
  138. DirectionalLight();
  139. };
  140. VARIANT_ENUM_CAST(DirectionalLight::ShadowMode)
  141. VARIANT_ENUM_CAST(DirectionalLight::ShadowDepthRange)
  142. class OmniLight : public Light {
  143. GDCLASS(OmniLight, Light);
  144. public:
  145. // omni light
  146. enum ShadowMode {
  147. SHADOW_DUAL_PARABOLOID,
  148. SHADOW_CUBE,
  149. };
  150. // omni light
  151. enum ShadowDetail {
  152. SHADOW_DETAIL_VERTICAL,
  153. SHADOW_DETAIL_HORIZONTAL
  154. };
  155. private:
  156. ShadowMode shadow_mode;
  157. ShadowDetail shadow_detail;
  158. protected:
  159. static void _bind_methods();
  160. public:
  161. void set_shadow_mode(ShadowMode p_mode);
  162. ShadowMode get_shadow_mode() const;
  163. void set_shadow_detail(ShadowDetail p_detail);
  164. ShadowDetail get_shadow_detail() const;
  165. OmniLight();
  166. };
  167. VARIANT_ENUM_CAST(OmniLight::ShadowMode)
  168. VARIANT_ENUM_CAST(OmniLight::ShadowDetail)
  169. class SpotLight : public Light {
  170. GDCLASS(SpotLight, Light);
  171. protected:
  172. static void _bind_methods();
  173. public:
  174. virtual String get_configuration_warning() const;
  175. SpotLight() :
  176. Light(VisualServer::LIGHT_SPOT) {}
  177. };
  178. #endif // LIGHT_H