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

88 lines
3.2 KiB

  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_SHADOW_MAP_PASS_HPP
  20. #define ANTKEEPER_SHADOW_MAP_PASS_HPP
  21. #include "renderer/render-pass.hpp"
  22. #include "utility/fundamental-types.hpp"
  23. #include "scene/directional-light.hpp"
  24. class shader_program;
  25. class shader_input;
  26. class resource_manager;
  27. /**
  28. *
  29. */
  30. class shadow_map_pass: public render_pass
  31. {
  32. public:
  33. shadow_map_pass(::rasterizer* rasterizer, const ::framebuffer* framebuffer, resource_manager* resource_manager);
  34. virtual ~shadow_map_pass();
  35. virtual void render(render_context* context) const final;
  36. /**
  37. * Sets the linear interpolation weight between uniform and logarithmic frustum-splitting schemes.
  38. *
  39. * @param weight Linear interpolation weight between uniform and logarithmic frustum-splitting schemes. A value of `0.0` indicates a uniform split scheme, while `1.0` indicates a logarithmic split scheme.
  40. */
  41. void set_split_scheme_weight(float weight);
  42. void set_light(const scene::directional_light* light);
  43. const float4x4* get_shadow_matrices() const;
  44. const float* get_split_distances() const;
  45. private:
  46. /**
  47. * Calculates the distances along the depth axis at which a view-frustum should be split, given a frustum-splitting scheme.
  48. *
  49. * @param[out] split_distances Array containing the distances to each split.
  50. * @param split_count Number of times the frustum should be split.
  51. * @param split_scheme Linear interpolation weight between uniform and logarithmic frustum-splitting schemes. A value of `0.0` indicates a uniform split scheme, while `1.0` indicates a logarithmic split scheme.
  52. * @param near Distance to the near clipping plane of the frustum to be split.
  53. * @param far Distance to the far clipping plane of the frustum to be split.
  54. */
  55. static void distribute_frustum_splits(float* split_distances, std::size_t split_count, float split_scheme, float near, float far);
  56. shader_program* unskinned_shader_program;
  57. const shader_input* unskinned_model_view_projection_input;
  58. shader_program* skinned_shader_program;
  59. const shader_input* skinned_model_view_projection_input;
  60. mutable float split_distances[5];
  61. mutable float4x4 shadow_matrices[4];
  62. float4x4 bias_tile_matrices[4];
  63. float split_scheme_weight;
  64. const scene::directional_light* light;
  65. };
  66. inline const float4x4* shadow_map_pass::get_shadow_matrices() const
  67. {
  68. return shadow_matrices;
  69. }
  70. inline const float* shadow_map_pass::get_split_distances() const
  71. {
  72. return split_distances;
  73. }
  74. #endif // ANTKEEPER_SHADOW_MAP_PASS_HPP