0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00
obs-studio/plugins/obs-transitions/data/slide_transition.effect
jpark37 9d7330ca44 obs-transitions: Blend in linear space
Color mismatch is apparent when using source transitions, which lerps
against transparent black and blends into the canvas nonlinearly. When
the transition is done, the blend switches to linear, leading to a pop.

Fix the issue by blending into the canvas in linear space. The lerp is
still nonlinear by design.
2021-05-08 20:53:44 -07:00

60 lines
1.2 KiB
Plaintext

uniform float4x4 ViewProj;
uniform texture2d tex_a;
uniform texture2d tex_b;
uniform float2 tex_a_dir;
uniform float2 tex_b_dir;
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;
}
float srgb_nonlinear_to_linear_channel(float u)
{
return (u <= 0.04045) ? (u / 12.92) : pow((u + 0.055) / 1.055, 2.4);
}
float3 srgb_nonlinear_to_linear(float3 v)
{
return float3(srgb_nonlinear_to_linear_channel(v.r), srgb_nonlinear_to_linear_channel(v.g), srgb_nonlinear_to_linear_channel(v.b));
}
float4 PSSlide(VertData v_in) : TARGET
{
float2 tex_a_uv = v_in.uv + tex_a_dir;
float2 tex_b_uv = v_in.uv - tex_b_dir;
float4 outc;
outc = (tex_a_uv.x - saturate(tex_a_uv.x) != 0.0) ||
(tex_a_uv.y - saturate(tex_a_uv.y) != 0.0)
? tex_b.Sample(textureSampler, tex_b_uv)
: tex_a.Sample(textureSampler, tex_a_uv);
outc.rgb = srgb_nonlinear_to_linear(outc.rgb);
return outc;
}
technique Slide
{
pass
{
vertex_shader = VSDefault(v_in);
pixel_shader = PSSlide(v_in);
}
}