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

141 lines
5.0 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_RENDER_MATERIAL_PASS_HPP
  20. #define ANTKEEPER_RENDER_MATERIAL_PASS_HPP
  21. #include "render/pass.hpp"
  22. #include "render/material.hpp"
  23. #include "utility/fundamental-types.hpp"
  24. #include "event/event-handler.hpp"
  25. #include "event/input-events.hpp"
  26. #include "gl/shader-program.hpp"
  27. #include "gl/shader-input.hpp"
  28. #include "gl/texture-2d.hpp"
  29. #include <unordered_map>
  30. class resource_manager;
  31. namespace render {
  32. class shadow_map_pass;
  33. /**
  34. * Renders scene objects using their material-specified shaders and properties.
  35. */
  36. class material_pass: public pass,
  37. public event_handler<mouse_moved_event>
  38. {
  39. public:
  40. material_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer, resource_manager* resource_manager);
  41. virtual ~material_pass();
  42. virtual void render(const render::context& ctx, render::queue& queue) const final;
  43. /// 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.
  44. void set_fallback_material(const material* fallback);
  45. const render::shadow_map_pass* shadow_map_pass;
  46. const gl::texture_2d* shadow_map;
  47. private:
  48. virtual void handle_event(const mouse_moved_event& event);
  49. /**
  50. * 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.
  51. */
  52. struct parameter_set
  53. {
  54. const gl::shader_input* time;
  55. const gl::shader_input* mouse;
  56. const gl::shader_input* resolution;
  57. const gl::shader_input* camera_position;
  58. const gl::shader_input* camera_exposure;
  59. const gl::shader_input* model;
  60. const gl::shader_input* view;
  61. const gl::shader_input* projection;
  62. const gl::shader_input* model_view;
  63. const gl::shader_input* view_projection;
  64. const gl::shader_input* model_view_projection;
  65. const gl::shader_input* normal_model;
  66. const gl::shader_input* normal_model_view;
  67. const gl::shader_input* clip_depth;
  68. const gl::shader_input* log_depth_coef;
  69. const gl::shader_input* ambient_light_count;
  70. const gl::shader_input* ambient_light_colors;
  71. const gl::shader_input* point_light_count;
  72. const gl::shader_input* point_light_colors;
  73. const gl::shader_input* point_light_positions;
  74. const gl::shader_input* point_light_attenuations;
  75. const gl::shader_input* directional_light_count;
  76. const gl::shader_input* directional_light_colors;
  77. const gl::shader_input* directional_light_directions;
  78. const gl::shader_input* directional_light_textures;
  79. const gl::shader_input* directional_light_texture_matrices;
  80. const gl::shader_input* directional_light_texture_opacities;
  81. const gl::shader_input* spot_light_count;
  82. const gl::shader_input* spot_light_colors;
  83. const gl::shader_input* spot_light_positions;
  84. const gl::shader_input* spot_light_directions;
  85. const gl::shader_input* spot_light_attenuations;
  86. const gl::shader_input* spot_light_cutoffs;
  87. const gl::shader_input* shadow_map_directional;
  88. const gl::shader_input* shadow_splits_directional;
  89. const gl::shader_input* shadow_matrices_directional;
  90. const gl::shader_input* skinning_palette;
  91. };
  92. const parameter_set* load_parameter_set(const gl::shader_program* program) const;
  93. mutable std::unordered_map<const gl::shader_program*, parameter_set*> parameter_sets;
  94. const material* fallback_material;
  95. float2 mouse_position;
  96. int max_ambient_light_count;
  97. int max_point_light_count;
  98. int max_directional_light_count;
  99. int max_spot_light_count;
  100. int max_bone_count;
  101. mutable int ambient_light_count;
  102. mutable int point_light_count;
  103. mutable int directional_light_count;
  104. mutable int spot_light_count;
  105. float3* ambient_light_colors;
  106. float3* point_light_colors;
  107. float3* point_light_positions;
  108. float3* point_light_attenuations;
  109. float3* directional_light_colors;
  110. float3* directional_light_directions;
  111. const gl::texture_2d** directional_light_textures;
  112. float4x4* directional_light_texture_matrices;
  113. float* directional_light_texture_opacities;
  114. float3* spot_light_colors;
  115. float3* spot_light_positions;
  116. float3* spot_light_directions;
  117. float3* spot_light_attenuations;
  118. float2* spot_light_cutoffs;
  119. };
  120. } // namespace render
  121. #endif // ANTKEEPER_RENDER_MATERIAL_PASS_HPP