blob: 3b1ba712fb43d060cbfdceeec8a6a7cf8255447b (
plain)
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
|
in vec3 vCoord;
in vec2 tCoord;
in vec4 textureBounds;
out vec2 sampleCoord;
out vec2 shadowSampleCoord;
out vec2 alphas;
out vec4 normalizedTextureBounds;
uniform mat4 mvp;
uniform mat4 modelView;
uniform int textureWidth;
uniform int textureHeight;
uniform float fontScale;
uniform vec2 shadowOffset;
float thresholdFunc(float scale)
{
float base = 0.5;
float baseDev = 0.065;
float devScaleMin = 0.15;
float devScaleMax = 0.3;
return base - ((clamp(scale, devScaleMin, devScaleMax) - devScaleMin)
/ (devScaleMax - devScaleMin) * -baseDev + baseDev);
}
float spreadFunc(float scale)
{
return 0.06 / scale;
}
vec2 alphaRange(float scale)
{
float base = thresholdFunc(scale);
float range = spreadFunc(scale);
float alphaMin = max(0.0, base - range);
float alphaMax = min(base + range, 1.0);
return vec2(alphaMin, alphaMax);
}
void main()
{
float scale = fontScale * sqrt(abs(determinant(modelView)));
alphas = alphaRange(scale);
vec2 textureSizeMultiplier = vec2(1.0 / float(textureWidth), 1.0 / float(textureHeight));
sampleCoord = tCoord * textureSizeMultiplier;
shadowSampleCoord = (tCoord - shadowOffset) * textureSizeMultiplier;
normalizedTextureBounds = vec4(textureBounds.xy * textureSizeMultiplier,
textureBounds.zw * textureSizeMultiplier);
gl_Position = mvp * vec4(vCoord, 1.0);
}
|