-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtxt.vert
70 lines (57 loc) · 2.01 KB
/
txt.vert
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#version 460
#define StageVertex
#include "config.h"
struct txtquad {
mat4 model; // (align 16) 64 +
vec4 rgba; // (align 16) 16 +
// uint pad[3]; // (align 4) (4 * 3
vec3 pad; // (align 16) OR 12) +
uint value; // (align 4) 4 = 96
}; // (align 16) 96 % 16 == 0
layout(set = SetUniform, binding = BindingUniform) uniform Uniform {
mat4 viewproj;
bool invertY;
} txtUniform;
layout(set = SetStorage, binding = BindingStorage) readonly buffer Storage {
txtquad quad[Quads];
} txtStorage;
const float WorldMin = 0.f;
const float WorldMax = QuadSize;
// NOTE QuadTopology, triangle strip with 2 triangles
const vec4 World[QuadVertices] =
{ { WorldMin, WorldMin, 0, 1 } // regular origin
, { WorldMax, WorldMin, 0, 1 }
, { WorldMin, WorldMax, 0, 1 } // Y-inverted orgin
, { WorldMax, WorldMax, 0, 1 } };
// Clipping helps with edge artifacts when rasterizing.
// Glyphs share edges in the font image.
const float Clipping = .002f;
// Unnormalized texel size of a quad is [1, 1].
const float StUnormMin = 0.f + Clipping;
const float StUnormMax = 1.f - Clipping;
// Unnormalized texel size of the font image is [FontQuads, FontQuads].
const uint FontQuads = FontPoints / QuadPoints;
const float StNorm = float(QuadPoints) / float(FontPoints);
void main() {
txtquad quad = txtStorage.quad[gl_InstanceIndex];
gl_Position = txtUniform.viewproj * quad.model * World[gl_VertexIndex];
rgba = quad.rgba;
// Map texture upside down if Y-inverted
float StUnormMinY;
float StUnormMaxY;
if (txtUniform.invertY) {
StUnormMinY = StUnormMax;
StUnormMaxY = StUnormMin;
} else {
StUnormMinY = StUnormMin;
StUnormMaxY = StUnormMax;
}
vec2 WorldToStUnorm[QuadVertices] =
{ { StUnormMin, StUnormMinY } // regular origin
, { StUnormMax, StUnormMinY }
, { StUnormMin, StUnormMaxY } // Y-inverted origin
, { StUnormMax, StUnormMaxY } };
vec2 stUnormOrigin = { quad.value % FontQuads
, quad.value / FontQuads };
st = (stUnormOrigin + WorldToStUnorm[gl_VertexIndex]) * StNorm;
}