-
Notifications
You must be signed in to change notification settings - Fork 15
/
VanillaSignedDistFontFragment.glsl
128 lines (94 loc) · 2.79 KB
/
VanillaSignedDistFontFragment.glsl
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#version 330 core
precision mediump float;
in vec2 texCoordOut;
in vec3 vertexWCS;
in vec3 normalECS;
in vec3 vertexToEyeECS;
in vec3 vertexToLightECS;
out vec4 color;
uniform sampler2D fontTexture;
uniform int effect;
uniform bool useLight;
uniform float lowThreshold;
uniform float highThreshold;
uniform float smoothing;
uniform vec3 baseColor;
uniform vec3 borderColor;
void main (void) {
if ( effect == 0 ) {
// Raw output with interpolation.
color.rgb = baseColor;
color.a = texture( fontTexture, texCoordOut ).r;
}
else if ( effect == 1 ) {
// Softened edge.
color.rgb = baseColor;
color.a = smoothstep( 0.5 - smoothing,
0.5 + smoothing,
texture( fontTexture, texCoordOut ).r );
}
else if ( effect == 2 ) {
// Sharp edge.
float alpha = texture(fontTexture, texCoordOut).r;
if ( alpha >= lowThreshold ) {
color.rgb = baseColor;
color.a = 1.0;
}
else {
color.rgb = baseColor;
color.a = 0.0;
}
}
else if ( effect == 3 ) {
// Sharp edge with outer glow.
float alpha = texture(fontTexture, texCoordOut).r;
if ( alpha >= lowThreshold ) {
color.rgb = baseColor;
color.a = 1.0;
}
else {
color.rgb = borderColor;
color.a = alpha;
}
}
else if ( effect == 4 ) {
// With border.
float alpha = texture(fontTexture, texCoordOut).r;
if ( alpha >= lowThreshold && alpha <= highThreshold ) {
color.rgb = borderColor;
color.a = 1.0;
}
else if ( alpha >= highThreshold ) {
color.rgb = baseColor;
color.a = 1.0;
}
else {
color.rgb = baseColor;
color.a = 0.0;
}
}
else if ( effect == 5 ) {
// Softened edge.
float alpha = texture(fontTexture, texCoordOut).r;
color.rgb = baseColor;
if ( alpha < 0.5) {
color.a = smoothstep( 0.5 - smoothing,
0.5 + smoothing,
alpha );
}
else {
color.a = 0.5 - smoothstep( 0.5 - smoothing,
0.5 + smoothing,
0.75 * alpha );
}
}
else {
// Rect box for debugging
color.rgb = baseColor;
color.a = 1.0;
}
float dist = distance( vertexToLightECS, vec3( 0.0, 0.0, 0.0 ) );
if ( useLight ) {
color.rgb = color.rgb / sqrt(dist);
}
}