Moving CheckerBoard

A moving Checkerboard patten with changable colours, directions, size and speed.

I used Simple CheckerBoard by leonharlov as a base:

https://godotshaders.com/shader/simple-checkerboard/

Shader code
shader_type canvas_item;

uniform float size : hint_range(1.0, 100.0) = 25.0;
uniform vec4 color1 : source_color = vec4(1.0, 1.0, 1.0, 1.0); 
uniform vec4 color2 : source_color = vec4(0.7, 0.7, 0.7, 1.0);
uniform float speed : hint_range(0.0, 10.0) = 1.0;
uniform float direction_x : hint_range(-1.0, 1.0) = 1.0; // Horizontal movement
uniform float direction_y : hint_range(-1.0, 1.0) = 1.0; // Vertical movement

void fragment() {
    vec2 pos = FRAGCOORD.xy / size;
    float time_offset = TIME * speed;

    // Use the slider values for direction and normalize them
    vec2 direction = normalize(vec2(direction_x, direction_y));
    vec2 movement = direction * time_offset;

    pos -= movement;
    pos = floor(pos);

    float pattern_mask = mod(pos.x + mod(pos.y, 2.0), 2.0);
    COLOR = mix(color1, color2, pattern_mask);
}
Tags
background, Checker, moving
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

Simple checkerboard

Moving Rainbow Gradient

Moving planets in space for Skyboxes

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments