render: introduce bt.1886 transfer function

This commit is contained in:
llyyr 2025-10-04 14:48:42 +05:30
parent d8fb7adcf0
commit 6e1c8748ff
10 changed files with 52 additions and 0 deletions

View file

@ -23,6 +23,7 @@ layout (constant_id = 0) const int OUTPUT_TRANSFORM = 0;
#define OUTPUT_TRANSFORM_INVERSE_ST2084_PQ 2
#define OUTPUT_TRANSFORM_LUT_3D 3
#define OUTPUT_TRANSFORM_INVERSE_GAMMA22 4
#define OUTPUT_TRANSFORM_INVERSE_BT1886 5
float linear_channel_to_srgb(float x) {
return max(min(x * 12.92, 0.04045), 1.055 * pow(x, 1. / 2.4) - 0.055);
@ -47,6 +48,14 @@ vec3 linear_color_to_pq(vec3 color) {
return pow((vec3(c1) + c2 * pow_n) / (vec3(1) + c3 * pow_n), vec3(m));
}
vec3 linear_color_to_bt1886(vec3 color) {
float lb = pow(0.0001, 1.0 / 2.4);
float lw = pow(1.0, 1.0 / 2.4);
float a = pow(lw - lb, 2.4);
float b = lb / (lw - lb);
return pow(color / a, vec3(1.0 / 2.4)) - vec3(b);
}
void main() {
vec4 in_color = subpassLoad(in_color).rgba;
@ -74,6 +83,8 @@ void main() {
rgb = linear_color_to_srgb(rgb);
} else if (OUTPUT_TRANSFORM == OUTPUT_TRANSFORM_INVERSE_GAMMA22) {
rgb = pow(rgb, vec3(1. / 2.2));
} else if (OUTPUT_TRANSFORM == OUTPUT_TRANSFORM_INVERSE_BT1886) {
rgb = linear_color_to_bt1886(rgb);
}
// Back to pre-multiplied alpha