shader_type spatial;

vec4 brickTile(vec2 _st, float _zoom, float _time){
    _st *= _zoom;
    float time = _time * 50.0;
   if (fract( _st.y * 0.5) > 0.5){
            _st.x += fract(time);
        } else {
            _st.x -= fract(time);
   
    return vec4(fract(_st), floor(_st));
}
}

float box(vec2 _st, vec2 _size){
    _size = vec2(0.5) - _size * 0.5;
    vec2 uv = smoothstep(_size, _size + vec2(1e-4), _st);
    uv *= smoothstep(_size, _size + vec2(1e-4), vec2(1.0) - _st);
    return uv.x * uv.y;
}

float hash(vec2 p){
    return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
}

void fragment() {
    vec4 tile = brickTile(UV, 10.0, TIME);
    vec2 st = tile.xy;
    vec2 id = tile.zw;

    vec3 brickColor = vec3(0.1, 0.1, 0.3);
    float mask = box(st, vec2(0.2));

    ALBEDO = brickColor * mask;
}