Source code
Revision control
Copy as Markdown
Other Tools
static const char *hb_gpu_vertex_wgsl =
"/*\n"
" * Copyright (C) 2026 Behdad Esfahbod\n"
" * Copyright (C) 2017 Eric Lengyel\n"
" *\n"
" * Based on the Slug algorithm by Eric Lengyel:\n"
" *\n"
" * This is part of HarfBuzz, a text shaping library.\n"
" *\n"
" * Permission is hereby granted, without written agreement and without\n"
" * license or royalty fees, to use, copy, modify, and distribute this\n"
" * software and its documentation for any purpose, provided that the\n"
" * above copyright notice and the following two paragraphs appear in\n"
" * all copies of this software.\n"
" *\n"
" * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR\n"
" * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES\n"
" * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN\n"
" * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\n"
" * DAMAGE.\n"
" *\n"
" * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,\n"
" * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n"
" * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS\n"
" * ON AN \"AS IS\" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO\n"
" * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.\n"
" */\n"
"\n"
"\n"
"/* Requires WGSL (WebGPU Shading Language). */\n"
"\n"
"\n"
"/* Dilate a glyph vertex by half a pixel on screen.\n"
" *\n"
" * position: object-space vertex position (modified in place)\n"
" * texcoord: em-space sample coordinates (modified in place)\n"
" * normal: object-space outward normal at this vertex\n"
" * jac: inverse of the 2x2 linear part of the em-to-object transform,\n"
" * stored row-major as (j00, j01, j10, j11). Maps object-space\n"
" * displacements back to em-space for texcoord adjustment.\n"
" * For simple scaling with y-flip (the common case):\n"
" * em-to-object = [[s, 0], [0, -s]]\n"
" * jac = (1/s, 0, 0, -1/s)\n"
" * m: model-view-projection matrix\n"
" * viewport: viewport size in pixels\n"
" *\n"
" * Returns (new_position, new_texcoord).\n"
" */\n"
"fn hb_gpu_dilate (position: vec2f, texcoord: vec2f,\n"
" normal: vec2f, jac: vec4f,\n"
" m: mat4x4f, viewport: vec2f) -> array<vec2f, 2>\n"
"{\n"
" let n = normalize (normal);\n"
"\n"
" let clipPos = m * vec4f (position, 0.0, 1.0);\n"
" let clipN = m * vec4f (n, 0.0, 0.0);\n"
"\n"
" let s = clipPos.w;\n"
" let t = clipN.w;\n"
"\n"
" let u = (s * clipN.x - t * clipPos.x) * viewport.x;\n"
" let v = (s * clipN.y - t * clipPos.y) * viewport.y;\n"
"\n"
" let s2 = s * s;\n"
" let st = s * t;\n"
" let uv = u * u + v * v;\n"
"\n"
" let denom = uv - st * st;\n"
" var d: f32;\n"
" if (abs (denom) > 1.0 / 16777216.0) {\n"
" d = s2 * (st + sqrt (uv)) / denom;\n"
" } else {\n"
" d = 0.0;\n"
" }\n"
"\n"
" let dPos = d * normal;\n"
" return array<vec2f, 2> (\n"
" position + dPos,\n"
" texcoord + vec2f (dot (dPos, jac.xy), dot (dPos, jac.zw))\n"
" );\n"
"}\n"
;