light_3d.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. bool distance_fade_enabled = false;
  73. real_t distance_fade_begin = 40.0;
  74. real_t distance_fade_shadow = 50.0;
  75. real_t distance_fade_length = 10.0;
  76. RS::LightType type = RenderingServer::LIGHT_DIRECTIONAL;
  77. bool editor_only = false;
  78. void _update_visibility();
  79. BakeMode bake_mode = BAKE_DYNAMIC;
  80. Ref<Texture2D> projector;
  81. Color correlated_color = Color(1.0, 1.0, 1.0);
  82. float temperature = 6500.0;
  83. // bind helpers
  84. virtual void owner_changed_notify() override;
  85. protected:
  86. RID light;
  87. static void _bind_methods();
  88. void _notification(int p_what);
  89. void _validate_property(PropertyInfo &p_property) const;
  90. Light3D(RenderingServer::LightType p_type);
  91. public:
  92. RS::LightType get_light_type() const { return type; }
  93. void set_editor_only(bool p_editor_only);
  94. bool is_editor_only() const;
  95. void set_param(Param p_param, real_t p_value);
  96. real_t get_param(Param p_param) const;
  97. void set_shadow(bool p_enable);
  98. bool has_shadow() const;
  99. void set_negative(bool p_enable);
  100. bool is_negative() const;
  101. void set_enable_distance_fade(bool p_enable);
  102. bool is_distance_fade_enabled() const;
  103. void set_distance_fade_begin(real_t p_distance);
  104. real_t get_distance_fade_begin() const;
  105. void set_distance_fade_shadow(real_t p_distance);
  106. real_t get_distance_fade_shadow() const;
  107. void set_distance_fade_length(real_t p_length);
  108. real_t get_distance_fade_length() const;
  109. void set_cull_mask(uint32_t p_cull_mask);
  110. uint32_t get_cull_mask() const;
  111. void set_color(const Color &p_color);
  112. Color get_color() const;
  113. void set_shadow_reverse_cull_face(bool p_enable);
  114. bool get_shadow_reverse_cull_face() const;
  115. void set_bake_mode(BakeMode p_mode);
  116. BakeMode get_bake_mode() const;
  117. void set_projector(const Ref<Texture2D> &p_texture);
  118. Ref<Texture2D> get_projector() const;
  119. void set_temperature(const float p_temperature);
  120. float get_temperature() const;
  121. Color get_correlated_color() const;
  122. virtual AABB get_aabb() const override;
  123. virtual PackedStringArray get_configuration_warnings() const override;
  124. Light3D();
  125. ~Light3D();
  126. };
  127. VARIANT_ENUM_CAST(Light3D::Param);
  128. VARIANT_ENUM_CAST(Light3D::BakeMode);
  129. class DirectionalLight3D : public Light3D {
  130. GDCLASS(DirectionalLight3D, Light3D);
  131. public:
  132. enum ShadowMode {
  133. SHADOW_ORTHOGONAL,
  134. SHADOW_PARALLEL_2_SPLITS,
  135. SHADOW_PARALLEL_4_SPLITS,
  136. };
  137. enum SkyMode {
  138. SKY_MODE_LIGHT_AND_SKY,
  139. SKY_MODE_LIGHT_ONLY,
  140. SKY_MODE_SKY_ONLY,
  141. };
  142. private:
  143. bool blend_splits;
  144. ShadowMode shadow_mode;
  145. SkyMode sky_mode = SKY_MODE_LIGHT_AND_SKY;
  146. protected:
  147. static void _bind_methods();
  148. void _validate_property(PropertyInfo &p_property) const;
  149. public:
  150. void set_shadow_mode(ShadowMode p_mode);
  151. ShadowMode get_shadow_mode() const;
  152. void set_blend_splits(bool p_enable);
  153. bool is_blend_splits_enabled() const;
  154. void set_sky_mode(SkyMode p_mode);
  155. SkyMode get_sky_mode() const;
  156. DirectionalLight3D();
  157. };
  158. VARIANT_ENUM_CAST(DirectionalLight3D::ShadowMode)
  159. VARIANT_ENUM_CAST(DirectionalLight3D::SkyMode)
  160. class OmniLight3D : public Light3D {
  161. GDCLASS(OmniLight3D, Light3D);
  162. public:
  163. // omni light
  164. enum ShadowMode {
  165. SHADOW_DUAL_PARABOLOID,
  166. SHADOW_CUBE,
  167. };
  168. private:
  169. ShadowMode shadow_mode;
  170. protected:
  171. static void _bind_methods();
  172. public:
  173. void set_shadow_mode(ShadowMode p_mode);
  174. ShadowMode get_shadow_mode() const;
  175. PackedStringArray get_configuration_warnings() const override;
  176. OmniLight3D();
  177. };
  178. VARIANT_ENUM_CAST(OmniLight3D::ShadowMode)
  179. class SpotLight3D : public Light3D {
  180. GDCLASS(SpotLight3D, Light3D);
  181. protected:
  182. static void _bind_methods();
  183. public:
  184. PackedStringArray get_configuration_warnings() const override;
  185. SpotLight3D();
  186. };
  187. #endif // LIGHT_3D_H