Skip to content

Code-first video & image, rendered natively on WebGPU.

fix(text): keep stroke and shadow colours under glyph animators

okanasl69e2ed8cef04
diff --git a/.changeset/glyph-animator-stroke-colour.md b/.changeset/glyph-animator-stroke-colour.md
new file mode 100644
index 00000000..765a50dc
--- /dev/null
+++ b/.changeset/glyph-animator-stroke-colour.md
@@ -0,0 +1,6 @@
+---
+"@framefields/webgpu-renderers": patch
+"framefields": patch
+---
+
+Text with glyph animators keeps its stroke and shadow colours. The animator colour used to start from the base fill and override every pass, so outlined or shadowed text turned into a solid fill-coloured blob; colour animators now start from each glyph's own fill (spans and highlights included) and tint only the fill pass.
diff --git a/packages/webgpu-renderers/src/nodes/paragraph.test.ts b/packages/webgpu-renderers/src/nodes/paragraph.test.ts
index 6e20c4b0..18703179 100644
--- a/packages/webgpu-renderers/src/nodes/paragraph.test.ts
+++ b/packages/webgpu-renderers/src/nodes/paragraph.test.ts
@@ -339,4 +339,41 @@ describe("Paragraph Node", () => {
expect(g).toBe(0);
expect(b).toBe(0);
});
+
+ it("keeps shadow and stroke passes in their own colours under glyph animators", () => {
+ // Each pass reuses one scratch buffer: copy the first glyph's colour at draw time.
+ const colours: number[][] = [];
+ mockCtx.renderer.slugPipeline.draw.mockImplementation(
+ (_pass: unknown, _stack: unknown, _font: unknown, data: Float32Array) => {
+ colours.push(Array.from(data.subarray(16, 19)));
+ },
+ );
+ drawParagraphNode(mockCtx, mockPass, {
+ text: "Outlined",
+ dstRect: { x: 0, y: 0, width: 300, height: 100 },
+ fontFamily: "Inter",
+ fontSize: 32,
+ color: "#00ff00",
+ stroke: "#0000ff",
+ strokeWidth: 3,
+ shadows: [{ color: "#ff0000", offset: { x: 0, y: 4 } }],
+ animators: [
+ {
+ id: "settled-fade",
+ unit: "character" as const,
+ rangeStart: 0,
+ rangeEnd: 0.4,
+ offset: 1,
+ easing: "linear",
+ transform: { opacity: 0 },
+ },
+ ],
+ });
+ // shadow, stroke, fill
+ expect(colours).toEqual([
+ [1, 0, 0],
+ [0, 0, 1],
+ [0, 1, 0],
+ ]);
+ });
});
diff --git a/packages/webgpu-renderers/src/nodes/paragraph.ts b/packages/webgpu-renderers/src/nodes/paragraph.ts
index 8ae0ed79..12e824bf 100644
--- a/packages/webgpu-renderers/src/nodes/paragraph.ts
+++ b/packages/webgpu-renderers/src/nodes/paragraph.ts
@@ -1495,9 +1495,14 @@ export function drawParagraphNode(
}
}
+ // The glyph's own fill: the start of any animator colour sweep.
+ const isHighlighted =
+ props.highlightWordIndex !== undefined &&
+ glyph.wordIndex === props.highlightWordIndex;
+ const spanColor = glyph.fill ? parseColor(glyph.fill) : undefined;
+ let fillColor = isHighlighted ? highlightColor : (spanColor ?? baseColor);
let customScaleX = 1.0;
let customScaleY = 1.0;
- let animatorColor: Color | undefined;
let transZ = 0;
let chromaticShift = 0;
let dissolveProgress = 0;
@@ -1521,7 +1526,7 @@ export function drawParagraphNode(
scaleY: customScaleY,
opacity,
blurAmount,
- color: baseColor,
+ color: fillColor,
},
false,
props.frame ?? 0,
@@ -1538,9 +1543,7 @@ export function drawParagraphNode(
if (blurOverride === undefined) {
blurAmount = kResult.blurAmount;
}
- if (kResult.color) {
- animatorColor = kResult.color;
- }
+ if (kResult.color) fillColor = kResult.color;
if (kResult.lineSpacing !== undefined) {
transY += computeLineLeadingDisplacement(
glyph.lineIndex,
@@ -1577,14 +1580,8 @@ export function drawParagraphNode(
);
}
- const isHighlighted =
- props.highlightWordIndex !== undefined &&
- glyph.wordIndex === props.highlightWordIndex;
- const spanColor = glyph.fill ? parseColor(glyph.fill) : undefined;
- const col =
- animatorColor ??
- colorOverride ??
- (isHighlighted ? highlightColor : (spanColor ?? baseColor));
+ // A stroke or shadow pass paints in its own colour; animators tint the fill.
+ const col = colorOverride ?? fillColor;
const writeInstance = (boldShift: number) => {
const offset = visibleCount * 24;