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

140 lines
4.6 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_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. class camera;
  29. class shader_program;
  30. class shader_input;
  31. class resource_manager;
  32. class texture_2d;
  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(::rasterizer* rasterizer, const ::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_shadow_strength(float strength);
  49. void set_focal_point_tween(const tween<float3>* focal_point);
  50. const ::shadow_map_pass* shadow_map_pass;
  51. const texture_2d* shadow_map;
  52. private:
  53. virtual void handle_event(const mouse_moved_event& event);
  54. /**
  55. * 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.
  56. */
  57. struct parameter_set
  58. {
  59. const shader_input* time;
  60. const shader_input* mouse;
  61. const shader_input* resolution;
  62. const shader_input* model;
  63. const shader_input* view;
  64. const shader_input* projection;
  65. const shader_input* model_view;
  66. const shader_input* view_projection;
  67. const shader_input* model_view_projection;
  68. const shader_input* normal_model_view;
  69. const shader_input* ambient_light_count;
  70. const shader_input* ambient_light_colors;
  71. const shader_input* point_light_count;
  72. const shader_input* point_light_colors;
  73. const shader_input* point_light_positions;
  74. const shader_input* point_light_attenuations;
  75. const shader_input* directional_light_count;
  76. const shader_input* directional_light_colors;
  77. const shader_input* directional_light_directions;
  78. const shader_input* spotlight_count;
  79. const shader_input* spotlight_colors;
  80. const shader_input* spotlight_positions;
  81. const shader_input* spotlight_directions;
  82. const shader_input* spotlight_attenuations;
  83. const shader_input* spotlight_cutoffs;
  84. const shader_input* soft_shadows;
  85. const shader_input* focal_point;
  86. const shader_input* shadow_map_matrices;
  87. const shader_input* shadow_map_split_distances;
  88. const shader_input* shadow_map;
  89. const shader_input* shadow_strength;
  90. };
  91. const parameter_set* load_parameter_set(const shader_program* program) const;
  92. mutable std::unordered_map<const shader_program*, parameter_set*> parameter_sets;
  93. const material* fallback_material;
  94. const tween<double>* time_tween;
  95. float2 mouse_position;
  96. const tween<float3>* focal_point_tween;
  97. texture_2d* soft_shadows_texture;
  98. float shadow_strength;
  99. int max_ambient_light_count;
  100. int max_point_light_count;
  101. int max_directional_light_count;
  102. int max_spotlight_count;
  103. mutable int ambient_light_count;
  104. mutable int point_light_count;
  105. mutable int directional_light_count;
  106. mutable int spotlight_count;
  107. float3* ambient_light_colors;
  108. float3* point_light_colors;
  109. float3* point_light_positions;
  110. float3* point_light_attenuations;
  111. float3* directional_light_colors;
  112. float3* directional_light_directions;
  113. float3* spotlight_colors;
  114. float3* spotlight_positions;
  115. float3* spotlight_directions;
  116. float3* spotlight_attenuations;
  117. float2* spotlight_cutoffs;
  118. };
  119. #endif // ANTKEEPER_MATERIAL_PASS_HPP