Unravel Engine C++ Reference
Loading...
Searching...
No Matches
auto_exposure_pass.h
Go to the documentation of this file.
1#pragma once
2
5#include <bgfx/bgfx.h>
6#include <cstdint>
7
8namespace unravel
9{
10
12enum class exposure_metering_mode : std::uint8_t
13{
15 average = 0,
19 spot = 2,
20};
21
23{
24public:
25 auto_exposure_pass() = default;
27 {
28 shutdown();
29 }
30 struct settings
31 {
35 float min_ev = -4.0f;
42 float max_ev = 0.0f;
44 float compensation = 0.0f;
47 float adaptation_speed_up = 3.0f;
51 float low_percentile = 0.50f;
53 float high_percentile = 0.95f;
58 float metering_area = 0.7f;
59 };
60
67
68 auto init(rtti::context& ctx) -> bool;
69 auto shutdown() -> int32_t;
71 void run(gfx::render_view& rview, const run_params& params);
72
76
78
79private:
80 static constexpr float min_log_lum = -10.0f;
81 static constexpr float max_log_lum = 20.0f;
82 static constexpr int histogram_bins = 256;
86 static constexpr std::uint32_t max_metering_dim = 512;
87
88 void ensure_resources(gfx::render_view& rview);
89 void run_histogram(gfx::render_view& rview, const settings& config, const gfx::frame_buffer::ptr& input);
90 void run_average(gfx::render_view& rview, const settings& config, float dt);
91
92 struct histogram_program : uniforms_cache
93 {
94 gpu_program::ptr program;
95 gfx::program::uniform_ptr s_hdr_input;
96 gfx::program::uniform_ptr u_histogram_params;
97 gfx::program::uniform_ptr u_metering_params;
98
99 void cache_uniforms()
100 {
101 cache_uniform(program.get(), s_hdr_input, "s_hdr_input", gfx::uniform_type::Sampler);
102 cache_uniform(program.get(), u_histogram_params, "u_histogram_params", gfx::uniform_type::Vec4);
103 cache_uniform(program.get(), u_metering_params, "u_metering_params", gfx::uniform_type::Vec4);
104 }
105 } histogram_program_;
106
107 struct average_program : uniforms_cache
108 {
109 gpu_program::ptr program;
110 gfx::program::uniform_ptr u_average_params0;
111 gfx::program::uniform_ptr u_average_params1;
112 gfx::program::uniform_ptr u_average_params2;
113
114 void cache_uniforms()
115 {
116 cache_uniform(program.get(), u_average_params0, "u_average_params0", gfx::uniform_type::Vec4);
117 cache_uniform(program.get(), u_average_params1, "u_average_params1", gfx::uniform_type::Vec4);
118 cache_uniform(program.get(), u_average_params2, "u_average_params2", gfx::uniform_type::Vec4);
119 }
120 } average_program_;
121
122 bgfx::DynamicIndexBufferHandle histogram_buffer_ = BGFX_INVALID_HANDLE;
123};
124
125} // namespace unravel
auto init(rtti::context &ctx) -> bool
void run(gfx::render_view &rview, const run_params &params)
Runs histogram + temporal average to produce a 1x1 adapted exposure texture.
void release_resources(gfx::render_view &rview)
auto get_exposure_texture(gfx::render_view &rview) const -> gfx::texture::ptr
std::shared_ptr< gpu_program > ptr
Definition gpu_program.h:19
exposure_metering_mode
Spatial weighting applied to pixels when building the luminance histogram.
@ center_weighted
Smooth radial falloff toward the screen edges (Gaussian). Default.
std::shared_ptr< uniform > uniform_ptr
Definition program.h:19
float high_percentile
Upper fraction kept before excluding the brightest (weighted) pixels.
float low_percentile
Fraction of the darkest (weighted) pixels excluded from the average.
exposure_metering_mode metering_mode
How pixels are spatially weighted when metering scene luminance.
float adaptation_speed_down
Time constant in seconds for the exposure to DECREASE (scene getting brighter).
float compensation
Exposure bias in EV stops applied on top of the metered result (+1 = 2x brighter).
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.