roleplay/client/shader_src/ui_text.vert

68 lines
1.5 KiB
GLSL

#version 450
#extension GL_EXT_buffer_reference : require
struct Symbol {
int top;
uint left;
uint width;
uint height;
uint advance;
};
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 Font {
uint num_symbols;
uint width;
uint height;
SymbolList symbol_list;
} font;
layout(buffer_reference, std430) readonly buffer Pointers {
uint padding[4];
CharacterList characters;
};
layout(std430, push_constant) uniform Push {
Pointers pointers;
} push;
layout(location = 0) in vec2 inVertexPosition;
layout(location = 0) out vec4 fragColor;
layout(location = 1) out vec2 fragUV;
layout(location = 2) out uint code;
void main() {
Character character = push.pointers.characters.characters[gl_InstanceIndex];
Symbol symbol = font.symbol_list.symbols[character.code];
float fragU = inVertexPosition.x * symbol.width/font.width;
float fragV = inVertexPosition.y * symbol.height/font.height;
float x = (inVertexPosition.x * symbol.width + symbol.left) * character.size / font.width;
float y = (inVertexPosition.y * symbol.height - symbol.top) * character.size / font.height;
fragUV = vec2(fragU, fragV);
fragColor = character.color;
gl_Position = ubo.screen * vec4(vec3(x, y, 0.0) + character.pos, 1.0);
code = character.code;
}