float random(vec2 st) {
    return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);
}

float grid(vec2 c) {
    if (mod((c.s * 512.) + random(c * niri_clamped_progress), 8.) >= 7.|| mod((c.t * 512.) + random(c * niri_clamped_progress), 8.) >= 7.) return 0.;
    else return 1.;
}

vec3 grid_colored(vec2 coords, vec3 col1, vec3 col2) {
    return mix(col1, col2, grid(coords));
}

vec4 gen_px_squares(vec2 coords, vec4 color) {
    vec2 coords_ = coords.xy;
    coords = ceil(coords * 32.) / 32.;
    float p = niri_clamped_progress;

    float mix_alpha =
        clamp((1. - clamp((p - length(coords)) * 3.0, 0.0, 1.0)) * 1.3, 0., 1.);
    // vec4 blue = vec4(0.3568, 0.8078, 0.9803, color.a);
    // vec3 blue = vec3(0.552, 0.631, 1.);
    // vec3 dblue = vec3(0.419, 0.482, 0.839);
    // vec3 dblue = vec3(float(0xd6) / 255., float(0x5d) / 255., float(0x0e) / 255.);
    // vec3 blue = vec3(float(0xfe) / 255., float(0x80) / 255., float(0x19) / 255.);
    vec3 dblue = vec3(float(0xdd) / 255., float(0xdd) / 255., float(0xdd) / 255.);
    vec3 blue = vec3(float(0x55) / 255., float(0x7f) / 255., float(0xff) / 255.);

    if (color.a != 0. && p * p >= dot(coords, coords))
        return mix(color, vec4(grid_colored(coords_, dblue, blue), color.a), mix_alpha);
    else return vec4(0.);
}

vec4 open_color(vec3 coords_geo, vec3 size_geo) {
    vec3 coords_tex = niri_geo_to_tex * coords_geo;
    vec4 color = texture2D(niri_tex, coords_tex.st);

    vec2 coords = (coords_geo.xy - vec2(0.5, 0.5)) * size_geo.xy * 2.0;
    coords = coords / length(size_geo.xy);

    return gen_px_squares(coords, color);
    // return vec4(vec3(grid(coords)),1.);
}
