From 5edc0c95800746171803f5adfab476dcd3e13da0 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sun, 24 Apr 2016 15:55:47 -0700 Subject: [PATCH] obs-filters: Fix more chroma key shader code In aa4e18740a219b I mistakenly thought that I could add the variables back in and that it would automatically cull variables that aren't used, but that wasn't the case -- the shader parser always checks to see whether parameters were set, and if they're not, it'll fail. This fixes an issue where the shader would try to access parameters that are no longer needed and fail due to the shader parameter check. YUV-based shader support has been removed (due to the fact that no sources ever use YUV shading) so there's no reason to keep around the YUV processing code. --- .../obs-filters/data/chroma_key_filter.effect | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/plugins/obs-filters/data/chroma_key_filter.effect b/plugins/obs-filters/data/chroma_key_filter.effect index cf1cae023..8a75968d7 100644 --- a/plugins/obs-filters/data/chroma_key_filter.effect +++ b/plugins/obs-filters/data/chroma_key_filter.effect @@ -1,8 +1,5 @@ uniform float4x4 ViewProj; uniform texture2d image; -uniform float4x4 color_matrix; -uniform float3 color_range_min = {0.0, 0.0, 0.0}; -uniform float3 color_range_max = {1.0, 1.0, 1.0}; uniform float4x4 yuv_mat = { 0.182586, 0.614231, 0.062007, 0.062745, -0.100644, -0.338572, 0.439216, 0.501961, @@ -51,41 +48,30 @@ float GetChromaDist(float3 rgb) return distance(chroma_key, yuvx.yz); } -float4 SampleYUVToRGB(float2 uv) +float4 SampleTexture(float2 uv) { - float4 yuv = image.Sample(textureSampler, uv); - yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max); - return saturate(mul(float4(yuv.xyz, 1.0), color_matrix)); + return image.Sample(textureSampler, uv); } -float4 SampleTexture(float2 uv, bool use_matrix) -{ - if (use_matrix) { - return SampleYUVToRGB(uv); - } else { - return image.Sample(textureSampler, uv); - } -} - -float GetBoxFilteredChromaDist(float3 rgb, float2 texCoord, bool use_matrix) +float GetBoxFilteredChromaDist(float3 rgb, float2 texCoord) { float distVal = GetChromaDist(rgb); - distVal += GetChromaDist(SampleTexture(texCoord-pixel_size, use_matrix).rgb); - distVal += GetChromaDist(SampleTexture(texCoord-float2(pixel_size.x, 0.0), use_matrix).rgb); - distVal += GetChromaDist(SampleTexture(texCoord-float2(pixel_size.x, -pixel_size.y), use_matrix).rgb); + distVal += GetChromaDist(SampleTexture(texCoord-pixel_size).rgb); + distVal += GetChromaDist(SampleTexture(texCoord-float2(pixel_size.x, 0.0)).rgb); + distVal += GetChromaDist(SampleTexture(texCoord-float2(pixel_size.x, -pixel_size.y)).rgb); - distVal += GetChromaDist(SampleTexture(texCoord-float2(0.0, pixel_size.y), use_matrix).rgb); - distVal += GetChromaDist(SampleTexture(texCoord+float2(0.0, pixel_size.y), use_matrix).rgb); + distVal += GetChromaDist(SampleTexture(texCoord-float2(0.0, pixel_size.y)).rgb); + distVal += GetChromaDist(SampleTexture(texCoord+float2(0.0, pixel_size.y)).rgb); - distVal += GetChromaDist(SampleTexture(texCoord+float2(pixel_size.x, -pixel_size.y), use_matrix).rgb); - distVal += GetChromaDist(SampleTexture(texCoord+float2(pixel_size.x, 0.0), use_matrix).rgb); - distVal += GetChromaDist(SampleTexture(texCoord+pixel_size, use_matrix).rgb); + distVal += GetChromaDist(SampleTexture(texCoord+float2(pixel_size.x, -pixel_size.y)).rgb); + distVal += GetChromaDist(SampleTexture(texCoord+float2(pixel_size.x, 0.0)).rgb); + distVal += GetChromaDist(SampleTexture(texCoord+pixel_size).rgb); return distVal / 9.0; } -float4 ProcessChromaKey(float4 rgba, VertData v_in, bool use_matrix) +float4 ProcessChromaKey(float4 rgba, VertData v_in) { - float chromaDist = GetBoxFilteredChromaDist(rgba.rgb, v_in.uv, use_matrix); + float chromaDist = GetBoxFilteredChromaDist(rgba.rgb, v_in.uv); float baseMask = chromaDist - similarity; float fullMask = pow(saturate(baseMask / smoothness), 1.5); float spillVal = pow(saturate(baseMask / spill), 1.5); @@ -101,7 +87,7 @@ float4 ProcessChromaKey(float4 rgba, VertData v_in, bool use_matrix) float4 PSChromaKeyRGBA(VertData v_in) : TARGET { float4 rgba = image.Sample(textureSampler, v_in.uv) * color; - return ProcessChromaKey(rgba, v_in, false); + return ProcessChromaKey(rgba, v_in); } technique Draw -- GitLab