💿🐜 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.

187 lines
6.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_observer_altitude(float altitude);
  61. void set_scale_heights(float rayleigh, float mie);
  62. void set_scattering_coefficients(const float3& r, const float3& m);
  63. void set_mie_anisotropy(float g);
  64. void set_atmosphere_radii(float inner, float outer);
  65. void set_moon_position(const float3& position);
  66. void set_moon_rotation(const math::quaternion<float>& rotation);
  67. void set_moon_angular_radius(float angular_radius);
  68. void set_moon_sunlight_direction(const float3& direction);
  69. void set_moon_sunlight_illuminance(const float3& illuminance);
  70. void set_moon_planetlight_direction(const float3& direction);
  71. void set_moon_planetlight_illuminance(const float3& illuminance);
  72. private:
  73. virtual void handle_event(const mouse_moved_event& event);
  74. gl::shader_program* sky_shader_program;
  75. const gl::shader_input* model_view_projection_input;
  76. const gl::shader_input* mouse_input;
  77. const gl::shader_input* resolution_input;
  78. const gl::shader_input* time_input;
  79. const gl::shader_input* exposure_input;
  80. const gl::shader_input* observer_altitude_input;
  81. const gl::shader_input* sun_direction_input;
  82. const gl::shader_input* sun_luminance_input;
  83. const gl::shader_input* sun_illuminance_input;
  84. const gl::shader_input* sun_angular_radius_input;
  85. const gl::shader_input* scale_height_rm_input;
  86. const gl::shader_input* rayleigh_scattering_input;
  87. const gl::shader_input* mie_scattering_input;
  88. const gl::shader_input* mie_anisotropy_input;
  89. const gl::shader_input* atmosphere_radii_input;
  90. gl::shader_program* moon_shader_program;
  91. const gl::shader_input* moon_model_input;
  92. const gl::shader_input* moon_view_projection_input;
  93. const gl::shader_input* moon_normal_model_input;
  94. const gl::shader_input* moon_camera_position_input;
  95. const gl::shader_input* moon_sunlight_direction_input;
  96. const gl::shader_input* moon_sunlight_illuminance_input;
  97. const gl::shader_input* moon_planetlight_direction_input;
  98. const gl::shader_input* moon_planetlight_illuminance_input;
  99. const model* sky_model;
  100. const material* sky_material;
  101. const gl::vertex_array* sky_model_vao;
  102. gl::drawing_mode sky_model_drawing_mode;
  103. std::size_t sky_model_start_index;
  104. std::size_t sky_model_index_count;
  105. const model* moon_model;
  106. const material* moon_material;
  107. const gl::vertex_array* moon_model_vao;
  108. gl::drawing_mode moon_model_drawing_mode;
  109. std::size_t moon_model_start_index;
  110. std::size_t moon_model_index_count;
  111. const model* stars_model;
  112. const material* star_material;
  113. const gl::vertex_array* stars_model_vao;
  114. gl::drawing_mode stars_model_drawing_mode;
  115. std::size_t stars_model_start_index;
  116. std::size_t stars_model_index_count;
  117. gl::shader_program* star_shader_program;
  118. const gl::shader_input* star_model_view_input;
  119. const gl::shader_input* star_projection_input;
  120. const gl::shader_input* star_exposure_input;
  121. const gl::shader_input* star_distance_input;
  122. const model* clouds_model;
  123. const material* cloud_material;
  124. const gl::vertex_array* clouds_model_vao;
  125. gl::drawing_mode clouds_model_drawing_mode;
  126. std::size_t clouds_model_start_index;
  127. std::size_t clouds_model_index_count;
  128. gl::shader_program* cloud_shader_program;
  129. const gl::shader_input* cloud_model_view_projection_input;
  130. const gl::shader_input* cloud_sun_direction_input;
  131. const gl::shader_input* cloud_sun_illuminance_input;
  132. const gl::shader_input* cloud_camera_position_input;
  133. const gl::shader_input* cloud_camera_exposure_input;
  134. const gl::texture_2d* blue_noise_map;
  135. const gl::texture_2d* sky_gradient;
  136. const gl::texture_2d* sky_gradient2;
  137. float2 mouse_position;
  138. tween<float> observer_altitude_tween;
  139. tween<float3> sun_position_tween;
  140. tween<float3> sun_luminance_tween;
  141. tween<float3> sun_illuminance_tween;
  142. tween<float3> icrf_to_eus_translation;
  143. tween<math::quaternion<float>> icrf_to_eus_rotation;
  144. tween<float3> moon_position_tween;
  145. tween<math::quaternion<float>> moon_rotation_tween;
  146. tween<float> moon_angular_radius_tween;
  147. tween<float3> moon_sunlight_direction_tween;
  148. tween<float3> moon_sunlight_illuminance_tween;
  149. tween<float3> moon_planetlight_direction_tween;
  150. tween<float3> moon_planetlight_illuminance_tween;
  151. float sun_angular_radius;
  152. float2 scale_height_rm;
  153. float3 rayleigh_scattering;
  154. float3 mie_scattering;
  155. float2 mie_anisotropy;
  156. float3 atmosphere_radii;
  157. float magnification;
  158. };
  159. } // namespace render
  160. #endif // ANTKEEPER_RENDER_SKY_PASS_HPP