quakeforge/libs/video/renderer/vulkan/shader/slice.vert
Bill Currie bffe9413b7 [vulkan] Add support for 9-slice rendering
There's no API yet as I need to look into the handling of qpic_t before
I can get any of this into the other renderers (or even vulkan, for that
matter).

However, the current design for slice rendering is based on glyphs (ie,
using instances and vertex pulling), with 3 strips of 3 quads, 16 verts,
and 26 indices (2 reset). Hacky testing seems to work, but real tests
need the API.
2022-11-18 09:44:01 +09:00

34 lines
960 B
GLSL

#version 450
layout (set = 0, binding = 0) uniform Matrices {
mat4 Projection3d;
mat4 View;
mat4 Sky;
mat4 Projection2d;
};
layout (set = 1, binding = 0) uniform textureBuffer glyph_data;
// per instance data
layout (location = 0) in uint glyph_index;
layout (location = 1) in vec4 glyph_color;
layout (location = 2) in vec2 glyph_position;
layout (location = 3) in vec2 glyph_offset; // for 9-slice
// rg -> offset x,y
// ba -> texture u,v
layout (location = 0) out vec2 uv;
layout (location = 1) out vec4 color;
void
main (void)
{
vec2 offset = vec2 ((gl_VertexIndex & 4) >> 2, (gl_VertexIndex & 8) >> 3);
vec4 glyph = texelFetch (glyph_data, int(glyph_index) * 4 + gl_VertexIndex);
// offset stored in glyph components 0 and 1
vec2 position = glyph_position + glyph.xy + offset * glyph_offset;
gl_Position = Projection2d * vec4 (position.xy, 0.0, 1.0);
// texture uv stored in glyph components 2 and 3
uv = glyph.pq;
color = glyph_color;
}