Perspective grid animated

Instructions

Just paste the code into a new shader for a Sprite node. The sprite should have a base texture.

Shader code
shader_type canvas_item;

float grid(vec2 uv, float velocity, float iTime)
{
    vec2 size = vec2(uv.y, uv.y * uv.y * 0.2) * 0.01;
    uv += vec2(0.0, iTime * 4.0 * (velocity + 0.05));
    uv = abs(fract(uv) - 0.5);
 	vec2 lines = smoothstep(size, vec2(0.0), uv);
 	lines += smoothstep(size * 5.0, vec2(0.0), uv) * 0.4 * velocity;
    return clamp(lines.x + lines.y, 0.0, 3.0);
}


void fragment()
{
    vec2 uv = (2.0 * FRAGCOORD.xy.xy - (1.0 / SCREEN_PIXEL_SIZE).xy)/(1.0 / SCREEN_PIXEL_SIZE).y;
    float velocity = 1.0;
   
    {
        // Grid
        vec3 col = vec3(0.0, 0.1, 0.2);
        if (uv.y < -0.2)
        {
            uv.y = 3.0 / (abs(uv.y + 0.2) + 0.05);
            uv.x *= uv.y * 1.0;
            float gridVal = grid(uv, velocity, TIME);
            col = mix(col, vec3(0.5, 0.5, 1.0), gridVal);
        }
        else
        {
            uv.y -= velocity * 1.1 - 0.51;
        }

        col = mix(vec3(col.r, col.r, col.r) * 0.5, col,  0.7);

        COLOR = vec4(col,1.0);
    }
      
}
Tags
grid, perspective
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

Perspective Grid Remix March2021

world coordinates grid b&w shader

Animated sketchy line

guest
0 Comments
Inline Feedbacks
View all comments