Skip to content

Instantly share code, notes, and snippets.

@mariusvn
Last active November 7, 2021 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariusvn/c7ad4c3859e0e381153568c22081bf27 to your computer and use it in GitHub Desktop.
Save mariusvn/c7ad4c3859e0e381153568c22081bf27 to your computer and use it in GitHub Desktop.
OBS shaderfilter VHS alpha
uniform float range = 0.05;
uniform float noiseQuality = 250.0;
uniform float noiseIntensity = 0.88;
uniform float offsetIntensity = 0.02;
uniform float colorOffsetIntensity = 1.3;
uniform float speed = 1.0;
uniform bool applyAlpha = true;
float rand(float2 co)
{
return frac(sin(dot(co.xy ,float2(12.9898,78.233))) * 43758.5453);
}
float verticalBar(float pos, float uvY, float offset)
{
float edge0 = (pos - range);
float edge1 = (pos + range);
float x = smoothstep(edge0, pos, uvY) * offset;
x -= smoothstep(pos, edge1, uvY) * offset;
return x;
}
float4 mainImage(VertData v_in) : TARGET
{
float elapsed_time_mod = speed * elapsed_time;
float2 uv = v_in.uv;
for (float i = 0.0; i < 0.71; i += 0.1313)
{
float d = (elapsed_time_mod * i) % 1.7;
float o = sin(1.0 - tan(elapsed_time_mod * 0.24 * i));
o *= offsetIntensity;
uv.x += verticalBar(d, uv.y, o);
}
float uvY = uv.y;
uvY *= noiseQuality;
uvY = float(int(uvY)) * (1.0 / noiseQuality);
float noise = rand(float2(elapsed_time_mod * 0.00001, uvY));
uv.x += noise * noiseIntensity / 100.0;
float2 offsetR = float2(0.006 * sin(elapsed_time_mod), 0.0) * colorOffsetIntensity;
float2 offsetG = float2(0.0073 * (cos(elapsed_time_mod * 0.97)), 0.0) * colorOffsetIntensity;
float r = image.Sample(textureSampler, uv + offsetR).r;
float g = image.Sample(textureSampler, uv + offsetG).g;
float b = image.Sample(textureSampler, uv).b;
float a = max(max(image.Sample(textureSampler, uv + offsetR).r, image.Sample(textureSampler, uv + offsetG).g), image.Sample(textureSampler, uv).b);
float4 output = float4(r, g, b, applyAlpha ? a : 1.0);
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment