light.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*************************************************************************/
  2. /* light.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. /**
  36. @author Juan Linietsky <reduzio@gmail.com>
  37. */
  38. class Light : public VisualInstance {
  39. GDCLASS(Light, VisualInstance);
  40. OBJ_CATEGORY("3D Light Nodes");
  41. public:
  42. enum Param {
  43. PARAM_ENERGY = VS::LIGHT_PARAM_ENERGY,
  44. PARAM_INDIRECT_ENERGY = VS::LIGHT_PARAM_INDIRECT_ENERGY,
  45. PARAM_SPECULAR = VS::LIGHT_PARAM_SPECULAR,
  46. PARAM_RANGE = VS::LIGHT_PARAM_RANGE,
  47. PARAM_ATTENUATION = VS::LIGHT_PARAM_ATTENUATION,
  48. PARAM_SPOT_ANGLE = VS::LIGHT_PARAM_SPOT_ANGLE,
  49. PARAM_SPOT_ATTENUATION = VS::LIGHT_PARAM_SPOT_ATTENUATION,
  50. PARAM_CONTACT_SHADOW_SIZE = VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE,
  51. PARAM_SHADOW_MAX_DISTANCE = VS::LIGHT_PARAM_SHADOW_MAX_DISTANCE,
  52. PARAM_SHADOW_SPLIT_1_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET,
  53. PARAM_SHADOW_SPLIT_2_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET,
  54. PARAM_SHADOW_SPLIT_3_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET,
  55. PARAM_SHADOW_NORMAL_BIAS = VS::LIGHT_PARAM_SHADOW_NORMAL_BIAS,
  56. PARAM_SHADOW_BIAS = VS::LIGHT_PARAM_SHADOW_BIAS,
  57. PARAM_SHADOW_BIAS_SPLIT_SCALE = VS::LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE,
  58. PARAM_MAX = VS::LIGHT_PARAM_MAX
  59. };
  60. enum BakeMode {
  61. BAKE_DISABLED,
  62. BAKE_INDIRECT,
  63. BAKE_ALL
  64. };
  65. private:
  66. Color color;
  67. float param[PARAM_MAX];
  68. Color shadow_color;
  69. bool shadow;
  70. bool negative;
  71. bool reverse_cull;
  72. uint32_t cull_mask;
  73. VS::LightType type;
  74. bool editor_only;
  75. void _update_visibility();
  76. BakeMode bake_mode;
  77. // bind helpers
  78. protected:
  79. RID light;
  80. virtual bool _can_gizmo_scale() const;
  81. static void _bind_methods();
  82. void _notification(int p_what);
  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_4_SPLITS
  118. };
  119. enum ShadowDepthRange {
  120. SHADOW_DEPTH_RANGE_STABLE = VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE,
  121. SHADOW_DEPTH_RANGE_OPTIMIZED = VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED,
  122. };
  123. private:
  124. bool blend_splits;
  125. ShadowMode shadow_mode;
  126. ShadowDepthRange shadow_depth_range;
  127. protected:
  128. static void _bind_methods();
  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. SpotLight() :
  173. Light(VisualServer::LIGHT_SPOT) {}
  174. };
  175. #endif