Toast Engine
Loading...
Searching...
No Matches
bloom_pass.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
10#include "../shader_layout.hpp"
11#include "../vulkan_common.hpp"
12#include "../vulkan_pipeline.hpp"
13
14#include <glm/glm.hpp>
15#include <optional>
16#include <vector>
17
18namespace renderer {
19class VulkanCore;
20
21class BloomPass : public IPostProcessPass {
22public:
23 BloomPass(const VulkanCore& core, vk::Format hdr_format, vk::Extent2D extent);
24
25 [[nodiscard]]
26 auto name() const -> std::string_view override {
27 return "Bloom";
28 }
29
30 auto record(vk::CommandBuffer cmd, uint32_t frame_index, vk::ImageView source_view) -> vk::ImageView override;
31
32 void onResize(vk::Extent2D extent) override;
33
34private:
36 struct Params {
37 glm::vec2 inverse_source_size {0.0f};
38 float threshold = 1.0f;
39 float knee = 0.5f;
40 float filter_radius = 1.0f;
41 float strength = 0.05f;
42 glm::vec2 pad0 {0.0f};
43 };
44
45 struct Mip {
46 std::optional<vma::raii::Image> image;
47 std::optional<vk::raii::ImageView> view;
48 vk::Extent2D extent;
49 sync::ImageState state;
50 };
51
52 void createTargets(const VulkanCore& core, vk::Extent2D extent);
53 void createPipelines(const VulkanCore& core);
54
55 void writeDescriptor(vk::DescriptorSet set, vk::ImageView source, vk::ImageView scene);
56
57 void drawInto(
58 vk::CommandBuffer cmd, const VulkanPipeline& pipeline, vk::DescriptorSet set, const Mip& target, const Params& params,
59 bool additive
60 );
61
62 const VulkanCore* m_core = nullptr;
63 vk::Format m_format = vk::Format::eUndefined;
64
65 ShaderLayout m_shader_layout;
66 VulkanPipeline m_downsample_first_pipeline;
67 VulkanPipeline m_downsample_pipeline;
68 VulkanPipeline m_upsample_pipeline;
69 VulkanPipeline m_composite_pipeline;
70
71 vk::raii::Sampler m_sampler = nullptr;
72
73 std::vector<Mip> m_mips;
74
75 Mip m_composite;
76
78 struct FrameSets {
79 std::vector<vk::raii::DescriptorSet> downsample;
80 std::vector<vk::raii::DescriptorSet> upsample;
81 vk::raii::DescriptorSet composite = nullptr;
82 vk::ImageView bound_source = nullptr;
83 };
84
85 std::vector<FrameSets> m_frame_sets;
86};
87
88}
auto record(vk::CommandBuffer cmd, uint32_t frame_index, vk::ImageView source_view) -> vk::ImageView override
Definition bloom_pass.cpp:215
Definition post_process_pass_base.hpp:14
Definition shader_layout.hpp:12
Definition vulkan_core.hpp:48
Definition vulkan_pipeline.hpp:19
Owned next to the image it describes.
Definition gpu_sync.hpp:74