-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathharfbuzz.frag
More file actions
57 lines (49 loc) · 1.45 KB
/
Copy pathharfbuzz.frag
File metadata and controls
57 lines (49 loc) · 1.45 KB
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
/*
* Copyright 2026 Behdad Esfahbod. All Rights Reserved.
*/
uniform float u_gamma;
uniform float u_debug;
uniform float u_stem_darkening;
uniform vec4 u_foreground;
uniform float u_runeIdx;
in vec2 v_texcoord;
in float v_runeIdx;
flat in uint v_glyphLoc;
out vec4 fragColor;
void main()
{
float cov;
#ifdef HB_GPU_DEMO_DRAW
cov = hb_gpu_draw(v_texcoord, v_glyphLoc);
vec4 c = vec4(u_foreground.rgb * u_foreground.a, u_foreground.a) * cov;
#else
vec4 c = hb_gpu_paint(v_texcoord, v_glyphLoc, u_foreground, cov);
#endif
/* Apply stem darkening and gamma correction to the edge
* coverage only, so interior color is unaffected. */
if (cov > 0.0 && cov < 1.0)
{
float adj = cov;
if (u_stem_darkening > 0.0)
{
float brightness = c.a > 0.0
? dot(c.rgb, vec3(1.0 / 3.0)) / c.a
: 0.0;
adj = hb_gpu_stem_darken(adj, brightness, 1.0 / max(fwidth(v_texcoord).x, fwidth(v_texcoord).y));
}
if (u_gamma != 1.0)
adj = pow(adj, u_gamma);
c *= adj / cov;
}
if (u_debug > 0.0)
{
ivec2 counts = _hb_gpu_curve_counts(v_texcoord, v_glyphLoc);
float r = clamp(float(counts.x) / 8.0, 0.0, 1.0);
float g = clamp(float(counts.y) / 8.0, 0.0, 1.0);
fragColor = vec4(r, g, c.a, max(max(r, g), c.a));
return;
}
if (c.a == 0 && v_runeIdx == u_runeIdx)
c = vec4(0.0f, 0.0f, 0.0f, 1.0);
fragColor = c;
}