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

145 lines
5.1 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_MATERIAL_PASS_HPP
  20. #define ANTKEEPER_MATERIAL_PASS_HPP
  21. #include "renderer/render-pass.hpp"
  22. #include "renderer/material.hpp"
  23. #include "animation/tween.hpp"
  24. #include "utility/fundamental-types.hpp"
  25. #include "event/event-handler.hpp"
  26. #include "event/input-events.hpp"
  27. #include <unordered_map>
  28. #include "gl/shader-program.hpp"
  29. #include "gl/shader-input.hpp"
  30. #include "gl/texture-2d.hpp"
  31. class camera;
  32. class resource_manager;
  33. class shadow_map_pass;
  34. /**
  35. * Renders scene objects using their material-specified shaders and properties.
  36. */
  37. class material_pass: public render_pass,
  38. public event_handler<mouse_moved_event>
  39. {
  40. public:
  41. material_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager);
  42. virtual ~material_pass();
  43. virtual void render(render_context* context) const final;
  44. /// Sets the material to be used when a render operation is missing a material. If no fallback material is specified, render operations without materials will not be processed.
  45. void set_fallback_material(const material* fallback);
  46. /// Sets the time tween, which is interpolated between updates
  47. void set_time_tween(const tween<double>* time);
  48. void set_focal_point_tween(const tween<float3>* focal_point);
  49. const ::shadow_map_pass* shadow_map_pass;
  50. const gl::texture_2d* shadow_map;
  51. private:
  52. virtual void handle_event(const mouse_moved_event& event);
  53. /**
  54. * Sets of known shader input parameters. Each time a new shader is encountered, a parameter set will be created and its inputs connected to the shader program. A null input indiciates that the shader doesn't have that parameter.
  55. */
  56. struct parameter_set
  57. {
  58. const gl::shader_input* time;
  59. const gl::shader_input* mouse;
  60. const gl::shader_input* resolution;
  61. const gl::shader_input* camera_position;
  62. const gl::shader_input* camera_exposure;
  63. const gl::shader_input* model;
  64. const gl::shader_input* view;
  65. const gl::shader_input* projection;
  66. const gl::shader_input* model_view;
  67. const gl::shader_input* view_projection;
  68. const gl::shader_input* model_view_projection;
  69. const gl::shader_input* normal_model;
  70. const gl::shader_input* normal_model_view;
  71. const gl::shader_input* clip_depth;
  72. const gl::shader_input* log_depth_coef;
  73. const gl::shader_input* ambient_light_count;
  74. const gl::shader_input* ambient_light_colors;
  75. const gl::shader_input* point_light_count;
  76. const gl::shader_input* point_light_colors;
  77. const gl::shader_input* point_light_positions;
  78. const gl::shader_input* point_light_attenuations;
  79. const gl::shader_input* directional_light_count;
  80. const gl::shader_input* directional_light_colors;
  81. const gl::shader_input* directional_light_directions;
  82. const gl::shader_input* directional_light_textures;
  83. const gl::shader_input* directional_light_texture_matrices;
  84. const gl::shader_input* directional_light_texture_opacities;
  85. const gl::shader_input* spot_light_count;
  86. const gl::shader_input* spot_light_colors;
  87. const gl::shader_input* spot_light_positions;
  88. const gl::shader_input* spot_light_directions;
  89. const gl::shader_input* spot_light_attenuations;
  90. const gl::shader_input* spot_light_cutoffs;
  91. const gl::shader_input* focal_point;
  92. const gl::shader_input* shadow_map_directional;
  93. const gl::shader_input* shadow_splits_directional;
  94. const gl::shader_input* shadow_matrices_directional;
  95. };
  96. const parameter_set* load_parameter_set(const gl::shader_program* program) const;
  97. mutable std::unordered_map<const gl::shader_program*, parameter_set*> parameter_sets;
  98. const material* fallback_material;
  99. const tween<double>* time_tween;
  100. float2 mouse_position;
  101. const tween<float3>* focal_point_tween;
  102. int max_ambient_light_count;
  103. int max_point_light_count;
  104. int max_directional_light_count;
  105. int max_spot_light_count;
  106. mutable int ambient_light_count;
  107. mutable int point_light_count;
  108. mutable int directional_light_count;
  109. mutable int spot_light_count;
  110. float3* ambient_light_colors;
  111. float3* point_light_colors;
  112. float3* point_light_positions;
  113. float3* point_light_attenuations;
  114. float3* directional_light_colors;
  115. float3* directional_light_directions;
  116. const gl::texture_2d** directional_light_textures;
  117. float4x4* directional_light_texture_matrices;
  118. float* directional_light_texture_opacities;
  119. float3* spot_light_colors;
  120. float3* spot_light_positions;
  121. float3* spot_light_directions;
  122. float3* spot_light_attenuations;
  123. float2* spot_light_cutoffs;
  124. };
  125. #endif // ANTKEEPER_MATERIAL_PASS_HPP