#version 330 core layout (location = 0) in vec3 aPos; layout (location = 1) in vec2 aTexCoord; layout (location = 2) in int aTileIndex; layout (location = 3) in mat4 aModel; uniform int tilesPerRow; uniform mat4 proj; uniform mat4 view; out vec2 texCoord; out int tileIndex; void main() { tileIndex = aTileIndex; gl_Position = proj * view * aModel * vec4(aPos, 1.0); if (tileIndex != 0) { int index = tileIndex - 1; float tileSize = 1.0 / float(tilesPerRow); int row = index / tilesPerRow; int col = index % tilesPerRow; float offsetX = float(col) * tileSize; float offsetY = float(row) * tileSize; texCoord.x = (aTexCoord.x + col) * tileSize; texCoord.y = (aTexCoord.y + row) * tileSize; } else { texCoord.x = 0.0; texCoord.y = 0.0; } }