in vec2 uv;
in vec2 uvn;

out vec4 C;

uniform vec4* gif_buff;
//uniform ivec4* uindices;
uniform u8vec4* uindices;
//uniform u8vec4* uindices8;
uniform int frame;
// indices

void main() {
    vec2 u = uvn;
    
    ivec2 tex_sz = ivec2(gif_buff[0].xy);
    ivec2 tex_coord = ivec2(
        int(U.x) % tex_sz.x,
        int(U.y) 
    );
    if(
        any(greaterThan(tex_coord,tex_sz)) ||
        U.x >= tex_sz.x ||
        U.y >= tex_sz.y
    ){
        tex_coord -= tex_coord;
//        C -= C;
        return;
    }
    
//    uint8_t potato = 4Us;
    vec2 uu = vec2(tex_coord) / vec2(tex_sz);
    int samp_idx = tex_coord.x + tex_coord.y * tex_sz.x;
//    samp_idx += frame * (tex_sz.x * tex_sz.y);
    samp_idx += frame * (tex_sz.x * tex_sz.y);
//    samp_idx += (int(sin(T*1)*10) + 30) * (tex_sz.x * tex_sz.y);
//    samp_idx = clamp(samp_idx,0,tex_sz.x * tex_sz.y);
    if(ivec2(U) == ivec2(2)){
        print(frame);
    }
    
    int idx = int(uindices[samp_idx/4][samp_idx%4]);
    idx = clamp(idx,0,256);
    
    C = gif_buff[idx + 1];
    C.w = 1.0;
}
