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

190 lines
6.6 KiB

4 years ago
4 years ago
4 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::shader_program* sky_shader_program;
  76. const gl::shader_input* model_view_projection_input;
  77. const gl::shader_input* mouse_input;
  78. const gl::shader_input* resolution_input;
  79. const gl::shader_input* time_input;
  80. const gl::shader_input* exposure_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* atmosphere_radii_input;
  86. const gl::shader_input* observer_elevation_input;
  87. const gl::shader_input* rayleigh_parameters_input;
  88. const gl::shader_input* mie_parameters_input;
  89. const gl::shader_input* ozone_distribution_input;
  90. const gl::shader_input* ozone_absorption_input;
  91. gl::shader_program* moon_shader_program;
  92. const gl::shader_input* moon_model_input;
  93. const gl::shader_input* moon_view_projection_input;
  94. const gl::shader_input* moon_normal_model_input;
  95. const gl::shader_input* moon_camera_position_input;
  96. const gl::shader_input* moon_sunlight_direction_input;
  97. const gl::shader_input* moon_sunlight_illuminance_input;
  98. const gl::shader_input* moon_planetlight_direction_input;
  99. const gl::shader_input* moon_planetlight_illuminance_input;
  100. const model* sky_model;
  101. const material* sky_material;
  102. const gl::vertex_array* sky_model_vao;
  103. gl::drawing_mode sky_model_drawing_mode;
  104. std::size_t sky_model_start_index;
  105. std::size_t sky_model_index_count;
  106. const model* moon_model;
  107. const material* moon_material;
  108. const gl::vertex_array* moon_model_vao;
  109. gl::drawing_mode moon_model_drawing_mode;
  110. std::size_t moon_model_start_index;
  111. std::size_t moon_model_index_count;
  112. const model* stars_model;
  113. const material* star_material;
  114. const gl::vertex_array* stars_model_vao;
  115. gl::drawing_mode stars_model_drawing_mode;
  116. std::size_t stars_model_start_index;
  117. std::size_t stars_model_index_count;
  118. gl::shader_program* star_shader_program;
  119. const gl::shader_input* star_model_view_input;
  120. const gl::shader_input* star_projection_input;
  121. const gl::shader_input* star_exposure_input;
  122. const gl::shader_input* star_distance_input;
  123. const model* clouds_model;
  124. const material* cloud_material;
  125. const gl::vertex_array* clouds_model_vao;
  126. gl::drawing_mode clouds_model_drawing_mode;
  127. std::size_t clouds_model_start_index;
  128. std::size_t clouds_model_index_count;
  129. gl::shader_program* cloud_shader_program;
  130. const gl::shader_input* cloud_model_view_projection_input;
  131. const gl::shader_input* cloud_sun_direction_input;
  132. const gl::shader_input* cloud_sun_illuminance_input;
  133. const gl::shader_input* cloud_camera_position_input;
  134. const gl::shader_input* cloud_camera_exposure_input;
  135. const gl::texture_2d* blue_noise_map;
  136. const gl::texture_2d* sky_gradient;
  137. const gl::texture_2d* sky_gradient2;
  138. float2 mouse_position;
  139. tween<float> observer_elevation_tween;
  140. tween<float3> sun_position_tween;
  141. tween<float3> sun_luminance_tween;
  142. tween<float3> sun_illuminance_tween;
  143. tween<float3> icrf_to_eus_translation;
  144. tween<math::quaternion<float>> icrf_to_eus_rotation;
  145. tween<float3> moon_position_tween;
  146. tween<math::quaternion<float>> moon_rotation_tween;
  147. tween<float> moon_angular_radius_tween;
  148. tween<float3> moon_sunlight_direction_tween;
  149. tween<float3> moon_sunlight_illuminance_tween;
  150. tween<float3> moon_planetlight_direction_tween;
  151. tween<float3> moon_planetlight_illuminance_tween;
  152. float sun_angular_radius;
  153. float atmosphere_upper_limit;
  154. float3 atmosphere_radii;
  155. float observer_elevation;
  156. float4 rayleigh_parameters;
  157. float4 mie_parameters;
  158. float3 ozone_distribution;
  159. float3 ozone_absorption;
  160. float magnification;
  161. };
  162. } // namespace render
  163. #endif // ANTKEEPER_RENDER_SKY_PASS_HPP