vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
exposure.h
1#pragma once
2
3#include <cstdint>
4#include <optional>
5
6namespace Vkm::Engine {
7
8struct RenderSettings;
9
16namespace Exposure {
17
24constexpr int BINS = 128;
26constexpr float MIN_LOG = -14.0f;
27constexpr float MAX_LOG = 10.0f;
29constexpr float BIN_STEP = (MAX_LOG - MIN_LOG) / (BINS - 1);
31constexpr int STRIDE = 2;
32
34constexpr int binOf(float log2Luminance) {
35 if (!(log2Luminance > MIN_LOG)) return 0;
36 if (!(log2Luminance < MAX_LOG)) return BINS - 1;
37 const int bin = 1 + static_cast<int>((log2Luminance - MIN_LOG) / BIN_STEP);
38 return bin < BINS - 1 ? bin : BINS - 1;
39}
40
42constexpr float binCentre(int bin) {
43 return MIN_LOG + (static_cast<float>(bin) - 0.5f) * BIN_STEP;
44}
45
47constexpr float LOW_SHARE = 0.4f;
49constexpr float HIGH_SHARE = 0.95f;
50
52constexpr float KEY = 0.09f;
53
64std::optional<float> targetStops(const uint32_t* bins, const RenderSettings& settings);
65
77float adaptStops(float current, float target, float seconds, const RenderSettings& settings);
78
85class Adaptation {
86 public:
87 Adaptation() = default;
88 ~Adaptation() = default;
89
90 Adaptation(const Adaptation& other) = default;
91 Adaptation& operator=(const Adaptation& other) = default;
92
93 Adaptation(Adaptation && other) = default;
94 Adaptation& operator=(Adaptation && other) = default;
95
96 public:
106 float update(const uint32_t* newest, float seconds, const RenderSettings& settings);
107
109 void forget() { m_snap = true; }
110
111 private:
112 float m_target = 0.0f;
113 float m_stops = 0.0f;
114 bool m_adapted = false;
115 bool m_snap = true;
116};
117
118} // namespace Exposure
119
120} // namespace Vkm::Engine
float update(const uint32_t *newest, float seconds, const RenderSettings &settings)
The stops this frame is exposed by, RenderSettings::exposure included.
void forget()
Take the next read whole, as for a replaced world; the stops hold until it comes.
Definition exposure.h:109
How auto-exposure (RenderSettings::autoExposure) measures a frame and adapts to it.
Definition exposure.h:16
constexpr int binOf(float log2Luminance)
The bin a pixel of log2 luminance log2Luminance counts in.
Definition exposure.h:34
constexpr float HIGH_SHARE
The share past which the brightest is left out: the sun and its glints do not either.
Definition exposure.h:49
constexpr float binCentre(int bin)
The log2 luminance at the middle of bin, one past the first.
Definition exposure.h:42
constexpr int STRIDE
A backend counts a pixel every STRIDE each way.
Definition exposure.h:31
std::optional< float > targetStops(const uint32_t *bins, const RenderSettings &settings)
The stops that bring a histogram's average to KEY, within the settings' range.
constexpr float BIN_STEP
The log2 luminance one bin spans.
Definition exposure.h:29
constexpr float KEY
Where the average lands before RenderSettings::exposure is added.
Definition exposure.h:52
constexpr int BINS
Histogram bins, laid out by binOf (which a backend's counting mirrors).
Definition exposure.h:24
constexpr float LOW_SHARE
The darkest share of what is lit, left out of the average: shade does not set the exposure.
Definition exposure.h:47
float adaptStops(float current, float target, float seconds, const RenderSettings &settings)
current moved toward target over seconds, as an eye adapts.
constexpr float MIN_LOG
log2 luminance at the floor of the second bin, and at the ceiling of the last.
Definition exposure.h:26
Editable render tuning: pass toggles + per-effect parameters.
Definition render_settings.h:101