roleplay/client/shader_src/ui_text.vert

61 lines
1.4 KiB
GLSL

#version 450
2024-10-14 14:16:59 -06:00
#extension GL_EXT_buffer_reference : require
struct Symbol {
uint x;
uint top;
uint width;
};
2024-10-14 21:32:21 -06:00
struct Character {
vec3 pos;
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-14 21:32:21 -06:00
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 {
2024-10-14 14:16:59 -06:00
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);
}