light.h 6.2 KB

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