obs-filters: Make mask/blend image center w/aspect by default
Fixes what is arguably the most annoying feature of the mask/blend filter, the fact that the image always stretches to the entire source. It now centers and preserves aspect ratio by default, with an option to make it stretch and discard aspect ratio to make it operate as it did before.
This commit is contained in:
@@ -6,6 +6,8 @@ uniform float3 color_range_max = {1.0, 1.0, 1.0};
|
||||
|
||||
uniform texture2d target;
|
||||
uniform float4 color;
|
||||
uniform float2 mul_val;
|
||||
uniform float2 add_val;
|
||||
|
||||
sampler_state textureSampler {
|
||||
Filter = Linear;
|
||||
@@ -13,29 +15,36 @@ sampler_state textureSampler {
|
||||
AddressV = Clamp;
|
||||
};
|
||||
|
||||
struct VertData {
|
||||
struct VertDataIn {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertData VSDefault(VertData v_in)
|
||||
struct VertDataOut {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 uv2 : TEXCOORD1;
|
||||
};
|
||||
|
||||
VertDataOut VSDefault(VertDataIn v_in)
|
||||
{
|
||||
VertData vert_out;
|
||||
VertDataOut vert_out;
|
||||
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
|
||||
vert_out.uv = v_in.uv;
|
||||
vert_out.uv2 = v_in.uv * mul_val + add_val;
|
||||
return vert_out;
|
||||
}
|
||||
|
||||
float4 PSAddImageRGBA(VertData v_in) : TARGET
|
||||
float4 PSAddImageRGBA(VertDataOut v_in) : TARGET
|
||||
{
|
||||
float4 rgba = image.Sample(textureSampler, v_in.uv) * color;
|
||||
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv);
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv2);
|
||||
rgba.rgb = saturate(rgba.rgb + targetRGB.rgb);
|
||||
return rgba;
|
||||
}
|
||||
|
||||
float4 PSAddImageMatrix(VertData v_in) : TARGET
|
||||
float4 PSAddImageMatrix(VertDataOut v_in) : TARGET
|
||||
{
|
||||
float4 yuv = image.Sample(textureSampler, v_in.uv);
|
||||
yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max);
|
||||
@@ -43,7 +52,7 @@ float4 PSAddImageMatrix(VertData v_in) : TARGET
|
||||
float4 rgba = saturate(mul(float4(yuv.xyz, 1.0), color_matrix)) *
|
||||
color;
|
||||
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv);
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv2);
|
||||
rgba.rgb = saturate(rgba.rgb + targetRGB.rgb);
|
||||
return rgba;
|
||||
}
|
||||
|
@@ -6,6 +6,8 @@ uniform float3 color_range_max = {1.0, 1.0, 1.0};
|
||||
|
||||
uniform texture2d target;
|
||||
uniform float4 color;
|
||||
uniform float2 mul_val;
|
||||
uniform float2 add_val;
|
||||
|
||||
sampler_state textureSampler {
|
||||
Filter = Linear;
|
||||
@@ -13,29 +15,36 @@ sampler_state textureSampler {
|
||||
AddressV = Clamp;
|
||||
};
|
||||
|
||||
struct VertData {
|
||||
struct VertDataIn {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertData VSDefault(VertData v_in)
|
||||
struct VertDataOut {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 uv2 : TEXCOORD1;
|
||||
};
|
||||
|
||||
VertDataOut VSDefault(VertDataIn v_in)
|
||||
{
|
||||
VertData vert_out;
|
||||
VertDataOut vert_out;
|
||||
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
|
||||
vert_out.uv = v_in.uv;
|
||||
vert_out.uv2 = v_in.uv * mul_val + add_val;
|
||||
return vert_out;
|
||||
}
|
||||
|
||||
float4 PSMuliplyImageRGBA(VertData v_in) : TARGET
|
||||
float4 PSMuliplyImageRGBA(VertDataOut v_in) : TARGET
|
||||
{
|
||||
float4 rgba = image.Sample(textureSampler, v_in.uv) * color;
|
||||
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv);
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv2);
|
||||
rgba.rgb = saturate(rgba.rgb * targetRGB.rgb);
|
||||
return rgba;
|
||||
}
|
||||
|
||||
float4 PSMuliplyImageMatrix(VertData v_in) : TARGET
|
||||
float4 PSMuliplyImageMatrix(VertDataOut v_in) : TARGET
|
||||
{
|
||||
float4 yuv = image.Sample(textureSampler, v_in.uv);
|
||||
yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max);
|
||||
@@ -43,7 +52,7 @@ float4 PSMuliplyImageMatrix(VertData v_in) : TARGET
|
||||
float4 rgba = saturate(mul(float4(yuv.xyz, 1.0), color_matrix)) *
|
||||
color;
|
||||
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv);
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv2);
|
||||
rgba.rgb = saturate(rgba.rgb * targetRGB.rgb);
|
||||
return rgba;
|
||||
}
|
||||
|
@@ -6,6 +6,8 @@ uniform float3 color_range_max = {1.0, 1.0, 1.0};
|
||||
|
||||
uniform texture2d target;
|
||||
uniform float4 color;
|
||||
uniform float2 mul_val;
|
||||
uniform float2 add_val;
|
||||
|
||||
sampler_state textureSampler {
|
||||
Filter = Linear;
|
||||
@@ -13,29 +15,36 @@ sampler_state textureSampler {
|
||||
AddressV = Clamp;
|
||||
};
|
||||
|
||||
struct VertData {
|
||||
struct VertDataIn {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertData VSDefault(VertData v_in)
|
||||
struct VertDataOut {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 uv2 : TEXCOORD1;
|
||||
};
|
||||
|
||||
VertDataOut VSDefault(VertDataIn v_in)
|
||||
{
|
||||
VertData vert_out;
|
||||
VertDataOut vert_out;
|
||||
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
|
||||
vert_out.uv = v_in.uv;
|
||||
vert_out.uv2 = v_in.uv * mul_val + add_val;
|
||||
return vert_out;
|
||||
}
|
||||
|
||||
float4 PSSubtractImageRGBA(VertData v_in) : TARGET
|
||||
float4 PSSubtractImageRGBA(VertDataOut v_in) : TARGET
|
||||
{
|
||||
float4 rgba = image.Sample(textureSampler, v_in.uv) * color;
|
||||
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv);
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv2);
|
||||
rgba.rgb = saturate(rgba.rgb - targetRGB.rgb);
|
||||
return rgba;
|
||||
}
|
||||
|
||||
float4 PSSubtractImageMatrix(VertData v_in) : TARGET
|
||||
float4 PSSubtractImageMatrix(VertDataOut v_in) : TARGET
|
||||
{
|
||||
float4 yuv = image.Sample(textureSampler, v_in.uv);
|
||||
yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max);
|
||||
@@ -43,7 +52,7 @@ float4 PSSubtractImageMatrix(VertData v_in) : TARGET
|
||||
float4 rgba = saturate(mul(float4(yuv.xyz, 1.0), color_matrix)) *
|
||||
color;
|
||||
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv);
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv2);
|
||||
rgba.rgb = saturate(rgba.rgb - targetRGB.rgb);
|
||||
return rgba;
|
||||
}
|
||||
|
@@ -50,3 +50,4 @@ NoiseGate.AttackTime="Attack Time (milliseconds)"
|
||||
NoiseGate.HoldTime="Hold Time (milliseconds)"
|
||||
NoiseGate.ReleaseTime="Release Time (milliseconds)"
|
||||
Gain.GainDB="Gain (dB)"
|
||||
StretchImage="Stretch Image (discard image aspect ratio)"
|
||||
|
@@ -6,6 +6,8 @@ uniform float3 color_range_max = {1.0, 1.0, 1.0};
|
||||
|
||||
uniform texture2d target;
|
||||
uniform float4 color;
|
||||
uniform float2 mul_val;
|
||||
uniform float2 add_val;
|
||||
|
||||
sampler_state textureSampler {
|
||||
Filter = Linear;
|
||||
@@ -13,29 +15,36 @@ sampler_state textureSampler {
|
||||
AddressV = Clamp;
|
||||
};
|
||||
|
||||
struct VertData {
|
||||
struct VertDataIn {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertData VSDefault(VertData v_in)
|
||||
struct VertDataOut {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 uv2 : TEXCOORD1;
|
||||
};
|
||||
|
||||
VertDataOut VSDefault(VertDataIn v_in)
|
||||
{
|
||||
VertData vert_out;
|
||||
VertDataOut vert_out;
|
||||
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
|
||||
vert_out.uv = v_in.uv;
|
||||
vert_out.uv2 = v_in.uv * mul_val + add_val;
|
||||
return vert_out;
|
||||
}
|
||||
|
||||
float4 PSAlphaMaskRGBA(VertData v_in) : TARGET
|
||||
float4 PSAlphaMaskRGBA(VertDataOut v_in) : TARGET
|
||||
{
|
||||
float4 rgba = image.Sample(textureSampler, v_in.uv) * color;
|
||||
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv);
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv2);
|
||||
rgba.a *= targetRGB.a;
|
||||
return rgba;
|
||||
}
|
||||
|
||||
float4 PSAlphaMaskMatrix(VertData v_in) : TARGET
|
||||
float4 PSAlphaMaskMatrix(VertDataOut v_in) : TARGET
|
||||
{
|
||||
float4 yuv = image.Sample(textureSampler, v_in.uv);
|
||||
yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max);
|
||||
@@ -43,7 +52,7 @@ float4 PSAlphaMaskMatrix(VertData v_in) : TARGET
|
||||
float4 rgba = saturate(mul(float4(yuv.xyz, 1.0), color_matrix)) *
|
||||
color;
|
||||
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv);
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv2);
|
||||
rgba.a = targetRGB.a;
|
||||
return rgba;
|
||||
}
|
||||
|
@@ -6,6 +6,8 @@ uniform float3 color_range_max = {1.0, 1.0, 1.0};
|
||||
|
||||
uniform texture2d target;
|
||||
uniform float4 color;
|
||||
uniform float2 mul_val;
|
||||
uniform float2 add_val;
|
||||
|
||||
sampler_state textureSampler {
|
||||
Filter = Linear;
|
||||
@@ -13,29 +15,36 @@ sampler_state textureSampler {
|
||||
AddressV = Clamp;
|
||||
};
|
||||
|
||||
struct VertData {
|
||||
struct VertDataIn {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertData VSDefault(VertData v_in)
|
||||
struct VertDataOut {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 uv2 : TEXCOORD1;
|
||||
};
|
||||
|
||||
VertDataOut VSDefault(VertDataIn v_in)
|
||||
{
|
||||
VertData vert_out;
|
||||
VertDataOut vert_out;
|
||||
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
|
||||
vert_out.uv = v_in.uv;
|
||||
vert_out.uv2 = v_in.uv * mul_val + add_val;
|
||||
return vert_out;
|
||||
}
|
||||
|
||||
float4 PSColorMaskRGBA(VertData v_in) : TARGET
|
||||
float4 PSColorMaskRGBA(VertDataOut v_in) : TARGET
|
||||
{
|
||||
float4 rgba = image.Sample(textureSampler, v_in.uv) * color;
|
||||
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv);
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv2);
|
||||
rgba.a *= (targetRGB.r + targetRGB.g + targetRGB.b) / 3.0;
|
||||
return rgba;
|
||||
}
|
||||
|
||||
float4 PSColorMaskMatrix(VertData v_in) : TARGET
|
||||
float4 PSColorMaskMatrix(VertDataOut v_in) : TARGET
|
||||
{
|
||||
float4 yuv = image.Sample(textureSampler, v_in.uv);
|
||||
yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max);
|
||||
@@ -43,7 +52,7 @@ float4 PSColorMaskMatrix(VertData v_in) : TARGET
|
||||
float4 rgba = saturate(mul(float4(yuv.xyz, 1.0), color_matrix)) *
|
||||
color;
|
||||
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv);
|
||||
float4 targetRGB = target.Sample(textureSampler, v_in.uv2);
|
||||
rgba.a = (targetRGB.r + targetRGB.g + targetRGB.b) / 3.0;
|
||||
return rgba;
|
||||
}
|
||||
|
Reference in New Issue
Block a user