| static const char *demo_fragment_glsl = |
| "/*\n" |
| " * Copyright 2026 Behdad Esfahbod. All Rights Reserved.\n" |
| " */\n" |
| "\n" |
| "uniform float u_gamma;\n" |
| "uniform float u_debug;\n" |
| "uniform float u_stem_darkening;\n" |
| "uniform vec4 u_foreground;\n" |
| "\n" |
| "in vec2 v_texcoord;\n" |
| "flat in uint v_glyphLoc;\n" |
| "\n" |
| "out vec4 fragColor;\n" |
| "\n" |
| "void main ()\n" |
| "{\n" |
| " float cov;\n" |
| "#ifdef HB_GPU_DEMO_DRAW\n" |
| " cov = hb_gpu_draw (v_texcoord, v_glyphLoc);\n" |
| " vec4 c = vec4 (u_foreground.rgb * u_foreground.a, u_foreground.a) * cov;\n" |
| "#else\n" |
| " vec4 c = hb_gpu_paint (v_texcoord, v_glyphLoc, u_foreground, cov);\n" |
| "#endif\n" |
| "\n" |
| " /* Apply stem darkening and gamma correction to the edge\n" |
| " * coverage only, so interior color is unaffected. */\n" |
| " if (cov > 0.0 && cov < 1.0)\n" |
| " {\n" |
| " float adj = cov;\n" |
| " if (u_stem_darkening > 0.0)\n" |
| " {\n" |
| " float brightness = c.a > 0.0\n" |
| " ? dot (c.rgb, vec3 (1.0 / 3.0)) / c.a : 0.0;\n" |
| " adj = hb_gpu_stem_darken (adj, brightness,\n" |
| " 1.0 / max (fwidth (v_texcoord).x, fwidth (v_texcoord).y));\n" |
| " }\n" |
| " if (u_gamma != 1.0)\n" |
| " adj = pow (adj, u_gamma);\n" |
| " c *= adj / cov;\n" |
| " }\n" |
| "\n" |
| " if (u_debug > 0.0)\n" |
| " {\n" |
| " ivec2 counts = _hb_gpu_curve_counts (v_texcoord, v_glyphLoc);\n" |
| " float r = clamp (float (counts.x) / 8.0, 0.0, 1.0);\n" |
| " float g = clamp (float (counts.y) / 8.0, 0.0, 1.0);\n" |
| " fragColor = vec4 (r, g, c.a, max (max (r, g), c.a));\n" |
| " return;\n" |
| " }\n" |
| "\n" |
| " fragColor = c;\n" |
| "}\n" |
| ; |