Expand description
HDR output helpers shared by guests (WGSL) and the host’s self-tests (Rust).
A game renders scene-linear BT.709 color in paper-white units (1.0 = the
brightness of SDR white, DEFAULT_PAPER_WHITE_NITS by default) and calls
sg_encode_output from WGSL as the last step of its final pass. That
function tone-maps to what the output can show and applies the output’s
encoding:
OutputMode | Surface format / color space | Encoding |
|---|---|---|
SdrSrgbFormat | *UnormSrgb / Srgb | roll-off to 1.0; the format applies the sRGB curve |
SdrUnorm | *Unorm / Srgb | roll-off to 1.0, sRGB curve in the shader |
ScRgb | Rgba16Float / ExtendedSrgbLinear | roll-off to peak, linear, 1.0 = 80 nits |
Pq | Rgb10a2Unorm or Rgba16Float / Bt2100Pq | roll-off to peak, BT.709→BT.2020, SMPTE ST 2084 |
negotiate picks the best mode from a surface’s format capabilities, and
falls back to SDR when no HDR color space is offered.
Structs§
- Output
- The negotiated output: what to put in
SurfaceConfigurationand the shader uniform.
Enums§
Constants§
- BT709_
TO_ BT2020 - BT.709 → BT.2020 primaries (ITU-R BT.2087), linear light.
- DEFAULT_
PAPER_ WHITE_ NITS - BT.2408 reference white for HDR signals.
- DEFAULT_
PEAK_ NITS - Peak assumed when the platform does not report one (Vulkan on Linux never does).
- KNEE
- Where the highlight roll-off starts, as a fraction of the peak.
- SCRGB_
NITS - scRGB 1.0 is 80 nits (IEC 61966-2-2).
- SDR_
KNEE - SDR: identity up to 0.8, then a roll-off towards 1.0 (paper white lands at 0.93).
- WGSL
- WGSL for guests: paste (or
concat!) into a shader module and bind anSgOutputuniform built byOutput::uniform.
Functions§
- bt709_
to_ bt2020 - encode_
output - What
sg_encode_outputwrites for scene-linear BT.709rgbin paper-white units. - negotiate
- Picks the output for a surface offering
formats(format, color spaces), in order of preference: PQ on a 10-bit format, scRGB, PQ on fp16, then SDR (an*Srgbformat first).allow_hdr = falseforces SDR. ReturnsNoneonly if no format is usable at all. - pq_eotf
- SMPTE ST 2084 EOTF: signal → absolute nits.
- pq_oetf
- SMPTE ST 2084 inverse EOTF: absolute nits → signal in [0, 1].
- rolloff
- Identity below
knee, then an exponential shoulder that approachespeakwith a continuous first derivative. - srgb_
eotf - srgb_
oetf - tonemap
- Tone-maps on max(R,G,B) so hue is kept.