light_3d.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /**************************************************************************/
  2. /* light_3d.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_3D_H
  31. #define LIGHT_3D_H
  32. #include "scene/3d/visual_instance_3d.h"
  33. class Light3D : public VisualInstance3D {
  34. GDCLASS(Light3D, VisualInstance3D);
  35. public:
  36. enum Param {
  37. PARAM_ENERGY = RS::LIGHT_PARAM_ENERGY,
  38. PARAM_INDIRECT_ENERGY = RS::LIGHT_PARAM_INDIRECT_ENERGY,
  39. PARAM_VOLUMETRIC_FOG_ENERGY = RS::LIGHT_PARAM_VOLUMETRIC_FOG_ENERGY,
  40. PARAM_SPECULAR = RS::LIGHT_PARAM_SPECULAR,
  41. PARAM_RANGE = RS::LIGHT_PARAM_RANGE,
  42. PARAM_SIZE = RS::LIGHT_PARAM_SIZE,
  43. PARAM_ATTENUATION = RS::LIGHT_PARAM_ATTENUATION,
  44. PARAM_SPOT_ANGLE = RS::LIGHT_PARAM_SPOT_ANGLE,
  45. PARAM_SPOT_ATTENUATION = RS::LIGHT_PARAM_SPOT_ATTENUATION,
  46. PARAM_SHADOW_MAX_DISTANCE = RS::LIGHT_PARAM_SHADOW_MAX_DISTANCE,
  47. PARAM_SHADOW_SPLIT_1_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET,
  48. PARAM_SHADOW_SPLIT_2_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET,
  49. PARAM_SHADOW_SPLIT_3_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET,
  50. PARAM_SHADOW_FADE_START = RS::LIGHT_PARAM_SHADOW_FADE_START,
  51. PARAM_SHADOW_NORMAL_BIAS = RS::LIGHT_PARAM_SHADOW_NORMAL_BIAS,
  52. PARAM_SHADOW_BIAS = RS::LIGHT_PARAM_SHADOW_BIAS,
  53. PARAM_SHADOW_PANCAKE_SIZE = RS::LIGHT_PARAM_SHADOW_PANCAKE_SIZE,
  54. PARAM_SHADOW_OPACITY = RS::LIGHT_PARAM_SHADOW_OPACITY,
  55. PARAM_SHADOW_BLUR = RS::LIGHT_PARAM_SHADOW_BLUR,
  56. PARAM_TRANSMITTANCE_BIAS = RS::LIGHT_PARAM_TRANSMITTANCE_BIAS,
  57. PARAM_INTENSITY = RS::LIGHT_PARAM_INTENSITY,
  58. PARAM_MAX = RS::LIGHT_PARAM_MAX
  59. };
  60. enum BakeMode {
  61. BAKE_DISABLED,
  62. BAKE_STATIC,
  63. BAKE_DYNAMIC,
  64. };
  65. private:
  66. Color color;
  67. real_t param[PARAM_MAX] = {};
  68. bool shadow = false;
  69. bool negative = false;
  70. bool reverse_cull = false;
  71. uint32_t cull_mask = 0;
  72. uint32_t shadow_caster_mask = 0xFFFFFFFF;
  73. bool distance_fade_enabled = false;
  74. real_t distance_fade_begin = 40.0;
  75. real_t distance_fade_shadow = 50.0;
  76. real_t distance_fade_length = 10.0;
  77. RS::LightType type = RenderingServer::LIGHT_DIRECTIONAL;
  78. bool editor_only = false;
  79. void _update_visibility();
  80. BakeMode bake_mode = BAKE_DYNAMIC;
  81. Ref<Texture2D> projector;
  82. Color correlated_color = Color(1.0, 1.0, 1.0);
  83. float temperature = 6500.0;
  84. // bind helpers
  85. virtual void owner_changed_notify() override;
  86. protected:
  87. RID light;
  88. static void _bind_methods();
  89. void _notification(int p_what);
  90. void _validate_property(PropertyInfo &p_property) const;
  91. Light3D(RenderingServer::LightType p_type);
  92. public:
  93. RS::LightType get_light_type() const { return type; }
  94. void set_editor_only(bool p_editor_only);
  95. bool is_editor_only() const;
  96. void set_param(Param p_param, real_t p_value);
  97. real_t get_param(Param p_param) const;
  98. void set_shadow(bool p_enable);
  99. bool has_shadow() const;
  100. void set_negative(bool p_enable);
  101. bool is_negative() const;
  102. void set_enable_distance_fade(bool p_enable);
  103. bool is_distance_fade_enabled() const;
  104. void set_distance_fade_begin(real_t p_distance);
  105. real_t get_distance_fade_begin() const;
  106. void set_distance_fade_shadow(real_t p_distance);
  107. real_t get_distance_fade_shadow() const;
  108. void set_distance_fade_length(real_t p_length);
  109. real_t get_distance_fade_length() const;
  110. void set_cull_mask(uint32_t p_cull_mask);
  111. uint32_t get_cull_mask() const;
  112. void set_color(const Color &p_color);
  113. Color get_color() const;
  114. void set_shadow_reverse_cull_face(bool p_enable);
  115. bool get_shadow_reverse_cull_face() const;
  116. void set_shadow_caster_mask(uint32_t p_caster_mask);
  117. uint32_t get_shadow_caster_mask() const;
  118. void set_bake_mode(BakeMode p_mode);
  119. BakeMode get_bake_mode() const;
  120. void set_projector(const Ref<Texture2D> &p_texture);
  121. Ref<Texture2D> get_projector() const;
  122. void set_temperature(const float p_temperature);
  123. float get_temperature() const;
  124. Color get_correlated_color() const;
  125. virtual AABB get_aabb() const override;
  126. virtual PackedStringArray get_configuration_warnings() const override;
  127. Light3D();
  128. ~Light3D();
  129. };
  130. VARIANT_ENUM_CAST(Light3D::Param);
  131. VARIANT_ENUM_CAST(Light3D::BakeMode);
  132. class DirectionalLight3D : public Light3D {
  133. GDCLASS(DirectionalLight3D, Light3D);
  134. public:
  135. enum ShadowMode {
  136. SHADOW_ORTHOGONAL,
  137. SHADOW_PARALLEL_2_SPLITS,
  138. SHADOW_PARALLEL_4_SPLITS,
  139. };
  140. enum SkyMode {
  141. SKY_MODE_LIGHT_AND_SKY,
  142. SKY_MODE_LIGHT_ONLY,
  143. SKY_MODE_SKY_ONLY,
  144. };
  145. private:
  146. bool blend_splits;
  147. ShadowMode shadow_mode;
  148. SkyMode sky_mode = SKY_MODE_LIGHT_AND_SKY;
  149. protected:
  150. static void _bind_methods();
  151. void _validate_property(PropertyInfo &p_property) const;
  152. public:
  153. void set_shadow_mode(ShadowMode p_mode);
  154. ShadowMode get_shadow_mode() const;
  155. void set_blend_splits(bool p_enable);
  156. bool is_blend_splits_enabled() const;
  157. void set_sky_mode(SkyMode p_mode);
  158. SkyMode get_sky_mode() const;
  159. DirectionalLight3D();
  160. };
  161. VARIANT_ENUM_CAST(DirectionalLight3D::ShadowMode)
  162. VARIANT_ENUM_CAST(DirectionalLight3D::SkyMode)
  163. class OmniLight3D : public Light3D {
  164. GDCLASS(OmniLight3D, Light3D);
  165. public:
  166. // omni light
  167. enum ShadowMode {
  168. SHADOW_DUAL_PARABOLOID,
  169. SHADOW_CUBE,
  170. };
  171. private:
  172. ShadowMode shadow_mode;
  173. protected:
  174. static void _bind_methods();
  175. public:
  176. void set_shadow_mode(ShadowMode p_mode);
  177. ShadowMode get_shadow_mode() const;
  178. PackedStringArray get_configuration_warnings() const override;
  179. OmniLight3D();
  180. };
  181. VARIANT_ENUM_CAST(OmniLight3D::ShadowMode)
  182. class SpotLight3D : public Light3D {
  183. GDCLASS(SpotLight3D, Light3D);
  184. protected:
  185. static void _bind_methods();
  186. public:
  187. PackedStringArray get_configuration_warnings() const override;
  188. SpotLight3D();
  189. };
  190. #endif // LIGHT_3D_H