vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::Exposure Namespace Reference

How auto-exposure (RenderSettings::autoExposure) measures a frame and adapts to it. More...

Classes

class  Adaptation
 The adapted stops across frames: a backend feeds it each histogram it reads back. More...

Functions

constexpr int binOf (float log2Luminance)
 The bin a pixel of log2 luminance log2Luminance counts in.
constexpr float binCentre (int bin)
 The log2 luminance at the middle of bin, one past the first.
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.
float adaptStops (float current, float target, float seconds, const RenderSettings &settings)
 current moved toward target over seconds, as an eye adapts.

Variables

constexpr int BINS = 128
 Histogram bins, laid out by binOf (which a backend's counting mirrors).
constexpr float MIN_LOG = -14.0f
 log2 luminance at the floor of the second bin, and at the ceiling of the last.
constexpr float BIN_STEP = (MAX_LOG - MIN_LOG) / (BINS - 1)
 The log2 luminance one bin spans.
constexpr int STRIDE = 2
 A backend counts a pixel every STRIDE each way.
constexpr float LOW_SHARE = 0.4f
 The darkest share of what is lit, left out of the average: shade does not set the exposure.
constexpr float HIGH_SHARE = 0.95f
 The share past which the brightest is left out: the sun and its glints do not either.
constexpr float KEY = 0.09f
 Where the average lands before RenderSettings::exposure is added.

Detailed Description

How auto-exposure (RenderSettings::autoExposure) measures a frame and adapts to it.

A backend counts the frame's pixels into a histogram of log2 luminance and hands the counts here; everything after the counting is decided here, so every backend adapts alike.

Function Documentation

◆ targetStops()

std::optional< float > Vkm::Engine::Exposure::targetStops ( const uint32_t * bins,
const RenderSettings & settings )

The stops that bring a histogram's average to KEY, within the settings' range.

The average is of log2 luminance, over what lies between LOW_SHARE and HIGH_SHARE of the lit pixels (every bin but the first).

Parameters
binsBINS counts.
settingsSupplies exposureMinimum and exposureMaximum.
Returns
The stops, or none for a frame with nothing lit.

◆ adaptStops()

float Vkm::Engine::Exposure::adaptStops ( float current,
float target,
float seconds,
const RenderSettings & settings )

current moved toward target over seconds, as an eye adapts.

Closes the share 1 - e^(-rate * seconds) of the gap: at adaptDarker toward fewer stops, at adaptBrighter toward more.

Parameters
currentThe stops the last frame was exposed by.
targetWhat the newest histogram asks for (targetStops).
secondsWall-clock time since the last frame.
settingsSupplies the rates.

Variable Documentation

◆ BINS

int Vkm::Engine::Exposure::BINS = 128
constexpr

Histogram bins, laid out by binOf (which a backend's counting mirrors).

The first counts what is darker than MIN_LOG, which no exposure is set by; the rest split MIN_LOG..MAX_LOG evenly in log2, the last also counting what is brighter.