2024-10-13 22:18:37 -06:00
|
|
|
#version 450
|
2024-10-14 14:16:59 -06:00
|
|
|
#extension GL_EXT_buffer_reference : require
|
|
|
|
|
|
|
|
struct Symbol {
|
2024-10-16 20:29:19 -06:00
|
|
|
int top;
|
|
|
|
uint left;
|
2024-10-14 14:16:59 -06:00
|
|
|
uint width;
|
2024-10-16 20:29:19 -06:00
|
|
|
uint height;
|
|
|
|
uint advance;
|
2024-10-14 14:16:59 -06:00
|
|
|
};
|
|
|
|
|
2024-10-14 21:32:21 -06:00
|
|
|
struct Character {
|
2024-10-18 10:02:39 -06:00
|
|
|
vec3 pos;
|
2024-10-14 22:10:14 -06:00
|
|
|
vec4 color;
|
|
|
|
float size;
|
2024-10-14 21:32:21 -06:00
|
|
|
uint code;
|
|
|
|
};
|
|
|
|
|
2024-10-14 14:16:59 -06:00
|
|
|
layout(buffer_reference, std430) readonly buffer SymbolList{
|
|
|
|
Symbol symbols[];
|
|
|
|
};
|
2024-10-13 22:18:37 -06:00
|
|
|
|
2024-10-14 21:32:21 -06:00
|
|
|
layout(buffer_reference, std430) readonly buffer CharacterList{
|
|
|
|
Character characters[];
|
|
|
|
};
|
|
|
|
|
2024-10-13 22:18:37 -06:00
|
|
|
layout(set = 0, binding = 0) uniform UIUniform {
|
|
|
|
mat4 screen;
|
|
|
|
} ubo;
|
|
|
|
|
2024-10-15 00:06:46 -06:00
|
|
|
layout(set = 1, binding = 0) uniform Font {
|
2024-10-14 14:16:59 -06:00
|
|
|
uint num_symbols;
|
|
|
|
uint width;
|
|
|
|
uint height;
|
|
|
|
SymbolList symbol_list;
|
2024-10-13 22:18:37 -06:00
|
|
|
} font;
|
|
|
|
|
2024-10-15 00:06:46 -06:00
|
|
|
layout(buffer_reference, std430) readonly buffer Pointers {
|
|
|
|
uint padding[4];
|
2024-10-14 22:10:14 -06:00
|
|
|
CharacterList characters;
|
2024-10-15 00:06:46 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
layout(std430, push_constant) uniform Push {
|
|
|
|
Pointers pointers;
|
2024-10-14 22:10:14 -06:00
|
|
|
} push;
|
|
|
|
|
2024-10-13 22:18:37 -06:00
|
|
|
layout(location = 0) out vec4 fragColor;
|
|
|
|
layout(location = 1) out vec2 fragUV;
|
2024-10-16 20:29:19 -06:00
|
|
|
layout(location = 2) out uint code;
|
2024-10-13 22:18:37 -06:00
|
|
|
|
2024-10-17 15:56:35 -06:00
|
|
|
const vec2 square[6] = {
|
|
|
|
vec2(0.0, 0.0),
|
|
|
|
vec2(1.0, 0.0),
|
|
|
|
vec2(0.0, 1.0),
|
|
|
|
vec2(1.0, 0.0),
|
|
|
|
vec2(1.0, 1.0),
|
|
|
|
vec2(0.0, 1.0),
|
|
|
|
};
|
|
|
|
|
2024-10-13 22:18:37 -06:00
|
|
|
void main() {
|
2024-10-15 00:06:46 -06:00
|
|
|
Character character = push.pointers.characters.characters[gl_InstanceIndex];
|
2024-10-14 22:10:14 -06:00
|
|
|
Symbol symbol = font.symbol_list.symbols[character.code];
|
2024-10-14 14:59:49 -06:00
|
|
|
|
2024-10-17 15:56:35 -06:00
|
|
|
float fragU = square[gl_VertexIndex].x * symbol.width/font.width;
|
|
|
|
float fragV = square[gl_VertexIndex].y * symbol.height/font.height;
|
|
|
|
float x = (square[gl_VertexIndex].x * symbol.width + symbol.left) * character.size / font.width;
|
|
|
|
float y = (square[gl_VertexIndex].y * symbol.height - symbol.top) * character.size / font.height;
|
2024-10-14 14:59:49 -06:00
|
|
|
|
|
|
|
fragUV = vec2(fragU, fragV);
|
2024-10-14 22:10:14 -06:00
|
|
|
fragColor = character.color;
|
2024-10-18 10:02:39 -06:00
|
|
|
gl_Position = ubo.screen * vec4(vec3(x, y, 0.0) + character.pos, 1.0);
|
2024-10-16 20:29:19 -06:00
|
|
|
code = character.code;
|
2024-10-13 22:18:37 -06:00
|
|
|
}
|
|
|
|
|