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

89 lines
3.1 KiB

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