提交 5edc0c95 编写于 作者: J jp9000

obs-filters: Fix more chroma key shader code

In aa4e1874 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.
上级 2974fda7
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册