Antkeeper  0.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bloom-pass.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_BLOOM_PASS_HPP
21 #define ANTKEEPER_RENDER_BLOOM_PASS_HPP
22 
23 #include <engine/render/pass.hpp>
29 #include <engine/gl/texture.hpp>
30 #include <engine/gl/sampler.hpp>
31 #include <memory>
32 #include <functional>
33 
34 class resource_manager;
35 
36 namespace render {
37 
44 class bloom_pass: public pass
45 {
46 public:
54 
61  void render(render::context& ctx) override;
62 
66  void resize();
67 
73  void set_source_texture(std::shared_ptr<gl::texture_2d> texture);
74 
80  void set_mip_chain_length(unsigned int length);
81 
87  void set_filter_radius(float radius);
88 
92  [[nodiscard]] inline std::shared_ptr<gl::texture_2d> get_bloom_texture() const
93  {
94  return m_target_textures.empty() ? nullptr : m_target_textures.front();
95  }
96 
97 private:
98  void rebuild_mip_chain();
99  void correct_filter_radius();
100  void rebuild_command_buffer();
101 
102  std::shared_ptr<gl::texture_2d> m_source_texture;
103  std::shared_ptr<gl::image_2d> m_target_image;
104  std::vector<std::shared_ptr<gl::texture_2d>> m_target_textures;
105  std::vector<std::shared_ptr<gl::framebuffer>> m_target_framebuffers;
106 
107  std::unique_ptr<gl::shader_program> m_downsample_karis_shader;
108  std::unique_ptr<gl::shader_program> m_downsample_shader;
109  std::unique_ptr<gl::shader_program> m_upsample_shader;
110 
111  std::shared_ptr<gl::sampler> m_sampler;
112  std::unique_ptr<gl::vertex_array> m_vertex_array;
113  unsigned int m_mip_chain_length{0};
114  float m_filter_radius{0.005f};
115  math::fvec2 m_corrected_filter_radius{0.005f, 0.005f};
116 
117  std::vector<std::function<void()>> m_command_buffer;
118 };
119 
120 } // namespace render
121 
122 #endif // ANTKEEPER_RENDER_BLOOM_PASS_HPP
Graphics pipeline interface.
Definition: pipeline.hpp:48
Physically-based bloom render pass.
Definition: bloom-pass.hpp:45
void set_mip_chain_length(unsigned int length)
Sets the mip chain length.
Definition: bloom-pass.cpp:94
void resize()
Resizes the mip chain resolution according to the resolution of the source texture.
void set_filter_radius(float radius)
Sets the upsample filter radius.
Definition: bloom-pass.cpp:101
void render(render::context &ctx) override
Renders a bloom texture.
Definition: bloom-pass.cpp:73
void set_source_texture(std::shared_ptr< gl::texture_2d > texture)
Sets the bloom source texture.
Definition: bloom-pass.cpp:82
std::shared_ptr< gl::texture_2d > get_bloom_texture() const
Returns the texture containing the bloom result.
Definition: bloom-pass.hpp:92
bloom_pass(gl::pipeline *pipeline, resource_manager *resource_manager)
Constructs a bloom pass.
Definition: bloom-pass.cpp:36
Render pass.
Definition: pass.hpp:34
Manages the loading, caching, and saving of resources.
T length(const quaternion< T > &q)
Calculates the length of a quaternion.
Definition: quaternion.hpp:602
High-level rendering.
n-dimensional vector.
Definition: vector.hpp:44
Context of a renderer.
Definition: context.hpp:40