light.h 6.5 KB

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