Skip to content

Class ExposureMath

Namespace: Apogee.Rendering
Assembly: Apogee.Rendering.dll

The photographic exposure maths of the renderer, on the CPU: the twin of exposure.slang and of the exposure functions in common.slang, which the tests compare it with.

Scene light is photometric: the forward pass writes luminance in cd/m2 (a sun of E lux on a white diffuse surface gives E / pi cd/m2). The camera's exposure is an EV100, the exposure value at ISO 100: EV100 = log2(N^2 / t) - log2(S / 100) for an aperture f/N, a shutter time t in seconds and a sensitivity S. The forward pass multiplies its result by , the saturation-based exposure of a camera at that EV100, so the HDR image holds exposed values: 1.0 is the luminance that just saturates the sensor, 1.2 * 2^EV100 cd/m2, and a fp16 image cannot overflow with a bright sun.

public static class ExposureMath

Inheritance

object ← ExposureMath

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Fields

DefaultMaxLog2Luminance

The highest luminance the histogram measures, as log2 cd/m2 (about 260 000 cd/m2, the sun's glare off a mirror).

public const float DefaultMaxLog2Luminance = 18

Field Value

float

DefaultMinLog2Luminance

The lowest luminance the histogram measures, as log2 cd/m2 (about 0.001 cd/m2, a moonless night).

public const float DefaultMinLog2Luminance = -10

Field Value

float

HistogramBins

The number of bins of the luminance histogram. Bin 0 counts the pixels that are not measured (black, below the range, NaN or infinite); bins 1 to 254 divide the log2-luminance range evenly, and bin 255 holds what is at or above the top of the range.

public const int HistogramBins = 256

Field Value

int

MeterCalibration

The reflected-light meter's calibration constant K: a gray of average luminance L is exposed correctly at EV100 = log2(L * 100 / K).

public const float MeterCalibration = 12.5

Field Value

float

SaturationFactor

The factor of the saturation-based exposure, 78 / (S * q) with q = 0.65 and S = 100: the luminance that saturates the sensor is this times 2^EV100 cd/m2.

public const float SaturationFactor = 1.2

Field Value

float

Methods

Adapt(float, float, float, float, float)

Moves current towards target over deltaSeconds: exponentially, so a frame rate does not change how fast the eye adapts. speedBright (per second) applies when the scene got brighter (the EV rises), speedDark when it got darker; the eye adapts to light faster than to dark.

public static float Adapt(float current, float target, float deltaSeconds, float speedBright, float speedDark)

Parameters

current float

target float

deltaSeconds float

speedBright float

speedDark float

Returns

float

AverageLog2Luminance(ReadOnlySpan<uint>, float, float, float, float)

The average log2 luminance of the pixels in a histogram, leaving out the darkest lowPercentile and the brightest 1 - highPercentile of the measured ones (a few very bright lamps or a dark corner should not set the exposure), and the unmeasurable ones in bin 0. An empty histogram gives minLog2.

public static float AverageLog2Luminance(ReadOnlySpan<uint> bins, float minLog2, float maxLog2, float lowPercentile = 0.1, float highPercentile = 0.9)

Parameters

bins ReadOnlySpan<uint>

minLog2 float

maxLog2 float

lowPercentile float

highPercentile float

Returns

float

BinLog2Luminance(int, float, float)

The log2 luminance at the center of a histogram bin (1 to 254; bin 255 holds everything from the top of the range up, and its "center" is just past it).

public static float BinLog2Luminance(int bin, float minLog2, float maxLog2)

Parameters

bin int

minLog2 float

maxLog2 float

Returns

float

Ev100(float, float, float)

The EV100 of a camera with the f-number aperture, a shutter open for shutterSeconds and the sensitivity iso.

public static float Ev100(float aperture, float shutterSeconds, float iso)

Parameters

aperture float

shutterSeconds float

iso float

Returns

float

Ev100FromLuminance(float)

The EV100 that exposes a scene of average luminance luminance (cd/m2) as a mid-gray.

public static float Ev100FromLuminance(float luminance)

Parameters

luminance float

Returns

float

HistogramBin(float, float, float)

The histogram bin of a luminance (cd/m2): 0 for black, below the range, NaN or infinite; otherwise 1 to 254 along the log2 range from minLog2 to maxLog2, and 255 at or above maxLog2.

public static int HistogramBin(float luminance, float minLog2, float maxLog2)

Parameters

luminance float

minLog2 float

maxLog2 float

Returns

int

Luminance(float, float, float)

The luminance of a linear Rec.709 color, in the units of the color.

public static float Luminance(float r, float g, float b)

Parameters

r float

g float

b float

Returns

float

LuminanceFromEv100(float)

The average luminance (cd/m2) that is exposed as a mid-gray at ev100; the inverse of .

public static float LuminanceFromEv100(float ev100)

Parameters

ev100 float

Returns

float

Scale(float)

The factor the scene's luminance is multiplied by at ev100: 1 / (1.2 * 2^EV100). The result is 1.0 for a luminance that saturates the sensor.

public static float Scale(float ev100)

Parameters

ev100 float

Returns

float

TargetEv100(float, float, float)

The EV100 the auto-exposure aims for in a scene of average log2 luminance averageLog2, kept between minEv100 and maxEv100.

public static float TargetEv100(float averageLog2, float minEv100, float maxEv100)

Parameters

averageLog2 float

minEv100 float

maxEv100 float

Returns

float