layout (binding = TEX_ATLAS) uniform sampler2DArray tex_atlas; struct AtlasPart { vec2 uv0; vec2 uv1; int zpos; int edges; // 0 = repeat, 1 = clamp }; layout(std140, binding = SSBO_ATLAS_BUFFER) readonly buffer AtlasBuffer { AtlasPart atlas[]; }; vec4 atlas_read_texture(uint tex, vec2 uv) { AtlasPart a = atlas[tex]; uv = (a.edges == 0 ? fract(uv) : clamp(uv, 0.f, 1.f)) * (a.uv1 - a.uv0) + a.uv0; return texture(tex_atlas, vec3(uv, a.zpos)); }