Thanks! I got the shader working after removing the unneeded multiplication by color on sampling.It was difficult to pry open OBS plugin building in one hour, so I opted to overwrite an existing shader in OBS to accomplish mixed reality streaming for SteamVR in OBS.
Okay so if you want to use OBS to use the color of the top-right quadrant of a source as the alpha on the top-left quadrant of a source, simply replace the contents of any .effect file in obs-studio/data/obs-plugins/obs-filters/ with
uniform float4x4 ViewProj;
uniform texture2d image;
uniform float4 color;
uniform float contrast;
uniform float brightness;
uniform float gamma;
uniform float4 key_color;
uniform float similarity;
uniform float smoothness;
sampler_state textureSampler {
Filter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
struct VertData {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
VertData VSDefault(VertData v_in)
{
VertData vert_out;
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
vert_out.uv = v_in.uv;
return vert_out;
}
float4 OffsetPixel(float4 rgba, VertData v_in)
{
float2 shiftedUV = v_in.uv;
shiftedUV.x += 0.5f;
return image.Sample( textureSampler, shiftedUV ) * color;
}
float4 PSColorKeyTRAppliedTLAndCroppedTL( VertData v_in )
{
float4 rgba = image.Sample( textureSampler, v_in.uv ) * color;
if ( v_in.uv.x < 0.5f && v_in.uv.y < 0.5f )
{
float4 offsetRgba = OffsetPixel( rgba, v_in );
rgba.w = offsetRgba.x;
}
return rgba;
}
float4 PSColorKeyRGBA(VertData v_in) : TARGET
{
float4 rgba = PSColorKeyTRAppliedTLAndCroppedTL( v_in );
return rgba;
}
technique Draw
{
pass
{
vertex_shader = VSDefault(v_in);
pixel_shader = PSColorKeyRGBA(v_in);
}
}
and then use the filter of the same name inside of OBS. I recommend not writing over an effect file for a filter you are already using, and to back up your original effects files before overwriting one or more of them.
The edited shader code that I got working:I tried replacing the Sharpen filter today, with the code you gave with no luck.
Any other pointers you have?
uniform float4x4 ViewProj;
uniform texture2d image;
sampler_state textureSampler {
Filter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
struct VertData {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
VertData VSDefault(VertData v_in)
{
VertData vert_out;
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
vert_out.uv = v_in.uv;
return vert_out;
}
float4 OffsetPixel(float4 rgba, VertData v_in)
{
float2 shiftedUV = v_in.uv;
shiftedUV.x += 0.5f;
return image.Sample( textureSampler, shiftedUV );
}
float4 PSColorKeyTRAppliedTLAndCroppedTL( VertData v_in )
{
float4 rgba = image.Sample( textureSampler, v_in.uv );
if ( v_in.uv.x < 0.5f && v_in.uv.y < 0.5f )
{
float4 offsetRgba = OffsetPixel( rgba, v_in );
rgba.w = offsetRgba.x;
}
return rgba;
}
float4 PSColorKeyRGBA(VertData v_in) : TARGET
{
float4 rgba = PSColorKeyTRAppliedTLAndCroppedTL( v_in );
return rgba;
}
technique Draw
{
pass
{
vertex_shader = VSDefault(v_in);
pixel_shader = PSColorKeyRGBA(v_in);
}
}