浏览代码

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.

(cherry picked from commit e79e28598bfc315a012822767207cc16f6321021)
jpark37 2 年之前
父节点
当前提交
d5a0a7450d

+ 0 - 16
libobs/data/area.effect

@@ -117,13 +117,6 @@ float4 PSDrawAreaRGBAMultiplyTonemap(FragData frag_in) : TARGET
 	return rgba;
 	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)
 float4 DrawAreaUpscale(FragData frag_in)
 {
 {
 	float2 uv = frag_in.uv;
 	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
 technique DrawUpscale
 {
 {
 	pass
 	pass

+ 0 - 16
libobs/data/bicubic_scale.effect

@@ -163,13 +163,6 @@ float4 PSDrawBicubicRGBAMultiplyTonemap(FragData f_in, bool undistort) : TARGET
 	return rgba;
 	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
 technique Draw
 {
 {
 	pass
 	pass
@@ -206,15 +199,6 @@ technique DrawMultiplyTonemap
 	}
 	}
 }
 }
 
 
-technique DrawAlphaDivide
-{
-	pass
-	{
-		vertex_shader = VSDefault(v_in);
-		pixel_shader = PSDrawBicubicRGBADivide(f_in);
-	}
-}
-
 technique DrawUndistort
 technique DrawUndistort
 {
 {
 	pass
 	pass

+ 0 - 16
libobs/data/bilinear_lowres_scale.effect

@@ -86,13 +86,6 @@ float4 PSDrawLowresBilinearRGBAMultiplyTonemap(VertData f_in) : TARGET
 	return rgba;
 	return rgba;
 }
 }
 
 
-float4 PSDrawLowresBilinearRGBADivide(VertData f_in) : TARGET
-{
-	float4 rgba = DrawLowresBilinear(f_in);
-	rgba.rgb *= max(1. / rgba.a, 0.);
-	return rgba;
-}
-
 technique Draw
 technique Draw
 {
 {
 	pass
 	pass
@@ -128,12 +121,3 @@ technique DrawMultiplyTonemap
 		pixel_shader  = PSDrawLowresBilinearRGBAMultiplyTonemap(f_in);
 		pixel_shader  = PSDrawLowresBilinearRGBAMultiplyTonemap(f_in);
 	}
 	}
 }
 }
-
-technique DrawAlphaDivide
-{
-	pass
-	{
-		vertex_shader = VSDefault(v_in);
-		pixel_shader  = PSDrawLowresBilinearRGBADivide(f_in);
-	}
-}

+ 3 - 4
libobs/data/default.effect

@@ -31,14 +31,14 @@ float4 PSDrawBare(VertInOut vert_in) : TARGET
 float4 PSDrawAlphaDivide(VertInOut vert_in) : TARGET
 float4 PSDrawAlphaDivide(VertInOut vert_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(def_sampler, vert_in.uv);
 	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;
 	return rgba;
 }
 }
 
 
 float4 PSDrawAlphaDivideTonemap(VertInOut vert_in) : TARGET
 float4 PSDrawAlphaDivideTonemap(VertInOut vert_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(def_sampler, vert_in.uv);
 	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 = rec709_to_rec2020(rgba.rgb);
 	rgba.rgb = reinhard(rgba.rgb);
 	rgba.rgb = reinhard(rgba.rgb);
 	rgba.rgb = rec2020_to_rec709(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 PSDrawAlphaDivideR10L(VertInOut vert_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(def_sampler, vert_in.uv);
 	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 = rec709_to_rec2020(rgba.rgb);
 	rgba.rgb = linear_to_st2084(rgba.rgb);
 	rgba.rgb = linear_to_st2084(rgba.rgb);
 	uint3 rgb1023 = uint3(mad(rgba.rgb, 1023., .5));
 	uint3 rgb1023 = uint3(mad(rgba.rgb, 1023., .5));

+ 0 - 16
libobs/data/lanczos_scale.effect

@@ -219,13 +219,6 @@ float4 PSDrawLanczosRGBAMultiplyTonemap(FragData f_in, bool undistort) : TARGET
 	return rgba;
 	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
 technique Draw
 {
 {
 	pass
 	pass
@@ -262,15 +255,6 @@ technique DrawMultiplyTonemap
 	}
 	}
 }
 }
 
 
-technique DrawAlphaDivide
-{
-	pass
-	{
-		vertex_shader = VSDefault(v_in);
-		pixel_shader  = PSDrawLanczosRGBADivide(f_in);
-	}
-}
-
 technique DrawUndistort
 technique DrawUndistort
 {
 {
 	pass
 	pass

+ 1 - 1
plugins/obs-filters/data/blend_add_filter.effect

@@ -35,7 +35,7 @@ VertDataOut VSDefault(VertDataIn v_in)
 float4 PSAddImageRGBA(VertDataOut v_in) : TARGET
 float4 PSAddImageRGBA(VertDataOut v_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(textureSampler, v_in.uv);
 	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;
 	rgba *= color;
 
 
 	float3 targetRGB = target.Sample(textureSampler, v_in.uv2).rgb;
 	float3 targetRGB = target.Sample(textureSampler, v_in.uv2).rgb;

+ 1 - 1
plugins/obs-filters/data/blend_mul_filter.effect

@@ -35,7 +35,7 @@ VertDataOut VSDefault(VertDataIn v_in)
 float4 PSMuliplyImageRGBA(VertDataOut v_in) : TARGET
 float4 PSMuliplyImageRGBA(VertDataOut v_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(textureSampler, v_in.uv);
 	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;
 	rgba *= color;
 
 
 	float3 targetRGB = target.Sample(textureSampler, v_in.uv2).rgb;
 	float3 targetRGB = target.Sample(textureSampler, v_in.uv2).rgb;

+ 1 - 1
plugins/obs-filters/data/blend_sub_filter.effect

@@ -35,7 +35,7 @@ VertDataOut VSDefault(VertDataIn v_in)
 float4 PSSubtractImageRGBA(VertDataOut v_in) : TARGET
 float4 PSSubtractImageRGBA(VertDataOut v_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(textureSampler, v_in.uv);
 	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;
 	rgba *= color;
 
 
 	float3 targetRGB = target.Sample(textureSampler, v_in.uv2).rgb;
 	float3 targetRGB = target.Sample(textureSampler, v_in.uv2).rgb;

+ 1 - 1
plugins/obs-filters/data/chroma_key_filter.effect

@@ -85,7 +85,7 @@ float4 ProcessChromaKey(float4 rgba, VertData v_in)
 float4 PSChromaKeyRGBA(VertData v_in) : TARGET
 float4 PSChromaKeyRGBA(VertData v_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(textureSampler, v_in.uv);
 	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);
 	return ProcessChromaKey(rgba, v_in);
 }
 }
 
 

+ 1 - 1
plugins/obs-filters/data/chroma_key_filter_v2.effect

@@ -95,7 +95,7 @@ float4 ProcessChromaKey(float4 rgba, VertData v_in)
 float4 PSChromaKeyRGBA(VertData v_in) : TARGET
 float4 PSChromaKeyRGBA(VertData v_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(textureSampler, v_in.uv);
 	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 = ProcessChromaKey(rgba, v_in);
 	rgba.rgb *= rgba.a;
 	rgba.rgb *= rgba.a;
 	return rgba;
 	return rgba;

+ 1 - 1
plugins/obs-filters/data/color_correction_filter.effect

@@ -47,7 +47,7 @@ float4 PSColorFilterRGBA(VertData vert_in) : TARGET
 {
 {
 	/* Grab the current pixel to perform operations on. */
 	/* Grab the current pixel to perform operations on. */
 	float4 currentPixel = image.Sample(textureSampler, vert_in.uv);
 	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. */
 	/* Always address the gamma first. */
 	currentPixel.rgb = pow(currentPixel.rgb, float3(gamma, gamma, gamma));
 	currentPixel.rgb = pow(currentPixel.rgb, float3(gamma, gamma, gamma));

+ 4 - 4
plugins/obs-filters/data/color_grade_filter.effect

@@ -47,7 +47,7 @@ float3 srgb_linear_to_nonlinear(float3 v)
 float4 LUT1D(VertDataOut v_in) : TARGET
 float4 LUT1D(VertDataOut v_in) : TARGET
 {
 {
 	float4 textureColor = image.Sample(textureSampler, v_in.uv);
 	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 nonlinear = srgb_linear_to_nonlinear(textureColor.rgb);
 
 
 	if (nonlinear.r >= domain_min.r && nonlinear.r <= domain_max.r) {
 	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 LUTAlpha3D(VertDataOut v_in) : TARGET
 {
 {
 	float4 textureColor = image.Sample(textureSampler, v_in.uv);
 	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 nonlinear = srgb_linear_to_nonlinear(textureColor.rgb);
 
 
 	float3 clut_uvw = nonlinear * clut_scale + clut_offset;
 	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 LUTAmount3D(VertDataOut v_in) : TARGET
 {
 {
 	float4 textureColor = image.Sample(textureSampler, v_in.uv);
 	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 nonlinear = srgb_linear_to_nonlinear(textureColor.rgb);
 
 
 	float3 clut_uvw = nonlinear * clut_scale + clut_offset;
 	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 LUTDomain3D(VertDataOut v_in) : TARGET
 {
 {
 	float4 textureColor = image.Sample(textureSampler, v_in.uv);
 	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 nonlinear = srgb_linear_to_nonlinear(textureColor.rgb);
 
 
 	float r = nonlinear.r;
 	float r = nonlinear.r;

+ 1 - 1
plugins/obs-filters/data/color_key_filter.effect

@@ -50,7 +50,7 @@ float4 ProcessColorKey(float4 rgba, VertData v_in)
 float4 PSColorKeyRGBA(VertData v_in) : TARGET
 float4 PSColorKeyRGBA(VertData v_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(textureSampler, v_in.uv);
 	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;
 	rgba *= color;
 	return ProcessColorKey(rgba, v_in);
 	return ProcessColorKey(rgba, v_in);
 }
 }

+ 1 - 1
plugins/obs-filters/data/color_key_filter_v2.effect

@@ -60,7 +60,7 @@ float4 ProcessColorKey(float4 rgba, VertData v_in)
 float4 PSColorKeyRGBA(VertData v_in) : TARGET
 float4 PSColorKeyRGBA(VertData v_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(textureSampler, v_in.uv);
 	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.a *= opacity;
 	rgba = ProcessColorKey(rgba, v_in);
 	rgba = ProcessColorKey(rgba, v_in);
 	rgba.rgb *= rgba.a;
 	rgba.rgb *= rgba.a;

+ 1 - 1
plugins/obs-filters/data/luma_key_filter.effect

@@ -28,7 +28,7 @@ VertData VSDefault(VertData v_in)
 float4 PSALumaKeyRGBA(VertData v_in) : TARGET
 float4 PSALumaKeyRGBA(VertData v_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(textureSampler, v_in.uv);
 	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);
 	float4 lumaCoef = float4(0.2989, 0.5870, 0.1140, 0.0);
 
 

+ 1 - 1
plugins/obs-filters/data/luma_key_filter_v2.effect

@@ -28,7 +28,7 @@ VertData VSDefault(VertData v_in)
 float4 PSALumaKeyRGBA(VertData v_in) : TARGET
 float4 PSALumaKeyRGBA(VertData v_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(textureSampler, v_in.uv);
 	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);
 	float3 lumaCoef = float3(0.2126, 0.7152, 0.0722);
 
 

+ 1 - 1
plugins/obs-filters/data/mask_alpha_filter.effect

@@ -35,7 +35,7 @@ VertDataOut VSDefault(VertDataIn v_in)
 float4 PSAlphaMaskRGBA(VertDataOut v_in) : TARGET
 float4 PSAlphaMaskRGBA(VertDataOut v_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(textureSampler, v_in.uv);
 	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;
 	rgba *= color;
 
 
 	float4 targetRGB = target.Sample(textureSampler, v_in.uv2);
 	float4 targetRGB = target.Sample(textureSampler, v_in.uv2);

+ 1 - 1
plugins/obs-filters/data/mask_color_filter.effect

@@ -35,7 +35,7 @@ VertDataOut VSDefault(VertDataIn v_in)
 float4 PSColorMaskRGBA(VertDataOut v_in) : TARGET
 float4 PSColorMaskRGBA(VertDataOut v_in) : TARGET
 {
 {
 	float4 rgba = image.Sample(textureSampler, v_in.uv);
 	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;
 	rgba *= color;
 
 
 	float4 targetRGB = target.Sample(textureSampler, v_in.uv2);
 	float4 targetRGB = target.Sample(textureSampler, v_in.uv2);