Antkeeper  0.0.1
light-probe-stage.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 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 
20 #ifndef ANTKEEPER_RENDER_LIGHT_PROBE_STAGE_HPP
21 #define ANTKEEPER_RENDER_LIGHT_PROBE_STAGE_HPP
22 
23 #include <engine/render/stage.hpp>
27 #include <engine/gl/pipeline.hpp>
31 #include <functional>
32 #include <memory>
33 #include <vector>
34 
35 namespace render {
36 
40 class light_probe_stage: public stage
41 {
42 public:
57 
58  void execute(render::context& ctx) override;
59 
71  void set_sh_sample_count(std::size_t count);
72 
78  void set_cubemap_filter_sample_count(std::size_t count);
79 
90  void set_cubemap_filter_mip_bias(float bias);
91 
93  [[nodiscard]] inline std::size_t get_sh_sample_count() const noexcept
94  {
95  return m_sh_sample_count;
96  }
97 
99  [[nodiscard]] inline std::size_t get_cubemap_filter_sample_count() const noexcept
100  {
101  return m_cubemap_filter_sample_count;
102  }
103 
104 private:
105  void rebuild_cubemap_to_sh_shader_program();
106  void rebuild_cubemap_downsample_shader_program();
107  void rebuild_cubemap_filter_lut_shader_program();
108  void rebuild_cubemap_filter_lut_texture();
109  void rebuild_cubemap_filter_shader_program();
110  void sh_parameters_changed();
111  void cubemap_filter_parameters_changed();
112 
113  void update_light_probes_luminance(const std::vector<scene::object_base*>& light_probes);
114  void update_light_probes_illuminance(const std::vector<scene::object_base*>& light_probes);
115 
116  gl::pipeline* m_pipeline;
117 
118  std::vector<std::shared_ptr<gl::sampler>> m_downsample_samplers;
119  std::vector<std::shared_ptr<gl::sampler>> m_filter_samplers;
120  std::unique_ptr<gl::vertex_array> m_vertex_array;
121 
122  std::shared_ptr<gl::shader_template> m_cubemap_to_sh_shader_template;
123  std::unique_ptr<gl::shader_program> m_cubemap_to_sh_shader_program;
124  const gl::shader_variable* m_cubemap_to_sh_cubemap_var{};
125  std::size_t m_sh_sample_count{512};
126  bool m_reproject_sh{true};
127 
128  std::shared_ptr<gl::shader_template> m_cubemap_downsample_shader_template;
129  std::unique_ptr<gl::shader_program> m_cubemap_downsample_shader_program;
130 
131  const gl::shader_variable* m_cubemap_downsample_cubemap_var{};
132  std::vector<std::unique_ptr<gl::framebuffer>> m_cubemap_downsample_framebuffers;
133  std::unique_ptr<gl::texture_cube> m_cubemap_downsample_texture;
134 
135  std::shared_ptr<gl::texture_2d> m_cubemap_filter_lut_texture;
136  std::unique_ptr<gl::framebuffer> m_cubemap_filter_lut_framebuffer;
137  std::shared_ptr<gl::shader_template> m_cubemap_filter_lut_shader_template;
138  std::unique_ptr<gl::shader_program> m_cubemap_filter_lut_shader_program;
139  const gl::shader_variable* m_cubemap_filter_lut_resolution_var{};
140  const gl::shader_variable* m_cubemap_filter_lut_face_size_var{};
141  const gl::shader_variable* m_cubemap_filter_lut_mip_bias_var{};
142 
143  std::shared_ptr<gl::shader_template> m_cubemap_filter_shader_template;
144  std::unique_ptr<gl::shader_program> m_cubemap_filter_shader_program;
145  const gl::shader_variable* m_cubemap_filter_cubemap_var{};
146  const gl::shader_variable* m_cubemap_filter_filter_lut_var{};
147  const gl::shader_variable* m_cubemap_filter_mip_level_var{};
148 
149  std::size_t m_cubemap_filter_sample_count{32};
150  std::size_t m_cubemap_filter_mip_count{5};
151  float m_cubemap_filter_mip_bias{1.0f};
152  bool m_refilter_cubemaps{true};
153 };
154 
155 } // namespace render
156 
157 #endif // ANTKEEPER_RENDER_LIGHT_PROBE_STAGE_HPP
Graphics pipeline interface.
Definition: pipeline.hpp:48
Shader program variable.
Updates light probes.
void execute(render::context &ctx) override
Executes the render stage.
std::size_t get_cubemap_filter_sample_count() const noexcept
Returns the number of samples used when filtering luminance cubemaps.
void set_cubemap_filter_sample_count(std::size_t count)
Sets the number of samples to use when filtering luminance cubemap mip chains.
void set_cubemap_filter_mip_bias(float bias)
Sets the mip bias to use when filtering luminance cubemap mip chains.
void set_sh_sample_count(std::size_t count)
Sets the number of samples to use when projecting luminance cubemaps into spherical harmonics.
std::size_t get_sh_sample_count() const noexcept
Returns the number of samples used when projecting luminance cubemaps into spherical harmonics.
light_probe_stage(gl::pipeline &pipeline, ::resource_manager &resource_manager)
Constructs a light probe stage.
Abstract base class for a single stage in a render pipeline.
Definition: stage.hpp:31
Manages the loading, caching, and saving of resources.
constexpr int count(T x) noexcept
Returns the number of set bits in a value, known as a population count or Hamming weight.
Definition: bit-math.hpp:211
High-level rendering.
Context of a renderer.
Definition: context.hpp:40