libobs,obs-filters: Use common straight alpha math

This pattern uses fewer instructions and also avoids using max, which
does not work on infinity.

Also remove unreferenced techniques from scale filters.
This commit is contained in:
jpark37
2023-11-04 18:12:22 -05:00
committed by Lain
parent c76760bc1c
commit e79e28598b
18 changed files with 19 additions and 84 deletions
-16
View File
@@ -117,13 +117,6 @@ float4 PSDrawAreaRGBAMultiplyTonemap(FragData frag_in) : TARGET
return rgba;
}
float4 PSDrawAreaRGBADivide(FragData frag_in) : TARGET
{
float4 rgba = DrawArea(frag_in);
rgba.rgb *= max(1. / rgba.a, 0.);
return rgba;
}
float4 DrawAreaUpscale(FragData frag_in)
{
float2 uv = frag_in.uv;
@@ -220,15 +213,6 @@ technique DrawMultiplyTonemap
}
}
technique DrawAlphaDivide
{
pass
{
vertex_shader = VSDefault(vert_in);
pixel_shader = PSDrawAreaRGBADivide(frag_in);
}
}
technique DrawUpscale
{
pass
-16
View File
@@ -163,13 +163,6 @@ float4 PSDrawBicubicRGBAMultiplyTonemap(FragData f_in, bool undistort) : TARGET
return rgba;
}
float4 PSDrawBicubicRGBADivide(FragData f_in) : TARGET
{
float4 rgba = DrawBicubic(f_in, false);
rgba.rgb *= max(1. / rgba.a, 0.);
return rgba;
}
technique Draw
{
pass
@@ -206,15 +199,6 @@ technique DrawMultiplyTonemap
}
}
technique DrawAlphaDivide
{
pass
{
vertex_shader = VSDefault(v_in);
pixel_shader = PSDrawBicubicRGBADivide(f_in);
}
}
technique DrawUndistort
{
pass
-16
View File
@@ -86,13 +86,6 @@ float4 PSDrawLowresBilinearRGBAMultiplyTonemap(VertData f_in) : TARGET
return rgba;
}
float4 PSDrawLowresBilinearRGBADivide(VertData f_in) : TARGET
{
float4 rgba = DrawLowresBilinear(f_in);
rgba.rgb *= max(1. / rgba.a, 0.);
return rgba;
}
technique Draw
{
pass
@@ -128,12 +121,3 @@ technique DrawMultiplyTonemap
pixel_shader = PSDrawLowresBilinearRGBAMultiplyTonemap(f_in);
}
}
technique DrawAlphaDivide
{
pass
{
vertex_shader = VSDefault(v_in);
pixel_shader = PSDrawLowresBilinearRGBADivide(f_in);
}
}
+3 -4
View File
@@ -31,14 +31,14 @@ float4 PSDrawBare(VertInOut vert_in) : TARGET
float4 PSDrawAlphaDivide(VertInOut vert_in) : TARGET
{
float4 rgba = image.Sample(def_sampler, vert_in.uv);
rgba.rgb = (rgba.a > 0.) ? (rgba.rgb / rgba.a) : float3(0., 0., 0.);
rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
return rgba;
}
float4 PSDrawAlphaDivideTonemap(VertInOut vert_in) : TARGET
{
float4 rgba = image.Sample(def_sampler, vert_in.uv);
rgba.rgb = (rgba.a > 0.) ? (rgba.rgb / rgba.a) : float3(0., 0., 0.);
rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
rgba.rgb = rec709_to_rec2020(rgba.rgb);
rgba.rgb = reinhard(rgba.rgb);
rgba.rgb = rec2020_to_rec709(rgba.rgb);
@@ -48,8 +48,7 @@ float4 PSDrawAlphaDivideTonemap(VertInOut vert_in) : TARGET
float4 PSDrawAlphaDivideR10L(VertInOut vert_in) : TARGET
{
float4 rgba = image.Sample(def_sampler, vert_in.uv);
rgba.rgb = (rgba.a > 0.) ? (rgba.rgb / rgba.a) : float3(0., 0., 0.);
rgba.rgb *= multiplier;
rgba.rgb *= (rgba.a > 0.) ? (multiplier / rgba.a) : 0.;
rgba.rgb = rec709_to_rec2020(rgba.rgb);
rgba.rgb = linear_to_st2084(rgba.rgb);
uint3 rgb1023 = uint3(mad(rgba.rgb, 1023., .5));
-16
View File
@@ -219,13 +219,6 @@ float4 PSDrawLanczosRGBAMultiplyTonemap(FragData f_in, bool undistort) : TARGET
return rgba;
}
float4 PSDrawLanczosRGBADivide(FragData f_in) : TARGET
{
float4 rgba = DrawLanczos(f_in, false);
rgba.rgb *= max(1. / rgba.a, 0.);
return rgba;
}
technique Draw
{
pass
@@ -262,15 +255,6 @@ technique DrawMultiplyTonemap
}
}
technique DrawAlphaDivide
{
pass
{
vertex_shader = VSDefault(v_in);
pixel_shader = PSDrawLanczosRGBADivide(f_in);
}
}
technique DrawUndistort
{
pass
@@ -35,7 +35,7 @@ VertDataOut VSDefault(VertDataIn v_in)
float4 PSAddImageRGBA(VertDataOut v_in) : TARGET
{
float4 rgba = image.Sample(textureSampler, v_in.uv);
rgba.rgb = max(float3(0.0, 0.0, 0.0), rgba.rgb / rgba.a);
rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
rgba *= color;
float3 targetRGB = target.Sample(textureSampler, v_in.uv2).rgb;
@@ -35,7 +35,7 @@ VertDataOut VSDefault(VertDataIn v_in)
float4 PSMuliplyImageRGBA(VertDataOut v_in) : TARGET
{
float4 rgba = image.Sample(textureSampler, v_in.uv);
rgba.rgb = max(float3(0.0, 0.0, 0.0), rgba.rgb / rgba.a);
rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
rgba *= color;
float3 targetRGB = target.Sample(textureSampler, v_in.uv2).rgb;
@@ -35,7 +35,7 @@ VertDataOut VSDefault(VertDataIn v_in)
float4 PSSubtractImageRGBA(VertDataOut v_in) : TARGET
{
float4 rgba = image.Sample(textureSampler, v_in.uv);
rgba.rgb = max(float3(0.0, 0.0, 0.0), rgba.rgb / rgba.a);
rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
rgba *= color;
float3 targetRGB = target.Sample(textureSampler, v_in.uv2).rgb;
@@ -85,7 +85,7 @@ float4 ProcessChromaKey(float4 rgba, VertData v_in)
float4 PSChromaKeyRGBA(VertData v_in) : TARGET
{
float4 rgba = image.Sample(textureSampler, v_in.uv);
rgba.rgb = max(float3(0.0, 0.0, 0.0), rgba.rgb / rgba.a);
rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
return ProcessChromaKey(rgba, v_in);
}
@@ -95,7 +95,7 @@ float4 ProcessChromaKey(float4 rgba, VertData v_in)
float4 PSChromaKeyRGBA(VertData v_in) : TARGET
{
float4 rgba = image.Sample(textureSampler, v_in.uv);
rgba.rgb = max(float3(0.0, 0.0, 0.0), rgba.rgb / rgba.a);
rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
rgba = ProcessChromaKey(rgba, v_in);
rgba.rgb *= rgba.a;
return rgba;
@@ -47,7 +47,7 @@ float4 PSColorFilterRGBA(VertData vert_in) : TARGET
{
/* Grab the current pixel to perform operations on. */
float4 currentPixel = image.Sample(textureSampler, vert_in.uv);
currentPixel.rgb = max(float3(0.0, 0.0, 0.0), currentPixel.rgb / currentPixel.a);
currentPixel.rgb *= (currentPixel.a > 0.) ? (1. / currentPixel.a) : 0.;
/* Always address the gamma first. */
currentPixel.rgb = pow(currentPixel.rgb, float3(gamma, gamma, gamma));
@@ -47,7 +47,7 @@ float3 srgb_linear_to_nonlinear(float3 v)
float4 LUT1D(VertDataOut v_in) : TARGET
{
float4 textureColor = image.Sample(textureSampler, v_in.uv);
textureColor.rgb = max(float3(0.0, 0.0, 0.0), textureColor.rgb / textureColor.a);
textureColor.rgb *= (textureColor.a > 0.) ? (1. / textureColor.a) : 0.;
float3 nonlinear = srgb_linear_to_nonlinear(textureColor.rgb);
if (nonlinear.r >= domain_min.r && nonlinear.r <= domain_max.r) {
@@ -85,7 +85,7 @@ float4 LUT3D(VertDataOut v_in) : TARGET
float4 LUTAlpha3D(VertDataOut v_in) : TARGET
{
float4 textureColor = image.Sample(textureSampler, v_in.uv);
textureColor.rgb = max(float3(0.0, 0.0, 0.0), textureColor.rgb / textureColor.a);
textureColor.rgb *= (textureColor.a > 0.) ? (1. / textureColor.a) : 0.;
float3 nonlinear = srgb_linear_to_nonlinear(textureColor.rgb);
float3 clut_uvw = nonlinear * clut_scale + clut_offset;
@@ -98,7 +98,7 @@ float4 LUTAlpha3D(VertDataOut v_in) : TARGET
float4 LUTAmount3D(VertDataOut v_in) : TARGET
{
float4 textureColor = image.Sample(textureSampler, v_in.uv);
textureColor.rgb = max(float3(0.0, 0.0, 0.0), textureColor.rgb / textureColor.a);
textureColor.rgb *= (textureColor.a > 0.) ? (1. / textureColor.a) : 0.;
float3 nonlinear = srgb_linear_to_nonlinear(textureColor.rgb);
float3 clut_uvw = nonlinear * clut_scale + clut_offset;
@@ -112,7 +112,7 @@ float4 LUTAmount3D(VertDataOut v_in) : TARGET
float4 LUTDomain3D(VertDataOut v_in) : TARGET
{
float4 textureColor = image.Sample(textureSampler, v_in.uv);
textureColor.rgb = max(float3(0.0, 0.0, 0.0), textureColor.rgb / textureColor.a);
textureColor.rgb *= (textureColor.a > 0.) ? (1. / textureColor.a) : 0.;
float3 nonlinear = srgb_linear_to_nonlinear(textureColor.rgb);
float r = nonlinear.r;
@@ -50,7 +50,7 @@ float4 ProcessColorKey(float4 rgba, VertData v_in)
float4 PSColorKeyRGBA(VertData v_in) : TARGET
{
float4 rgba = image.Sample(textureSampler, v_in.uv);
rgba.rgb = max(float3(0.0, 0.0, 0.0), rgba.rgb / rgba.a);
rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
rgba *= color;
return ProcessColorKey(rgba, v_in);
}
@@ -60,7 +60,7 @@ float4 ProcessColorKey(float4 rgba, VertData v_in)
float4 PSColorKeyRGBA(VertData v_in) : TARGET
{
float4 rgba = image.Sample(textureSampler, v_in.uv);
rgba.rgb = max(float3(0.0, 0.0, 0.0), rgba.rgb / rgba.a);
rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
rgba.a *= opacity;
rgba = ProcessColorKey(rgba, v_in);
rgba.rgb *= rgba.a;
@@ -28,7 +28,7 @@ VertData VSDefault(VertData v_in)
float4 PSALumaKeyRGBA(VertData v_in) : TARGET
{
float4 rgba = image.Sample(textureSampler, v_in.uv);
rgba.rgb = max(float3(0.0, 0.0, 0.0), rgba.rgb / rgba.a);
rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
float4 lumaCoef = float4(0.2989, 0.5870, 0.1140, 0.0);
@@ -28,7 +28,7 @@ VertData VSDefault(VertData v_in)
float4 PSALumaKeyRGBA(VertData v_in) : TARGET
{
float4 rgba = image.Sample(textureSampler, v_in.uv);
rgba.rgb = max(float3(0.0, 0.0, 0.0), rgba.rgb / rgba.a);
rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
float3 lumaCoef = float3(0.2126, 0.7152, 0.0722);
@@ -35,7 +35,7 @@ VertDataOut VSDefault(VertDataIn v_in)
float4 PSAlphaMaskRGBA(VertDataOut v_in) : TARGET
{
float4 rgba = image.Sample(textureSampler, v_in.uv);
rgba.rgb = max(float3(0.0, 0.0, 0.0), rgba.rgb / rgba.a);
rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
rgba *= color;
float4 targetRGB = target.Sample(textureSampler, v_in.uv2);
@@ -35,7 +35,7 @@ VertDataOut VSDefault(VertDataIn v_in)
float4 PSColorMaskRGBA(VertDataOut v_in) : TARGET
{
float4 rgba = image.Sample(textureSampler, v_in.uv);
rgba.rgb = max(float3(0.0, 0.0, 0.0), rgba.rgb / rgba.a);
rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
rgba *= color;
float4 targetRGB = target.Sample(textureSampler, v_in.uv2);