mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-28 09:09:13 +01:00
[gpu] Preserve paint-tree alpha for foreground entries in shaders
When is_foreground was set, the shader replaced the entire baked color with the foreground uniform, discarding the paint-tree alpha encoded in the color's alpha channel. This meant COLRv1 glyphs with a separate alpha on their foreground color sentinel would lose that alpha at render time. Now the shader multiplies the foreground uniform by the baked alpha (ct.a / 32767 for LAYER_SOLID, b.a / 32767 for gradient stops), preserving the paint-tree modulation. Updated all four shader languages (GLSL, HLSL, MSL, WGSL) and regenerated the .hh artifacts. Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
7f333335b1
commit
f546f73b1f
9 files changed
+34
-31
No files matched your search
@@ -40,9 +40,9 @@ static const char *hb_gpu_paint_fragment_glsl =
|
||||
"{\n"
|
||||
" ivec4 a = hb_gpu_fetch (stops_base + i * 2);\n"
|
||||
" offset = float (a.r) / 32767.0;\n"
|
||||
" if ((a.g & 1) != 0)\n"
|
||||
" return foreground;\n"
|
||||
" ivec4 b = hb_gpu_fetch (stops_base + i * 2 + 1);\n"
|
||||
" if ((a.g & 1) != 0)\n"
|
||||
" return foreground * (float (b.a) / 32767.0);\n"
|
||||
" return vec4 (b) / 32767.0;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
@@ -324,7 +324,7 @@ static const char *hb_gpu_paint_fragment_glsl =
|
||||
" int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);\n"
|
||||
" ivec4 ct = hb_gpu_fetch (cursor + 2);\n"
|
||||
" vec4 col = ((aux & 1) != 0)\n"
|
||||
" ? foreground\n"
|
||||
" ? foreground * (float (ct.a) / 32767.0)\n"
|
||||
" : vec4 (ct) / 32767.0;\n"
|
||||
"\n"
|
||||
" float cov = _hb_gpu_layer_coverage (renderCoord, pixelsPerEm,\n"
|
||||
|
||||
@@ -37,9 +37,9 @@ static const char *hb_gpu_paint_fragment_hlsl =
|
||||
"{\n"
|
||||
" int4 a = hb_gpu_fetch (stops_base + i * 2);\n"
|
||||
" offset = (float) a.r / 32767.0;\n"
|
||||
" if ((a.g & 1) != 0)\n"
|
||||
" return foreground;\n"
|
||||
" int4 b = hb_gpu_fetch (stops_base + i * 2 + 1);\n"
|
||||
" if ((a.g & 1) != 0)\n"
|
||||
" return foreground * ((float) b.a / 32767.0);\n"
|
||||
" return (float4) b / 32767.0;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
@@ -271,7 +271,7 @@ static const char *hb_gpu_paint_fragment_hlsl =
|
||||
" int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);\n"
|
||||
" int4 ct = hb_gpu_fetch (cursor + 2);\n"
|
||||
" float4 col = ((aux & 1) != 0)\n"
|
||||
" ? foreground\n"
|
||||
" ? foreground * ((float) ct.a / 32767.0)\n"
|
||||
" : (float4) ct / 32767.0;\n"
|
||||
"\n"
|
||||
" float cov = _hb_gpu_layer_coverage (renderCoord, pixelsPerEm,\n"
|
||||
|
||||
@@ -39,9 +39,9 @@ static const char *hb_gpu_paint_fragment_msl =
|
||||
"{\n"
|
||||
" int4 a = int4 (hb_gpu_atlas[stops_base + i * 2]);\n"
|
||||
" offset = float (a.r) / 32767.0;\n"
|
||||
" if ((a.g & 1) != 0)\n"
|
||||
" return foreground;\n"
|
||||
" int4 b = int4 (hb_gpu_atlas[stops_base + i * 2 + 1]);\n"
|
||||
" if ((a.g & 1) != 0)\n"
|
||||
" return foreground * (float (b.a) / 32767.0);\n"
|
||||
" return float4 (b) / 32767.0;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
@@ -292,7 +292,7 @@ static const char *hb_gpu_paint_fragment_msl =
|
||||
" int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);\n"
|
||||
" int4 ct = int4 (hb_gpu_atlas[cursor + 2]);\n"
|
||||
" float4 col = ((aux & 1) != 0)\n"
|
||||
" ? foreground\n"
|
||||
" ? foreground * (float (ct.a) / 32767.0)\n"
|
||||
" : float4 (ct) / 32767.0;\n"
|
||||
"\n"
|
||||
" float cov = _hb_gpu_layer_coverage (renderCoord, pixelsPerEm,\n"
|
||||
|
||||
@@ -41,10 +41,10 @@ static const char *hb_gpu_paint_fragment_wgsl =
|
||||
"{\n"
|
||||
" let a = hb_gpu_fetch (hb_gpu_atlas, stops_base + i * 2);\n"
|
||||
" *offset = f32 (a.r) / 32767.0;\n"
|
||||
" if ((a.g & 1) != 0) {\n"
|
||||
" return foreground;\n"
|
||||
" }\n"
|
||||
" let b = hb_gpu_fetch (hb_gpu_atlas, stops_base + i * 2 + 1);\n"
|
||||
" if ((a.g & 1) != 0) {\n"
|
||||
" return foreground * (f32 (b.a) / 32767.0);\n"
|
||||
" }\n"
|
||||
" return vec4f (b) / 32767.0;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
@@ -293,7 +293,7 @@ static const char *hb_gpu_paint_fragment_wgsl =
|
||||
" let ct = hb_gpu_fetch (hb_gpu_atlas, cursor + 2);\n"
|
||||
" var col: vec4f;\n"
|
||||
" if ((aux & 1) != 0) {\n"
|
||||
" col = foreground;\n"
|
||||
" col = foreground * (f32 (ct.a) / 32767.0);\n"
|
||||
" } else {\n"
|
||||
" col = vec4f (ct) / 32767.0;\n"
|
||||
" }\n"
|
||||
|
||||
@@ -39,9 +39,9 @@ vec4 _hb_gpu_stop_color (int stops_base, int i, vec4 foreground, out float offse
|
||||
{
|
||||
ivec4 a = hb_gpu_fetch (stops_base + i * 2);
|
||||
offset = float (a.r) / 32767.0;
|
||||
if ((a.g & 1) != 0)
|
||||
return foreground;
|
||||
ivec4 b = hb_gpu_fetch (stops_base + i * 2 + 1);
|
||||
if ((a.g & 1) != 0)
|
||||
return foreground * (float (b.a) / 32767.0);
|
||||
return vec4 (b) / 32767.0;
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ vec4 hb_gpu_paint (vec2 renderCoord, uint glyphLoc, vec4 foreground)
|
||||
int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);
|
||||
ivec4 ct = hb_gpu_fetch (cursor + 2);
|
||||
vec4 col = ((aux & 1) != 0)
|
||||
? foreground
|
||||
? foreground * (float (ct.a) / 32767.0)
|
||||
: vec4 (ct) / 32767.0;
|
||||
|
||||
float cov = _hb_gpu_layer_coverage (renderCoord, pixelsPerEm,
|
||||
|
||||
@@ -36,9 +36,9 @@ float4 _hb_gpu_stop_color (int stops_base, int i, float4 foreground,
|
||||
{
|
||||
int4 a = hb_gpu_fetch (stops_base + i * 2);
|
||||
offset = (float) a.r / 32767.0;
|
||||
if ((a.g & 1) != 0)
|
||||
return foreground;
|
||||
int4 b = hb_gpu_fetch (stops_base + i * 2 + 1);
|
||||
if ((a.g & 1) != 0)
|
||||
return foreground * ((float) b.a / 32767.0);
|
||||
return (float4) b / 32767.0;
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc_, float4 foreground)
|
||||
int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);
|
||||
int4 ct = hb_gpu_fetch (cursor + 2);
|
||||
float4 col = ((aux & 1) != 0)
|
||||
? foreground
|
||||
? foreground * ((float) ct.a / 32767.0)
|
||||
: (float4) ct / 32767.0;
|
||||
|
||||
float cov = _hb_gpu_layer_coverage (renderCoord, pixelsPerEm,
|
||||
|
||||
@@ -38,9 +38,9 @@ static float4 _hb_gpu_stop_color (device const short4* hb_gpu_atlas,
|
||||
{
|
||||
int4 a = int4 (hb_gpu_atlas[stops_base + i * 2]);
|
||||
offset = float (a.r) / 32767.0;
|
||||
if ((a.g & 1) != 0)
|
||||
return foreground;
|
||||
int4 b = int4 (hb_gpu_atlas[stops_base + i * 2 + 1]);
|
||||
if ((a.g & 1) != 0)
|
||||
return foreground * (float (b.a) / 32767.0);
|
||||
return float4 (b) / 32767.0;
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc_, float4 foreground,
|
||||
int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);
|
||||
int4 ct = int4 (hb_gpu_atlas[cursor + 2]);
|
||||
float4 col = ((aux & 1) != 0)
|
||||
? foreground
|
||||
? foreground * (float (ct.a) / 32767.0)
|
||||
: float4 (ct) / 32767.0;
|
||||
|
||||
float cov = _hb_gpu_layer_coverage (renderCoord, pixelsPerEm,
|
||||
|
||||
@@ -40,10 +40,10 @@ fn _hb_gpu_stop_color (hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>,
|
||||
{
|
||||
let a = hb_gpu_fetch (hb_gpu_atlas, stops_base + i * 2);
|
||||
*offset = f32 (a.r) / 32767.0;
|
||||
if ((a.g & 1) != 0) {
|
||||
return foreground;
|
||||
}
|
||||
let b = hb_gpu_fetch (hb_gpu_atlas, stops_base + i * 2 + 1);
|
||||
if ((a.g & 1) != 0) {
|
||||
return foreground * (f32 (b.a) / 32767.0);
|
||||
}
|
||||
return vec4f (b) / 32767.0;
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ fn hb_gpu_paint (renderCoord: vec2f, glyphLoc_: u32, foreground: vec4f,
|
||||
let ct = hb_gpu_fetch (hb_gpu_atlas, cursor + 2);
|
||||
var col: vec4f;
|
||||
if ((aux & 1) != 0) {
|
||||
col = foreground;
|
||||
col = foreground * (f32 (ct.a) / 32767.0);
|
||||
} else {
|
||||
col = vec4f (ct) / 32767.0;
|
||||
}
|
||||
|
||||
+8
-5
@@ -1276,12 +1276,15 @@ hb_gpu_paint_glyph_or_fail (hb_gpu_paint_t *paint,
|
||||
return hb_font_paint_glyph_or_fail (font, glyph,
|
||||
hb_gpu_paint_get_funcs (paint), paint,
|
||||
paint->palette,
|
||||
/* Foreground value is never read
|
||||
* from our encoded blob -- the
|
||||
/* Foreground RGB is not read from
|
||||
* the encoded blob -- the
|
||||
* is_foreground flag routes to the
|
||||
* shader's foreground uniform at
|
||||
* render time -- so any sentinel
|
||||
* works here. */
|
||||
* shader's foreground uniform.
|
||||
* Alpha must be opaque so the
|
||||
* baked color carries only the
|
||||
* paint-tree alpha (which the
|
||||
* shader applies on top of the
|
||||
* uniform). */
|
||||
HB_COLOR (0, 0, 0, 0xff));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user