sky_box.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*************************************************************************/
  2. /* sky_box.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 SKY_BOX_H
  31. #define SKY_BOX_H
  32. #include "core/os/thread.h"
  33. #include "scene/resources/texture.h"
  34. class Sky : public Resource {
  35. GDCLASS(Sky, Resource);
  36. public:
  37. enum RadianceSize {
  38. RADIANCE_SIZE_32,
  39. RADIANCE_SIZE_64,
  40. RADIANCE_SIZE_128,
  41. RADIANCE_SIZE_256,
  42. RADIANCE_SIZE_512,
  43. RADIANCE_SIZE_1024,
  44. RADIANCE_SIZE_2048,
  45. RADIANCE_SIZE_MAX
  46. };
  47. private:
  48. RadianceSize radiance_size;
  49. protected:
  50. static void _bind_methods();
  51. virtual void _radiance_changed() = 0;
  52. public:
  53. void set_radiance_size(RadianceSize p_size);
  54. RadianceSize get_radiance_size() const;
  55. Sky();
  56. };
  57. VARIANT_ENUM_CAST(Sky::RadianceSize)
  58. class PanoramaSky : public Sky {
  59. GDCLASS(PanoramaSky, Sky);
  60. private:
  61. RID sky;
  62. Ref<Texture> panorama;
  63. protected:
  64. static void _bind_methods();
  65. virtual void _radiance_changed();
  66. public:
  67. void set_panorama(const Ref<Texture> &p_panorama);
  68. Ref<Texture> get_panorama() const;
  69. virtual RID get_rid() const;
  70. PanoramaSky();
  71. ~PanoramaSky();
  72. };
  73. class ProceduralSky : public Sky {
  74. GDCLASS(ProceduralSky, Sky);
  75. public:
  76. enum TextureSize {
  77. TEXTURE_SIZE_256,
  78. TEXTURE_SIZE_512,
  79. TEXTURE_SIZE_1024,
  80. TEXTURE_SIZE_2048,
  81. TEXTURE_SIZE_4096,
  82. TEXTURE_SIZE_MAX
  83. };
  84. private:
  85. Thread *sky_thread;
  86. Color sky_top_color;
  87. Color sky_horizon_color;
  88. float sky_curve;
  89. float sky_energy;
  90. Color ground_bottom_color;
  91. Color ground_horizon_color;
  92. float ground_curve;
  93. float ground_energy;
  94. Color sun_color;
  95. float sun_latitude;
  96. float sun_longitude;
  97. float sun_angle_min;
  98. float sun_angle_max;
  99. float sun_curve;
  100. float sun_energy;
  101. TextureSize texture_size;
  102. RID sky;
  103. RID texture;
  104. bool update_queued;
  105. bool regen_queued;
  106. bool first_time;
  107. void _thread_done(const Ref<Image> &p_image);
  108. static void _thread_function(void *p_ud);
  109. protected:
  110. static void _bind_methods();
  111. virtual void _radiance_changed();
  112. Ref<Image> _generate_sky();
  113. void _update_sky();
  114. void _queue_update();
  115. public:
  116. void set_sky_top_color(const Color &p_sky_top);
  117. Color get_sky_top_color() const;
  118. void set_sky_horizon_color(const Color &p_sky_horizon);
  119. Color get_sky_horizon_color() const;
  120. void set_sky_curve(float p_curve);
  121. float get_sky_curve() const;
  122. void set_sky_energy(float p_energy);
  123. float get_sky_energy() const;
  124. void set_ground_bottom_color(const Color &p_ground_bottom);
  125. Color get_ground_bottom_color() const;
  126. void set_ground_horizon_color(const Color &p_ground_horizon);
  127. Color get_ground_horizon_color() const;
  128. void set_ground_curve(float p_curve);
  129. float get_ground_curve() const;
  130. void set_ground_energy(float p_energy);
  131. float get_ground_energy() const;
  132. void set_sun_color(const Color &p_sun);
  133. Color get_sun_color() const;
  134. void set_sun_latitude(float p_angle);
  135. float get_sun_latitude() const;
  136. void set_sun_longitude(float p_angle);
  137. float get_sun_longitude() const;
  138. void set_sun_angle_min(float p_angle);
  139. float get_sun_angle_min() const;
  140. void set_sun_angle_max(float p_angle);
  141. float get_sun_angle_max() const;
  142. void set_sun_curve(float p_curve);
  143. float get_sun_curve() const;
  144. void set_sun_energy(float p_energy);
  145. float get_sun_energy() const;
  146. void set_texture_size(TextureSize p_size);
  147. TextureSize get_texture_size() const;
  148. virtual RID get_rid() const;
  149. ProceduralSky();
  150. ~ProceduralSky();
  151. };
  152. VARIANT_ENUM_CAST(ProceduralSky::TextureSize)
  153. #endif // SKY_BOX_H