roleplay/client/shader_src/ui_text.vert

75 lines
1.7 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) out vec4 fragColor;
layout(location = 1) out vec2 fragUV;
layout(location = 2) out uint code;
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),
};
void main() {
Character character = push.pointers.characters.characters[gl_InstanceIndex];
Symbol symbol = font.symbol_list.symbols[character.code];
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;
fragUV = vec2(fragU, fragV);
fragColor = character.color;
gl_Position = ubo.screen * vec4(vec3(x, y, 0.0) + character.pos, 1.0);
code = character.code;
}