VHS Glitch

Shader ported from shadertoy: https://www.shadertoy.com/view/Ms3XWH

Shader code
shader_type canvas_item;

uniform float range : hint_range(0.0, 0.1, 0.005)= 0.05;
uniform float noiseQuality : hint_range(0.0, 300.0, 0.1)= 250.0;
uniform float noiseIntensity : hint_range(-0.6, 0.6, 0.0010)= 0.0088;
uniform float offsetIntensity : hint_range(-0.1, 0.1, 0.001) = 0.03;
uniform float colorOffsetIntensity : hint_range(0.0, 5.0, 0.001) = 1.3;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture;
float rand(vec2 co)
{
    return fract(sin(dot(co.xy ,vec2(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;
}
const float saturation = 0.2;
void fragment()
{
    vec2 uv = SCREEN_UV;
    for (float i = 0.0; i < 0.71; i += 0.1313)
    {
        float d = mod(TIME * i, 1.7);
        float o = sin(1.0 - tan(TIME * 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(vec2(TIME * 0.00001, UVY));
    uv.x += noise * noiseIntensity;

    vec2 offsetR = vec2(0.009 * sin(TIME), 0.0) * colorOffsetIntensity;
    vec2 offsetG = vec2(0.0073 * (cos(TIME * 0.97)), 0.0) * colorOffsetIntensity;
    
    float r = texture(SCREEN_TEXTURE, uv + offsetR).r;
    float g = texture(SCREEN_TEXTURE, uv + offsetG).g;
    float b = texture(SCREEN_TEXTURE, uv).b;
    vec4 tex = vec4(r, g, b, 1.0);
    COLOR = tex;
}
Live Preview
Tags
canvas item, fnaf, godot4, VHS
This shader is a port from an existing Shadertoy project. Shadertoy shaders are by default protected under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) license unless anything else has been stated by the author. For more info, see our License terms.

Related shaders

guest

5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Vapoenitis
Vapoenitis
2 years ago

This works beautifully. I need to lower the intensity of it, but it’s perfect for the game I’m making. Is it okay if I use it?

arcticseal
arcticseal
2 years ago
Reply to  Vapoenitis

I tried to use this shader but it just makes the sprite invisible. How did you get it to work?

TheYellowArchitect
2 years ago
Reply to  arcticseal

You use this shader on an empty sprite, and overlay it (Zindex+) atop any sprite. It’s a mask basically, for other CanvasItems.

TheYellowArchitect
2 years ago

Incredible. Must-have for any sci-fi game.

vibecheck
vibecheck
1 year ago

Nice work. Thank you!