sky_material.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**************************************************************************/
  2. /* sky_material.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 SKY_MATERIAL_H
  31. #define SKY_MATERIAL_H
  32. #include "core/templates/rid.h"
  33. #include "scene/resources/material.h"
  34. class ProceduralSkyMaterial : public Material {
  35. GDCLASS(ProceduralSkyMaterial, Material);
  36. private:
  37. Color sky_top_color;
  38. Color sky_horizon_color;
  39. float sky_curve = 0.0f;
  40. float sky_energy_multiplier = 0.0f;
  41. Ref<Texture2D> sky_cover;
  42. Color sky_cover_modulate;
  43. Color ground_bottom_color;
  44. Color ground_horizon_color;
  45. float ground_curve = 0.0f;
  46. float ground_energy_multiplier = 0.0f;
  47. float sun_angle_max = 0.0f;
  48. float sun_curve = 0.0f;
  49. bool use_debanding = true;
  50. float global_energy_multiplier = 1.0f;
  51. static Mutex shader_mutex;
  52. static RID shader_cache[2];
  53. static void _update_shader();
  54. mutable bool shader_set = false;
  55. protected:
  56. static void _bind_methods();
  57. void _validate_property(PropertyInfo &property) const;
  58. public:
  59. void set_sky_top_color(const Color &p_sky_top);
  60. Color get_sky_top_color() const;
  61. void set_sky_horizon_color(const Color &p_sky_horizon);
  62. Color get_sky_horizon_color() const;
  63. void set_sky_curve(float p_curve);
  64. float get_sky_curve() const;
  65. void set_sky_energy_multiplier(float p_multiplier);
  66. float get_sky_energy_multiplier() const;
  67. void set_sky_cover(const Ref<Texture2D> &p_sky_cover);
  68. Ref<Texture2D> get_sky_cover() const;
  69. void set_sky_cover_modulate(const Color &p_sky_cover_modulate);
  70. Color get_sky_cover_modulate() const;
  71. void set_ground_bottom_color(const Color &p_ground_bottom);
  72. Color get_ground_bottom_color() const;
  73. void set_ground_horizon_color(const Color &p_ground_horizon);
  74. Color get_ground_horizon_color() const;
  75. void set_ground_curve(float p_curve);
  76. float get_ground_curve() const;
  77. void set_ground_energy_multiplier(float p_energy);
  78. float get_ground_energy_multiplier() const;
  79. void set_sun_angle_max(float p_angle);
  80. float get_sun_angle_max() const;
  81. void set_sun_curve(float p_curve);
  82. float get_sun_curve() const;
  83. void set_use_debanding(bool p_use_debanding);
  84. bool get_use_debanding() const;
  85. void set_energy_multiplier(float p_multiplier);
  86. float get_energy_multiplier() const;
  87. virtual Shader::Mode get_shader_mode() const override;
  88. virtual RID get_shader_rid() const override;
  89. virtual RID get_rid() const override;
  90. static void cleanup_shader();
  91. ProceduralSkyMaterial();
  92. ~ProceduralSkyMaterial();
  93. };
  94. //////////////////////////////////////////////////////
  95. /* PanoramaSkyMaterial */
  96. class PanoramaSkyMaterial : public Material {
  97. GDCLASS(PanoramaSkyMaterial, Material);
  98. private:
  99. Ref<Texture2D> panorama;
  100. float energy_multiplier = 1.0f;
  101. static Mutex shader_mutex;
  102. static RID shader_cache[2];
  103. static void _update_shader();
  104. mutable bool shader_set = false;
  105. bool filter = true;
  106. protected:
  107. static void _bind_methods();
  108. public:
  109. void set_panorama(const Ref<Texture2D> &p_panorama);
  110. Ref<Texture2D> get_panorama() const;
  111. void set_filtering_enabled(bool p_enabled);
  112. bool is_filtering_enabled() const;
  113. void set_energy_multiplier(float p_multiplier);
  114. float get_energy_multiplier() const;
  115. virtual Shader::Mode get_shader_mode() const override;
  116. virtual RID get_shader_rid() const override;
  117. virtual RID get_rid() const override;
  118. static void cleanup_shader();
  119. PanoramaSkyMaterial();
  120. ~PanoramaSkyMaterial();
  121. };
  122. //////////////////////////////////////////////////////
  123. /* PanoramaSkyMaterial */
  124. class PhysicalSkyMaterial : public Material {
  125. GDCLASS(PhysicalSkyMaterial, Material);
  126. private:
  127. static Mutex shader_mutex;
  128. static RID shader_cache[2];
  129. float rayleigh = 0.0f;
  130. Color rayleigh_color;
  131. float mie = 0.0f;
  132. float mie_eccentricity = 0.0f;
  133. Color mie_color;
  134. float turbidity = 0.0f;
  135. float sun_disk_scale = 0.0f;
  136. Color ground_color;
  137. float energy_multiplier = 1.0f;
  138. bool use_debanding = true;
  139. Ref<Texture2D> night_sky;
  140. static void _update_shader();
  141. mutable bool shader_set = false;
  142. protected:
  143. static void _bind_methods();
  144. void _validate_property(PropertyInfo &property) const;
  145. public:
  146. void set_rayleigh_coefficient(float p_rayleigh);
  147. float get_rayleigh_coefficient() const;
  148. void set_rayleigh_color(Color p_rayleigh_color);
  149. Color get_rayleigh_color() const;
  150. void set_turbidity(float p_turbidity);
  151. float get_turbidity() const;
  152. void set_mie_coefficient(float p_mie);
  153. float get_mie_coefficient() const;
  154. void set_mie_eccentricity(float p_eccentricity);
  155. float get_mie_eccentricity() const;
  156. void set_mie_color(Color p_mie_color);
  157. Color get_mie_color() const;
  158. void set_sun_disk_scale(float p_sun_disk_scale);
  159. float get_sun_disk_scale() const;
  160. void set_ground_color(Color p_ground_color);
  161. Color get_ground_color() const;
  162. void set_energy_multiplier(float p_multiplier);
  163. float get_energy_multiplier() const;
  164. void set_exposure_value(float p_exposure);
  165. float get_exposure_value() const;
  166. void set_use_debanding(bool p_use_debanding);
  167. bool get_use_debanding() const;
  168. void set_night_sky(const Ref<Texture2D> &p_night_sky);
  169. Ref<Texture2D> get_night_sky() const;
  170. virtual Shader::Mode get_shader_mode() const override;
  171. virtual RID get_shader_rid() const override;
  172. static void cleanup_shader();
  173. virtual RID get_rid() const override;
  174. PhysicalSkyMaterial();
  175. ~PhysicalSkyMaterial();
  176. };
  177. #endif // SKY_MATERIAL_H