Unravel Engine C++ Reference
Loading...
Searching...
No Matches
bloom_pass.h
Go to the documentation of this file.
1#pragma once
2
6#include <math/color.h>
7
8namespace unravel
9{
10
12{
13public:
14 struct settings
15 {
16 float threshold = 5.0f;
17 float soft_knee = 0.5f;
18 float clamp = 100.0f;
19 float intensity = 1.0f;
20 int mip_count = 8;
21
22 // Per-mip tint (RGB) and weight (alpha). Applied during upsample cascade.
23 // Tint controls color, alpha controls contribution weight (0 = disabled, 1 = full).
24 math::color mip0_tint{1.0f, 1.0f, 1.0f, 1.0f}; // 1/2 res - tightest halo
25 math::color mip1_tint{1.0f, 1.0f, 1.0f, 1.0f}; // 1/4 res
26 math::color mip2_tint{1.0f, 1.0f, 1.0f, 1.0f}; // 1/8 res
27 math::color mip3_tint{1.0f, 1.0f, 1.0f, 1.0f}; // 1/16 res
28 math::color mip4_tint{1.0f, 1.0f, 1.0f, 1.0f}; // 1/32 res
29 math::color mip5_tint{1.0f, 1.0f, 1.0f, 1.0f}; // 1/64 res - widest bloom
30
31 float dirt_intensity = 0.0f;
32
33 auto get_mip_tint(int idx) const -> const math::color&
34 {
35 switch(idx)
36 {
37 case 0: return mip0_tint;
38 case 1: return mip1_tint;
39 case 2: return mip2_tint;
40 case 3: return mip3_tint;
41 case 4: return mip4_tint;
42 case 5: return mip5_tint;
43 default:
44 {
45 static const math::color default_tint(1.0f, 1.0f, 1.0f, 1.0f);
46 return default_tint;
47 }
48 }
49 }
50 };
51
59
60 auto init(rtti::context& ctx) -> bool;
61 auto run(gfx::render_view& rview, const run_params& params) -> gfx::frame_buffer::ptr;
63
64private:
65 static constexpr int max_mip_count = 10;
66
67 auto create_or_resize_mip_chain(gfx::render_view& rview,
68 const usize32_t& viewport_size,
69 int mip_count) -> void;
70 auto get_mip_fbo(gfx::render_view& rview, int mip_index) -> const gfx::frame_buffer::ptr&;
71 auto create_or_update_output_fb(gfx::render_view& rview,
74
75 struct downsample_program : uniforms_cache
76 {
77 void cache_uniforms()
78 {
79 cache_uniform(program.get(), u_pixel_size, "u_pixelSize", gfx::uniform_type::Vec4);
80 cache_uniform(program.get(), u_params, "u_params", gfx::uniform_type::Vec4);
81 cache_uniform(program.get(), s_tex, "s_tex", gfx::uniform_type::Sampler);
82 cache_uniform(program.get(), s_exposure, "s_exposure", gfx::uniform_type::Sampler);
83 }
84 gfx::program::uniform_ptr u_pixel_size;
88 std::unique_ptr<gpu_program> program;
89 } downsample_program_;
90
91 struct upsample_program : uniforms_cache
92 {
93 void cache_uniforms()
94 {
95 cache_uniform(program.get(), u_pixel_size, "u_pixelSize", gfx::uniform_type::Vec4);
96 cache_uniform(program.get(), u_tint, "u_tint", gfx::uniform_type::Vec4);
97 cache_uniform(program.get(), s_tex, "s_tex", gfx::uniform_type::Sampler);
98 }
99 gfx::program::uniform_ptr u_pixel_size;
102 std::unique_ptr<gpu_program> program;
103 } upsample_program_;
104
105 struct combine_program : uniforms_cache
106 {
107 void cache_uniforms()
108 {
109 cache_uniform(program.get(), s_scene, "s_scene", gfx::uniform_type::Sampler);
110 cache_uniform(program.get(), s_bloom, "s_bloom", gfx::uniform_type::Sampler);
111 }
114 std::unique_ptr<gpu_program> program;
115 } combine_program_;
116};
117
118} // namespace unravel
auto run(gfx::render_view &rview, const run_params &params) -> gfx::frame_buffer::ptr
auto init(rtti::context &ctx) -> bool
void release_resources(gfx::render_view &rview)
std::shared_ptr< uniform > uniform_ptr
Definition program.h:19
gfx::frame_buffer::ptr input
Definition bloom_pass.h:54
gfx::frame_buffer::ptr output
Definition bloom_pass.h:55
gfx::texture::ptr exposure_texture
Definition bloom_pass.h:57
auto get_mip_tint(int idx) const -> const math::color &
Definition bloom_pass.h:33
Structure for caching uniforms.
void cache_uniform(gpu_program *program, gfx::program::uniform_ptr &uniform, const hpp::string_view &name, gfx::uniform_type type, uint16_t num=1)
Caches a uniform in the GPU program.