
uniform sampler2DArray u_textures;

in vec2 v_uv;
in vec4 v_color;
flat in vec4 v_texture_info;
flat in int v_atlas;
out vec4 frag_color;

void main() {
    ivec3 texture_size = textureSize(u_textures, 0);
    vec4 col = texture(u_textures, vec3(
        (vec2(v_texture_info.xy) + vec2(v_texture_info.zw) * fract(v_uv)) / vec2(texture_size.xy),
        float(v_atlas))
    );
    frag_color = col * v_color;
    // Gamma correction
    frag_color.rgb = pow(frag_color.rgb, vec3(1.0 / 2.6));
}
