libobs: Add color spaces to scale shaders

This commit is contained in:
jpark37
2022-03-26 13:00:34 -07:00
committed by Jim
parent f0f0cb3038
commit a8bc994f07
8 changed files with 418 additions and 69 deletions
+21 -46
View File
@@ -1,3 +1,5 @@
#include "color.effect"
uniform float4x4 ViewProj;
uniform texture2d image;
uniform float multiplier;
@@ -34,26 +36,6 @@ float4 PSDrawAlphaDivide(VertInOut vert_in) : TARGET
return float4(rgba.rgb * multiplier, alpha);
}
float srgb_linear_to_nonlinear_channel(float u)
{
return (u <= 0.0031308) ? (12.92 * u) : ((1.055 * pow(u, 1.0 / 2.4)) - 0.055);
}
float3 srgb_linear_to_nonlinear(float3 v)
{
return float3(srgb_linear_to_nonlinear_channel(v.r), srgb_linear_to_nonlinear_channel(v.g), srgb_linear_to_nonlinear_channel(v.b));
}
float srgb_nonlinear_to_linear_channel(float u)
{
return (u <= 0.04045) ? (u / 12.92) : pow((u + 0.055) / 1.055, 2.4);
}
float3 srgb_nonlinear_to_linear(float3 v)
{
return float3(srgb_nonlinear_to_linear_channel(v.r), srgb_nonlinear_to_linear_channel(v.g), srgb_nonlinear_to_linear_channel(v.b));
}
float4 PSDrawNonlinearAlpha(VertInOut vert_in) : TARGET
{
float4 rgba = image.Sample(def_sampler, vert_in.uv);
@@ -77,32 +59,6 @@ float4 PSDrawMultiply(VertInOut vert_in) : TARGET
return rgba;
}
float3 rec709_to_rec2020(float3 v)
{
float r = dot(v, float3(0.6274040f, 0.3292820f, 0.0433136f));
float g = dot(v, float3(0.0690970f, 0.9195400f, 0.0113612f));
float b = dot(v, float3(0.0163916f, 0.0880132f, 0.8955950f));
return float3(r, g, b);
}
float3 rec2020_to_rec709(float3 v)
{
float r = dot(v, float3(1.6604910, -0.5876411, -0.0728499));
float g = dot(v, float3(-0.1245505, 1.1328999, -0.0083494));
float b = dot(v, float3(-0.0181508, -0.1005789, 1.1187297));
return float3(r, g, b);
}
float reinhard_channel(float x)
{
return x / (x + 1.0);
}
float3 reinhard(float3 rgb)
{
return float3(reinhard_channel(rgb.r), reinhard_channel(rgb.g), reinhard_channel(rgb.b));
}
float4 PSDrawTonemap(VertInOut vert_in) : TARGET
{
float4 rgba = image.Sample(def_sampler, vert_in.uv);
@@ -112,6 +68,16 @@ float4 PSDrawTonemap(VertInOut vert_in) : TARGET
return rgba;
}
float4 PSDrawMultiplyTonemap(VertInOut vert_in) : TARGET
{
float4 rgba = image.Sample(def_sampler, vert_in.uv);
rgba.rgb *= multiplier;
rgba.rgb = rec709_to_rec2020(rgba.rgb);
rgba.rgb = reinhard(rgba.rgb);
rgba.rgb = rec2020_to_rec709(rgba.rgb);
return rgba;
}
technique Draw
{
pass
@@ -165,3 +131,12 @@ technique DrawTonemap
pixel_shader = PSDrawTonemap(vert_in);
}
}
technique DrawMultiplyTonemap
{
pass
{
vertex_shader = VSDefault(vert_in);
pixel_shader = PSDrawMultiplyTonemap(vert_in);
}
}