diff options
Diffstat (limited to 'runtime/src/present_compose.comp')
| -rw-r--r-- | runtime/src/present_compose.comp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/runtime/src/present_compose.comp b/runtime/src/present_compose.comp index 4592daf70..ff3b0a0c0 100644 --- a/runtime/src/present_compose.comp +++ b/runtime/src/present_compose.comp | |||
| @@ -12,8 +12,8 @@ | |||
| 12 | // it is weighted (SDR: the EOTF, 1.0 = SDR white, Rec.709; HDR10: PQ to nits, Rec.2020). The filtered plane is converted to | 12 | // it is weighted (SDR: the EOTF, 1.0 = SDR white, Rec.709; HDR10: PQ to nits, Rec.2020). The filtered plane is converted to |
| 13 | // the working space of the output (HDR10 output: linear Rec.2020 nits, SDR white = sdr_white nits; SDR output: linear | 13 | // the working space of the output (HDR10 output: linear Rec.2020 nits, SDR white = sdr_white nits; SDR output: linear |
| 14 | // Rec.709, 1.0 = SDR white), plane 1 is blended over plane 0 there, and the sum is encoded once (PQ, or the inverse of | 14 | // Rec.709, 1.0 = SDR white), plane 1 is blended over plane 0 there, and the sum is encoded once (PQ, or the inverse of |
| 15 | // the SDR EOTF). HDR10 plane -> SDR output: extended Reinhard on luminance with the white point at hdr_peak nits, then | 15 | // the SDR EOTF). HDR10 plane -> SDR output: a luminance shoulder (identity below 0.8 of SDR white, extended Reinhard above, peak at |
| 16 | // clipped per channel (no gamut mapping). | 16 | // hdr_peak nits mapped to 1.0), then clipped per channel (no gamut mapping). |
| 17 | #version 450 | 17 | #version 450 |
| 18 | #extension GL_EXT_samplerless_texture_functions : require | 18 | #extension GL_EXT_samplerless_texture_functions : require |
| 19 | 19 | ||
| @@ -106,12 +106,18 @@ vec3 bt2020_to_bt709(vec3 v) { | |||
| 106 | dot(vec3(-0.018151, -0.100579, 1.118730), v)); | 106 | dot(vec3(-0.018151, -0.100579, 1.118730), v)); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | // Extended Reinhard on luminance (Reinhard et al. 2002, eq. 4): Ld = L (1 + L / Lw^2) / (1 + L), colour scaled by Ld / L. | 109 | // Tone map: a shoulder on luminance. Identity up to the knee (0.8 of SDR white), then extended Reinhard (Reinhard et al. |
| 110 | // `v`: linear Rec.709, 1.0 = SDR white; Lw = hdr_peak / sdr_white maps to 1.0. | 110 | // 2002, eq. 4) on the excess, scaled to be continuous in value and slope at the knee and to map the content peak to 1.0: |
| 111 | // with t = 1 - knee, u = (Y - knee) / t, w = (Lw - knee) / t: Yd = knee + t u (1 + u / w^2) / (1 + u). The colour is scaled | ||
| 112 | // by Yd / Y. `v`: linear Rec.709, 1.0 = SDR white; Lw = hdr_peak / sdr_white (at least 1). | ||
| 111 | vec3 tone_map(vec3 v) { | 113 | vec3 tone_map(vec3 v) { |
| 112 | float lw = max(pc.hdr_peak / pc.sdr_white, 1.0); | 114 | const float knee = 0.8; |
| 113 | float y = dot(v, vec3(0.2126, 0.7152, 0.0722)); | 115 | float y = dot(v, vec3(0.2126, 0.7152, 0.0722)); |
| 114 | return v * ((1.0 + y / (lw * lw)) / (1.0 + y)); | 116 | if (y <= knee) return v; |
| 117 | float t = 1.0 - knee; | ||
| 118 | float w = (max(pc.hdr_peak / pc.sdr_white, 1.0) - knee) / t; | ||
| 119 | float u = (y - knee) / t; | ||
| 120 | return v * ((knee + t * u * (1.0 + u / (w * w)) / (1.0 + u)) / y); | ||
| 115 | } | 121 | } |
| 116 | 122 | ||
| 117 | // A linear premultiplied colour of alpha `a` from the plane's space to the output's working space. Both conversions are | 123 | // A linear premultiplied colour of alpha `a` from the plane's space to the output's working space. Both conversions are |