#version 450 #extension GL_EXT_buffer_reference : require struct Symbol { uint x; uint top; uint width; }; struct Character { vec3 pos; vec4 color; float size; uint code; }; layout(buffer_reference, std430) readonly buffer SymbolList{ Symbol symbols[]; }; layout(buffer_reference, std430) readonly buffer CharacterList{ Character characters[]; }; layout(set = 0, binding = 0) uniform UIUniform { mat4 screen; } ubo; layout(set = 1, binding = 0) uniform FontUniform { uint num_symbols; uint width; uint height; uint space_width; SymbolList symbol_list; } font; layout(std430, push_constant) uniform Push { CharacterList characters; } push; layout(location = 0) in vec2 inVertexPosition; layout(location = 0) out vec4 fragColor; layout(location = 1) out vec2 fragUV; void main() { Character character = push.characters.characters[gl_InstanceIndex]; Symbol symbol = font.symbol_list.symbols[character.code]; float fragU = (inVertexPosition.x*symbol.width + symbol.x) / font.width; float fragV = inVertexPosition.y + symbol.top / font.height; float x = inVertexPosition.x * character.size * symbol.width / font.height; float y = (inVertexPosition.y + float(symbol.top)/float(font.height)) * character.size; fragUV = vec2(fragU, fragV); fragColor = character.color; gl_Position = ubo.screen * vec4(vec3(x, y, 0.0) + character.pos, 1.0); }