libobs: Add high-precision sRGB support

This commit is contained in:
jpark37
2022-03-30 22:39:53 -07:00
committed by Jim
parent 848e128435
commit 06111d5b10
10 changed files with 329 additions and 101 deletions

View File

@@ -205,7 +205,7 @@ float PS_PQ_Y_709_2020(FragPos frag_in) : TARGET
rgb = rec709_to_rec2020(rgb);
rgb = linear_to_st2084(rgb);
float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
y = (65472. / 65535.) * y + 0.00048828125; // set up truncation to 10 bits
y = (65472. / 65535.) * y + (32. / 65535.); // set up truncation to 10 bits
return y;
}
@@ -215,7 +215,16 @@ float PS_HLG_Y_709_2020(FragPos frag_in) : TARGET
rgb = rec709_to_rec2020(rgb);
rgb = linear_to_hlg(rgb);
float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
y = (65472. / 65535.) * y + 0.00048828125; // set up truncation to 10 bits
y = (65472. / 65535.) * y + (32. / 65535.); // set up truncation to 10 bits
return y;
}
float PS_SRGB_Y(FragPos frag_in) : TARGET
{
float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
rgb = srgb_linear_to_nonlinear(rgb);
float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
y = (65472. / 65535.) * y + (32. / 65535.); // set up truncation to 10 bits
return y;
}
@@ -237,6 +246,14 @@ float PS_I010_HLG_Y_709_2020(FragPos frag_in) : TARGET
return y * (1023. / 65535.);
}
float PS_I010_SRGB_Y(FragPos frag_in) : TARGET
{
float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
rgb = srgb_linear_to_nonlinear(rgb);
float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
return y * (1023. / 65535.);
}
float2 PS_UV_Wide(FragTexWide frag_in) : TARGET
{
float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
@@ -259,7 +276,7 @@ float2 PS_PQ_UV_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
float2 uv = float2(u, v);
uv = (65472. / 65535.) * uv + 0.00048828125; // set up truncation to 10 bits
uv = (65472. / 65535.) * uv + (32. / 65535.); // set up truncation to 10 bits
return uv;
}
@@ -275,7 +292,22 @@ float2 PS_HLG_UV_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
float2 uv = float2(u, v);
uv = (65472. / 65535.) * uv + 0.00048828125; // set up truncation to 10 bits
uv = (65472. / 65535.) * uv + (32. / 65535.); // set up truncation to 10 bits
return uv;
}
float2 PS_SRGB_UV_WideWide(FragTexWideWide frag_in) : TARGET
{
float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * 0.25;
rgb = srgb_linear_to_nonlinear(rgb);
float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
float2 uv = float2(u, v);
uv = (65472. / 65535.) * uv + (32. / 65535.); // set up truncation to 10 bits
return uv;
}
@@ -337,6 +369,18 @@ float PS_I010_HLG_U_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
return u * (1023. / 65535.);
}
float PS_I010_SRGB_U_WideWide(FragTexWideWide frag_in) : TARGET
{
float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * 0.25;
rgb = srgb_linear_to_nonlinear(rgb);
float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
return u * (1023. / 65535.);
}
float PS_I010_PQ_V_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
{
float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
@@ -363,6 +407,18 @@ float PS_I010_HLG_V_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
return v * (1023. / 65535.);
}
float PS_I010_SRGB_V_WideWide(FragTexWideWide frag_in) : TARGET
{
float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * 0.25;
rgb = srgb_linear_to_nonlinear(rgb);
float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
return v * (1023. / 65535.);
}
float3 YUV_to_RGB(float3 yuv)
{
yuv = clamp(yuv, color_range_min, color_range_max);
@@ -495,6 +551,19 @@ float3 PSNV12_Reverse(VertTexPos frag_in) : TARGET
return rgb;
}
float4 PSI010_SRGB_Reverse(VertTexPos frag_in) : TARGET
{
float ratio = 65535. / 1023.;
float y = image.Load(int3(frag_in.pos.xy, 0)).x * ratio;
int3 xy0_chroma = int3(frag_in.uv, 0);
float cb = image1.Load(xy0_chroma).x * ratio;
float cr = image2.Load(xy0_chroma).x * ratio;
float3 yuv = float3(y, cb, cr);
float3 rgb = YUV_to_RGB(yuv);
rgb = srgb_nonlinear_to_linear(rgb);
return float4(rgb, 1.0);
}
float4 PSI010_PQ_2020_709_Reverse(VertTexPos frag_in) : TARGET
{
float ratio = 65535. / 1023.;
@@ -523,6 +592,16 @@ float4 PSI010_HLG_2020_709_Reverse(VertTexPos frag_in) : TARGET
return float4(rgb, 1.0);
}
float4 PSP010_SRGB_Reverse(VertTexPos frag_in) : TARGET
{
float y = image.Load(int3(frag_in.pos.xy, 0)).x;
float2 cbcr = image1.Load(int3(frag_in.uv, 0)).xy;
float3 yuv = float3(y, cbcr);
float3 rgb = YUV_to_RGB(yuv);
rgb = srgb_nonlinear_to_linear(rgb);
return float4(rgb, 1.0);
}
float4 PSP010_PQ_2020_709_Reverse(VertTexPos frag_in) : TARGET
{
float y = image.Load(int3(frag_in.pos.xy, 0)).x;
@@ -669,6 +748,15 @@ technique I010_HLG_Y
}
}
technique I010_SRGB_Y
{
pass
{
vertex_shader = VSPos(id);
pixel_shader = PS_I010_SRGB_Y(frag_in);
}
}
technique I010_PQ_U
{
pass
@@ -687,6 +775,15 @@ technique I010_HLG_U
}
}
technique I010_SRGB_U
{
pass
{
vertex_shader = VSTexPos_TopLeft(id);
pixel_shader = PS_I010_SRGB_U_WideWide(frag_in);
}
}
technique I010_PQ_V
{
pass
@@ -705,6 +802,15 @@ technique I010_HLG_V
}
}
technique I010_SRGB_V
{
pass
{
vertex_shader = VSTexPos_TopLeft(id);
pixel_shader = PS_I010_SRGB_V_WideWide(frag_in);
}
}
technique P010_PQ_Y
{
pass
@@ -723,6 +829,15 @@ technique P010_HLG_Y
}
}
technique P010_SRGB_Y
{
pass
{
vertex_shader = VSPos(id);
pixel_shader = PS_SRGB_Y(frag_in);
}
}
technique P010_PQ_UV
{
pass
@@ -741,6 +856,15 @@ technique P010_HLG_UV
}
}
technique P010_SRGB_UV
{
pass
{
vertex_shader = VSTexPos_TopLeft(id);
pixel_shader = PS_SRGB_UV_WideWide(frag_in);
}
}
technique UYVY_Reverse
{
pass
@@ -840,6 +964,15 @@ technique NV12_Reverse
}
}
technique I010_SRGB_Reverse
{
pass
{
vertex_shader = VSTexPosHalfHalf_Reverse(id);
pixel_shader = PSI010_SRGB_Reverse(frag_in);
}
}
technique I010_PQ_2020_709_Reverse
{
pass
@@ -858,6 +991,15 @@ technique I010_HLG_2020_709_Reverse
}
}
technique P010_SRGB_Reverse
{
pass
{
vertex_shader = VSTexPosHalfHalf_Reverse(id);
pixel_shader = PSP010_SRGB_Reverse(frag_in);
}
}
technique P010_PQ_2020_709_Reverse
{
pass