ultra-text 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -115
- package/dist/assets/{cpuSdf.worker--X1Qpmdp.js → cpuSdf.worker-Dy4P5_TI.js} +98 -43
- package/dist/assets/cpuSdf.worker-Dy4P5_TI.js.map +1 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js +1725 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js.map +1 -0
- package/dist/atlas/appendAtlas.js +35 -11
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +1 -1
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/colorGlyphs.d.ts +0 -10
- package/dist/atlas/colorGlyphs.js +97 -155
- package/dist/atlas/colorGlyphs.js.map +1 -1
- package/dist/atlas/colorTexture.d.ts +1 -0
- package/dist/atlas/colorTexture.js +64 -0
- package/dist/atlas/colorTexture.js.map +1 -0
- package/dist/atlas/cpuAtlas.js +8 -3
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.d.ts +1 -1
- package/dist/atlas/cpuSdf.js +97 -42
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +10 -4
- package/dist/atlas/cpuWorker.js +99 -49
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +133 -56
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +140 -18
- package/dist/atlas/gpuCommon.js +726 -104
- package/dist/atlas/gpuCommon.js.map +1 -1
- package/dist/atlas/jfaWgsl.d.ts +1 -1
- package/dist/atlas/jfaWgsl.js +232 -61
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +22 -0
- package/dist/atlas/rasterize.js +237 -111
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/vanillaCore.js +156 -103
- package/dist/atlas/vanillaCore.js.map +1 -1
- package/dist/atlas/vanillaCpuAtlas.js +37 -52
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -1
- package/dist/atlas/vanillaExtras.js +91 -90
- package/dist/atlas/vanillaExtras.js.map +1 -1
- package/dist/atlas/vanillaGpuHelpers.d.ts +70 -7
- package/dist/atlas/vanillaGpuHelpers.js +262 -27
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -1
- package/dist/dom/DomSdf.js +85 -79
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +23 -18
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/Text.d.ts +4 -1
- package/dist/dom/Text.js +5 -1
- package/dist/dom/Text.js.map +1 -1
- package/dist/dom/browserShaping.js +31 -14
- package/dist/dom/browserShaping.js.map +1 -1
- package/dist/dom/clusters.js +13 -2
- package/dist/dom/clusters.js.map +1 -1
- package/dist/dom/cssEffects.d.ts +4 -0
- package/dist/dom/cssEffects.js +72 -0
- package/dist/dom/cssEffects.js.map +1 -0
- package/dist/dom/domAnalytic.d.ts +1 -2
- package/dist/dom/domAnalytic.js +1 -1
- package/dist/dom/domAnalytic.js.map +1 -1
- package/dist/dom/fontCanvas.d.ts +16 -0
- package/dist/dom/fontCanvas.js +4 -4
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +28 -12
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/markup.d.ts +10 -0
- package/dist/dom/markup.js +16 -1
- package/dist/dom/markup.js.map +1 -1
- package/dist/dom/pretextLayout.js +27 -19
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.d.ts +4 -0
- package/dist/dom/snapshot.js +747 -505
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/snapshotsEqual.d.ts +7 -0
- package/dist/dom/snapshotsEqual.js +68 -0
- package/dist/dom/snapshotsEqual.js.map +1 -0
- package/dist/dom/svgCapture.js +30 -27
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/textTransform.d.ts +13 -1
- package/dist/dom/textTransform.js +31 -13
- package/dist/dom/textTransform.js.map +1 -1
- package/dist/dom/tone.js +15 -8
- package/dist/dom/tone.js.map +1 -1
- package/dist/slug/SlugMaterial.d.ts +6 -0
- package/dist/slug/SlugMaterial.js +48 -20
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/cff.d.ts +5 -0
- package/dist/slug/cff.js +780 -0
- package/dist/slug/cff.js.map +1 -0
- package/dist/slug/coverage.d.ts +3 -3
- package/dist/slug/coverage.js +283 -101
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +1 -1
- package/dist/slug/preprocessCore.js +100 -80
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.js +32 -39
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.js +47 -37
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.d.ts +14 -6
- package/dist/slug/truetype.js +190 -62
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +74 -4
- package/dist/slug/vanillaCore.js +226 -217
- package/dist/slug/vanillaCore.js.map +1 -1
- package/dist/slug-vanilla.d.ts +1 -1
- package/dist/slug-vanilla.js +5 -4
- package/dist/slug.d.ts +1 -1
- package/dist/slug.js +3 -3
- package/dist/text/GlyphTextMaterial.d.ts +5 -0
- package/dist/text/GlyphTextMaterial.js +11 -7
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/RectMaterial.js +6 -10
- package/dist/text/RectMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +9 -3
- package/dist/text/SdfTextMaterial.js +122 -37
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.d.ts +7 -2
- package/dist/text/decorations.js +187 -96
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometryUtils.d.ts +5 -0
- package/dist/text/geometryUtils.js +63 -9
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +1 -1
- package/dist/text/glyphGeometry.js +281 -200
- package/dist/text/glyphGeometry.js.map +1 -1
- package/dist/text/rectGeometry.js +46 -42
- package/dist/text/rectGeometry.js.map +1 -1
- package/dist/text/reflow.d.ts +5 -0
- package/dist/text/reflow.js +127 -68
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +15 -1
- package/dist/text/snap.js +1 -1
- package/dist/text/snap.js.map +1 -1
- package/dist/text/tone.js +2 -2
- package/dist/text/tone.js.map +1 -1
- package/dist/types.d.ts +23 -7
- package/dist/vanilla.js +1 -1
- package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
- package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
- package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
- package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
- package/dist/windfoil/WindfoilMaterial.js +71 -8
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/compositeGeometry.js +12 -5
- package/dist/windfoil/compositeGeometry.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +10 -2
- package/dist/windfoil/coverage.js +147 -59
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/geometry.d.ts +15 -0
- package/dist/windfoil/geometry.js +154 -64
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +8 -8
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/mixed.js +13 -4
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +1 -0
- package/dist/windfoil/preprocessCore.js +63 -36
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.d.ts +1 -1
- package/dist/windfoil/requests.js +11 -4
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/resolveOutline.d.ts +9 -0
- package/dist/windfoil/resolveOutline.js +20 -0
- package/dist/windfoil/resolveOutline.js.map +1 -0
- package/dist/windfoil/runtime.d.ts +1 -0
- package/dist/windfoil/runtime.js +8 -24
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeGeometry.js +80 -34
- package/dist/windfoil/shapeGeometry.js.map +1 -1
- package/dist/windfoil/sizeSwitch.d.ts +1 -1
- package/dist/windfoil/sizeSwitch.js +13 -8
- package/dist/windfoil/sizeSwitch.js.map +1 -1
- package/dist/windfoil/storage.d.ts +23 -9
- package/dist/windfoil/storage.js +49 -30
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/svg/curves.d.ts +20 -0
- package/dist/windfoil/svg/curves.js +145 -42
- package/dist/windfoil/svg/curves.js.map +1 -1
- package/dist/windfoil/svg/document.js +10 -1
- package/dist/windfoil/svg/document.js.map +1 -1
- package/dist/windfoil/svg/pathConverter.js +66 -50
- package/dist/windfoil/svg/pathConverter.js.map +1 -1
- package/dist/windfoil/svg/pathData.d.ts +9 -0
- package/dist/windfoil/svg/pathData.js +142 -109
- package/dist/windfoil/svg/pathData.js.map +1 -1
- package/dist/windfoil/svg/winding.js +34 -10
- package/dist/windfoil/svg/winding.js.map +1 -1
- package/dist/windfoil/trace/contours.js +120 -50
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.js +578 -224
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/traceOutline.worker.d.ts +24 -0
- package/dist/windfoil/trace/traceWorker.d.ts +13 -0
- package/dist/windfoil/trace/traceWorker.js +192 -0
- package/dist/windfoil/trace/traceWorker.js.map +1 -0
- package/dist/windfoil/tracedOutlines.d.ts +2 -0
- package/dist/windfoil/tracedOutlines.js +335 -70
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +48 -29
- package/skills/ultra-text/SKILL.md +9 -10
- package/skills/ultra-text/references/frameworks.md +46 -2
- package/skills/ultra-text/references/three-tsl.md +26 -24
- package/skills/ultra-text/references/vanilla-webgpu.md +3 -1
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GlyphTextMaterial } from "./GlyphTextMaterial.js";
|
|
2
2
|
import { Color, LinearFilter, NearestFilter, Node, Vector2 } from "three/webgpu";
|
|
3
|
-
import { attribute, clamp, dFdx, dFdy, dot, float, max, min, mix, smoothstep, step, texture, uniform, varying, varyingProperty, vec2, vec4 } from "three/tsl";
|
|
3
|
+
import { attribute, clamp, dFdx, dFdy, dot, float, max, min, mix, saturate, smoothstep, step, texture, uniform, varying, varyingProperty, vec2, vec4 } from "three/tsl";
|
|
4
4
|
// src/text/SdfTextMaterial.ts
|
|
5
5
|
/**
|
|
6
6
|
* Whether minified text samples the atlas's mipmaps, whose texels blur the field beyond the
|
|
@@ -25,7 +25,7 @@ var GeometryProbeNode = class extends Node {
|
|
|
25
25
|
return this.positionNode.getNodeType(builder);
|
|
26
26
|
}
|
|
27
27
|
setup(builder) {
|
|
28
|
-
this.probe(builder.geometry ?? null);
|
|
28
|
+
this.probe(builder.geometry ?? null, builder);
|
|
29
29
|
return this.positionNode;
|
|
30
30
|
}
|
|
31
31
|
};
|
|
@@ -35,6 +35,8 @@ var SdfTextMaterial = class extends GlyphTextMaterial {
|
|
|
35
35
|
#sc = uniform(.5);
|
|
36
36
|
#sd = uniform(0);
|
|
37
37
|
#ur = uniform(new Vector2());
|
|
38
|
+
#vc;
|
|
39
|
+
#rl;
|
|
38
40
|
quality;
|
|
39
41
|
get threshold() {
|
|
40
42
|
return this.#th;
|
|
@@ -54,6 +56,39 @@ var SdfTextMaterial = class extends GlyphTextMaterial {
|
|
|
54
56
|
target.shadowCutoff.value = this.#sc.value;
|
|
55
57
|
target.stemDarkening.value = this.#sd.value;
|
|
56
58
|
}
|
|
59
|
+
#isBeautyPass(builder) {
|
|
60
|
+
const mat = builder.material;
|
|
61
|
+
return mat.transparent !== false && !mat.depthWrite && !mat.wireframe && !mat.isShadowPassMaterial && this.maskNode !== this.maskShadowNode;
|
|
62
|
+
}
|
|
63
|
+
/** @internal Skips `vUltraTextLocal` when vertex clipping covers the clip and fills do not read it. */
|
|
64
|
+
needsLocalVarying(builder) {
|
|
65
|
+
return !(this.#vc && !this.#rl && this.#isBeautyPass(builder));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Keeps beauty alpha-blended draws discard-free on TBDR GPUs (`insideClip` gates `colorNode.a`
|
|
69
|
+
* to 0 unless already clipped in vertex), while depth-writing, wireframe, and shadow passes
|
|
70
|
+
* keep `maskNode` early discard.
|
|
71
|
+
*/
|
|
72
|
+
setupDiffuseColor(builder) {
|
|
73
|
+
const dropMask = this.#isBeautyPass(builder);
|
|
74
|
+
const savedMask = dropMask ? this.maskNode : null;
|
|
75
|
+
const savedColor = dropMask ? this.colorNode : null;
|
|
76
|
+
if (dropMask) {
|
|
77
|
+
this.maskNode = null;
|
|
78
|
+
if (savedColor && !this.#vc) {
|
|
79
|
+
const color = savedColor;
|
|
80
|
+
this.colorNode = vec4(color.rgb, this.insideClip.select(color.a, 0).context({ uniformFlow: true }));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
super.setupDiffuseColor(builder);
|
|
85
|
+
} finally {
|
|
86
|
+
if (dropMask) {
|
|
87
|
+
this.maskNode = savedMask;
|
|
88
|
+
this.colorNode = savedColor;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
57
92
|
constructor(options) {
|
|
58
93
|
const outline = options.outline;
|
|
59
94
|
const shadow = options.dropShadow;
|
|
@@ -62,13 +97,17 @@ var SdfTextMaterial = class extends GlyphTextMaterial {
|
|
|
62
97
|
const offsetY = shadow ? shadow.offsetY ?? -2 : 0;
|
|
63
98
|
const outlineOpacity = outline?.opacity ?? 1;
|
|
64
99
|
const shadowOpacity = shadow?.opacity ?? .5;
|
|
100
|
+
const outlineBlur = outline ? outline.blur ?? 0 : 0;
|
|
101
|
+
const shadowBlur = shadow ? shadow.blur ?? 0 : 0;
|
|
65
102
|
if (![
|
|
66
103
|
width,
|
|
67
104
|
offsetX,
|
|
68
105
|
offsetY,
|
|
69
106
|
outlineOpacity,
|
|
70
|
-
shadowOpacity
|
|
71
|
-
|
|
107
|
+
shadowOpacity,
|
|
108
|
+
outlineBlur,
|
|
109
|
+
shadowBlur
|
|
110
|
+
].every(Number.isFinite) || width < 0 || outlineBlur < 0 || shadowBlur < 0) throw new RangeError("SdfTextMaterial: effects require finite values and non-negative outline width and blur");
|
|
72
111
|
const effects = outline !== void 0 || shadow !== void 0;
|
|
73
112
|
const trimmable = !effects && !(options.runMotion ?? options.textShaping === "browser") && !blurred(options.atlas);
|
|
74
113
|
const glyphUvRect = attribute("sdfUvRect", "vec4");
|
|
@@ -102,7 +141,8 @@ var SdfTextMaterial = class extends GlyphTextMaterial {
|
|
|
102
141
|
const uvSpan = glyphUvRect.zw.sub(glyphUvRect.xy);
|
|
103
142
|
if (uvBounds && uvPerLocal) {
|
|
104
143
|
const size = rect.zw.sub(rect.xy).max(1e-6);
|
|
105
|
-
const
|
|
144
|
+
const blurPad = Math.max(outlineBlur, shadowBlur);
|
|
145
|
+
const padding = vec2(width + blurPad + Math.abs(offsetX), width + blurPad + Math.abs(offsetY));
|
|
106
146
|
const extra = quad.mul(2).sub(1).mul(padding);
|
|
107
147
|
uvPerLocal.assign(uvSpan.div(size));
|
|
108
148
|
uvBounds.assign(vec4(min(glyphUvRect.xy, glyphUvRect.zw), max(glyphUvRect.xy, glyphUvRect.zw)));
|
|
@@ -112,33 +152,55 @@ var SdfTextMaterial = class extends GlyphTextMaterial {
|
|
|
112
152
|
return position.add(options.motion === false ? extra : extra.mul(motionScale));
|
|
113
153
|
}
|
|
114
154
|
const material = built.material;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
155
|
+
const hasTrim = !!(material && built.geometry?.hasAttribute("sdfTrim") && !blurred(options.atlas));
|
|
156
|
+
const clipInVertex = built.clipInVertex === true;
|
|
157
|
+
if (hasTrim || clipInVertex) {
|
|
158
|
+
const span = hasTrim ? uvSpan.toConst() : uvSpan;
|
|
159
|
+
let trimLimits = null;
|
|
160
|
+
let inside = null;
|
|
161
|
+
if (hasTrim) {
|
|
162
|
+
const bounds = attribute("sdfTrim", "vec4").sub(glyphUvRect.xyxy).div(vec4(span, span)).toConst();
|
|
163
|
+
const sum = bounds.xy.add(bounds.zw).sub(1).abs().toConst();
|
|
164
|
+
inside = max(sum.x, sum.y).lessThan(1);
|
|
165
|
+
const reach = !built.cast && material.quality === "high" ? material.unitRange.mul(.5).div(span.abs()).toConst() : null;
|
|
166
|
+
trimLimits = saturate(reach ? bounds.add(vec4(reach.negate(), reach)) : bounds).toConst();
|
|
167
|
+
}
|
|
168
|
+
const rectSpan = clipInVertex ? rect.zw.sub(rect.xy).toConst() : rect.zw.sub(rect.xy);
|
|
169
|
+
let trimmed;
|
|
170
|
+
if (clipInVertex) {
|
|
171
|
+
const safeRectSpan = rectSpan.max(1e-6).toConst();
|
|
172
|
+
const clipBounds = attribute("sdfClip", "vec4").sub(rect.xyxy).div(vec4(safeRectSpan, safeRectSpan)).toConst();
|
|
173
|
+
const effTrim = trimLimits && inside ? inside.select(trimLimits, vec4(0, 0, 1, 1)).context({ uniformFlow: true }).toConst() : null;
|
|
174
|
+
const lo = saturate(effTrim ? max(effTrim.xy, clipBounds.xy) : clipBounds.xy).toConst();
|
|
175
|
+
const hi = max(lo, saturate(effTrim ? min(effTrim.zw, clipBounds.zw) : clipBounds.zw)).toConst();
|
|
176
|
+
trimmed = mix(lo, hi, quad).context({ uniformFlow: true }).toConst();
|
|
177
|
+
} else trimmed = inside.select(mix(trimLimits.xy, trimLimits.zw, quad), quad).context({ uniformFlow: true }).toConst();
|
|
124
178
|
fillUv?.assign(trimmed);
|
|
125
179
|
uvVarying.assign(glyphUvRect.xy.add(span.mul(trimmed)));
|
|
126
|
-
if (options.motion === false) return rect.xy.add(
|
|
127
|
-
const step =
|
|
180
|
+
if (options.motion === false) return rect.xy.add(rectSpan.mul(trimmed));
|
|
181
|
+
const step = rectSpan.mul(trimmed.sub(quad));
|
|
128
182
|
return position.add(step.mul(motionScale));
|
|
129
183
|
}
|
|
130
184
|
uvVarying.assign(glyphUvRect.xy.add(uvSpan.mul(quad)));
|
|
131
185
|
}, void 0, paint);
|
|
132
186
|
built.material = this;
|
|
133
|
-
|
|
187
|
+
this.#vc = options.motion === false && !effects && !options.vertex;
|
|
188
|
+
let readsLocal = false;
|
|
189
|
+
this.fillNode?.traverse((node) => {
|
|
190
|
+
if ("name" in node && node.name === "vUltraTextLocal") readsLocal = true;
|
|
191
|
+
});
|
|
192
|
+
this.#rl = readsLocal;
|
|
193
|
+
if (trimmable || this.#vc) {
|
|
134
194
|
const graph = this.positionNode;
|
|
135
|
-
this.positionNode = new GeometryProbeNode(graph, (geometry) => {
|
|
195
|
+
this.positionNode = new GeometryProbeNode(graph, (geometry, builder) => {
|
|
136
196
|
built.geometry = geometry;
|
|
137
197
|
built.cast = false;
|
|
198
|
+
built.clipInVertex = this.#vc && this.#isBeautyPass(builder);
|
|
138
199
|
});
|
|
139
200
|
this.castShadowPositionNode = new GeometryProbeNode(graph, (geometry) => {
|
|
140
201
|
built.geometry = geometry;
|
|
141
202
|
built.cast = true;
|
|
203
|
+
built.clipInVertex = false;
|
|
142
204
|
});
|
|
143
205
|
}
|
|
144
206
|
this.name = "ultra-text TSL runtime SDF text";
|
|
@@ -147,11 +209,13 @@ var SdfTextMaterial = class extends GlyphTextMaterial {
|
|
|
147
209
|
this.stemDarkening.value = Math.max(0, options.stemDarkening ?? 0);
|
|
148
210
|
this.quality = options.quality ?? "standard";
|
|
149
211
|
this.unitRange.value.set(options.pxRange / options.atlasWidth, options.pxRange / options.atlasHeight);
|
|
212
|
+
const uvDxFull = uvBounds ? dFdx(uvVarying).toConst() : null;
|
|
213
|
+
const uvDyFull = uvBounds ? dFdy(uvVarying).toConst() : null;
|
|
150
214
|
const squared = (derivative) => derivative(uvVarying).mul(derivative(uvVarying));
|
|
151
215
|
const screenTextureSize = squared(dFdx).add(squared(dFdy)).max(1e-18).inverseSqrt();
|
|
152
216
|
const local = (node) => effects ? node.toVar() : node.toConst();
|
|
153
217
|
const screenPxRange = local(max(dot(this.unitRange, screenTextureSize).mul(.5), 1));
|
|
154
|
-
const rawStemBoost = this.stemDarkening.mul(
|
|
218
|
+
const rawStemBoost = this.stemDarkening.mul(saturate(float(2).sub(screenPxRange)));
|
|
155
219
|
const stemBoost = local(inBand ? rawStemBoost.mul(inBand.oneMinus()) : rawStemBoost);
|
|
156
220
|
const contour = inBand ? this.threshold.add(inBand.mul(uniform(options.threshold === void 0 ? .015 : 0))) : this.threshold;
|
|
157
221
|
const colour = layer ? this.colorWeight : null;
|
|
@@ -166,34 +230,37 @@ var SdfTextMaterial = class extends GlyphTextMaterial {
|
|
|
166
230
|
smoothed = local(exact ? small.mul(exact.oneMinus()) : small);
|
|
167
231
|
rise = local(min(emPx.mul(tone.dilation.x), tone.dilation.y).mul(smoothed));
|
|
168
232
|
}
|
|
169
|
-
const
|
|
233
|
+
const rawTapScale = this.quality === "high" ? local(max(clamp(min(this.unitRange.x.mul(screenTextureSize.x), this.unitRange.y.mul(screenTextureSize.y)).sub(2.9).mul(10), 0, 1), clamp(float(3.2).sub(screenPxRange).mul(.8), 0, 1)).add(1)) : 1;
|
|
234
|
+
const tapScale = typeof rawTapScale === "number" ? rawTapScale : colour ? local(mix(rawTapScale, float(1), colour)) : rawTapScale;
|
|
235
|
+
const rampAtEmptyField = (edge, lift = stemBoost, steep, scale = 1) => local(min(scale === 1 ? steep ? steep.mul(lift.sub(screenPxRange.mul(edge))).add(.5) : lift.add(.5).sub(screenPxRange.mul(edge)) : steep ? steep.mul(lift.sub(screenPxRange.mul(edge))).mul(scale).add(.5) : lift.sub(screenPxRange.mul(edge)).mul(scale).add(.5), 0));
|
|
170
236
|
const lift = rise ? stemBoost.add(rise) : stemBoost;
|
|
171
237
|
const invClamp = rise ? local(float(1).div(clamp(screenPxRange.sub(rise.mul(2)), .25, 1))) : void 0;
|
|
172
238
|
const inkSlope = invClamp ? local(screenPxRange.mul(invClamp)) : void 0;
|
|
239
|
+
const beautySlope = tapScale === 1 ? inkSlope ?? screenPxRange : local((inkSlope ?? screenPxRange).mul(tapScale));
|
|
173
240
|
const castRamp = rampAtEmptyField(contour);
|
|
174
|
-
const fillRamp = rise || colour ? rampAtEmptyField(inkContour, lift, invClamp) : castRamp;
|
|
175
|
-
const
|
|
241
|
+
const fillRamp = rise || colour || tapScale !== 1 ? rampAtEmptyField(inkContour, lift, invClamp, tapScale) : castRamp;
|
|
242
|
+
const uvDx = this.quality === "high" ? (uvDxFull ? uvDxFull.mul(.125) : dFdx(uvVarying).mul(.125)).toConst() : null;
|
|
243
|
+
const uvDy = this.quality === "high" ? (uvDyFull ? uvDyFull.mul(.125) : dFdy(uvVarying).mul(.125)).toConst() : null;
|
|
244
|
+
const inkUv = rise ? uvVarying.sub((uvDyFull ?? dFdy(uvVarying)).mul(rise)) : uvVarying;
|
|
176
245
|
const coverageAt = (sampleUv) => {
|
|
177
|
-
return distanceCoverage(sampleUv, castRamp, inBand, screenPxRange);
|
|
246
|
+
return distanceCoverage(sampleUv, castRamp, inBand, screenPxRange, false);
|
|
178
247
|
};
|
|
179
|
-
const fieldAt = (sampleUv) => {
|
|
248
|
+
const fieldAt = (sampleUv, useHoistedGrad = true) => {
|
|
180
249
|
const halfTexel = vec2(.5 / options.atlasWidth, .5 / options.atlasHeight);
|
|
181
250
|
const safeUv = uvBounds ? clamp(sampleUv, uvBounds.xy.add(halfTexel), uvBounds.zw.sub(halfTexel)) : sampleUv;
|
|
182
251
|
const sample = texture(options.atlas, safeUv);
|
|
183
|
-
return (uvBounds ? sample.grad(dFdx(uvVarying), dFdy(uvVarying)) : sample).r;
|
|
252
|
+
return (useHoistedGrad && uvDxFull && uvDyFull ? sample.grad(uvDxFull, uvDyFull) : uvBounds ? sample.grad(dFdx(uvVarying), dFdy(uvVarying)) : sample).r;
|
|
184
253
|
};
|
|
185
|
-
const contourAt = (field, ramp = fillRamp, eased = colour ?? inBand, slope =
|
|
254
|
+
const contourAt = (field, ramp = fillRamp, eased = colour ?? inBand, slope = beautySlope) => {
|
|
186
255
|
const across = slope.mul(field).add(ramp);
|
|
187
|
-
const linear =
|
|
256
|
+
const linear = saturate(across);
|
|
188
257
|
return eased ? mix(linear, smoothstep(0, 1, across), eased) : linear;
|
|
189
258
|
};
|
|
190
259
|
const insideCell = (sampleUv, bounds) => sampleUv.x.greaterThanEqual(bounds.x).and(sampleUv.y.greaterThanEqual(bounds.y)).and(sampleUv.x.lessThanEqual(bounds.z)).and(sampleUv.y.lessThanEqual(bounds.w));
|
|
191
|
-
const distanceCoverage = (sampleUv, ramp, eased = colour ?? inBand, slope) => {
|
|
192
|
-
const alpha = contourAt(fieldAt(sampleUv), ramp, eased, slope);
|
|
260
|
+
const distanceCoverage = (sampleUv, ramp, eased = colour ?? inBand, slope, useHoistedGrad = true) => {
|
|
261
|
+
const alpha = contourAt(fieldAt(sampleUv, useHoistedGrad), ramp, eased, slope);
|
|
193
262
|
return uvBounds ? insideCell(sampleUv, uvBounds).select(alpha, 0) : alpha;
|
|
194
263
|
};
|
|
195
|
-
const uvDx = this.quality === "high" ? dFdx(uvVarying).mul(.125).toConst() : null;
|
|
196
|
-
const uvDy = this.quality === "high" ? dFdy(uvVarying).mul(.125).toConst() : null;
|
|
197
264
|
const tapsAround = (sampleUv) => uvDx && uvDy ? [
|
|
198
265
|
sampleUv.sub(uvDx).sub(uvDy.mul(3)),
|
|
199
266
|
sampleUv.add(uvDx.mul(3)).sub(uvDy),
|
|
@@ -209,14 +276,22 @@ var SdfTextMaterial = class extends GlyphTextMaterial {
|
|
|
209
276
|
const toned = this.toned(baked, this.fillNode?.rgb, smoothed, fold);
|
|
210
277
|
return exact && tone ? mix(toned, baked, exact) : toned;
|
|
211
278
|
};
|
|
279
|
+
const blurRamp = (edge, blurLocal) => {
|
|
280
|
+
const halfBlur = local(min(uvPerLocal.x.abs().mul(options.atlasWidth * blurLocal / options.pxRange), max(edge.sub(.01), 0)));
|
|
281
|
+
const slope = local(min(inkSlope ?? screenPxRange, float(.5).div(max(halfBlur, 1e-6))));
|
|
282
|
+
return [slope, local(min(float(.5).sub(slope.mul(edge)), 0))];
|
|
283
|
+
};
|
|
212
284
|
const expansion = outline && uvPerLocal ? min(uvPerLocal.x.abs().mul(options.atlasWidth * width / options.pxRange), .49) : null;
|
|
213
|
-
const
|
|
285
|
+
const outlineEdge = expansion ? inkContour.sub(expansion) : inkContour;
|
|
286
|
+
const softOutline = outline && uvPerLocal && outlineBlur > 0 ? blurRamp(outlineEdge, outlineBlur) : null;
|
|
287
|
+
const outlineRamp = softOutline ? softOutline[1] : expansion ? rampAtEmptyField(outlineEdge, lift, invClamp, tapScale) : fillRamp;
|
|
214
288
|
let coverage;
|
|
215
289
|
let outlined = null;
|
|
216
290
|
if (expansion && uvBounds) {
|
|
217
291
|
const pairs = tapsAround(inkUv).map((tap) => {
|
|
218
292
|
const field = fieldAt(tap);
|
|
219
|
-
|
|
293
|
+
const out = softOutline ? smoothstep(0, 1, softOutline[0].mul(field).add(softOutline[1])) : contourAt(field, outlineRamp);
|
|
294
|
+
return insideCell(tap, uvBounds).select(vec2(contourAt(field), out), vec2(0));
|
|
220
295
|
});
|
|
221
296
|
const sums = (pairs.length === 1 ? pairs[0] : pairs.reduce((sum, pair) => sum.add(pair)).mul(.25)).toVar();
|
|
222
297
|
coverage = sums.x;
|
|
@@ -225,7 +300,7 @@ var SdfTextMaterial = class extends GlyphTextMaterial {
|
|
|
225
300
|
if (effects && uvPerLocal) {
|
|
226
301
|
coverage = coverage.toConst();
|
|
227
302
|
const inked = tone ? ink(coverage, false).toConst() : coverage;
|
|
228
|
-
const fillOpacity = this.fillNode ?
|
|
303
|
+
const fillOpacity = this.fillNode ? saturate(this.fillNode.a) : float(1);
|
|
229
304
|
const fillAlpha = inked.mul(fillOpacity).toConst();
|
|
230
305
|
const fillColor = this.fillNode?.rgb ?? this.baseColor;
|
|
231
306
|
const silhouette = outlined ? outlined.toConst() : inked;
|
|
@@ -235,13 +310,23 @@ var SdfTextMaterial = class extends GlyphTextMaterial {
|
|
|
235
310
|
const rest = options.underlay ? float(1).sub(min((tone ? ink(coverage) : coverage).mul(this.inkAlpha()).mul(fillOpacity), 1)).toConst() : null;
|
|
236
311
|
const flood = rest?.lessThan(.001);
|
|
237
312
|
if (flood) ring = flood.select(outline ? silhouette.mul(ringOpacity) : 0, ring).toConst();
|
|
238
|
-
|
|
313
|
+
let shadowAlpha;
|
|
314
|
+
if (shadow) {
|
|
315
|
+
const shadowUv = inkUv.sub(uvPerLocal.mul(vec2(offsetX, offsetY)));
|
|
316
|
+
let shadowCov;
|
|
317
|
+
if (shadowBlur > 0 && uvBounds) {
|
|
318
|
+
const [shadowSlope, shadowRamp] = blurRamp(inkContour, shadowBlur);
|
|
319
|
+
const taps = tapsAround(shadowUv).map((tap) => insideCell(tap, uvBounds).select(smoothstep(0, 1, shadowSlope.mul(fieldAt(tap)).add(shadowRamp)), 0));
|
|
320
|
+
shadowCov = taps.length === 1 ? taps[0] : taps.reduce((sum, tap) => sum.add(tap)).mul(.25);
|
|
321
|
+
} else shadowCov = filteredCoverage(shadowUv);
|
|
322
|
+
shadowAlpha = shadowCov.mul(Math.min(1, Math.max(0, shadowOpacity))).mul(float(1).sub(flood ? flood.select(ring, glyphAlpha) : glyphAlpha)).toConst();
|
|
323
|
+
} else shadowAlpha = float(0).toConst();
|
|
239
324
|
const alpha = (flood ? ring : glyphAlpha).add(shadowAlpha).toConst();
|
|
240
325
|
const outlineInk = uniform(new Color(outline?.color ?? 0)).mul(ring);
|
|
241
326
|
const rgb = (flood ? outlineInk : fillColor.mul(fillAlpha).add(outlineInk)).add(uniform(new Color(shadow?.color ?? 0)).mul(shadowAlpha)).div(max(alpha, 1e-6));
|
|
242
327
|
const shadowFill = coverageAt(uvVarying).toConst();
|
|
243
|
-
const castOutlineRamp = expansion && (rise || colour) ? rampAtEmptyField(contour.sub(expansion)) : outlineRamp;
|
|
244
|
-
const shadowRing = outline ? max(distanceCoverage(uvVarying, castOutlineRamp, inBand, screenPxRange).sub(shadowFill), 0).mul(ringOpacity) : float(0);
|
|
328
|
+
const castOutlineRamp = expansion && (softOutline || rise || colour || tapScale !== 1) ? rampAtEmptyField(contour.sub(expansion)) : outlineRamp;
|
|
329
|
+
const shadowRing = outline ? max(distanceCoverage(uvVarying, castOutlineRamp, inBand, screenPxRange, false).sub(shadowFill), 0).mul(ringOpacity) : float(0);
|
|
245
330
|
this.applyCoverage(coverage, shadowFill.mul(fillOpacity).add(shadowRing), this.shadowCutoff, vec4(rgb, flood && rest ? alpha.div(flood.select(1, rest)) : alpha), !!flood);
|
|
246
331
|
} else this.applyCoverage(tone ? ink(coverage.toConst()) : coverage, coverageAt(uvVarying), this.shadowCutoff, void 0, !!tone);
|
|
247
332
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SdfTextMaterial.js","names":[],"sources":["../../src/text/SdfTextMaterial.ts"],"sourcesContent":["import {\n Color,\n LinearFilter,\n NearestFilter,\n Node,\n Vector2,\n type NodeBuilder,\n type Texture,\n type UniformNode,\n} from 'three/webgpu'\nimport {\n attribute,\n clamp,\n dFdx,\n dFdy,\n dot,\n float,\n max,\n min,\n mix,\n smoothstep,\n step,\n texture,\n uniform,\n varying,\n varyingProperty,\n vec2,\n vec4,\n} from 'three/tsl'\n\nimport type {\n SdfColorLayer,\n SdfDropShadowOptions,\n SdfOutlineOptions,\n SdfTextQuality,\n} from '../types.js'\nimport {\n GlyphTextMaterial,\n type GlyphTextMaterialOptions,\n type GlyphPaintExtension,\n} from './GlyphTextMaterial.js'\n\n// Effect composition and atlas-cell clamping adapted from pmndrs/glyph (MIT).\n// Copyright (c) 2026 Poimandres. See THIRD_PARTY_NOTICES.md and licenses/GLYPH-MIT.txt.\n\nexport interface SdfTextMaterialOptions extends GlyphTextMaterialOptions {\n /** Companion colour band from SdfAtlas; omitted keeps the original shader graph. */\n colorLayer?: SdfColorLayer\n outline?: SdfOutlineOptions\n dropShadow?: SdfDropShadowOptions\n /** The single-channel distance-field texture, from `SdfAtlas.texture`. */\n atlas: Texture\n /** Atlas width in texels, from `SdfAtlas.width`. */\n atlasWidth: number\n /** Atlas height in texels, from `SdfAtlas.height`. */\n atlasHeight: number\n /** Distance-field pixel range, from `SdfAtlas.pxRange`. */\n pxRange: number\n /** Font size of the atlas bake in texels, from `SdfAtlas.bakeSize`. Defaults to `96`. */\n bakeSize?: number\n /**\n * First texel row of the atlas's monochrome shapes, from `SdfAtlas.shapeTop`: glyphs from\n * that row down keep their baked coverage where text takes a tone. Defaults to none.\n */\n shapeTop?: number | undefined\n /**\n * SDF contour in the atlas encoding. Defaults to `0.5`, the baked outline; colour glyphs\n * then keep `0.515`, which hides the faint shading around some emoji strikes.\n */\n threshold?: number\n /** Coverage required by the shadow silhouette. Defaults to `0.5`. */\n shadowCutoff?: number\n /** `'high'` adds four derivative-offset samples. Defaults to `'standard'`. */\n quality?: SdfTextQuality\n /** Extra weight in screen pixels for glyphs under 16 pixels per em. Defaults to `0`. */\n stemDarkening?: number\n /**\n * @internal Draws the outline ring and drop shadow alone, under analytic text drawn after\n * it with the same coverage: the underlay of the Windfoil and Slug backends. Needs an\n * outline or a drop shadow.\n */\n underlay?: boolean\n}\n\ntype GlyphGeometry = { hasAttribute(name: string): boolean } | null\n\n/**\n * Whether minified text samples the atlas's mipmaps, whose texels blur the field beyond the\n * support box of a slot: about a pixel of faint halo around small glyphs, which only whole\n * quads keep.\n */\nconst blurred = (atlas: Texture): boolean =>\n atlas.minFilter !== LinearFilter &&\n atlas.minFilter !== NearestFilter &&\n (atlas.generateMipmaps || atlas.mipmaps.length > 1)\n\n/**\n * The position graph, with the geometry of the build it is set up in handed over first: the\n * vertex extension is JavaScript run while the graph is set up, and reads the attributes there.\n */\nclass GeometryProbeNode extends Node {\n static readonly type = 'UltraTextGeometryProbeNode'\n\n constructor(\n readonly positionNode: Node,\n readonly probe: (geometry: GlyphGeometry) => void,\n ) {\n super()\n }\n\n override getNodeType(builder: NodeBuilder): string {\n return this.positionNode.getNodeType(builder)\n }\n\n override setup(builder: NodeBuilder): Node {\n this.probe((builder as { geometry?: GlyphGeometry }).geometry ?? null)\n return this.positionNode\n }\n}\n\n/** Retained single-channel SDF text with TSL motion, clipping, and shadows. */\nexport class SdfTextMaterial extends GlyphTextMaterial {\n readonly #th: UniformNode<'float', number> = uniform(0.5)\n readonly #sc: UniformNode<'float', number> = uniform(0.5)\n readonly #sd: UniformNode<'float', number> = uniform(0)\n readonly #ur: UniformNode<'vec2', Vector2> = uniform(new Vector2())\n readonly quality: SdfTextQuality\n\n get threshold(): UniformNode<'float', number> {\n return this.#th\n }\n get shadowCutoff(): UniformNode<'float', number> {\n return this.#sc\n }\n get stemDarkening(): UniformNode<'float', number> {\n return this.#sd\n }\n get unitRange(): UniformNode<'vec2', Vector2> {\n return this.#ur\n }\n\n /** @internal */\n protected override copySubclassUniforms(target: this): void {\n target.threshold.value = this.#th.value\n target.shadowCutoff.value = this.#sc.value\n target.stemDarkening.value = this.#sd.value\n }\n\n constructor(options: SdfTextMaterialOptions) {\n const outline = options.outline\n const shadow = options.dropShadow\n const width = outline ? (outline.width ?? 1) : 0\n const offsetX = shadow ? (shadow.offsetX ?? 2) : 0\n const offsetY = shadow ? (shadow.offsetY ?? -2) : 0\n const outlineOpacity = outline?.opacity ?? 1\n const shadowOpacity = shadow?.opacity ?? 0.5\n if (\n ![width, offsetX, offsetY, outlineOpacity, shadowOpacity].every(Number.isFinite) ||\n width < 0\n ) {\n throw new RangeError(\n 'SdfTextMaterial: effects require finite values and a non-negative outline width',\n )\n }\n const effects = outline !== undefined || shadow !== undefined\n // Whether quads may shrink to their glyphs' support boxes (`sdfTrim`): effect quads reach\n // past the cell, run motion's vertex buffer leaves none for the trim, and mipmaps blur the\n // field past the box.\n const trimmable =\n !effects &&\n !(options.runMotion ?? options.textShaping === 'browser') &&\n !blurred(options.atlas)\n const glyphUvRect = attribute<'vec4'>('sdfUvRect', 'vec4')\n const uvVarying = varyingProperty('vec2', 'vUltraSdfUv')\n const uvBounds = effects ? varyingProperty('vec4', 'vUltraSdfUvBounds') : null\n const uvPerLocal = effects ? varyingProperty('vec2', 'vUltraSdfUvPerLocal') : null\n const layer = options.colorLayer\n const inBand = layer ? varyingProperty('float', 'vUltraColorGlyph') : null\n const bandTop = layer ? uniform((layer.top + 0.5) / options.atlasHeight) : null\n const bandMap = layer\n ? uniform(new Vector2(options.atlasHeight / layer.height, layer.top / layer.height))\n : null\n // Monochrome shapes keep their baked coverage where text takes a tone. Their rows lie\n // below the text and above the colour band, from the one the atlas names; a texture from\n // `buildSdfAtlas` repeats it for a caller that passes no `shapeTop`. Only a shader whose\n // fragment reads the flag carries it, flat from `either` vertex like GlyphTextMaterial's.\n // A toned shader that can trim its quads carries it whether or not the atlas has shapes:\n // without them the row is one below the atlas, which no glyph reaches, so the flag is 0 and\n // the shader is the one a shape atlas uses (the row is a uniform), mixing the exact\n // coverage in at weight 0. Whole quads would pay for that per fragment with nothing back.\n const shapeTop: unknown = options.shapeTop ?? options.atlas.userData['ultraShapeTop']\n const shaped = typeof shapeTop === 'number'\n const inShapes =\n options.tone !== false && (shaped || trimmable)\n ? varying(\n step(\n uniform(((shaped ? shapeTop : options.atlasHeight) + 0.5) / options.atlasHeight),\n min(glyphUvRect.y, glyphUvRect.w),\n ),\n 'vUltraShapeGlyph',\n ).setInterpolation('flat', 'either')\n : null\n const paint: GlyphPaintExtension | undefined = layer\n ? (css) => {\n const halfTexel = vec2(0.5 / options.atlasWidth, 0.5 / options.atlasHeight)\n const safeUv = uvBounds\n ? clamp(uvVarying, uvBounds.xy.add(halfTexel), uvBounds.zw.sub(halfTexel))\n : uvVarying\n const bandUv = vec2(safeUv.x, safeUv.y.mul(bandMap!.x).sub(bandMap!.y))\n const sample = texture(layer.texture, bandUv)\n const scale = vec2(1, bandMap!.x)\n const texel = (\n uvBounds ? sample.grad(dFdx(uvVarying).mul(scale), dFdy(uvVarying).mul(scale)) : sample\n ).toConst()\n const glyph = step(0.5, inBand!).toConst()\n const weight = texel.a.mul(glyph).toConst()\n return { rgb: css.mul(weight.oneMinus()).add(texel.rgb.mul(glyph)), weight }\n }\n : undefined\n // Set once constructed and per build, before the vertex extension below runs.\n const built: { material?: SdfTextMaterial; geometry?: GlyphGeometry; cast?: boolean } = {}\n super(\n options,\n (quad, rect, position, _depth, motionScale, fillUv) => {\n inBand?.assign(step(bandTop!, min(glyphUvRect.y, glyphUvRect.w)))\n const uvSpan = glyphUvRect.zw.sub(glyphUvRect.xy)\n if (uvBounds && uvPerLocal) {\n const size = rect.zw.sub(rect.xy).max(1e-6)\n const padding = vec2(width + Math.abs(offsetX), width + Math.abs(offsetY))\n const extra = quad.mul(2).sub(1).mul(padding)\n uvPerLocal.assign(uvSpan.div(size))\n uvBounds.assign(\n vec4(min(glyphUvRect.xy, glyphUvRect.zw), max(glyphUvRect.xy, glyphUvRect.zw)),\n )\n const expandedQuad = quad.add(extra.div(size))\n fillUv?.assign(expandedQuad)\n uvVarying.assign(glyphUvRect.xy.add(uvSpan.mul(expandedQuad)))\n return position.add(options.motion === false ? extra : extra.mul(motionScale))\n }\n const material = built.material\n if (material && built.geometry?.hasAttribute('sdfTrim') && !blurred(options.atlas)) {\n // Most of a glyph's quad is empty field, which every fragment there samples to no\n // coverage. `sdfTrim` is the slot's support box in the order and units of the UV\n // rect, the macOS rise included: the quad shrinks to it, in quad units. A box outside\n // this instance's slot (a UV rect rewritten to another glyph) leaves the whole quad.\n // 'high' samples a quarter pixel around each fragment: half the field's range more\n // covers that down to about 6 pixels per em at the default bake.\n const trim = attribute<'vec4'>('sdfTrim', 'vec4')\n const span = uvSpan.toConst()\n const bounds = trim.sub(glyphUvRect.xyxy).div(vec4(span, span)).toConst()\n const sum = bounds.xy.add(bounds.zw).sub(1).abs().toConst()\n const inside = max(sum.x, sum.y).lessThan(1)\n const reach =\n !built.cast && material.quality === 'high'\n ? material.unitRange.mul(0.5).div(span.abs()).toConst()\n : null\n const limits = clamp(\n reach ? bounds.add(vec4(reach.negate(), reach)) : bounds,\n 0,\n 1,\n ).toConst()\n const trimmed = inside\n .select(mix(limits.xy, limits.zw, quad), quad)\n .context({ uniformFlow: true })\n .toConst()\n fillUv?.assign(trimmed)\n uvVarying.assign(glyphUvRect.xy.add(span.mul(trimmed)))\n // The quad's own size times the motion's scale: exact for every motion mode, whose\n // centre stays the untrimmed rect's.\n if (options.motion === false) return rect.xy.add(rect.zw.sub(rect.xy).mul(trimmed))\n const step = rect.zw.sub(rect.xy).mul(trimmed.sub(quad))\n return position.add(step.mul(motionScale))\n }\n uvVarying.assign(glyphUvRect.xy.add(uvSpan.mul(quad)))\n },\n undefined,\n paint,\n )\n built.material = this\n // Where quads may be trimmed, the geometry decides: a custom geometry without `sdfTrim`\n // keeps the whole quads and the vertex stage it always had. Glyph geometry with run motion\n // has none. A shadow map samples each fragment's own UV, so its quads keep to the support\n // box itself.\n if (trimmable) {\n const graph = this.positionNode!\n this.positionNode = new GeometryProbeNode(graph, (geometry) => {\n built.geometry = geometry\n built.cast = false\n })\n this.castShadowPositionNode = new GeometryProbeNode(graph, (geometry) => {\n built.geometry = geometry\n built.cast = true\n })\n }\n this.name = 'ultra-text TSL runtime SDF text'\n this.threshold.value = options.threshold ?? 0.5\n this.shadowCutoff.value = Math.min(1, Math.max(0, options.shadowCutoff ?? 0.5))\n this.stemDarkening.value = Math.max(0, options.stemDarkening ?? 0)\n this.quality = options.quality ?? 'standard'\n this.unitRange.value.set(\n options.pxRange / options.atlasWidth,\n options.pxRange / options.atlasHeight,\n )\n\n // Texels per pixel along each atlas axis: one over the length of that axis's screen\n // gradient, as Windfoil's pixel box measures it. `fwidth()` is the footprint's bounding box,\n // which reads text turned in its plane up to √2 smaller than it is: a wider ramp, and a\n // stem darkening and tone size gate that moved with the angle. Axis-aligned text gets the\n // same value. Each derivative is its own node, so the shader gains no local and the vertex\n // stage, which shares their numbering, keeps its text.\n // The floor only guards a zero footprint. A larger one, such as 1e-5 on the gradient, capped\n // the range once a texel spanned more than 1e5 / atlasWidth pixels and blurred magnified\n // edges over several pixels, unevenly on a non-square atlas.\n const squared = (derivative: typeof dFdx) => derivative(uvVarying).mul(derivative(uvVarying))\n const screenTextureSize = squared(dFdx).add(squared(dFdy)).max(1e-18).inverseSqrt()\n // Effect contours revisit shared coverage nodes in several conditional branches.\n // Three r186 can redeclare a toConst() local twice in the same branch; mutable\n // locals hoist that shared calculation. Keep the ordinary text graph unchanged.\n const local = (node: Node<'float'>): Node<'float'> => (effects ? node.toVar() : node.toConst())\n const screenPxRange = local(max(dot(this.unitRange, screenTextureSize).mul(0.5), 1))\n const rawStemBoost = this.stemDarkening.mul(clamp(float(2).sub(screenPxRange), 0, 1))\n const stemBoost = local(inBand ? rawStemBoost.mul(inBand.oneMinus()) : rawStemBoost)\n // Colour glyphs sit a little inside the default contour; an explicit threshold moves both.\n const contour = inBand\n ? this.threshold.add(inBand.mul(uniform(options.threshold === undefined ? 0.015 : 0)))\n : this.threshold\n // A slot of the colour band can hold text beside its colour ink, as a shaped line does\n // beside its emoji. The beauty pass therefore tells the two apart per fragment, by the\n // band's own alpha: 1 around colour ink, 0 around foreground ink. Shadow maps keep the\n // row flag.\n const colour = layer ? this.colorWeight : null\n const inkContour = colour\n ? this.threshold.add(colour.mul(uniform(options.threshold === undefined ? 0.015 : 0)))\n : contour\n // 1 where the baked coverage is kept: a shape's rows or colour ink.\n const exact =\n colour && inShapes && inBand\n ? max(inShapes.mul(inBand.oneMinus()), colour)\n : (colour ?? inShapes)\n // macOS font smoothing, for text ink below the size where the browser stops applying it:\n // the outline grows by d = min(dilationEm ems, dilationPx pixels) to each side, by 2 d\n // upwards and not at all downwards, which is a dilation by d and a rise by d. `smoothed`\n // is 1 where that holds, `rise` is d in screen pixels. Other models add no node here.\n const tone = this.tone\n let smoothed: Node<'float'> | undefined\n let rise: Node<'float'> | undefined\n if (tone?.dilates) {\n const emPx = screenPxRange.mul(uniform((options.bakeSize ?? 96) / options.pxRange)).toConst()\n const small = step(tone.dilation.z, emPx).oneMinus()\n smoothed = local(exact ? small.mul(exact.oneMinus()) : small)\n rise = local(min(emPx.mul(tone.dilation.x), tone.dilation.y).mul(smoothed))\n }\n // The ramp input where the field saturates to 0, the empty rest of the atlas cell, capped\n // at the ramp's foot so that background keeps exactly zero coverage. Uncapped, a glyph a\n // few pixels tall lifted its whole quad to ~3% alpha through stem darkening, and an outline\n // near the range limit to over a third; the mask then kept every fragment of the quad.\n // `lift` moves the contour outwards by that many screen pixels.\n const rampAtEmptyField = (\n edge: Node<'float'>,\n lift: Node<'float'> = stemBoost,\n steep?: Node<'float'>,\n ) =>\n local(\n min(\n steep\n ? steep.mul(lift.sub(screenPxRange.mul(edge))).add(0.5)\n : lift.add(0.5).sub(screenPxRange.mul(edge)),\n 0,\n ),\n )\n // Shadow maps keep the baked contour; only the beauty contour is dilated. A distance field\n // has one offset for every edge: d, which is exact on upright and level strokes.\n const lift = rise ? stemBoost.add(rise) : stemBoost\n // The field reaches zero screenPxRange / 2 pixels outside the contour. Where that is less\n // than the half pixel of ramp plus the dilation, the ramp steepens so that it still starts\n // at the empty field and its middle still lies `rise` outside: s / (s - 2 rise) for s.\n const invClamp = rise\n ? local(float(1).div(clamp(screenPxRange.sub(rise.mul(2)), 0.25, 1)))\n : undefined\n const inkSlope = invClamp ? local(screenPxRange.mul(invClamp)) : undefined\n const castRamp = rampAtEmptyField(contour)\n const fillRamp = rise || colour ? rampAtEmptyField(inkContour, lift, invClamp) : castRamp\n // The rise samples the field that many pixels lower on screen.\n const inkUv = rise ? uvVarying.sub(dFdy(uvVarying).mul(rise)) : uvVarying\n const coverageAt = (sampleUv: Node<'vec2'>): Node<'float'> => {\n return distanceCoverage(sampleUv, castRamp, inBand, screenPxRange)\n }\n // The atlas texel under one sample, read with the glyph's own footprint.\n const fieldAt = (sampleUv: Node<'vec2'>): Node<'float'> => {\n const halfTexel = vec2(0.5 / options.atlasWidth, 0.5 / options.atlasHeight)\n const safeUv = uvBounds\n ? clamp(sampleUv, uvBounds.xy.add(halfTexel), uvBounds.zw.sub(halfTexel))\n : sampleUv\n const sample = texture(options.atlas, safeUv)\n // Clamping changes the implicit derivatives at a cell boundary. Preserve\n // the original footprint so mip/anisotropic filtering cannot form seams.\n return (uvBounds ? sample.grad(dFdx(uvVarying), dFdy(uvVarying)) : sample).r\n }\n // One pixel of linear ramp across the contour: the coverage of a straight edge. Colour\n // glyphs keep the eased ramp, whose shorter foot hides the ink colour around their texels.\n const contourAt = (\n field: Node<'float'>,\n ramp: Node<'float'> = fillRamp,\n eased: Node<'float'> | null = colour ?? inBand,\n slope: Node<'float'> = inkSlope ?? screenPxRange,\n ): Node<'float'> => {\n const across = slope.mul(field).add(ramp)\n const linear = clamp(across, 0, 1)\n return eased ? mix(linear, smoothstep(0, 1, across), eased) : linear\n }\n // Effect quads reach past the glyph's cell; samples there read nothing.\n const insideCell = (sampleUv: Node<'vec2'>, bounds: Node<'vec4'>): Node<'bool'> =>\n sampleUv.x\n .greaterThanEqual(bounds.x)\n .and(sampleUv.y.greaterThanEqual(bounds.y))\n .and(sampleUv.x.lessThanEqual(bounds.z))\n .and(sampleUv.y.lessThanEqual(bounds.w))\n const distanceCoverage = (\n sampleUv: Node<'vec2'>,\n ramp?: Node<'float'>,\n eased: Node<'float'> | null = colour ?? inBand,\n slope?: Node<'float'>,\n ): Node<'float'> => {\n const alpha = contourAt(fieldAt(sampleUv), ramp, eased, slope)\n return uvBounds ? insideCell(sampleUv, uvBounds).select(alpha, 0) : alpha\n }\n const uvDx = this.quality === 'high' ? dFdx(uvVarying).mul(0.125).toConst() : null\n const uvDy = this.quality === 'high' ? dFdy(uvVarying).mul(0.125).toConst() : null\n // 'high' filters a contour over a 4-rook rotated grid (±1/8, ±3/8 px) so horizontal,\n // vertical and diagonal strokes each see four distinct subpixel strata instead of two.\n const tapsAround = (sampleUv: Node<'vec2'>): Node<'vec2'>[] =>\n uvDx && uvDy\n ? [\n sampleUv.sub(uvDx).sub(uvDy.mul(3)),\n sampleUv.add(uvDx.mul(3)).sub(uvDy),\n sampleUv.sub(uvDx.mul(3)).add(uvDy),\n sampleUv.add(uvDx).add(uvDy.mul(3)),\n ]\n : [sampleUv]\n // Filter every beauty contour alike: subtracting differently filtered\n // silhouettes produces a jagged ring, even when its requested width is zero.\n const filteredCoverage = (sampleUv: Node<'vec2'>, ramp?: Node<'float'>): Node<'float'> => {\n const taps = tapsAround(sampleUv).map((tap) => distanceCoverage(tap, ramp))\n if (taps.length === 1) return taps[0]!\n return taps.reduce((sum, tap) => sum.add(tap)).mul(0.25)\n }\n // Text ink is shown at the weight a browser gives it. Shapes, colour glyphs, outline rings,\n // drop shadows and shadow maps keep the exact coverage. `fold` false where the result is\n // composed with a ring and a drop shadow before the ink's alpha.\n const ink = (baked: Node<'float'>, fold = true): Node<'float'> => {\n const toned = this.toned(baked, this.fillNode?.rgb, smoothed, fold)\n return exact && tone ? mix(toned, baked, exact) : toned\n }\n // The field encodes only half of pxRange outside the contour. Clamp the\n // requested expansion so the outline's contour stays inside it; its ramp\n // is capped at the empty field like the fill's.\n const expansion =\n outline && uvPerLocal\n ? min(uvPerLocal.x.abs().mul((options.atlasWidth * width) / options.pxRange), 0.49)\n : null\n const outlineRamp = expansion\n ? rampAtEmptyField(inkContour.sub(expansion), lift, invClamp)\n : fillRamp\n let coverage: Node<'float'>\n let outlined: Node<'float'> | null = null\n if (expansion && uvBounds) {\n // The fill and the outline's silhouette are two contours of the same taps. Each tap is\n // read once, in the one branch that skips taps outside the glyph's cell (most of an\n // effect quad), and gives both contours: component for component the sums of\n // filteredCoverage, in the same order.\n const pairs = tapsAround(inkUv).map((tap) => {\n const field = fieldAt(tap)\n return insideCell(tap, uvBounds).select(\n vec2(contourAt(field), contourAt(field, outlineRamp)),\n vec2(0),\n )\n })\n const sums = (\n pairs.length === 1 ? pairs[0]! : pairs.reduce((sum, pair) => sum.add(pair)).mul(0.25)\n ).toVar()\n coverage = sums.x\n outlined = sums.y\n } else coverage = filteredCoverage(inkUv)\n // Shadow maps filter the finished silhouette; don't supersample that path.\n if (effects && uvPerLocal) {\n coverage = coverage.toConst()\n const inked = tone ? ink(coverage, false).toConst() : coverage\n const fillOpacity = this.fillNode ? clamp(this.fillNode.a, 0, 1) : float(1)\n const fillAlpha = inked.mul(fillOpacity).toConst()\n const fillColor = this.fillNode?.rgb ?? this.baseColor\n const silhouette = outlined ? outlined.toConst() : inked\n const ringOpacity = Math.min(1, Math.max(0, outlineOpacity))\n // The ring is what the exact silhouette shows around the fill as it is drawn.\n let ring = max(silhouette.sub(inked), 0).mul(ringOpacity).toConst()\n const glyphAlpha = fillAlpha.add(ring).toConst()\n // An underlay draws the ring and shadow alone; analytic text then fills the glyph at the\n // alpha k this coverage gives, toned and folded with the ink's alpha as that fill is, and\n // hides k of whatever lies under it. Drawn over the rest, 1 - k, the two draws blend as\n // the one above does, at any ink alpha. Where k is about 1 the fill hides the underlay,\n // and the ring floods the outline's whole silhouette: it covers what an analytic edge\n // leaves bare where the field rounds a corner.\n const rest = options.underlay\n ? float(1)\n .sub(min((tone ? ink(coverage) : coverage).mul(this.inkAlpha()).mul(fillOpacity), 1))\n .toConst()\n : null\n const flood = rest?.lessThan(1e-3)\n if (flood) ring = flood.select(outline ? silhouette.mul(ringOpacity) : 0, ring).toConst()\n const shadowAlpha = (\n shadow\n ? filteredCoverage(inkUv.sub(uvPerLocal.mul(vec2(offsetX, offsetY))))\n .mul(Math.min(1, Math.max(0, shadowOpacity)))\n .mul(float(1).sub(flood ? flood.select(ring, glyphAlpha) : glyphAlpha))\n : float(0)\n ).toConst()\n const alpha = (flood ? ring : glyphAlpha).add(shadowAlpha).toConst()\n const outlineInk = uniform(new Color(outline?.color ?? 0x000000)).mul(ring)\n const rgb = (flood ? outlineInk : fillColor.mul(fillAlpha).add(outlineInk))\n .add(uniform(new Color(shadow?.color ?? 0x000000)).mul(shadowAlpha))\n .div(max(alpha, 1e-6))\n const shadowFill = coverageAt(uvVarying).toConst()\n const castOutlineRamp =\n expansion && (rise || colour) ? rampAtEmptyField(contour.sub(expansion)) : outlineRamp\n const shadowRing = outline\n ? max(\n distanceCoverage(uvVarying, castOutlineRamp, inBand, screenPxRange).sub(shadowFill),\n 0,\n ).mul(ringOpacity)\n : float(0)\n this.applyCoverage(\n coverage,\n shadowFill.mul(fillOpacity).add(shadowRing),\n this.shadowCutoff,\n vec4(rgb, flood && rest ? alpha.div(flood.select(1, rest)) : alpha),\n !!flood,\n )\n } else {\n this.applyCoverage(\n tone ? ink(coverage.toConst()) : coverage,\n coverageAt(uvVarying),\n this.shadowCutoff,\n undefined,\n !!tone,\n )\n }\n }\n}\n"],"mappings":";;;;;;;;;AA2FA,IAAM,WAAW,UACf,MAAM,cAAc,gBACpB,MAAM,cAAc,kBACnB,MAAM,mBAAmB,MAAM,QAAQ,SAAS;;;;;AAMnD,IAAM,oBAAN,cAAgC,KAAK;CAIxB;CACA;CAJX,OAAgB,OAAO;CAEvB,YACE,cACA,OACA;EACA,MAAM;EAHG,KAAA,eAAA;EACA,KAAA,QAAA;CAGX;CAEA,YAAqB,SAA8B;EACjD,OAAO,KAAK,aAAa,YAAY,OAAO;CAC9C;CAEA,MAAe,SAA4B;EACzC,KAAK,MAAO,QAAyC,YAAY,IAAI;EACrE,OAAO,KAAK;CACd;AACF;;AAGA,IAAa,kBAAb,cAAqC,kBAAkB;CACrD,MAA6C,QAAQ,EAAG;CACxD,MAA6C,QAAQ,EAAG;CACxD,MAA6C,QAAQ,CAAC;CACtD,MAA6C,QAAQ,IAAI,QAAQ,CAAC;CAClE;CAEA,IAAI,YAA0C;EAC5C,OAAO,KAAK;CACd;CACA,IAAI,eAA6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CAAC,CAAC,IAAI,IAAI;GAC1E,MAAM,OAAO,QAAQ,aAAa,UAAU,IAAI,SAAS,CAAC,CAAC,IAAI,UAAU,EAAA,CACtE,IAAI,QAAQ,IAAI,MAAM,QAAQ,SAAS,CAAQ,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CACnE,IAAI,IAAI,OAAO,IAAI,CAAC;GACvB,MAAM,aAAa,WAAW,SAAS,CAAC,CAAC,QAAQ;GACjD,MAAM,kBACJ,cAAc,QAAQ,UAAU,iBAAiB,QAAQ,IAAI,SAAS,CAAC,IAAI;GAC7E,MAAM,aAAa,UACf,IACE,iBAAiB,WAAW,iBAAiB,QAAQ,aAAa,CAAC,CAAC,IAAI,UAAU,GAClF,CACF,CAAC,CAAC,IAAI,WAAW,IACjB,MAAM,CAAC;GACX,KAAK,cACH,UACA,WAAW,IAAI,WAAW,CAAC,CAAC,IAAI,UAAU,GAC1C,KAAK,cACL,KAAK,KAAK,SAAS,OAAO,MAAM,IAAI,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,KAAK,GAClE,CAAC,CAAC,KACJ;EACF,OACE,KAAK,cACH,OAAO,IAAI,SAAS,QAAQ,CAAC,IAAI,UACjC,WAAW,SAAS,GACpB,KAAK,cACL,KAAA,GACA,CAAC,CAAC,IACJ;CAEJ;AACF"}
|
|
1
|
+
{"version":3,"file":"SdfTextMaterial.js","names":[],"sources":["../../src/text/SdfTextMaterial.ts"],"sourcesContent":["import {\n Color,\n LinearFilter,\n NearestFilter,\n Node,\n Vector2,\n type NodeBuilder,\n type Texture,\n type UniformNode,\n} from 'three/webgpu'\nimport {\n attribute,\n clamp,\n dFdx,\n dFdy,\n dot,\n float,\n max,\n min,\n mix,\n saturate,\n smoothstep,\n step,\n texture,\n uniform,\n varying,\n varyingProperty,\n vec2,\n vec4,\n} from 'three/tsl'\n\nimport type {\n SdfColorLayer,\n SdfDropShadowOptions,\n SdfOutlineOptions,\n SdfTextQuality,\n} from '../types.js'\nimport {\n GlyphTextMaterial,\n type GlyphTextMaterialOptions,\n type GlyphPaintExtension,\n} from './GlyphTextMaterial.js'\n\n// Effect composition and atlas-cell clamping adapted from pmndrs/glyph (MIT).\n// Copyright (c) 2026 Poimandres. See THIRD_PARTY_NOTICES.md and licenses/GLYPH-MIT.txt.\n\nexport interface SdfTextMaterialOptions extends GlyphTextMaterialOptions {\n /** Companion colour band from SdfAtlas; omitted keeps the original shader graph. */\n colorLayer?: SdfColorLayer\n outline?: SdfOutlineOptions | undefined\n dropShadow?: SdfDropShadowOptions | undefined\n /** The single-channel distance-field texture, from `SdfAtlas.texture`. */\n atlas: Texture\n /** Atlas width in texels, from `SdfAtlas.width`. */\n atlasWidth: number\n /** Atlas height in texels, from `SdfAtlas.height`. */\n atlasHeight: number\n /** Distance-field pixel range, from `SdfAtlas.pxRange`. */\n pxRange: number\n /** Font size of the atlas bake in texels, from `SdfAtlas.bakeSize`. Defaults to `96`. */\n bakeSize?: number\n /**\n * First texel row of the atlas's monochrome shapes, from `SdfAtlas.shapeTop`: glyphs from\n * that row down keep their baked coverage where text takes a tone. Defaults to none.\n */\n shapeTop?: number | undefined\n /**\n * SDF contour in the atlas encoding. Defaults to `0.5`, the baked outline; colour glyphs\n * then keep `0.515`, which hides the faint shading around some emoji strikes.\n */\n threshold?: number\n /** Coverage required by the shadow silhouette. Defaults to `0.5`. */\n shadowCutoff?: number\n /** `'high'` adds four derivative-offset samples. Defaults to `'standard'`. */\n quality?: SdfTextQuality\n /** Extra weight in screen pixels for glyphs under 16 pixels per em. Defaults to `0`. */\n stemDarkening?: number\n /**\n * @internal Draws the outline ring and drop shadow alone, under analytic text drawn after\n * it with the same coverage: the underlay of the Windfoil and Slug backends. Needs an\n * outline or a drop shadow.\n */\n underlay?: boolean\n}\n\ntype GlyphGeometry = { hasAttribute(name: string): boolean } | null\n\n/**\n * Whether minified text samples the atlas's mipmaps, whose texels blur the field beyond the\n * support box of a slot: about a pixel of faint halo around small glyphs, which only whole\n * quads keep.\n */\nconst blurred = (atlas: Texture): boolean =>\n atlas.minFilter !== LinearFilter &&\n atlas.minFilter !== NearestFilter &&\n (atlas.generateMipmaps || atlas.mipmaps.length > 1)\n\n/**\n * The position graph, with the geometry of the build it is set up in handed over first: the\n * vertex extension is JavaScript run while the graph is set up, and reads the attributes there.\n */\nclass GeometryProbeNode extends Node {\n static readonly type = 'UltraTextGeometryProbeNode'\n\n constructor(\n readonly positionNode: Node,\n readonly probe: (geometry: GlyphGeometry, builder: NodeBuilder) => void,\n ) {\n super()\n }\n\n override getNodeType(builder: NodeBuilder): string {\n return this.positionNode.getNodeType(builder)\n }\n\n override setup(builder: NodeBuilder): Node {\n this.probe((builder as { geometry?: GlyphGeometry }).geometry ?? null, builder)\n return this.positionNode\n }\n}\n\n/** Retained single-channel SDF text with TSL motion, clipping, and shadows. */\nexport class SdfTextMaterial extends GlyphTextMaterial {\n readonly #th: UniformNode<'float', number> = uniform(0.5)\n readonly #sc: UniformNode<'float', number> = uniform(0.5)\n readonly #sd: UniformNode<'float', number> = uniform(0)\n readonly #ur: UniformNode<'vec2', Vector2> = uniform(new Vector2())\n readonly #vc: boolean\n readonly #rl: boolean\n readonly quality: SdfTextQuality\n\n get threshold(): UniformNode<'float', number> {\n return this.#th\n }\n get shadowCutoff(): UniformNode<'float', number> {\n return this.#sc\n }\n get stemDarkening(): UniformNode<'float', number> {\n return this.#sd\n }\n get unitRange(): UniformNode<'vec2', Vector2> {\n return this.#ur\n }\n\n /** @internal */\n protected override copySubclassUniforms(target: this): void {\n target.threshold.value = this.#th.value\n target.shadowCutoff.value = this.#sc.value\n target.stemDarkening.value = this.#sd.value\n }\n\n #isBeautyPass(builder: NodeBuilder): boolean {\n const mat = builder.material as {\n depthWrite?: boolean\n wireframe?: boolean\n transparent?: boolean\n isShadowPassMaterial?: boolean\n }\n return (\n mat.transparent !== false &&\n !mat.depthWrite &&\n !mat.wireframe &&\n !mat.isShadowPassMaterial &&\n this.maskNode !== this.maskShadowNode\n )\n }\n\n /** @internal Skips `vUltraTextLocal` when vertex clipping covers the clip and fills do not read it. */\n protected override needsLocalVarying(builder: NodeBuilder): boolean {\n return !(this.#vc && !this.#rl && this.#isBeautyPass(builder))\n }\n\n /**\n * Keeps beauty alpha-blended draws discard-free on TBDR GPUs (`insideClip` gates `colorNode.a`\n * to 0 unless already clipped in vertex), while depth-writing, wireframe, and shadow passes\n * keep `maskNode` early discard.\n */\n override setupDiffuseColor(builder: NodeBuilder): void {\n const dropMask = this.#isBeautyPass(builder)\n const savedMask = dropMask ? this.maskNode : null\n const savedColor = dropMask ? this.colorNode : null\n if (dropMask) {\n this.maskNode = null\n if (savedColor && !this.#vc) {\n const color = savedColor as Node<'vec4'>\n this.colorNode = vec4(\n color.rgb,\n this.insideClip.select(color.a, 0).context({ uniformFlow: true }),\n )\n }\n }\n try {\n super.setupDiffuseColor(builder)\n } finally {\n if (dropMask) {\n this.maskNode = savedMask\n this.colorNode = savedColor\n }\n }\n }\n\n constructor(options: SdfTextMaterialOptions) {\n const outline = options.outline\n const shadow = options.dropShadow\n const width = outline ? (outline.width ?? 1) : 0\n const offsetX = shadow ? (shadow.offsetX ?? 2) : 0\n const offsetY = shadow ? (shadow.offsetY ?? -2) : 0\n const outlineOpacity = outline?.opacity ?? 1\n const shadowOpacity = shadow?.opacity ?? 0.5\n const outlineBlur = outline ? (outline.blur ?? 0) : 0\n const shadowBlur = shadow ? (shadow.blur ?? 0) : 0\n if (\n ![width, offsetX, offsetY, outlineOpacity, shadowOpacity, outlineBlur, shadowBlur].every(\n Number.isFinite,\n ) ||\n width < 0 ||\n outlineBlur < 0 ||\n shadowBlur < 0\n ) {\n throw new RangeError(\n 'SdfTextMaterial: effects require finite values and non-negative outline width and blur',\n )\n }\n const effects = outline !== undefined || shadow !== undefined\n // Whether quads may shrink to their glyphs' support boxes (`sdfTrim`): effect quads reach\n // past the cell, run motion's vertex buffer leaves none for the trim, and mipmaps blur the\n // field past the box.\n const trimmable =\n !effects &&\n !(options.runMotion ?? options.textShaping === 'browser') &&\n !blurred(options.atlas)\n const glyphUvRect = attribute<'vec4'>('sdfUvRect', 'vec4')\n const uvVarying = varyingProperty('vec2', 'vUltraSdfUv')\n const uvBounds = effects ? varyingProperty('vec4', 'vUltraSdfUvBounds') : null\n const uvPerLocal = effects ? varyingProperty('vec2', 'vUltraSdfUvPerLocal') : null\n const layer = options.colorLayer\n const inBand = layer ? varyingProperty('float', 'vUltraColorGlyph') : null\n const bandTop = layer ? uniform((layer.top + 0.5) / options.atlasHeight) : null\n const bandMap = layer\n ? uniform(new Vector2(options.atlasHeight / layer.height, layer.top / layer.height))\n : null\n // Monochrome shapes keep their baked coverage where text takes a tone. Their rows lie\n // below the text and above the colour band, from the one the atlas names; a texture from\n // `buildSdfAtlas` repeats it for a caller that passes no `shapeTop`. Only a shader whose\n // fragment reads the flag carries it, flat from `either` vertex like GlyphTextMaterial's.\n // A toned shader that can trim its quads carries it whether or not the atlas has shapes:\n // without them the row is one below the atlas, which no glyph reaches, so the flag is 0 and\n // the shader is the one a shape atlas uses (the row is a uniform), mixing the exact\n // coverage in at weight 0. Whole quads would pay for that per fragment with nothing back.\n const shapeTop: unknown = options.shapeTop ?? options.atlas.userData['ultraShapeTop']\n const shaped = typeof shapeTop === 'number'\n const inShapes =\n options.tone !== false && (shaped || trimmable)\n ? varying(\n step(\n uniform(((shaped ? shapeTop : options.atlasHeight) + 0.5) / options.atlasHeight),\n min(glyphUvRect.y, glyphUvRect.w),\n ),\n 'vUltraShapeGlyph',\n ).setInterpolation('flat', 'either')\n : null\n const paint: GlyphPaintExtension | undefined = layer\n ? (css) => {\n const halfTexel = vec2(0.5 / options.atlasWidth, 0.5 / options.atlasHeight)\n const safeUv = uvBounds\n ? clamp(uvVarying, uvBounds.xy.add(halfTexel), uvBounds.zw.sub(halfTexel))\n : uvVarying\n const bandUv = vec2(safeUv.x, safeUv.y.mul(bandMap!.x).sub(bandMap!.y))\n const sample = texture(layer.texture, bandUv)\n const scale = vec2(1, bandMap!.x)\n const texel = (\n uvBounds ? sample.grad(dFdx(uvVarying).mul(scale), dFdy(uvVarying).mul(scale)) : sample\n ).toConst()\n const glyph = step(0.5, inBand!).toConst()\n const weight = texel.a.mul(glyph).toConst()\n return { rgb: css.mul(weight.oneMinus()).add(texel.rgb.mul(glyph)), weight }\n }\n : undefined\n // Set once constructed and per build, before the vertex extension below runs.\n const built: {\n material?: SdfTextMaterial\n geometry?: GlyphGeometry\n cast?: boolean\n clipInVertex?: boolean\n } = {}\n super(\n options,\n (quad, rect, position, _depth, motionScale, fillUv) => {\n inBand?.assign(step(bandTop!, min(glyphUvRect.y, glyphUvRect.w)))\n const uvSpan = glyphUvRect.zw.sub(glyphUvRect.xy)\n if (uvBounds && uvPerLocal) {\n const size = rect.zw.sub(rect.xy).max(1e-6)\n const blurPad = Math.max(outlineBlur, shadowBlur)\n const padding = vec2(\n width + blurPad + Math.abs(offsetX),\n width + blurPad + Math.abs(offsetY),\n )\n const extra = quad.mul(2).sub(1).mul(padding)\n uvPerLocal.assign(uvSpan.div(size))\n uvBounds.assign(\n vec4(min(glyphUvRect.xy, glyphUvRect.zw), max(glyphUvRect.xy, glyphUvRect.zw)),\n )\n const expandedQuad = quad.add(extra.div(size))\n fillUv?.assign(expandedQuad)\n uvVarying.assign(glyphUvRect.xy.add(uvSpan.mul(expandedQuad)))\n return position.add(options.motion === false ? extra : extra.mul(motionScale))\n }\n const material = built.material\n const hasTrim = !!(\n material &&\n built.geometry?.hasAttribute('sdfTrim') &&\n !blurred(options.atlas)\n )\n const clipInVertex = built.clipInVertex === true\n if (hasTrim || clipInVertex) {\n const span = hasTrim ? uvSpan.toConst() : uvSpan\n let trimLimits: Node<'vec4'> | null = null\n let inside: Node<'bool'> | null = null\n if (hasTrim) {\n // Most of a glyph's quad is empty field, which every fragment there samples to no\n // coverage. `sdfTrim` is the slot's support box in the order and units of the UV\n // rect, the macOS rise included: the quad shrinks to it, in quad units. A box outside\n // this instance's slot (a UV rect rewritten to another glyph) leaves the whole quad.\n // 'high' samples a quarter pixel around each fragment: half the field's range more\n // covers that down to about 6 pixels per em at the default bake.\n const trim = attribute<'vec4'>('sdfTrim', 'vec4')\n const bounds = trim.sub(glyphUvRect.xyxy).div(vec4(span, span)).toConst()\n const sum = bounds.xy.add(bounds.zw).sub(1).abs().toConst()\n inside = max(sum.x, sum.y).lessThan(1)\n const reach =\n !built.cast && material.quality === 'high'\n ? material.unitRange.mul(0.5).div(span.abs()).toConst()\n : null\n trimLimits = saturate(\n reach ? bounds.add(vec4(reach.negate(), reach)) : bounds,\n ).toConst()\n }\n const rectSpan = clipInVertex ? rect.zw.sub(rect.xy).toConst() : rect.zw.sub(rect.xy)\n let trimmed: Node<'vec2'>\n if (clipInVertex) {\n const safeRectSpan = rectSpan.max(1e-6).toConst()\n const clipBounds = attribute<'vec4'>('sdfClip', 'vec4')\n .sub(rect.xyxy)\n .div(vec4(safeRectSpan, safeRectSpan))\n .toConst()\n const effTrim =\n trimLimits && inside\n ? inside\n .select(trimLimits, vec4(0, 0, 1, 1))\n .context({ uniformFlow: true })\n .toConst()\n : null\n const lo = saturate(effTrim ? max(effTrim.xy, clipBounds.xy) : clipBounds.xy).toConst()\n const hi = max(\n lo,\n saturate(effTrim ? min(effTrim.zw, clipBounds.zw) : clipBounds.zw),\n ).toConst()\n trimmed = mix(lo, hi, quad).context({ uniformFlow: true }).toConst()\n } else {\n trimmed = inside!\n .select(mix(trimLimits!.xy, trimLimits!.zw, quad), quad)\n .context({ uniformFlow: true })\n .toConst()\n }\n fillUv?.assign(trimmed)\n uvVarying.assign(glyphUvRect.xy.add(span.mul(trimmed)))\n // The quad's own size times the motion's scale: exact for every motion mode, whose\n // centre stays the untrimmed rect's.\n if (options.motion === false) return rect.xy.add(rectSpan.mul(trimmed))\n const step = rectSpan.mul(trimmed.sub(quad))\n return position.add(step.mul(motionScale))\n }\n uvVarying.assign(glyphUvRect.xy.add(uvSpan.mul(quad)))\n },\n undefined,\n paint,\n )\n built.material = this\n this.#vc = options.motion === false && !effects && !options.vertex\n let readsLocal = false\n this.fillNode?.traverse((node) => {\n if ('name' in node && node.name === 'vUltraTextLocal') readsLocal = true\n })\n this.#rl = readsLocal\n // Where quads may be trimmed, the geometry decides: a custom geometry without `sdfTrim`\n // keeps the whole quads and the vertex stage it always had. Glyph geometry with run motion\n // has none. A shadow map samples each fragment's own UV, so its quads keep to the support\n // box itself.\n if (trimmable || this.#vc) {\n const graph = this.positionNode!\n this.positionNode = new GeometryProbeNode(graph, (geometry, builder) => {\n built.geometry = geometry\n built.cast = false\n built.clipInVertex = this.#vc && this.#isBeautyPass(builder)\n })\n this.castShadowPositionNode = new GeometryProbeNode(graph, (geometry) => {\n built.geometry = geometry\n built.cast = true\n built.clipInVertex = false\n })\n }\n this.name = 'ultra-text TSL runtime SDF text'\n this.threshold.value = options.threshold ?? 0.5\n this.shadowCutoff.value = Math.min(1, Math.max(0, options.shadowCutoff ?? 0.5))\n this.stemDarkening.value = Math.max(0, options.stemDarkening ?? 0)\n this.quality = options.quality ?? 'standard'\n this.unitRange.value.set(\n options.pxRange / options.atlasWidth,\n options.pxRange / options.atlasHeight,\n )\n\n // Texels per pixel along each atlas axis: one over the length of that axis's screen\n // gradient, as Windfoil's pixel box measures it. `fwidth()` is the footprint's bounding box,\n // which reads text turned in its plane up to √2 smaller than it is: a wider ramp, and a\n // stem darkening and tone size gate that moved with the angle. Axis-aligned text gets the\n // same value. Each derivative is its own node, so the shader gains no local and the vertex\n // stage, which shares their numbering, keeps its text.\n // The floor only guards a zero footprint. A larger one, such as 1e-5 on the gradient, capped\n // the range once a texel spanned more than 1e5 / atlasWidth pixels and blurred magnified\n // edges over several pixels, unevenly on a non-square atlas.\n const uvDxFull = uvBounds ? dFdx(uvVarying).toConst() : null\n const uvDyFull = uvBounds ? dFdy(uvVarying).toConst() : null\n const squared = (derivative: typeof dFdx) => derivative(uvVarying).mul(derivative(uvVarying))\n const screenTextureSize = squared(dFdx).add(squared(dFdy)).max(1e-18).inverseSqrt()\n // Effect contours revisit shared coverage nodes in several conditional branches.\n // Three r186 can redeclare a toConst() local twice in the same branch; mutable\n // locals hoist that shared calculation. Keep the ordinary text graph unchanged.\n const local = (node: Node<'float'>): Node<'float'> => (effects ? node.toVar() : node.toConst())\n const screenPxRange = local(max(dot(this.unitRange, screenTextureSize).mul(0.5), 1))\n const rawStemBoost = this.stemDarkening.mul(saturate(float(2).sub(screenPxRange)))\n const stemBoost = local(inBand ? rawStemBoost.mul(inBand.oneMinus()) : rawStemBoost)\n // Colour glyphs sit a little inside the default contour; an explicit threshold moves both.\n const contour = inBand\n ? this.threshold.add(inBand.mul(uniform(options.threshold === undefined ? 0.015 : 0)))\n : this.threshold\n // A slot of the colour band can hold text beside its colour ink, as a shaped line does\n // beside its emoji. The beauty pass therefore tells the two apart per fragment, by the\n // band's own alpha: 1 around colour ink, 0 around foreground ink. Shadow maps keep the\n // row flag.\n const colour = layer ? this.colorWeight : null\n const inkContour = colour\n ? this.threshold.add(colour.mul(uniform(options.threshold === undefined ? 0.015 : 0)))\n : contour\n // 1 where the baked coverage is kept: a shape's rows or colour ink.\n const exact =\n colour && inShapes && inBand\n ? max(inShapes.mul(inBand.oneMinus()), colour)\n : (colour ?? inShapes)\n // macOS font smoothing, for text ink below the size where the browser stops applying it:\n // the outline grows by d = min(dilationEm ems, dilationPx pixels) to each side, by 2 d\n // upwards and not at all downwards, which is a dilation by d and a rise by d. `smoothed`\n // is 1 where that holds, `rise` is d in screen pixels. Other models add no node here.\n const tone = this.tone\n let smoothed: Node<'float'> | undefined\n let rise: Node<'float'> | undefined\n if (tone?.dilates) {\n const emPx = screenPxRange.mul(uniform((options.bakeSize ?? 96) / options.pxRange)).toConst()\n const small = step(tone.dilation.z, emPx).oneMinus()\n smoothed = local(exact ? small.mul(exact.oneMinus()) : small)\n rise = local(min(emPx.mul(tone.dilation.x), tone.dilation.y).mul(smoothed))\n }\n // The ramp input where the field saturates to 0, the empty rest of the atlas cell, capped\n // at the ramp's foot so that background keeps exactly zero coverage. Uncapped, a glyph a\n // few pixels tall lifted its whole quad to ~3% alpha through stem darkening, and an outline\n // near the range limit to over a third; the mask then kept every fragment of the quad.\n // `lift` moves the contour outwards by that many screen pixels.\n const rawTapScale: number | Node<'float'> =\n this.quality === 'high'\n ? local(\n max(\n clamp(\n min(\n this.unitRange.x.mul(screenTextureSize.x),\n this.unitRange.y.mul(screenTextureSize.y),\n )\n .sub(2.9)\n .mul(10),\n 0,\n 1,\n ),\n clamp(float(3.2).sub(screenPxRange).mul(0.8), 0, 1),\n ).add(1),\n )\n : 1\n const tapScale: number | Node<'float'> =\n typeof rawTapScale === 'number'\n ? rawTapScale\n : colour\n ? local(mix(rawTapScale, float(1), colour))\n : rawTapScale\n const rampAtEmptyField = (\n edge: Node<'float'>,\n lift: Node<'float'> = stemBoost,\n steep?: Node<'float'>,\n scale: number | Node<'float'> = 1,\n ) =>\n local(\n min(\n scale === 1\n ? steep\n ? steep.mul(lift.sub(screenPxRange.mul(edge))).add(0.5)\n : lift.add(0.5).sub(screenPxRange.mul(edge))\n : steep\n ? steep\n .mul(lift.sub(screenPxRange.mul(edge)))\n .mul(scale)\n .add(0.5)\n : lift.sub(screenPxRange.mul(edge)).mul(scale).add(0.5),\n 0,\n ),\n )\n // Shadow maps keep the baked contour; only the beauty contour is dilated. A distance field\n // has one offset for every edge: d, which is exact on upright and level strokes.\n const lift = rise ? stemBoost.add(rise) : stemBoost\n // The field reaches zero screenPxRange / 2 pixels outside the contour. Where that is less\n // than the half pixel of ramp plus the dilation, the ramp steepens so that it still starts\n // at the empty field and its middle still lies `rise` outside: s / (s - 2 rise) for s.\n const invClamp = rise\n ? local(float(1).div(clamp(screenPxRange.sub(rise.mul(2)), 0.25, 1)))\n : undefined\n const inkSlope = invClamp ? local(screenPxRange.mul(invClamp)) : undefined\n const beautySlope =\n tapScale === 1\n ? (inkSlope ?? screenPxRange)\n : local((inkSlope ?? screenPxRange).mul(tapScale))\n const castRamp = rampAtEmptyField(contour)\n const fillRamp =\n rise || colour || tapScale !== 1\n ? rampAtEmptyField(inkContour, lift, invClamp, tapScale)\n : castRamp\n const uvDx =\n this.quality === 'high'\n ? (uvDxFull ? uvDxFull.mul(0.125) : dFdx(uvVarying).mul(0.125)).toConst()\n : null\n const uvDy =\n this.quality === 'high'\n ? (uvDyFull ? uvDyFull.mul(0.125) : dFdy(uvVarying).mul(0.125)).toConst()\n : null\n // The rise samples the field that many pixels lower on screen.\n const inkUv = rise ? uvVarying.sub((uvDyFull ?? dFdy(uvVarying)).mul(rise)) : uvVarying\n const coverageAt = (sampleUv: Node<'vec2'>): Node<'float'> => {\n return distanceCoverage(sampleUv, castRamp, inBand, screenPxRange, false)\n }\n // The atlas texel under one sample, read with the glyph's own footprint.\n const fieldAt = (sampleUv: Node<'vec2'>, useHoistedGrad = true): Node<'float'> => {\n const halfTexel = vec2(0.5 / options.atlasWidth, 0.5 / options.atlasHeight)\n const safeUv = uvBounds\n ? clamp(sampleUv, uvBounds.xy.add(halfTexel), uvBounds.zw.sub(halfTexel))\n : sampleUv\n const sample = texture(options.atlas, safeUv)\n // Clamping changes the implicit derivatives at a cell boundary. Preserve\n // the original footprint so mip/anisotropic filtering cannot form seams.\n return (\n useHoistedGrad && uvDxFull && uvDyFull\n ? sample.grad(uvDxFull, uvDyFull)\n : uvBounds\n ? sample.grad(dFdx(uvVarying), dFdy(uvVarying))\n : sample\n ).r\n }\n // One pixel of linear ramp across the contour: the coverage of a straight edge. Colour\n // glyphs keep the eased ramp, whose shorter foot hides the ink colour around their texels.\n const contourAt = (\n field: Node<'float'>,\n ramp: Node<'float'> = fillRamp,\n eased: Node<'float'> | null = colour ?? inBand,\n slope: Node<'float'> = beautySlope,\n ): Node<'float'> => {\n const across = slope.mul(field).add(ramp)\n const linear = saturate(across)\n return eased ? mix(linear, smoothstep(0, 1, across), eased) : linear\n }\n // Effect quads reach past the glyph's cell; samples there read nothing.\n const insideCell = (sampleUv: Node<'vec2'>, bounds: Node<'vec4'>): Node<'bool'> =>\n sampleUv.x\n .greaterThanEqual(bounds.x)\n .and(sampleUv.y.greaterThanEqual(bounds.y))\n .and(sampleUv.x.lessThanEqual(bounds.z))\n .and(sampleUv.y.lessThanEqual(bounds.w))\n const distanceCoverage = (\n sampleUv: Node<'vec2'>,\n ramp?: Node<'float'>,\n eased: Node<'float'> | null = colour ?? inBand,\n slope?: Node<'float'>,\n useHoistedGrad = true,\n ): Node<'float'> => {\n const alpha = contourAt(fieldAt(sampleUv, useHoistedGrad), ramp, eased, slope)\n return uvBounds ? insideCell(sampleUv, uvBounds).select(alpha, 0) : alpha\n }\n // 'high' filters a contour over a 4-rook rotated grid (±1/8, ±3/8 px) so horizontal,\n // vertical and diagonal strokes each see four distinct subpixel strata instead of two.\n const tapsAround = (sampleUv: Node<'vec2'>): Node<'vec2'>[] =>\n uvDx && uvDy\n ? [\n sampleUv.sub(uvDx).sub(uvDy.mul(3)),\n sampleUv.add(uvDx.mul(3)).sub(uvDy),\n sampleUv.sub(uvDx.mul(3)).add(uvDy),\n sampleUv.add(uvDx).add(uvDy.mul(3)),\n ]\n : [sampleUv]\n // Filter every beauty contour alike: subtracting differently filtered\n // silhouettes produces a jagged ring, even when its requested width is zero.\n const filteredCoverage = (sampleUv: Node<'vec2'>, ramp?: Node<'float'>): Node<'float'> => {\n const taps = tapsAround(sampleUv).map((tap) => distanceCoverage(tap, ramp))\n if (taps.length === 1) return taps[0]!\n return taps.reduce((sum, tap) => sum.add(tap)).mul(0.25)\n }\n // Text ink is shown at the weight a browser gives it. Shapes, colour glyphs, outline rings,\n // drop shadows and shadow maps keep the exact coverage. `fold` false where the result is\n // composed with a ring and a drop shadow before the ink's alpha.\n const ink = (baked: Node<'float'>, fold = true): Node<'float'> => {\n const toned = this.toned(baked, this.fillNode?.rgb, smoothed, fold)\n return exact && tone ? mix(toned, baked, exact) : toned\n }\n // The field encodes only half of pxRange outside the contour. Clamp the\n // requested expansion so the outline's contour stays inside it; its ramp\n // is capped at the empty field like the fill's.\n const blurRamp = (edge: Node<'float'>, blurLocal: number) => {\n const halfBlur = local(\n min(\n uvPerLocal!.x.abs().mul((options.atlasWidth * blurLocal) / options.pxRange),\n max(edge.sub(0.01), 0),\n ),\n )\n const slope = local(min(inkSlope ?? screenPxRange, float(0.5).div(max(halfBlur, 1e-6))))\n const ramp = local(min(float(0.5).sub(slope.mul(edge)), 0))\n return [slope, ramp] as const\n }\n const expansion =\n outline && uvPerLocal\n ? min(uvPerLocal.x.abs().mul((options.atlasWidth * width) / options.pxRange), 0.49)\n : null\n const outlineEdge = expansion ? inkContour.sub(expansion) : inkContour\n const softOutline =\n outline && uvPerLocal && outlineBlur > 0 ? blurRamp(outlineEdge, outlineBlur) : null\n const outlineRamp = softOutline\n ? softOutline[1]\n : expansion\n ? rampAtEmptyField(outlineEdge, lift, invClamp, tapScale)\n : fillRamp\n let coverage: Node<'float'>\n let outlined: Node<'float'> | null = null\n if (expansion && uvBounds) {\n // The fill and the outline's silhouette are two contours of the same taps. Each tap is\n // read once, in the one branch that skips taps outside the glyph's cell (most of an\n // effect quad), and gives both contours: component for component the sums of\n // filteredCoverage, in the same order.\n const pairs = tapsAround(inkUv).map((tap) => {\n const field = fieldAt(tap)\n const out = softOutline\n ? smoothstep(0, 1, softOutline[0].mul(field).add(softOutline[1]))\n : contourAt(field, outlineRamp)\n return insideCell(tap, uvBounds).select(vec2(contourAt(field), out), vec2(0))\n })\n const sums = (\n pairs.length === 1 ? pairs[0]! : pairs.reduce((sum, pair) => sum.add(pair)).mul(0.25)\n ).toVar()\n coverage = sums.x\n outlined = sums.y\n } else coverage = filteredCoverage(inkUv)\n // Shadow maps filter the finished silhouette; don't supersample that path.\n if (effects && uvPerLocal) {\n coverage = coverage.toConst()\n const inked = tone ? ink(coverage, false).toConst() : coverage\n const fillOpacity = this.fillNode ? saturate(this.fillNode.a) : float(1)\n const fillAlpha = inked.mul(fillOpacity).toConst()\n const fillColor = this.fillNode?.rgb ?? this.baseColor\n const silhouette = outlined ? outlined.toConst() : inked\n const ringOpacity = Math.min(1, Math.max(0, outlineOpacity))\n // The ring is what the exact silhouette shows around the fill as it is drawn.\n let ring = max(silhouette.sub(inked), 0).mul(ringOpacity).toConst()\n const glyphAlpha = fillAlpha.add(ring).toConst()\n // An underlay draws the ring and shadow alone; analytic text then fills the glyph at the\n // alpha k this coverage gives, toned and folded with the ink's alpha as that fill is, and\n // hides k of whatever lies under it. Drawn over the rest, 1 - k, the two draws blend as\n // the one above does, at any ink alpha. Where k is about 1 the fill hides the underlay,\n // and the ring floods the outline's whole silhouette: it covers what an analytic edge\n // leaves bare where the field rounds a corner.\n const rest = options.underlay\n ? float(1)\n .sub(min((tone ? ink(coverage) : coverage).mul(this.inkAlpha()).mul(fillOpacity), 1))\n .toConst()\n : null\n const flood = rest?.lessThan(1e-3)\n if (flood) ring = flood.select(outline ? silhouette.mul(ringOpacity) : 0, ring).toConst()\n let shadowAlpha: Node<'float'>\n if (shadow) {\n const shadowUv = inkUv.sub(uvPerLocal.mul(vec2(offsetX, offsetY)))\n let shadowCov: Node<'float'>\n if (shadowBlur > 0 && uvBounds) {\n const [shadowSlope, shadowRamp] = blurRamp(inkContour, shadowBlur)\n const taps = tapsAround(shadowUv).map((tap) =>\n insideCell(tap, uvBounds).select(\n smoothstep(0, 1, shadowSlope.mul(fieldAt(tap)).add(shadowRamp)),\n 0,\n ),\n )\n shadowCov =\n taps.length === 1 ? taps[0]! : taps.reduce((sum, tap) => sum.add(tap)).mul(0.25)\n } else {\n shadowCov = filteredCoverage(shadowUv)\n }\n shadowAlpha = shadowCov\n .mul(Math.min(1, Math.max(0, shadowOpacity)))\n .mul(float(1).sub(flood ? flood.select(ring, glyphAlpha) : glyphAlpha))\n .toConst()\n } else {\n shadowAlpha = float(0).toConst()\n }\n const alpha = (flood ? ring : glyphAlpha).add(shadowAlpha).toConst()\n const outlineInk = uniform(new Color(outline?.color ?? 0x000000)).mul(ring)\n const rgb = (flood ? outlineInk : fillColor.mul(fillAlpha).add(outlineInk))\n .add(uniform(new Color(shadow?.color ?? 0x000000)).mul(shadowAlpha))\n .div(max(alpha, 1e-6))\n const shadowFill = coverageAt(uvVarying).toConst()\n const castOutlineRamp =\n expansion && (softOutline || rise || colour || tapScale !== 1)\n ? rampAtEmptyField(contour.sub(expansion))\n : outlineRamp\n const shadowRing = outline\n ? max(\n distanceCoverage(uvVarying, castOutlineRamp, inBand, screenPxRange, false).sub(\n shadowFill,\n ),\n 0,\n ).mul(ringOpacity)\n : float(0)\n this.applyCoverage(\n coverage,\n shadowFill.mul(fillOpacity).add(shadowRing),\n this.shadowCutoff,\n vec4(rgb, flood && rest ? alpha.div(flood.select(1, rest)) : alpha),\n !!flood,\n )\n } else {\n this.applyCoverage(\n tone ? ink(coverage.toConst()) : coverage,\n coverageAt(uvVarying),\n this.shadowCutoff,\n undefined,\n !!tone,\n )\n }\n }\n}\n"],"mappings":";;;;;;;;;AA4FA,IAAM,WAAW,UACf,MAAM,cAAc,gBACpB,MAAM,cAAc,kBACnB,MAAM,mBAAmB,MAAM,QAAQ,SAAS;;;;;AAMnD,IAAM,oBAAN,cAAgC,KAAK;CAIxB;CACA;CAJX,OAAgB,OAAO;CAEvB,YACE,cACA,OACA;EACA,MAAM;EAHG,KAAA,eAAA;EACA,KAAA,QAAA;CAGX;CAEA,YAAqB,SAA8B;EACjD,OAAO,KAAK,aAAa,YAAY,OAAO;CAC9C;CAEA,MAAe,SAA4B;EACzC,KAAK,MAAO,QAAyC,YAAY,MAAM,OAAO;EAC9E,OAAO,KAAK;CACd;AACF;;AAGA,IAAa,kBAAb,cAAqC,kBAAkB;CACrD,MAA6C,QAAQ,EAAG;CACxD,MAA6C,QAAQ,EAAG;CACxD,MAA6C,QAAQ,CAAC;CACtD,MAA6C,QAAQ,IAAI,QAAQ,CAAC;CAClE;CACA;CACA;CAEA,IAAI,YAA0C;EAC5C,OAAO,KAAK;CACd;CACA,IAAI,eAA6C;EAC/C,OAAO,KAAK;CACd;CACA,IAAI,gBAA8C;EAChD,OAAO,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stancedBufferGeometry } from 'three/webgpu';
|
|
1
|
+
import { InstancedBufferGeometry, type NodeBuilder } from 'three/webgpu';
|
|
2
2
|
import type { DomLayoutSnapshot } from '../types.js';
|
|
3
3
|
import { GlyphTextMaterial, type GlyphTextMaterialOptions } from './GlyphTextMaterial.js';
|
|
4
4
|
export declare const GLYPH_RECTS_KEY = "ultraGlyphRects";
|
|
5
5
|
export declare function glyphRectTable(geometry: InstancedBufferGeometry): ArrayLike<number>;
|
|
6
6
|
/** Decoration quads share their source glyph's motion center, index, and clip. */
|
|
7
7
|
export declare class TextDecorationMaterial extends GlyphTextMaterial {
|
|
8
|
+
/**
|
|
9
|
+
* Keeps beauty alpha-blended draws discard-free on TBDR GPUs (`insideClip` gates `colorNode.a`
|
|
10
|
+
* to 0), while depth-writing, wireframe, opaque, and shadow passes retain `maskNode` discard.
|
|
11
|
+
*/
|
|
12
|
+
setupDiffuseColor(builder: NodeBuilder): void;
|
|
8
13
|
constructor(options: GlyphTextMaterialOptions);
|
|
9
14
|
}
|
|
10
15
|
/**
|
|
11
|
-
* True when an existing decoration batch can
|
|
16
|
+
* True when an existing decoration batch can reuse its instance buffers.
|
|
12
17
|
* A null geometry matches only an empty decoration list.
|
|
13
18
|
*/
|
|
14
19
|
export declare function canUpdateDecorationGeometry(geometry: InstancedBufferGeometry | null, snapshot: DomLayoutSnapshot, drawable: (key: string) => boolean): boolean;
|