💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
7.4 KiB

3 years ago
3 years ago
3 years ago
  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_RENDER_SKY_PASS_HPP
  20. #define ANTKEEPER_RENDER_SKY_PASS_HPP
  21. #include "render/pass.hpp"
  22. #include "utility/fundamental-types.hpp"
  23. #include "event/event-handler.hpp"
  24. #include "event/input-events.hpp"
  25. #include "animation/tween.hpp"
  26. #include "math/quaternion-type.hpp"
  27. #include "gl/shader-program.hpp"
  28. #include "gl/shader-input.hpp"
  29. #include "gl/vertex-buffer.hpp"
  30. #include "gl/vertex-array.hpp"
  31. #include "gl/texture-2d.hpp"
  32. #include "gl/drawing-mode.hpp"
  33. #include "math/se3.hpp"
  34. #include "scene/object.hpp"
  35. class resource_manager;
  36. namespace render {
  37. class material;
  38. class model;
  39. /**
  40. *
  41. */
  42. class sky_pass: public pass,
  43. public event_handler<mouse_moved_event>
  44. {
  45. public:
  46. sky_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager);
  47. virtual ~sky_pass();
  48. virtual void render(const render::context& ctx, render::queue& queue) const final;
  49. void update_tweens();
  50. void set_magnification(float scale);
  51. void set_sky_model(const model* model);
  52. void set_moon_model(const model* model);
  53. void set_stars_model(const model* model);
  54. void set_clouds_model(const model* model);
  55. void set_icrf_to_eus(const math::transformation::se3<float>& transformation);
  56. void set_sun_position(const float3& position);
  57. void set_sun_luminance(const float3& luminance);
  58. void set_sun_illuminance(const float3& illuminance);
  59. void set_sun_angular_radius(float radius);
  60. void set_planet_radius(float radius);
  61. void set_atmosphere_upper_limit(float limit);
  62. void set_observer_elevation(float elevation);
  63. void set_rayleigh_parameters(float scale_height, const float3& scattering);
  64. void set_mie_parameters(float scale_height, float scattering, float absorption, float anisotropy);
  65. void set_ozone_parameters(float lower_limit, float upper_limit, float mode, const float3& absorption);
  66. void set_moon_position(const float3& position);
  67. void set_moon_rotation(const math::quaternion<float>& rotation);
  68. void set_moon_angular_radius(float angular_radius);
  69. void set_moon_sunlight_direction(const float3& direction);
  70. void set_moon_sunlight_illuminance(const float3& illuminance);
  71. void set_moon_planetlight_direction(const float3& direction);
  72. void set_moon_planetlight_illuminance(const float3& illuminance);
  73. private:
  74. virtual void handle_event(const mouse_moved_event& event);
  75. gl::vertex_buffer* quad_vbo;
  76. gl::vertex_array* quad_vao;
  77. gl::texture_2d* transmittance_texture;
  78. gl::framebuffer* transmittance_framebuffer;
  79. float2 transmittance_inverse_lut_resolution;
  80. gl::shader_program* transmittance_shader_program;
  81. const gl::shader_input* transmittance_atmosphere_radii_input;
  82. const gl::shader_input* transmittance_rayleigh_parameters_input;
  83. const gl::shader_input* transmittance_mie_parameters_input;
  84. const gl::shader_input* transmittance_ozone_distribution_input;
  85. const gl::shader_input* transmittance_ozone_absorption_input;
  86. const gl::shader_input* transmittance_inverse_lut_resolution_input;
  87. gl::shader_program* sky_shader_program;
  88. const gl::shader_input* model_view_projection_input;
  89. const gl::shader_input* mouse_input;
  90. const gl::shader_input* resolution_input;
  91. const gl::shader_input* time_input;
  92. const gl::shader_input* exposure_input;
  93. const gl::shader_input* sun_direction_input;
  94. const gl::shader_input* sun_luminance_input;
  95. const gl::shader_input* sun_illuminance_input;
  96. const gl::shader_input* sun_angular_radius_input;
  97. const gl::shader_input* atmosphere_radii_input;
  98. const gl::shader_input* observer_position_input;
  99. const gl::shader_input* rayleigh_parameters_input;
  100. const gl::shader_input* mie_parameters_input;
  101. const gl::shader_input* ozone_distribution_input;
  102. const gl::shader_input* ozone_absorption_input;
  103. const gl::shader_input* transmittance_lut_input;
  104. const gl::shader_input* inverse_transmittance_lut_resolution_input;
  105. gl::shader_program* moon_shader_program;
  106. const gl::shader_input* moon_model_input;
  107. const gl::shader_input* moon_view_projection_input;
  108. const gl::shader_input* moon_normal_model_input;
  109. const gl::shader_input* moon_camera_position_input;
  110. const gl::shader_input* moon_sunlight_direction_input;
  111. const gl::shader_input* moon_sunlight_illuminance_input;
  112. const gl::shader_input* moon_planetlight_direction_input;
  113. const gl::shader_input* moon_planetlight_illuminance_input;
  114. const model* sky_model;
  115. const material* sky_material;
  116. const gl::vertex_array* sky_model_vao;
  117. gl::drawing_mode sky_model_drawing_mode;
  118. std::size_t sky_model_start_index;
  119. std::size_t sky_model_index_count;
  120. const model* moon_model;
  121. const material* moon_material;
  122. const gl::vertex_array* moon_model_vao;
  123. gl::drawing_mode moon_model_drawing_mode;
  124. std::size_t moon_model_start_index;
  125. std::size_t moon_model_index_count;
  126. const model* stars_model;
  127. const material* star_material;
  128. const gl::vertex_array* stars_model_vao;
  129. gl::drawing_mode stars_model_drawing_mode;
  130. std::size_t stars_model_start_index;
  131. std::size_t stars_model_index_count;
  132. gl::shader_program* star_shader_program;
  133. const gl::shader_input* star_model_view_input;
  134. const gl::shader_input* star_projection_input;
  135. const gl::shader_input* star_exposure_input;
  136. const gl::shader_input* star_distance_input;
  137. const model* clouds_model;
  138. const material* cloud_material;
  139. const gl::vertex_array* clouds_model_vao;
  140. gl::drawing_mode clouds_model_drawing_mode;
  141. std::size_t clouds_model_start_index;
  142. std::size_t clouds_model_index_count;
  143. gl::shader_program* cloud_shader_program;
  144. const gl::shader_input* cloud_model_view_projection_input;
  145. const gl::shader_input* cloud_sun_direction_input;
  146. const gl::shader_input* cloud_sun_illuminance_input;
  147. const gl::shader_input* cloud_camera_position_input;
  148. const gl::shader_input* cloud_camera_exposure_input;
  149. const gl::texture_2d* blue_noise_map;
  150. const gl::texture_2d* sky_gradient;
  151. const gl::texture_2d* sky_gradient2;
  152. float2 mouse_position;
  153. tween<float3> sun_position_tween;
  154. tween<float3> sun_luminance_tween;
  155. tween<float3> sun_illuminance_tween;
  156. tween<float3> icrf_to_eus_translation;
  157. tween<math::quaternion<float>> icrf_to_eus_rotation;
  158. tween<float3> moon_position_tween;
  159. tween<math::quaternion<float>> moon_rotation_tween;
  160. tween<float> moon_angular_radius_tween;
  161. tween<float3> moon_sunlight_direction_tween;
  162. tween<float3> moon_sunlight_illuminance_tween;
  163. tween<float3> moon_planetlight_direction_tween;
  164. tween<float3> moon_planetlight_illuminance_tween;
  165. float sun_angular_radius;
  166. float atmosphere_upper_limit;
  167. float3 atmosphere_radii;
  168. float observer_elevation;
  169. tween<float3> observer_position_tween;
  170. float4 rayleigh_parameters;
  171. float4 mie_parameters;
  172. float3 ozone_distribution;
  173. float3 ozone_absorption;
  174. float magnification;
  175. };
  176. } // namespace render
  177. #endif // ANTKEEPER_RENDER_SKY_PASS_HPP