feat: add text rendering with SDF's

This commit is contained in:
2026-10-17 16:00:51 +02:00
parent 7dd5ee7903
commit 67c685a158
12 changed files with 746 additions and 51 deletions
+18 -10
View File
@@ -7,27 +7,35 @@ layout (location = 0) out vec2 outLocalPos;
layout (location = 1) out vec2 outQuadPos;
layout (location = 2) flat out uint outShapeIndex;
// Room for the antialiased edge outside the shape's bounds
const float EDGE_MARGIN = 1.0;
const vec2 CORNERS[6] = vec2[](
const vec2 QUAD_CORNERS[6] = vec2[](
vec2(-1.0, -1.0), vec2(1.0, -1.0), vec2(1.0, 1.0),
vec2(-1.0, -1.0), vec2(1.0, 1.0), vec2(-1.0, 1.0)
);
vec2 rotate(vec2 position, float angle)
{
float cosAngle = cos(angle);
float sinAngle = sin(angle);
return vec2(
position.x * cosAngle - position.y * sinAngle,
position.x * sinAngle + position.y * cosAngle
);
}
void main()
{
Shape2D shape = pcs.shapeBuffer.shapes[gl_InstanceIndex];
vec2 corner = CORNERS[gl_VertexIndex];
vec2 localPos = corner * (shape.halfSize + EDGE_MARGIN);
vec2 corner = QUAD_CORNERS[gl_VertexIndex];
vec2 localPosition = corner * (shape.halfSize + EDGE_MARGIN);
vec2 screenPosition = shape.center + rotate(localPosition, shape.rotation);
float c = cos(shape.rotation);
float s = sin(shape.rotation);
vec2 rotated = vec2(localPos.x * c - localPos.y * s, localPos.x * s + localPos.y * c);
gl_Position = pcs.projection * vec4(screenPosition, 0.0, 1.0);
gl_Position = pcs.projection * vec4(shape.center + rotated, 0.0, 1.0);
outLocalPos = localPos;
outQuadPos = localPos / max(shape.halfSize, vec2(1e-6)) * 0.5 + 0.5;
outLocalPos = localPosition;
outQuadPos = localPosition / max(shape.halfSize, vec2(1e-6)) * 0.5 + 0.5;
outShapeIndex = gl_InstanceIndex;
}