Skip to content

Struct Gt7ToneMapping

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

The Gran Turismo 7 tone mapping operator, on the CPU: the twin of the one in tonemap.slang, which the tests compare it with. It is a port of Polyphony Digital's sample implementation gt7_tone_mapping.cpp (version 1.0, MIT licence, Copyright (c) 2025 Polyphony Digital Inc.; the notice is in Legal/THIRD_PARTY_NOTICES.md).

The operator works on linear Rec.2020 colors in "frame-buffer" units, where 1.0 is (100) cd/m2. It tone-maps each channel with a curve (a toe, a linear section and an exponential shoulder that converges on the display's peak), then blends that with a version whose lightness comes from the curved color but whose chroma (in ICtCp) is kept and faded out near the peak, so bright colors desaturate towards white instead of changing hue. In SDR mode the peak is (250 cd/m2) and the result is scaled so that 1.0 is the display's white, ready for the sRGB transfer function.

public readonly struct Gt7ToneMapping

Inherited Members

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

Fields

ReferenceLuminance

The luminance in cd/m2 that a frame-buffer value of 1.0 stands for.

public const float ReferenceLuminance = 100

Field Value

float

SdrPaperWhite

The luminance of the SDR display's white, in cd/m2, that the curve's parameters were tuned for.

public const float SdrPaperWhite = 250

Field Value

float

SdrPaperWhiteFrameBuffer

The SDR paper white as a frame-buffer value (2.5): the scene value the renderer's exposure maps to the display's white.

public const float SdrPaperWhiteFrameBuffer = 2.5

Field Value

float

Methods

Apply(Vector3)

The tone-mapped color (frame-buffer units, linear Rec.2020) of a scene color in linear Rec.2020 frame-buffer units.

public Vector3 Apply(Vector3 rgb)

Parameters

rgb Vector3

Returns

Vector3

ChromaCurve(float, float, float)

1 below a, fading to 0 at b: how much of the input's chroma is kept.

public static float ChromaCurve(float x, float a, float b)

Parameters

x float

a float

b float

Returns

float

Curve(float)

The per-channel curve: a power-law toe into a linear section (blended by a smoothstep), then the shoulder.

public float Curve(float x)

Parameters

x float

Returns

float

Hdr(float)

The operator for an HDR display of peakNits cd/m2; the result is in frame-buffer units, up to the peak. The original supports 250 to 10 000 (its curve's parameters were tuned for an SDR paper white of 250), so the peak is clamped to that range.

public static Gt7ToneMapping Hdr(float peakNits)

Parameters

peakNits float

Returns

Gt7ToneMapping

ICtCpToRgb(float, float, float)

ICtCp to linear Rec.2020 (frame-buffer units), with negative channels clipped to 0.

public static Vector3 ICtCpToRgb(float i, float ct, float cp)

Parameters

i float

ct float

cp float

Returns

Vector3

LinearToPq(float)

A frame-buffer luminance value to its PQ code value (0..1).

public static float LinearToPq(float v)

Parameters

v float

Returns

float

PqToLinear(float)

PQ code value (0..1) to a frame-buffer luminance value.

public static float PqToLinear(float n)

Parameters

n float

Returns

float

Rec2020ToRec709(Vector3)

Linear Rec.2020 back to linear Rec.709. Colors outside the sRGB gamut come out with a negative channel; the caller clips.

public static Vector3 Rec2020ToRec709(Vector3 c)

Parameters

c Vector3

Returns

Vector3

Rec709ToRec2020(Vector3)

Linear Rec.709 (the renderer's working space, the sRGB primaries) to linear Rec.2020, where the operator works. White stays white.

public static Vector3 Rec709ToRec2020(Vector3 c)

Parameters

c Vector3

Returns

Vector3

RgbToICtCp(Vector3)

Linear Rec.2020 (frame-buffer units) to ICtCp, as (I, Ct, Cp): I is the lightness, Ct and Cp the chroma.

public static Vector3 RgbToICtCp(Vector3 rgb)

Parameters

rgb Vector3

Returns

Vector3

Sdr()

The operator for an SDR display: the curve peaks at 250 cd/m2 and the result is scaled to 0..1 for the sRGB transfer function.

public static Gt7ToneMapping Sdr()

Returns

Gt7ToneMapping

SmoothStep(float, float, float)

0 below edge0, 1 above edge1, a cubic smoothstep between (note the argument order of the original: the value comes first).

public static float SmoothStep(float x, float edge0, float edge1)

Parameters

x float

edge0 float

edge1 float

Returns

float

ToDisplay(Vector3)

The whole SDR path of the renderer's tone-mapping pass for one pixel, as bytes' source values: a color in the HDR image (linear Rec.709, exposed so that 1.0 is the exposure's saturation point) to the linear Rec.709 color that is encoded with the sRGB transfer function. Negative and NaN channels are taken as 0, and an infinity as 65 504 (the largest half float): an infinity would make NaN in the ICtCp conversion.

public static Vector3 ToDisplay(Vector3 exposed)

Parameters

exposed Vector3

Returns

Vector3