ultra-text 1.0.1 → 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.
Files changed (237) hide show
  1. package/README.md +339 -1039
  2. package/dist/assets/cpuSdf.worker-Dy4P5_TI.js +466 -0
  3. package/dist/assets/cpuSdf.worker-Dy4P5_TI.js.map +1 -0
  4. package/dist/assets/traceOutline.worker-B5uVKmR4.js +1725 -0
  5. package/dist/assets/traceOutline.worker-B5uVKmR4.js.map +1 -0
  6. package/dist/atlas/appendAtlas.js +97 -31
  7. package/dist/atlas/appendAtlas.js.map +1 -1
  8. package/dist/atlas/buildAtlas.js +4 -3
  9. package/dist/atlas/buildAtlas.js.map +1 -1
  10. package/dist/atlas/colorGlyphs.d.ts +0 -10
  11. package/dist/atlas/colorGlyphs.js +97 -155
  12. package/dist/atlas/colorGlyphs.js.map +1 -1
  13. package/dist/atlas/colorTexture.d.ts +1 -0
  14. package/dist/atlas/colorTexture.js +64 -0
  15. package/dist/atlas/colorTexture.js.map +1 -0
  16. package/dist/atlas/cpuAtlas.d.ts +4 -1
  17. package/dist/atlas/cpuAtlas.js +14 -7
  18. package/dist/atlas/cpuAtlas.js.map +1 -1
  19. package/dist/atlas/cpuSdf.d.ts +1 -1
  20. package/dist/atlas/cpuSdf.js +235 -68
  21. package/dist/atlas/cpuSdf.js.map +1 -1
  22. package/dist/atlas/cpuWorker.d.ts +11 -3
  23. package/dist/atlas/cpuWorker.js +179 -22
  24. package/dist/atlas/cpuWorker.js.map +1 -1
  25. package/dist/atlas/gpuAtlas.js +188 -287
  26. package/dist/atlas/gpuAtlas.js.map +1 -1
  27. package/dist/atlas/gpuCommon.d.ts +257 -0
  28. package/dist/atlas/gpuCommon.js +845 -0
  29. package/dist/atlas/gpuCommon.js.map +1 -0
  30. package/dist/atlas/jfaWgsl.d.ts +1 -1
  31. package/dist/atlas/jfaWgsl.js +226 -249
  32. package/dist/atlas/jfaWgsl.js.map +1 -1
  33. package/dist/atlas/rasterize.d.ts +22 -0
  34. package/dist/atlas/rasterize.js +329 -158
  35. package/dist/atlas/rasterize.js.map +1 -1
  36. package/dist/atlas/shapeRaster.js +2 -1
  37. package/dist/atlas/shapeRaster.js.map +1 -1
  38. package/dist/atlas/vanillaBounds.d.ts +64 -0
  39. package/dist/atlas/vanillaBounds.js +42 -0
  40. package/dist/atlas/vanillaBounds.js.map +1 -0
  41. package/dist/atlas/vanillaCore.d.ts +100 -0
  42. package/dist/atlas/vanillaCore.js +1065 -0
  43. package/dist/atlas/vanillaCore.js.map +1 -0
  44. package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
  45. package/dist/atlas/vanillaCpuAtlas.js +72 -0
  46. package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
  47. package/dist/atlas/vanillaExtras.d.ts +8 -0
  48. package/dist/atlas/vanillaExtras.js +167 -0
  49. package/dist/atlas/vanillaExtras.js.map +1 -0
  50. package/dist/atlas/vanillaGpuHelpers.d.ts +295 -0
  51. package/dist/atlas/vanillaGpuHelpers.js +354 -0
  52. package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
  53. package/dist/dom/DomSdf.js +243 -297
  54. package/dist/dom/DomSdf.js.map +1 -1
  55. package/dist/dom/DomSlug.js +94 -165
  56. package/dist/dom/DomSlug.js.map +1 -1
  57. package/dist/dom/Text.d.ts +4 -1
  58. package/dist/dom/Text.js +5 -1
  59. package/dist/dom/Text.js.map +1 -1
  60. package/dist/dom/browserShaping.js +31 -14
  61. package/dist/dom/browserShaping.js.map +1 -1
  62. package/dist/dom/clusters.js +13 -2
  63. package/dist/dom/clusters.js.map +1 -1
  64. package/dist/dom/cssEffects.d.ts +4 -0
  65. package/dist/dom/cssEffects.js +72 -0
  66. package/dist/dom/cssEffects.js.map +1 -0
  67. package/dist/dom/domAnalytic.d.ts +53 -0
  68. package/dist/dom/domAnalytic.js +282 -0
  69. package/dist/dom/domAnalytic.js.map +1 -0
  70. package/dist/dom/domExtras.d.ts +27 -0
  71. package/dist/dom/domExtras.js +137 -0
  72. package/dist/dom/domExtras.js.map +1 -0
  73. package/dist/dom/fontCanvas.d.ts +16 -0
  74. package/dist/dom/fontCanvas.js +31 -13
  75. package/dist/dom/fontCanvas.js.map +1 -1
  76. package/dist/dom/layoutSignature.js +175 -57
  77. package/dist/dom/layoutSignature.js.map +1 -1
  78. package/dist/dom/markup.d.ts +10 -0
  79. package/dist/dom/markup.js +16 -1
  80. package/dist/dom/markup.js.map +1 -1
  81. package/dist/dom/pretextLayout.js +78 -28
  82. package/dist/dom/pretextLayout.js.map +1 -1
  83. package/dist/dom/snapshot.d.ts +4 -0
  84. package/dist/dom/snapshot.js +891 -484
  85. package/dist/dom/snapshot.js.map +1 -1
  86. package/dist/dom/snapshotsEqual.d.ts +7 -0
  87. package/dist/dom/snapshotsEqual.js +68 -0
  88. package/dist/dom/snapshotsEqual.js.map +1 -0
  89. package/dist/dom/svgCapture.d.ts +8 -1
  90. package/dist/dom/svgCapture.js +105 -28
  91. package/dist/dom/svgCapture.js.map +1 -1
  92. package/dist/dom/textTransform.d.ts +13 -1
  93. package/dist/dom/textTransform.js +31 -13
  94. package/dist/dom/textTransform.js.map +1 -1
  95. package/dist/dom/tone.js +91 -44
  96. package/dist/dom/tone.js.map +1 -1
  97. package/dist/index.js +4 -3
  98. package/dist/slug/SlugMaterial.d.ts +17 -3
  99. package/dist/slug/SlugMaterial.js +98 -26
  100. package/dist/slug/SlugMaterial.js.map +1 -1
  101. package/dist/slug/cff.d.ts +5 -0
  102. package/dist/slug/cff.js +780 -0
  103. package/dist/slug/cff.js.map +1 -0
  104. package/dist/slug/coverage.d.ts +19 -15
  105. package/dist/slug/coverage.js +380 -225
  106. package/dist/slug/coverage.js.map +1 -1
  107. package/dist/slug/preprocessCore.d.ts +6 -2
  108. package/dist/slug/preprocessCore.js +199 -148
  109. package/dist/slug/preprocessCore.js.map +1 -1
  110. package/dist/slug/runtime.d.ts +1 -0
  111. package/dist/slug/runtime.js +113 -74
  112. package/dist/slug/runtime.js.map +1 -1
  113. package/dist/slug/standaloneRuntime.d.ts +3 -2
  114. package/dist/slug/standaloneRuntime.js +112 -67
  115. package/dist/slug/standaloneRuntime.js.map +1 -1
  116. package/dist/slug/truetype.d.ts +14 -6
  117. package/dist/slug/truetype.js +356 -255
  118. package/dist/slug/truetype.js.map +1 -1
  119. package/dist/slug/vanillaCore.d.ts +410 -0
  120. package/dist/slug/vanillaCore.js +1630 -0
  121. package/dist/slug/vanillaCore.js.map +1 -0
  122. package/dist/slug-vanilla.d.ts +13 -364
  123. package/dist/slug-vanilla.js +7 -1454
  124. package/dist/slug.d.ts +2 -2
  125. package/dist/slug.js +7 -7
  126. package/dist/text/GlyphTextMaterial.d.ts +6 -1
  127. package/dist/text/GlyphTextMaterial.js +16 -12
  128. package/dist/text/GlyphTextMaterial.js.map +1 -1
  129. package/dist/text/RectMaterial.js +6 -10
  130. package/dist/text/RectMaterial.js.map +1 -1
  131. package/dist/text/SdfTextMaterial.d.ts +9 -3
  132. package/dist/text/SdfTextMaterial.js +125 -38
  133. package/dist/text/SdfTextMaterial.js.map +1 -1
  134. package/dist/text/decorations.d.ts +7 -2
  135. package/dist/text/decorations.js +187 -79
  136. package/dist/text/decorations.js.map +1 -1
  137. package/dist/text/geometry.d.ts +3 -22
  138. package/dist/text/geometryUtils.d.ts +16 -1
  139. package/dist/text/geometryUtils.js +83 -8
  140. package/dist/text/geometryUtils.js.map +1 -1
  141. package/dist/text/glyphGeometry.d.ts +9 -0
  142. package/dist/text/glyphGeometry.js +434 -0
  143. package/dist/text/glyphGeometry.js.map +1 -0
  144. package/dist/text/index.d.ts +2 -1
  145. package/dist/text/rectGeometry.d.ts +13 -0
  146. package/dist/text/rectGeometry.js +101 -0
  147. package/dist/text/rectGeometry.js.map +1 -0
  148. package/dist/text/reflow.d.ts +23 -1
  149. package/dist/text/reflow.js +223 -94
  150. package/dist/text/reflow.js.map +1 -1
  151. package/dist/text/snap.d.ts +15 -0
  152. package/dist/text/snap.js +26 -0
  153. package/dist/text/snap.js.map +1 -0
  154. package/dist/text/tone.js +2 -2
  155. package/dist/text/tone.js.map +1 -1
  156. package/dist/types.d.ts +23 -7
  157. package/dist/vanilla.d.ts +13 -363
  158. package/dist/vanilla.js +7 -1474
  159. package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
  160. package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
  161. package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
  162. package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
  163. package/dist/windfoil/WindfoilMaterial.js +71 -8
  164. package/dist/windfoil/WindfoilMaterial.js.map +1 -1
  165. package/dist/windfoil/compositeGeometry.js +12 -5
  166. package/dist/windfoil/compositeGeometry.js.map +1 -1
  167. package/dist/windfoil/coverage.d.ts +10 -2
  168. package/dist/windfoil/coverage.js +147 -59
  169. package/dist/windfoil/coverage.js.map +1 -1
  170. package/dist/windfoil/geometry.d.ts +17 -2
  171. package/dist/windfoil/geometry.js +220 -57
  172. package/dist/windfoil/geometry.js.map +1 -1
  173. package/dist/windfoil/layerGrid.js +8 -8
  174. package/dist/windfoil/layerGrid.js.map +1 -1
  175. package/dist/windfoil/mixed.d.ts +1 -0
  176. package/dist/windfoil/mixed.js +57 -29
  177. package/dist/windfoil/mixed.js.map +1 -1
  178. package/dist/windfoil/preprocess.js +2 -2
  179. package/dist/windfoil/preprocessCore.d.ts +2 -0
  180. package/dist/windfoil/preprocessCore.js +69 -37
  181. package/dist/windfoil/preprocessCore.js.map +1 -1
  182. package/dist/windfoil/requests.d.ts +1 -1
  183. package/dist/windfoil/requests.js +11 -4
  184. package/dist/windfoil/requests.js.map +1 -1
  185. package/dist/windfoil/resolveOutline.d.ts +9 -0
  186. package/dist/windfoil/resolveOutline.js +20 -0
  187. package/dist/windfoil/resolveOutline.js.map +1 -0
  188. package/dist/windfoil/runtime.d.ts +4 -1
  189. package/dist/windfoil/runtime.js +69 -63
  190. package/dist/windfoil/runtime.js.map +1 -1
  191. package/dist/windfoil/shapeGeometry.js +80 -34
  192. package/dist/windfoil/shapeGeometry.js.map +1 -1
  193. package/dist/windfoil/sizeSwitch.d.ts +1 -1
  194. package/dist/windfoil/sizeSwitch.js +13 -8
  195. package/dist/windfoil/sizeSwitch.js.map +1 -1
  196. package/dist/windfoil/storage.d.ts +78 -6
  197. package/dist/windfoil/storage.js +166 -11
  198. package/dist/windfoil/storage.js.map +1 -1
  199. package/dist/windfoil/svg/curves.d.ts +20 -0
  200. package/dist/windfoil/svg/curves.js +145 -42
  201. package/dist/windfoil/svg/curves.js.map +1 -1
  202. package/dist/windfoil/svg/document.js +10 -1
  203. package/dist/windfoil/svg/document.js.map +1 -1
  204. package/dist/windfoil/svg/pathConverter.js +66 -50
  205. package/dist/windfoil/svg/pathConverter.js.map +1 -1
  206. package/dist/windfoil/svg/pathData.d.ts +9 -0
  207. package/dist/windfoil/svg/pathData.js +142 -109
  208. package/dist/windfoil/svg/pathData.js.map +1 -1
  209. package/dist/windfoil/svg/winding.js +34 -10
  210. package/dist/windfoil/svg/winding.js.map +1 -1
  211. package/dist/windfoil/trace/contours.d.ts +5 -0
  212. package/dist/windfoil/trace/contours.js +256 -62
  213. package/dist/windfoil/trace/contours.js.map +1 -1
  214. package/dist/windfoil/trace/fit.d.ts +3 -1
  215. package/dist/windfoil/trace/fit.js +915 -265
  216. package/dist/windfoil/trace/fit.js.map +1 -1
  217. package/dist/windfoil/trace/outline.js +55 -30
  218. package/dist/windfoil/trace/outline.js.map +1 -1
  219. package/dist/windfoil/trace/traceOutline.worker.d.ts +24 -0
  220. package/dist/windfoil/trace/traceWorker.d.ts +13 -0
  221. package/dist/windfoil/trace/traceWorker.js +192 -0
  222. package/dist/windfoil/trace/traceWorker.js.map +1 -0
  223. package/dist/windfoil/trace/types.d.ts +10 -0
  224. package/dist/windfoil/tracedOutlines.d.ts +2 -0
  225. package/dist/windfoil/tracedOutlines.js +393 -103
  226. package/dist/windfoil/tracedOutlines.js.map +1 -1
  227. package/package.json +48 -29
  228. package/skills/ultra-text/SKILL.md +9 -10
  229. package/skills/ultra-text/references/frameworks.md +46 -2
  230. package/skills/ultra-text/references/three-tsl.md +27 -25
  231. package/skills/ultra-text/references/vanilla-webgpu.md +5 -2
  232. package/dist/assets/cpuSdf.worker-xS57yQbP.js +0 -322
  233. package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +0 -1
  234. package/dist/slug-vanilla.js.map +0 -1
  235. package/dist/text/geometry.js +0 -348
  236. package/dist/text/geometry.js.map +0 -1
  237. package/dist/vanilla.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { type StorageBufferNode, type UniformNode } from 'three/webgpu';
2
2
  import { GlyphTextMaterial, type GlyphTextMaterialOptions } from '../text/GlyphTextMaterial.js';
3
- import type { WindfoilMaterialOptions } from './WindfoilMaterial.js';
3
+ import { type WindfoilMaterialOptions } from './WindfoilMaterial.js';
4
4
  export interface WindfoilCompositeMaterialOptions extends WindfoilMaterialOptions, GlyphTextMaterialOptions {
5
5
  readonly layers: StorageBufferNode<'uint'>;
6
6
  readonly paintFunctions: NonNullable<WindfoilMaterialOptions['paintFunctions']>;
@@ -1,5 +1,6 @@
1
1
  import { GlyphTextMaterial, srgbAttributeToWorking } from "../text/GlyphTextMaterial.js";
2
- import { createWindfoilCoverage, windfoilPixelBox, windfoilVertexExtension } from "./coverage.js";
2
+ import { createWindfoilCoverage, lazyFloat, windfoilPixelBox, windfoilVertexExtension } from "./coverage.js";
3
+ import { runBeautyClipDiffuseColor } from "./WindfoilMaterial.js";
3
4
  import { WINDFOIL_SOLID } from "./layerGrid.js";
4
5
  import { SRGBColorSpace } from "three/webgpu";
5
6
  import { Break, Continue, Fn, If, Loop, abs, attribute, bitcast, clamp, float, floor, mix, step, uint, uniform, varying, varyingProperty, vec2, vec4, wgslFn, workingToColorSpace } from "three/tsl";
@@ -35,6 +36,12 @@ var WindfoilCompositeMaterial = class extends GlyphTextMaterial {
35
36
  shadowCutoff = uniform(.5);
36
37
  /** The layer table with each glyph's cell index (see `appendWindfoilLayerGrids`). */
37
38
  windfoilLayers;
39
+ /** @internal */
40
+ setupDiffuseColor(builder) {
41
+ runBeautyClipDiffuseColor(this, builder, this.insideClip, () => {
42
+ super.setupDiffuseColor(builder);
43
+ });
44
+ }
38
45
  constructor(options) {
39
46
  const bounds = attribute("windfoilBounds", "vec4");
40
47
  const range = attribute("windfoilLayers", "vec3");
@@ -176,7 +183,7 @@ var WindfoilCompositeMaterial = class extends GlyphTextMaterial {
176
183
  });
177
184
  return acc;
178
185
  })();
179
- const shadow = Fn(() => {
186
+ const shadow = lazyFloat(() => Fn(() => {
180
187
  const size = windfoilPixelBox(position).toConst();
181
188
  const halfSize = size.mul(.5).toConst();
182
189
  const pixelLow = position.sub(halfSize).toConst(), pixelHigh = position.add(halfSize).toConst(), invArea = float(1).div(size.x.mul(size.y)).toConst();
@@ -207,7 +214,7 @@ var WindfoilCompositeMaterial = class extends GlyphTextMaterial {
207
214
  });
208
215
  });
209
216
  return acc.mul(clipped);
210
- })();
217
+ })());
211
218
  this.applyCoverage(composite.a, shadow, this.shadowCutoff, composite);
212
219
  const clip = Fn(() => {
213
220
  this.insideClip.not().discard();
@@ -1 +1 @@
1
- {"version":3,"file":"WindfoilCompositeMaterial.js","names":[],"sources":["../../src/windfoil/WindfoilCompositeMaterial.ts"],"sourcesContent":["import { SRGBColorSpace, type Node, type StorageBufferNode, type UniformNode } from 'three/webgpu'\nimport {\n Break,\n Continue,\n Fn,\n If,\n Loop,\n abs,\n attribute,\n bitcast,\n clamp,\n float,\n floor,\n mix,\n step,\n uint,\n uniform,\n varying,\n varyingProperty,\n vec2,\n vec4,\n wgslFn,\n workingToColorSpace,\n} from 'three/tsl'\nimport {\n GlyphTextMaterial,\n srgbAttributeToWorking,\n type GlyphTextMaterialOptions,\n} from '../text/GlyphTextMaterial.js'\nimport { createWindfoilCoverage, windfoilPixelBox, windfoilVertexExtension } from './coverage.js'\nimport type { WindfoilMaterialOptions } from './WindfoilMaterial.js'\nimport { WINDFOIL_SOLID, WINDFOIL_TREE_DEPTH } from './layerGrid.js'\n\nconst swapVec2 = wgslFn<{ v: Node<'vec2'>; swap: Node<'bool'> }>(`\nfn windfoil_swap2(v: vec2f, swap: bool) -> vec2f {\n return select(v, v.yx, swap);\n}\n`)\n\nconst swapVec4 = wgslFn<{ v: Node<'vec4'>; swap: Node<'bool'> }>(`\nfn windfoil_swap4(v: vec4f, swap: bool) -> vec4f {\n return select(v, v.yxwz, swap);\n}\n`)\n\nconst clipCoverageFn = wgslFn<{\n layerCount: Node<'float'>\n pixelLow: Node<'vec2'>\n pixelHigh: Node<'vec2'>\n clipBounds: Node<'vec4'>\n invArea: Node<'float'>\n}>(`\nfn windfoil_clip_coverage(layerCount: f32, pixelLow: vec2f, pixelHigh: vec2f, clipBounds: vec4f, invArea: f32) -> f32 {\n if (layerCount >= 0.0) { return 1.0; }\n let overlap = max(min(pixelHigh, clipBounds.zw) - max(pixelLow, clipBounds.xy), vec2f(0.0));\n return overlap.x * overlap.y * invArea;\n}\n`)\n\nconst cellFitsFn = wgslFn<{\n pixelLow: Node<'vec2'>\n pixelHigh: Node<'vec2'>\n corner: Node<'vec2'>\n extent: Node<'float'>\n}>(`\nfn windfoil_cell_fits(pixelLow: vec2f, pixelHigh: vec2f, corner: vec2f, extent: f32) -> bool {\n let margin = extent * 0.125;\n return all(pixelLow >= corner - margin) && all(pixelHigh <= corner + (extent + margin));\n}\n`)\n\ntype AssignableNode<T extends string> = Node<T> & {\n toVar(name?: string): Node<T> & { setAssignable(value: boolean): Node<T> }\n}\n\nfunction localVar<T extends string>(node: Node<T>, name?: string): Node<T> {\n return (node as AssignableNode<T>).toVar(name).setAssignable(true)\n}\n\nexport interface WindfoilCompositeMaterialOptions\n extends WindfoilMaterialOptions, GlyphTextMaterialOptions {\n readonly layers: StorageBufferNode<'uint'>\n readonly paintFunctions: NonNullable<WindfoilMaterialOptions['paintFunctions']>\n}\n/** Composites in encoded sRGB before the shared DOM/motion alpha multiplier. */\nexport class WindfoilCompositeMaterial extends GlyphTextMaterial {\n readonly shadowCutoff: UniformNode<'float', number> = uniform(0.5)\n /** The layer table with each glyph's cell index (see `appendWindfoilLayerGrids`). */\n readonly windfoilLayers: StorageBufferNode<'uint'>\n constructor(options: WindfoilCompositeMaterialOptions) {\n const bounds = attribute<'vec4'>('windfoilBounds', 'vec4')\n const range = attribute<'vec3'>('windfoilLayers', 'vec3')\n // The fragment truncates the first layer to an index: interpolated, that constant can arrive\n // a hair under itself (Safari's relaxed math on Apple GPUs) and walk another glyph's layer\n // list. Flat keeps it exact (from `either` vertex, all equal); the vertex stage reads the motion\n // index from `range.z`.\n const layerRange = varying(range.xy, 'vUltraWindfoilLayers').setInterpolation('flat', 'either')\n const position = varyingProperty('vec2', 'vUltraWindfoilPosition')\n const foreground = varyingProperty('vec3', 'vUltraWindfoilForeground')\n const extend = windfoilVertexExtension(bounds, position)\n super(\n options,\n (quad, rect, local, depth, scale, uv) => {\n foreground.assign(attribute<'vec4'>('sdfColor', 'vec4').rgb)\n return extend(quad, rect, local, depth, scale, uv)\n },\n range.z,\n )\n this.name = 'ultra-text TSL Windfoil colour'\n this.windfoilLayers = options.layers\n this.shadowCutoff.value = Math.min(1, Math.max(0, options.shadowCutoff ?? 0.5))\n // Share the rounded-edge correction with the per-layer renderer. Most pixels\n // need only their intersecting bands, rather than two unconditional neighbours.\n const { profileFace, integrateFace } = createWindfoilCoverage(options)\n const { layers } = options\n const clipCoverage = (\n pixelLow: Node<'vec2'>,\n pixelHigh: Node<'vec2'>,\n invArea: Node<'float'>,\n ): Node<'float'> =>\n clipCoverageFn({\n layerCount: layerRange.y,\n pixelLow,\n pixelHigh,\n clipBounds: bounds,\n invArea,\n }) as Node<'float'>\n /**\n * Word range of this pixel's top-down layer list: the deepest quadtree cell whose\n * footprint allowance (an eighth of its side) holds the pixel box, or every layer.\n */\n const layerList = (\n pixelLow: Node<'vec2'>,\n pixelHigh: Node<'vec2'>,\n ): [Node<'uint'>, Node<'uint'>] => {\n const block = uint(layers.element(uint(layerRange.x).mul(uint(12)).add(uint(11)))).toConst(\n 'windfoilGrid',\n )\n const cell = localVar(block.add(uint(4)), 'windfoilCell')\n If(uint(layers.element(block)).greaterThan(uint(0)), () => {\n const word = (offset: number): Node<'float'> =>\n bitcast(layers.element(block.add(uint(offset))), 'float') as unknown as Node<'float'>\n const origin = localVar(vec2(word(1), word(2))),\n side = localVar(word(3)),\n candidate = localVar(block.add(uint(8)))\n const fits = (corner: Node<'vec2'>, extent: Node<'float'>): Node<'bool'> =>\n cellFitsFn({ pixelLow, pixelHigh, corner, extent }) as Node<'bool'>\n // Start at the top grid's cell, a direct index, when the footprint fits it.\n const span = float(uint(1).shiftLeft(uint(layers.element(block.add(uint(4)))))).toConst()\n const cellStep = side.div(span).toConst()\n const index = clamp(\n floor(position.sub(origin).div(cellStep)),\n vec2(0),\n vec2(span.sub(1)),\n ).toConst()\n const corner = origin.add(index.mul(cellStep)).toConst()\n const descend = localVar(uint(1))\n If(fits(corner, cellStep), () => {\n const topCell = uint(\n layers.element(\n uint(layers.element(block.add(uint(7)))).add(uint(index.y.mul(span).add(index.x))),\n ),\n ).toConst()\n cell.assign(topCell)\n const firstChild = uint(layers.element(topCell)).toConst()\n If(firstChild.equal(uint(0)), () => {\n descend.assign(uint(0))\n }).Else(() => {\n const halfStep = cellStep.mul(0.5).toConst()\n const stepXY = step(corner.add(halfStep), position).toConst()\n origin.assign(corner.add(halfStep.mul(stepXY)))\n side.assign(halfStep)\n candidate.assign(firstChild.add(uint(stepXY.x.mul(3).add(stepXY.y.mul(6)))))\n })\n })\n If(descend.greaterThan(uint(0)), () => {\n Loop(WINDFOIL_TREE_DEPTH + 1, () => {\n If(fits(origin, side).not(), () => {\n Break()\n })\n cell.assign(candidate)\n const child = uint(layers.element(candidate)).toConst()\n If(child.equal(uint(0)), () => {\n Break()\n })\n side.mulAssign(0.5)\n const stepXY = step(origin.add(side), position).toConst()\n origin.addAssign(side.mul(stepXY))\n candidate.assign(child.add(uint(stepXY.x.mul(3).add(stepXY.y.mul(6)))))\n })\n })\n })\n const offset = cell.add(uint(1)).toConst()\n return [\n uint(layers.element(offset)).toConst(),\n uint(layers.element(offset.add(uint(1)))).toConst(),\n ]\n }\n /** Coverage of list entry `entry`: 1 for a cell-covering layer, else the pixel integral. */\n const entryCoverage = (\n entry: Node<'uint'>,\n row: Node<'uint'>,\n size: Node<'vec2'>,\n pixelLow: Node<'vec2'>,\n pixelHigh: Node<'vec2'>,\n invArea: Node<'float'>,\n ) => {\n const coverage = localVar(float(1))\n If(entry.lessThan(uint(WINDFOIL_SOLID)), () => {\n const read = (index: number): Node<'float'> =>\n bitcast(layers.element(row.add(uint(index))), 'float') as unknown as Node<'float'>\n const box = vec4(read(4), read(5), read(6), read(7)).toConst()\n const outside = pixelHigh.lessThan(box.xy).any().or(pixelLow.greaterThan(box.zw).any())\n If(outside, () => {\n Continue()\n })\n const header = vec4(\n float(layers.element(row)),\n float(layers.element(row.add(uint(1)))),\n read(2),\n read(3),\n ).toConst()\n // A transposed layer's pieces and bands run along x: integrate it in swapped axes.\n const swap = uint(layers.element(row.add(uint(9))))\n .bitAnd(uint(2))\n .notEqual(uint(0))\n .toConst()\n const center = (swapVec2({ v: position, swap }) as Node<'vec2'>).toConst(),\n extent = (swapVec2({ v: size, swap }) as Node<'vec2'>).toConst(),\n bounds = (swapVec4({ v: box, swap }) as Node<'vec4'>).toConst()\n If(size.mul(3.7).greaterThanEqual(box.zw.sub(box.xy)).all(), () => {\n coverage.assign(\n clamp(abs(profileFace(header, bounds, center, extent).mul(invArea)), 0, 1),\n )\n }).Else(() => {\n coverage.assign(\n clamp(abs(integrateFace(header, bounds.y, center, extent).mul(invArea)), 0, 1),\n )\n })\n })\n return coverage\n }\n const composite = Fn<Node<'vec4'>>(() => {\n const size = windfoilPixelBox(position).toConst()\n const halfSize = size.mul(0.5).toConst()\n const pixelLow = position.sub(halfSize).toConst(),\n pixelHigh = position.add(halfSize).toConst(),\n invArea = float(1).div(size.x.mul(size.y)).toConst()\n const acc = localVar(vec4(0), 'windfoilComposite')\n const clipped = clipCoverage(pixelLow, pixelHigh, invArea).toConst()\n If(clipped.greaterThanEqual(1 / 1024), () => {\n const [begin, finish] = layerList(pixelLow, pixelHigh)\n const fg = this.fillNode\n ? vec4(\n (workingToColorSpace(this.fillNode.rgb, SRGBColorSpace) as unknown as Node<'vec4'>)\n .rgb,\n clamp(this.fillNode.a, 0, 1),\n ).toConst()\n : vec4(foreground, 1).toConst()\n Loop({ start: begin, end: finish, type: 'uint', condition: '<' }, ({ i }) => {\n const entry = uint(layers.element(i)).toConst()\n const row = entry\n .bitAnd(uint(WINDFOIL_SOLID - 1))\n .mul(uint(12))\n .toConst()\n const coverage = entryCoverage(entry, row, size, pixelLow, pixelHigh, invArea)\n If(coverage.lessThan(1 / 1024), () => {\n Continue()\n })\n const paint = options.paintFunctions.evaluatePaint(\n uint(layers.element(row.add(uint(8)))),\n position,\n fg,\n )\n acc.addAssign(paint.mul(coverage.mul(acc.a.oneMinus())))\n If(acc.a.greaterThan(0.998), () => {\n Break()\n })\n })\n If(acc.a.greaterThan(0), () => {\n acc.assign(vec4(srgbAttributeToWorking(acc.rgb.div(acc.a)), acc.a.mul(clipped)))\n })\n })\n return acc\n })()\n const shadow = Fn<Node<'float'>>(() => {\n const size = windfoilPixelBox(position).toConst()\n const halfSize = size.mul(0.5).toConst()\n const pixelLow = position.sub(halfSize).toConst(),\n pixelHigh = position.add(halfSize).toConst(),\n invArea = float(1).div(size.x.mul(size.y)).toConst()\n const acc = localVar(float(0), 'windfoilShadowUnion')\n const clipped = clipCoverage(pixelLow, pixelHigh, invArea).toConst()\n If(clipped.greaterThan(this.shadowCutoff), () => {\n const [begin, finish] = layerList(pixelLow, pixelHigh)\n const fgAlpha = this.fillNode ? clamp(this.fillNode.a, 0, 1).toConst() : null\n const cutoff = this.shadowCutoff.div(clipped).toConst()\n Loop({ start: begin, end: finish, type: 'uint', condition: '<' }, ({ i }) => {\n const entry = uint(layers.element(i)).toConst()\n const row = entry\n .bitAnd(uint(WINDFOIL_SOLID - 1))\n .mul(uint(12))\n .toConst()\n const coverage = entryCoverage(entry, row, size, pixelLow, pixelHigh, invArea)\n If(coverage.lessThan(1 / 1024), () => {\n Continue()\n })\n const alpha = bitcast(\n layers.element(row.add(uint(10))),\n 'float',\n ) as unknown as Node<'float'>\n const layerAlpha = fgAlpha\n ? alpha.mul(\n mix(\n float(1),\n fgAlpha,\n float(uint(layers.element(row.add(uint(9)))).bitAnd(uint(1))),\n ),\n )\n : alpha\n acc.addAssign(coverage.mul(layerAlpha).mul(acc.oneMinus()))\n If(acc.greaterThan(cutoff), () => {\n Break()\n })\n })\n })\n return acc.mul(clipped)\n })()\n this.applyCoverage(composite.a, shadow, this.shadowCutoff, composite)\n const clip = Fn(() => {\n this.insideClip.not().discard()\n })()\n this.maskNode = this.maskNode!.bypass(clip)\n this.maskShadowNode = this.maskShadowNode!.bypass(clip)\n }\n}\n"],"mappings":";;;;;;AAiCA,IAAM,WAAW,OAAgD;;;;CAIhE;AAED,IAAM,WAAW,OAAgD;;;;CAIhE;AAED,IAAM,iBAAiB,OAMpB;;;;;;CAMF;AAED,IAAM,aAAa,OAKhB;;;;;CAKF;AAMD,SAAS,SAA2B,MAAe,MAAwB;CACzE,OAAQ,KAA2B,MAAM,IAAI,CAAC,CAAC,cAAc,IAAI;AACnE;;AAQA,IAAa,4BAAb,cAA+C,kBAAkB;CAC/D,eAAsD,QAAQ,EAAG;;CAEjE;CACA,YAAY,SAA2C;EACrD,MAAM,SAAS,UAAkB,kBAAkB,MAAM;EACzD,MAAM,QAAQ,UAAkB,kBAAkB,MAAM;EAKxD,MAAM,aAAa,QAAQ,MAAM,IAAI,sBAAsB,CAAC,CAAC,iBAAiB,QAAQ,QAAQ;EAC9F,MAAM,WAAW,gBAAgB,QAAQ,wBAAwB;EACjE,MAAM,aAAa,gBAAgB,QAAQ,0BAA0B;EACrE,MAAM,SAA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AC,CAAC,CACb,QAAQ;KACX,MAAM,WAAW,cAAc,OAAO,KAAK,MAAM,UAAU,WAAW,OAAO;KAC7E,GAAG,SAAS,SAAS,IAAI,IAAI,SAAS;MACpC,SAAS;KACX,CAAC;KACD,MAAM,QAAQ,QACZ,OAAO,QAAQ,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC,GAChC,OACF;KACA,MAAM,aAAa,UACf,MAAM,IACJ,IACE,MAAM,CAAC,GACP,SACA,MAAM,KAAK,OAAO,QAAQ,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAC9D,CACF,IACA;KACJ,IAAI,UAAU,SAAS,IAAI,UAAU,CAAC,CAAC,IAAI,IAAI,SAAS,CAAC,CAAC;KAC1D,GAAG,IAAI,YAAY,MAAM,SAAS;MAChC,MAAM;KACR,CAAC;IACH,CAAC;GACH,CAAC;GACD,OAAO,IAAI,IAAI,OAAO;EACxB,CAAC,CAAC,CAAC;EACH,KAAK,cAAc,UAAU,GAAG,QAAQ,KAAK,cAAc,SAAS;EACpE,MAAM,OAAO,SAAS;GACpB,KAAK,WAAW,IAAI,CAAC,CAAC,QAAQ;EAChC,CAAC,CAAC,CAAC;EACH,KAAK,WAAW,KAAK,SAAU,OAAO,IAAI;EAC1C,KAAK,iBAAiB,KAAK,eAAgB,OAAO,IAAI;CACxD;AACF"}
1
+ {"version":3,"file":"WindfoilCompositeMaterial.js","names":[],"sources":["../../src/windfoil/WindfoilCompositeMaterial.ts"],"sourcesContent":["import {\n SRGBColorSpace,\n type Node,\n type NodeBuilder,\n type StorageBufferNode,\n type UniformNode,\n} from 'three/webgpu'\nimport {\n Break,\n Continue,\n Fn,\n If,\n Loop,\n abs,\n attribute,\n bitcast,\n clamp,\n float,\n floor,\n mix,\n step,\n uint,\n uniform,\n varying,\n varyingProperty,\n vec2,\n vec4,\n wgslFn,\n workingToColorSpace,\n} from 'three/tsl'\nimport {\n GlyphTextMaterial,\n srgbAttributeToWorking,\n type GlyphTextMaterialOptions,\n} from '../text/GlyphTextMaterial.js'\nimport {\n createWindfoilCoverage,\n lazyFloat,\n windfoilPixelBox,\n windfoilVertexExtension,\n} from './coverage.js'\nimport { runBeautyClipDiffuseColor, type WindfoilMaterialOptions } from './WindfoilMaterial.js'\nimport { WINDFOIL_SOLID, WINDFOIL_TREE_DEPTH } from './layerGrid.js'\n\nconst swapVec2 = wgslFn<{ v: Node<'vec2'>; swap: Node<'bool'> }>(`\nfn windfoil_swap2(v: vec2f, swap: bool) -> vec2f {\n return select(v, v.yx, swap);\n}\n`)\n\nconst swapVec4 = wgslFn<{ v: Node<'vec4'>; swap: Node<'bool'> }>(`\nfn windfoil_swap4(v: vec4f, swap: bool) -> vec4f {\n return select(v, v.yxwz, swap);\n}\n`)\n\nconst clipCoverageFn = wgslFn<{\n layerCount: Node<'float'>\n pixelLow: Node<'vec2'>\n pixelHigh: Node<'vec2'>\n clipBounds: Node<'vec4'>\n invArea: Node<'float'>\n}>(`\nfn windfoil_clip_coverage(layerCount: f32, pixelLow: vec2f, pixelHigh: vec2f, clipBounds: vec4f, invArea: f32) -> f32 {\n if (layerCount >= 0.0) { return 1.0; }\n let overlap = max(min(pixelHigh, clipBounds.zw) - max(pixelLow, clipBounds.xy), vec2f(0.0));\n return overlap.x * overlap.y * invArea;\n}\n`)\n\nconst cellFitsFn = wgslFn<{\n pixelLow: Node<'vec2'>\n pixelHigh: Node<'vec2'>\n corner: Node<'vec2'>\n extent: Node<'float'>\n}>(`\nfn windfoil_cell_fits(pixelLow: vec2f, pixelHigh: vec2f, corner: vec2f, extent: f32) -> bool {\n let margin = extent * 0.125;\n return all(pixelLow >= corner - margin) && all(pixelHigh <= corner + (extent + margin));\n}\n`)\n\ntype AssignableNode<T extends string> = Node<T> & {\n toVar(name?: string): Node<T> & { setAssignable(value: boolean): Node<T> }\n}\n\nfunction localVar<T extends string>(node: Node<T>, name?: string): Node<T> {\n return (node as AssignableNode<T>).toVar(name).setAssignable(true)\n}\n\nexport interface WindfoilCompositeMaterialOptions\n extends WindfoilMaterialOptions, GlyphTextMaterialOptions {\n readonly layers: StorageBufferNode<'uint'>\n readonly paintFunctions: NonNullable<WindfoilMaterialOptions['paintFunctions']>\n}\n/** Composites in encoded sRGB before the shared DOM/motion alpha multiplier. */\nexport class WindfoilCompositeMaterial extends GlyphTextMaterial {\n readonly shadowCutoff: UniformNode<'float', number> = uniform(0.5)\n /** The layer table with each glyph's cell index (see `appendWindfoilLayerGrids`). */\n readonly windfoilLayers: StorageBufferNode<'uint'>\n\n /** @internal */\n override setupDiffuseColor(builder: NodeBuilder): void {\n runBeautyClipDiffuseColor(this, builder, this.insideClip, () => {\n super.setupDiffuseColor(builder)\n })\n }\n constructor(options: WindfoilCompositeMaterialOptions) {\n const bounds = attribute<'vec4'>('windfoilBounds', 'vec4')\n const range = attribute<'vec3'>('windfoilLayers', 'vec3')\n // The fragment truncates the first layer to an index: interpolated, that constant can arrive\n // a hair under itself (Safari's relaxed math on Apple GPUs) and walk another glyph's layer\n // list. Flat keeps it exact (from `either` vertex, all equal); the vertex stage reads the motion\n // index from `range.z`.\n const layerRange = varying(range.xy, 'vUltraWindfoilLayers').setInterpolation('flat', 'either')\n const position = varyingProperty('vec2', 'vUltraWindfoilPosition')\n const foreground = varyingProperty('vec3', 'vUltraWindfoilForeground')\n const extend = windfoilVertexExtension(bounds, position)\n super(\n options,\n (quad, rect, local, depth, scale, uv) => {\n foreground.assign(attribute<'vec4'>('sdfColor', 'vec4').rgb)\n return extend(quad, rect, local, depth, scale, uv)\n },\n range.z,\n )\n this.name = 'ultra-text TSL Windfoil colour'\n this.windfoilLayers = options.layers\n this.shadowCutoff.value = Math.min(1, Math.max(0, options.shadowCutoff ?? 0.5))\n // Share the rounded-edge correction with the per-layer renderer. Most pixels\n // need only their intersecting bands, rather than two unconditional neighbours.\n const { profileFace, integrateFace } = createWindfoilCoverage(options)\n const { layers } = options\n const clipCoverage = (\n pixelLow: Node<'vec2'>,\n pixelHigh: Node<'vec2'>,\n invArea: Node<'float'>,\n ): Node<'float'> =>\n clipCoverageFn({\n layerCount: layerRange.y,\n pixelLow,\n pixelHigh,\n clipBounds: bounds,\n invArea,\n }) as Node<'float'>\n /**\n * Word range of this pixel's top-down layer list: the deepest quadtree cell whose\n * footprint allowance (an eighth of its side) holds the pixel box, or every layer.\n */\n const layerList = (\n pixelLow: Node<'vec2'>,\n pixelHigh: Node<'vec2'>,\n ): [Node<'uint'>, Node<'uint'>] => {\n const block = uint(layers.element(uint(layerRange.x).mul(uint(12)).add(uint(11)))).toConst(\n 'windfoilGrid',\n )\n const cell = localVar(block.add(uint(4)), 'windfoilCell')\n If(uint(layers.element(block)).greaterThan(uint(0)), () => {\n const word = (offset: number): Node<'float'> =>\n bitcast(layers.element(block.add(uint(offset))), 'float') as unknown as Node<'float'>\n const origin = localVar(vec2(word(1), word(2))),\n side = localVar(word(3)),\n candidate = localVar(block.add(uint(8)))\n const fits = (corner: Node<'vec2'>, extent: Node<'float'>): Node<'bool'> =>\n cellFitsFn({ pixelLow, pixelHigh, corner, extent }) as Node<'bool'>\n // Start at the top grid's cell, a direct index, when the footprint fits it.\n const span = float(uint(1).shiftLeft(uint(layers.element(block.add(uint(4)))))).toConst()\n const cellStep = side.div(span).toConst()\n const index = clamp(\n floor(position.sub(origin).div(cellStep)),\n vec2(0),\n vec2(span.sub(1)),\n ).toConst()\n const corner = origin.add(index.mul(cellStep)).toConst()\n const descend = localVar(uint(1))\n If(fits(corner, cellStep), () => {\n const topCell = uint(\n layers.element(\n uint(layers.element(block.add(uint(7)))).add(uint(index.y.mul(span).add(index.x))),\n ),\n ).toConst()\n cell.assign(topCell)\n const firstChild = uint(layers.element(topCell)).toConst()\n If(firstChild.equal(uint(0)), () => {\n descend.assign(uint(0))\n }).Else(() => {\n const halfStep = cellStep.mul(0.5).toConst()\n const stepXY = step(corner.add(halfStep), position).toConst()\n origin.assign(corner.add(halfStep.mul(stepXY)))\n side.assign(halfStep)\n candidate.assign(firstChild.add(uint(stepXY.x.mul(3).add(stepXY.y.mul(6)))))\n })\n })\n If(descend.greaterThan(uint(0)), () => {\n Loop(WINDFOIL_TREE_DEPTH + 1, () => {\n If(fits(origin, side).not(), () => {\n Break()\n })\n cell.assign(candidate)\n const child = uint(layers.element(candidate)).toConst()\n If(child.equal(uint(0)), () => {\n Break()\n })\n side.mulAssign(0.5)\n const stepXY = step(origin.add(side), position).toConst()\n origin.addAssign(side.mul(stepXY))\n candidate.assign(child.add(uint(stepXY.x.mul(3).add(stepXY.y.mul(6)))))\n })\n })\n })\n const offset = cell.add(uint(1)).toConst()\n return [\n uint(layers.element(offset)).toConst(),\n uint(layers.element(offset.add(uint(1)))).toConst(),\n ]\n }\n /** Coverage of list entry `entry`: 1 for a cell-covering layer, else the pixel integral. */\n const entryCoverage = (\n entry: Node<'uint'>,\n row: Node<'uint'>,\n size: Node<'vec2'>,\n pixelLow: Node<'vec2'>,\n pixelHigh: Node<'vec2'>,\n invArea: Node<'float'>,\n ) => {\n const coverage = localVar(float(1))\n If(entry.lessThan(uint(WINDFOIL_SOLID)), () => {\n const read = (index: number): Node<'float'> =>\n bitcast(layers.element(row.add(uint(index))), 'float') as unknown as Node<'float'>\n const box = vec4(read(4), read(5), read(6), read(7)).toConst()\n const outside = pixelHigh.lessThan(box.xy).any().or(pixelLow.greaterThan(box.zw).any())\n If(outside, () => {\n Continue()\n })\n const header = vec4(\n float(layers.element(row)),\n float(layers.element(row.add(uint(1)))),\n read(2),\n read(3),\n ).toConst()\n // A transposed layer's pieces and bands run along x: integrate it in swapped axes.\n const swap = uint(layers.element(row.add(uint(9))))\n .bitAnd(uint(2))\n .notEqual(uint(0))\n .toConst()\n const center = (swapVec2({ v: position, swap }) as Node<'vec2'>).toConst(),\n extent = (swapVec2({ v: size, swap }) as Node<'vec2'>).toConst(),\n bounds = (swapVec4({ v: box, swap }) as Node<'vec4'>).toConst()\n If(size.mul(3.7).greaterThanEqual(box.zw.sub(box.xy)).all(), () => {\n coverage.assign(\n clamp(abs(profileFace(header, bounds, center, extent).mul(invArea)), 0, 1),\n )\n }).Else(() => {\n coverage.assign(\n clamp(abs(integrateFace(header, bounds.y, center, extent).mul(invArea)), 0, 1),\n )\n })\n })\n return coverage\n }\n const composite = Fn<Node<'vec4'>>(() => {\n const size = windfoilPixelBox(position).toConst()\n const halfSize = size.mul(0.5).toConst()\n const pixelLow = position.sub(halfSize).toConst(),\n pixelHigh = position.add(halfSize).toConst(),\n invArea = float(1).div(size.x.mul(size.y)).toConst()\n const acc = localVar(vec4(0), 'windfoilComposite')\n const clipped = clipCoverage(pixelLow, pixelHigh, invArea).toConst()\n If(clipped.greaterThanEqual(1 / 1024), () => {\n const [begin, finish] = layerList(pixelLow, pixelHigh)\n const fg = this.fillNode\n ? vec4(\n (workingToColorSpace(this.fillNode.rgb, SRGBColorSpace) as unknown as Node<'vec4'>)\n .rgb,\n clamp(this.fillNode.a, 0, 1),\n ).toConst()\n : vec4(foreground, 1).toConst()\n Loop({ start: begin, end: finish, type: 'uint', condition: '<' }, ({ i }) => {\n const entry = uint(layers.element(i)).toConst()\n const row = entry\n .bitAnd(uint(WINDFOIL_SOLID - 1))\n .mul(uint(12))\n .toConst()\n const coverage = entryCoverage(entry, row, size, pixelLow, pixelHigh, invArea)\n If(coverage.lessThan(1 / 1024), () => {\n Continue()\n })\n const paint = options.paintFunctions.evaluatePaint(\n uint(layers.element(row.add(uint(8)))),\n position,\n fg,\n )\n acc.addAssign(paint.mul(coverage.mul(acc.a.oneMinus())))\n If(acc.a.greaterThan(0.998), () => {\n Break()\n })\n })\n If(acc.a.greaterThan(0), () => {\n acc.assign(vec4(srgbAttributeToWorking(acc.rgb.div(acc.a)), acc.a.mul(clipped)))\n })\n })\n return acc\n })()\n const shadow = lazyFloat(() =>\n Fn<Node<'float'>>(() => {\n const size = windfoilPixelBox(position).toConst()\n const halfSize = size.mul(0.5).toConst()\n const pixelLow = position.sub(halfSize).toConst(),\n pixelHigh = position.add(halfSize).toConst(),\n invArea = float(1).div(size.x.mul(size.y)).toConst()\n const acc = localVar(float(0), 'windfoilShadowUnion')\n const clipped = clipCoverage(pixelLow, pixelHigh, invArea).toConst()\n If(clipped.greaterThan(this.shadowCutoff), () => {\n const [begin, finish] = layerList(pixelLow, pixelHigh)\n const fgAlpha = this.fillNode ? clamp(this.fillNode.a, 0, 1).toConst() : null\n const cutoff = this.shadowCutoff.div(clipped).toConst()\n Loop({ start: begin, end: finish, type: 'uint', condition: '<' }, ({ i }) => {\n const entry = uint(layers.element(i)).toConst()\n const row = entry\n .bitAnd(uint(WINDFOIL_SOLID - 1))\n .mul(uint(12))\n .toConst()\n const coverage = entryCoverage(entry, row, size, pixelLow, pixelHigh, invArea)\n If(coverage.lessThan(1 / 1024), () => {\n Continue()\n })\n const alpha = bitcast(\n layers.element(row.add(uint(10))),\n 'float',\n ) as unknown as Node<'float'>\n const layerAlpha = fgAlpha\n ? alpha.mul(\n mix(\n float(1),\n fgAlpha,\n float(uint(layers.element(row.add(uint(9)))).bitAnd(uint(1))),\n ),\n )\n : alpha\n acc.addAssign(coverage.mul(layerAlpha).mul(acc.oneMinus()))\n If(acc.greaterThan(cutoff), () => {\n Break()\n })\n })\n })\n return acc.mul(clipped)\n })(),\n )\n this.applyCoverage(composite.a, shadow, this.shadowCutoff, composite)\n const clip = Fn(() => {\n this.insideClip.not().discard()\n })()\n this.maskNode = this.maskNode!.bypass(clip)\n this.maskShadowNode = this.maskShadowNode!.bypass(clip)\n }\n}\n"],"mappings":";;;;;;;AA4CA,IAAM,WAAW,OAAgD;;;;CAIhE;AAED,IAAM,WAAW,OAAgD;;;;CAIhE;AAED,IAAM,iBAAiB,OAMpB;;;;;;CAMF;AAED,IAAM,aAAa,OAKhB;;;;;CAKF;AAMD,SAAS,SAA2B,MAAe,MAAwB;CACzE,OAAQ,KAA2B,MAAM,IAAI,CAAC,CAAC,cAAc,IAAI;AACnE;;AAQA,IAAa,4BAAb,cAA+C,kBAAkB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AAK,SAAU,OAAO,IAAI;EAC1C,KAAK,iBAAiB,KAAK,eAAgB,OAAO,IAAI;CACxD;AACF"}
@@ -1,13 +1,14 @@
1
- import type { Node, StorageBufferNode, UniformNode } from 'three/webgpu';
1
+ import { Node, type NodeBuilder, type StorageBufferNode, type UniformNode } from 'three/webgpu';
2
2
  import { GlyphTextMaterial, type GlyphTextMaterialOptions } from '../text/GlyphTextMaterial.js';
3
3
  /** Storage buffers retained by one Windfoil outline atlas. */
4
4
  export interface WindfoilStorage {
5
5
  /**
6
- * Three vec2 entries per xy-monotone quadratic piece. Each row stores its pieces
7
- * by descending x-maximum, followed by the same pieces by ascending x-minimum.
6
+ * Per-row SoA `[q1, q3] | [q2_0, q2_1]` xy-monotone quadratic pieces (`vec4f` default,
7
+ * or `vec2f` fallback). Each row stores its pieces by descending x-maximum, followed by
8
+ * the same pieces by ascending x-minimum.
8
9
  */
9
- readonly curves: StorageBufferNode<'vec2'>;
10
- /** Six uint entries per row: start, count, density, x-min, x-max and split bits. */
10
+ readonly curves: StorageBufferNode<'vec4' | 'vec2'>;
11
+ /** Six uint entries per row: start, count|allLinear, density, x-min, x-max and split bits. */
11
12
  readonly rows: StorageBufferNode<'uint'>;
12
13
  }
13
14
  export interface WindfoilMaterialOptions extends WindfoilStorage, GlyphTextMaterialOptions {
@@ -21,5 +22,11 @@ export interface WindfoilMaterialOptions extends WindfoilStorage, GlyphTextMater
21
22
  export declare class WindfoilMaterial extends GlyphTextMaterial {
22
23
  #private;
23
24
  get shadowCutoff(): UniformNode<'float', number>;
25
+ /**
26
+ * Reuses `clip0 + colX * offset.x + colY * offset.y` from the skirt pass so
27
+ * Three skips the extra `modelViewMatrix * positionLocal` and projection matrix
28
+ * multiply when no custom `vertex`, `keepGlyph`, fog, or shadow pass overrides it.
29
+ */
30
+ setupVertex(builder: NodeBuilder): Node;
24
31
  constructor(options: WindfoilMaterialOptions);
25
32
  }
@@ -1,11 +1,52 @@
1
1
  import { resolveTextTone } from "../dom/tone.js";
2
2
  import { GlyphTextMaterial, srgbAttributeToWorking } from "../text/GlyphTextMaterial.js";
3
- import { createWindfoilCoverage, windfoilPixelBox, windfoilVertexExtension } from "./coverage.js";
3
+ import { createWindfoilCoverage, lazyFloat, windfoilPixelBox, windfoilVertexExtension } from "./coverage.js";
4
+ import { Node } from "three/webgpu";
4
5
  import { Fn, If, abs, attribute, clamp, dFdy, float, max, mix, step, uint, uniform, varying, varyingProperty, vec3, vec4 } from "three/tsl";
5
6
  // src/windfoil/WindfoilMaterial.ts
7
+ /** @internal Keeps alpha-blended beauty draws discard-free on TBDR GPUs while preserving mask discard on depth-writing, wireframe, opaque, and shadow passes. */
8
+ function runBeautyClipDiffuseColor(material, builder, insideClip, runSuper) {
9
+ const mat = builder.material;
10
+ const dropMask = mat.transparent !== false && !mat.depthWrite && !mat.wireframe && !mat.isShadowPassMaterial && material.maskNode !== material.maskShadowNode;
11
+ const savedMask = dropMask ? material.maskNode : null;
12
+ const savedColor = dropMask ? material.colorNode : null;
13
+ if (dropMask) {
14
+ material.maskNode = null;
15
+ if (savedColor) {
16
+ const color = savedColor;
17
+ material.colorNode = vec4(color.rgb, insideClip.select(color.a, 0).context({ uniformFlow: true }));
18
+ }
19
+ }
20
+ try {
21
+ runSuper();
22
+ } finally {
23
+ if (dropMask) {
24
+ material.maskNode = savedMask;
25
+ material.colorNode = savedColor;
26
+ }
27
+ }
28
+ }
29
+ var WindfoilClipSpaceNode = class extends Node {
30
+ clipBox;
31
+ fallback;
32
+ static type = "UltraWindfoilClipSpaceNode";
33
+ constructor(clipBox, fallback) {
34
+ super("vec4");
35
+ this.clipBox = clipBox;
36
+ this.fallback = fallback;
37
+ }
38
+ setup(builder) {
39
+ const clip = this.clipBox.current;
40
+ const mat = builder.material;
41
+ if (clip && !mat.isShadowPassMaterial && !(builder.fogNode && mat.fog)) return clip.clip0.add(clip.colX.mul(clip.offset.x)).add(clip.colY.mul(clip.offset.y));
42
+ return this.fallback;
43
+ }
44
+ };
6
45
  /** Analytic, atlas-free quadratic-outline text using the Windfoil coverage integral. */
7
46
  var WindfoilMaterial = class extends GlyphTextMaterial {
8
47
  #sc = uniform(.5);
48
+ #canFastClip;
49
+ #clipBox;
9
50
  get shadowCutoff() {
10
51
  return this.#sc;
11
52
  }
@@ -13,13 +54,33 @@ var WindfoilMaterial = class extends GlyphTextMaterial {
13
54
  copySubclassUniforms(target) {
14
55
  target.shadowCutoff.value = this.#sc.value;
15
56
  }
57
+ /** @internal */
58
+ setupDiffuseColor(builder) {
59
+ runBeautyClipDiffuseColor(this, builder, this.insideClip, () => {
60
+ super.setupDiffuseColor(builder);
61
+ });
62
+ }
63
+ /**
64
+ * Reuses `clip0 + colX * offset.x + colY * offset.y` from the skirt pass so
65
+ * Three skips the extra `modelViewMatrix * positionLocal` and projection matrix
66
+ * multiply when no custom `vertex`, `keepGlyph`, fog, or shadow pass overrides it.
67
+ */
68
+ setupVertex(builder) {
69
+ const mvp = super.setupVertex(builder);
70
+ return this.#canFastClip ? new WindfoilClipSpaceNode(this.#clipBox, mvp) : mvp;
71
+ }
16
72
  constructor(options) {
17
73
  const bounds = attribute("windfoilBounds", "vec4");
74
+ const fragmentBounds = varying(bounds, "vUltraWindfoilBounds").setInterpolation("flat", "either");
18
75
  const band = varying(attribute("windfoilBand", "vec4"), "vUltraWindfoilBand").setInterpolation("flat", "either");
19
76
  const glyphPosition = varyingProperty("vec2", "vUltraWindfoilPosition");
20
77
  const layer = options.layered ? attribute("windfoilLayer", "vec4") : null;
21
78
  const paintVarying = layer ? varying(layer.w, "vUltraWindfoilPaint").setInterpolation("flat", "either") : null;
22
79
  const dilation = resolveTextTone(options.tone)?.dilationPx ? varyingProperty("float", "vUltraWindfoilDilation") : null;
80
+ const clipBox = {};
81
+ const setClip = (clip) => {
82
+ clipBox.current = clip;
83
+ };
23
84
  const extension = dilation ? (...vertex) => {
24
85
  const meta = attribute("sdfMeta", "vec3");
25
86
  meta.getHash = () => String(meta.id);
@@ -28,12 +89,14 @@ var WindfoilMaterial = class extends GlyphTextMaterial {
28
89
  law: this.tone.dilation,
29
90
  em: layer ? em.mul(step(layer.w, .25)) : em,
30
91
  amount: dilation
31
- })(...vertex);
32
- } : windfoilVertexExtension(bounds, glyphPosition);
92
+ }, setClip)(...vertex);
93
+ } : windfoilVertexExtension(bounds, glyphPosition, void 0, setClip);
33
94
  super(options, extension, layer ? {
34
95
  index: layer.z,
35
96
  center: layer.xy
36
97
  } : void 0);
98
+ this.#canFastClip = !options.vertex && !options.keepGlyph;
99
+ this.#clipBox = clipBox;
37
100
  this.name = "ultra-text TSL Windfoil text";
38
101
  this.shadowCutoff.value = Math.min(1, Math.max(0, options.shadowCutoff ?? .5));
39
102
  const { integrateFace, profileFace } = createWindfoilCoverage(options);
@@ -51,14 +114,14 @@ var WindfoilMaterial = class extends GlyphTextMaterial {
51
114
  area = area.mul(growth);
52
115
  }
53
116
  const integral = float(0).toVar("windfoilIntegral");
54
- If(pixel.mul(3.7).greaterThanEqual(bounds.zw.sub(bounds.xy)).all(), () => {
55
- integral.assign(profileFace(band, bounds, center, size));
117
+ If(pixel.mul(3.7).greaterThanEqual(fragmentBounds.zw.sub(fragmentBounds.xy)).all(), () => {
118
+ integral.assign(profileFace(band, fragmentBounds, center, size));
56
119
  }).Else(() => {
57
- integral.assign(integrateFace(band, bounds.y, center, size));
120
+ integral.assign(integrateFace(band, fragmentBounds.y, center, size));
58
121
  });
59
122
  return clamp(abs(integral.div(area)), 0, 1);
60
123
  })();
61
- const coverage = coverageOf(null);
124
+ const coverage = dilation && !paintVarying ? lazyFloat(() => coverageOf(null)) : coverageOf(null);
62
125
  const tone = this.tone;
63
126
  const exact = tone ? (dilation ? coverageOf(dilation) : coverage).toConst() : coverage;
64
127
  const gate = dilation ? step(0, dilation) : void 0;
@@ -94,6 +157,6 @@ var WindfoilMaterial = class extends GlyphTextMaterial {
94
157
  this.maskShadowNode = this.maskShadowNode.bypass(clip);
95
158
  }
96
159
  };
97
- export { WindfoilMaterial };
160
+ export { WindfoilMaterial, runBeautyClipDiffuseColor };
98
161
 
99
162
  //# sourceMappingURL=WindfoilMaterial.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"WindfoilMaterial.js","names":[],"sources":["../../src/windfoil/WindfoilMaterial.ts"],"sourcesContent":["import { createWindfoilCoverage, windfoilVertexExtension, windfoilPixelBox } from './coverage.js'\nimport type { Node, StorageBufferNode, UniformNode } from 'three/webgpu'\nimport {\n Fn,\n If,\n abs,\n attribute,\n clamp,\n dFdy,\n float,\n max,\n mix,\n step,\n uint,\n uniform,\n varying,\n varyingProperty,\n vec3,\n vec4,\n} from 'three/tsl'\n\nimport {\n GlyphTextMaterial,\n srgbAttributeToWorking,\n type GlyphTextMaterialOptions,\n type GlyphVertexExtension,\n} from '../text/GlyphTextMaterial.js'\nimport { resolveTextTone } from '../text/tone.js'\n\n/** Storage buffers retained by one Windfoil outline atlas. */\nexport interface WindfoilStorage {\n /**\n * Three vec2 entries per xy-monotone quadratic piece. Each row stores its pieces\n * by descending x-maximum, followed by the same pieces by ascending x-minimum.\n */\n readonly curves: StorageBufferNode<'vec2'>\n /** Six uint entries per row: start, count, density, x-min, x-max and split bits. */\n readonly rows: StorageBufferNode<'uint'>\n}\n\nexport interface WindfoilMaterialOptions extends WindfoilStorage, GlyphTextMaterialOptions {\n shadowCutoff?: number\n layered?: boolean\n paintFunctions?: {\n evaluatePaint(index: Node<'uint'>, point: Node<'vec2'>, foreground: Node<'vec4'>): Node<'vec4'>\n }\n}\n\n/** Analytic, atlas-free quadratic-outline text using the Windfoil coverage integral. */\nexport class WindfoilMaterial extends GlyphTextMaterial {\n readonly #sc: UniformNode<'float', number> = uniform(0.5)\n\n get shadowCutoff(): UniformNode<'float', number> {\n return this.#sc\n }\n\n /** @internal */\n protected override copySubclassUniforms(target: this): void {\n target.shadowCutoff.value = this.#sc.value\n }\n\n constructor(options: WindfoilMaterialOptions) {\n const bounds = attribute<'vec4'>('windfoilBounds', 'vec4')\n // The band header's first row and row count, like the paint index below, are integers the\n // fragment truncates. Interpolated, an instance's constant can arrive a hair under itself\n // (Safari's relaxed math on Apple GPUs) and read the previous row: flat keeps them exact. Any\n // vertex of the glyph gives the same value, so `either` serves compatibility-mode devices.\n const band = varying(\n attribute<'vec4'>('windfoilBand', 'vec4'),\n 'vUltraWindfoilBand',\n ).setInterpolation('flat', 'either')\n const glyphPosition = varyingProperty('vec2', 'vUltraWindfoilPosition')\n const layer = options.layered ? attribute<'vec4'>('windfoilLayer', 'vec4') : null\n const paintVarying = layer\n ? varying(layer.w, 'vUltraWindfoilPaint').setInterpolation('flat', 'either')\n : null\n // A tone model that dilates the outline: each glyph's dilation in pixels, below zero from\n // the size where the model stops. Its em is the font size the instance carries in\n // `sdfMeta.z`, whose sign belongs to the size switch. An instance without one, and every\n // colour layer, reads as text of no size: the outline stays where it is.\n const dilation = resolveTextTone(options.tone)?.dilationPx\n ? varyingProperty('float', 'vUltraWindfoilDilation')\n : null\n const extension: GlyphVertexExtension = dilation\n ? (...vertex) => {\n const meta = attribute<'vec3'>('sdfMeta', 'vec3')\n // Attribute nodes are shared by name, and the shared graph may have declared this\n // one two wide: its own identity keeps the third component.\n meta.getHash = () => String(meta.id)\n const em = abs(meta.z)\n // The tone's uniforms exist by the time a shader function first runs.\n return windfoilVertexExtension(bounds, glyphPosition, {\n law: this.tone!.dilation,\n em: layer ? em.mul(step(layer.w, 0.25)) : em,\n amount: dilation,\n })(...vertex)\n }\n : windfoilVertexExtension(bounds, glyphPosition)\n super(options, extension, layer ? { index: layer.z, center: layer.xy } : undefined)\n this.name = 'ultra-text TSL Windfoil text'\n this.shadowCutoff.value = Math.min(1, Math.max(0, options.shadowCutoff ?? 0.5))\n\n const { integrateFace, profileFace } = createWindfoilCoverage(options)\n const coverageOf = (grown: Node<'float'> | null): Node<'float'> =>\n Fn<Node<'float'>>(() => {\n // The integration box matches the pixel footprint's spread along each\n // outline axis: a box of width w has variance w²/12, as does the footprint\n // when w is the length of that axis's screen gradient. fwidth() would use\n // the footprint's bounding box, blurring rotated or sheared text by up to\n // √2 per axis. Axis-aligned text gets the same box either way.\n const dy = grown ? dFdy(glyphPosition) : undefined\n const pixel = windfoilPixelBox(glyphPosition, dy)\n let size = pixel\n let center: Node<'vec2'> = glyphPosition\n let area = pixel.x.mul(pixel.y)\n if (grown) {\n // A box 2d pixels larger, divided by one growth: a straight edge at x pixels from\n // the centre then covers clamp(0.5 + x + d), the exact coverage of the outline moved\n // out by d. Sampled d pixels lower on screen, edges facing down keep their place\n // and edges facing up rise by 2d. Empty pixels stay 0 and pixels inside the ink 1,\n // but where a corner faces down the box overhangs the ink on two sides: that pixel\n // row gets no dilation from the side, and at worst (1 + d) / (1 + 2d) of its ink.\n const amount = max(grown, 0).toConst()\n const growth = amount.mul(2).add(1).toConst()\n size = pixel.mul(growth).toConst()\n center = glyphPosition.sub(dy!.mul(amount)).toConst()\n area = area.mul(growth)\n }\n const integral = float(0).toVar('windfoilIntegral')\n // Glyphs of a few pixels use their ink profile, whatever the dilation.\n If(pixel.mul(3.7).greaterThanEqual(bounds.zw.sub(bounds.xy)).all(), () => {\n integral.assign(profileFace(band, bounds, center, size))\n }).Else(() => {\n integral.assign(integrateFace(band, bounds.y, center, size))\n })\n return clamp(abs(integral.div(area)), 0, 1)\n })()\n // The exact coverage: every shadow mask, and the beauty pass of the models that keep the\n // outline as it is.\n const coverage = coverageOf(null)\n // Beauty coverage of foreground text ink, toned from the instance colour or from a fill's\n // own colour. Colour layers, paint and every shadow mask keep the exact coverage, and\n // with `tone: false` this is that same node: the graph has no trace of the conversion.\n const tone = this.tone\n // A toned graph reads the exact coverage more than once. One local keeps the integral in\n // one place; a conditional would evaluate it again in each of its branches.\n const exact = tone ? (dilation ? coverageOf(dilation) : coverage).toConst() : coverage\n // The model's table stops where its dilation does.\n const gate = dilation ? step(0, dilation) : undefined\n const inked = (ink?: Node<'vec3'>): Node<'float'> => this.toned(exact, ink, gate)\n // Layered geometry also carries solid colour layers, which stay exact.\n const foreground = (ink?: Node<'vec3'>): Node<'float'> =>\n tone && paintVarying ? mix(exact, inked(ink), step(paintVarying, 0.25)) : inked(ink)\n\n if (paintVarying && options.paintFunctions) {\n // `toning` false rebuilds the exact paint, whose alpha the shadow mask keeps.\n const painted = (toning: boolean): Node<'vec4'> =>\n Fn<Node<'vec4'>>(() => {\n const own = toning ? exact : coverage\n const result = (\n vec4(this.colorVarying.rgb, own).toVar() as unknown as {\n setAssignable(value: boolean): Node<'vec4'>\n }\n ).setAssignable(true)\n If(own.greaterThan(0), () => {\n If(paintVarying.greaterThanEqual(2), () => {\n const encoded = options.paintFunctions!.evaluatePaint(\n uint(paintVarying.sub(2)),\n glyphPosition,\n vec4(0),\n )\n result.assign(\n vec4(\n srgbAttributeToWorking(vec3(encoded.rgb.div(max(encoded.a, 1e-6)))),\n encoded.a.mul(own),\n ),\n )\n }).ElseIf(paintVarying.lessThan(0.5), () => {\n if (this.fillNode)\n result.assign(\n vec4(\n this.fillNode.rgb,\n (toning ? inked(this.fillNode.rgb) : own).mul(clamp(this.fillNode.a, 0, 1)),\n ),\n )\n else if (toning) result.assign(vec4(this.colorVarying.rgb, inked()))\n })\n })\n return result\n })()\n // A shadow pass reads the exact paint alone, so it evaluates one paint.\n const exactPaint = painted(false)\n this.applyCoverage(\n coverage,\n exactPaint.a,\n this.shadowCutoff,\n tone ? painted(true) : exactPaint,\n !!tone,\n )\n } else if (paintVarying && this.fillNode) {\n const solid = paintVarying.greaterThan(0.5).toConst()\n const opacity = solid\n .select(float(1), clamp(this.fillNode.a, 0, 1))\n .context({ uniformFlow: true })\n .toConst()\n const alpha = coverage.mul(opacity).toConst()\n this.applyCoverage(\n coverage,\n alpha,\n this.shadowCutoff,\n vec4(\n solid.select(this.colorVarying.rgb, this.fillNode.rgb).context({ uniformFlow: true }),\n tone ? foreground(this.fillNode.rgb).mul(opacity).toConst() : alpha,\n ),\n !!tone,\n )\n } else {\n this.applyCoverage(\n foreground(this.fillNode?.rgb),\n coverage,\n this.shadowCutoff,\n undefined,\n !!tone,\n )\n }\n // Clip before the analytic coverage loops. A logical AND on the final mask\n // alone materializes coverage first, even for fragments outside the block.\n // Keep the test separate from derivative-dependent coverage: discard retains\n // helper invocations for derivatives at the surviving clip edge.\n const clip = Fn(() => {\n this.insideClip.not().discard()\n })()\n this.maskNode = this.maskNode!.bypass(clip)\n this.maskShadowNode = this.maskShadowNode!.bypass(clip)\n }\n}\n"],"mappings":";;;;;;AAiDA,IAAa,mBAAb,cAAsC,kBAAkB;CACtD,MAA6C,QAAQ,EAAG;CAExD,IAAI,eAA6C;EAC/C,OAAO,KAAK;CACd;;CAGA,qBAAwC,QAAoB;EAC1D,OAAO,aAAa,QAAQ,KAAK,IAAI;CACvC;CAEA,YAAY,SAAkC;EAC5C,MAAM,SAAS,UAAkB,kBAAkB,MAAM;EAKzD,MAAM,OAAO,QACX,UAAkB,gBAAgB,MAAM,GACxC,oBACF,CAAC,CAAC,iBAAiB,QAAQ,QAAQ;EACnC,MAAM,gBAAgB,gBAAgB,QAAQ,wBAAwB;EACtE,MAAM,QAAQ,QAAQ,UAAU,UAAkB,iBAAiB,MAAM,IAAI;EAC7E,MAAM,eAAe,QACjB,QAAQ,MAAM,GAAG,qBAAqB,CAAC,CAAC,iBAAiB,QAAQ,QAAQ,IACzE;EAKJ,MAAM,WAAW,gBAAgB,QAAQ,IAAI,CAAC,EAAE,aAC5C,gBAAgB,SAAS,wBAAwB,IACjD;EACJ,MAAM,YAAkC,YACnC,GAAG,WAAW;GACb,MAAM,OAAO,UAAkB,WAAW,MAAM;GAGhD,KAAK,gBAAgB,OAAO,KAAK,EAAE;GACnC,MAAM,KAAK,IAAI,KAAK,CAAC;GAErB,OAAO,wBAAwB,QAAQ,eAAe;IACpD,KAAK,KAAK,KAAM;IAChB,IAAI,QAAQ,GAAG,IAAI,KAAK,MAAM,GAAG,GAAI,CAAC,IAAI;IAC1C,QAAQ;GACV,CAAC,CAAC,CAAC,GAAG,MAAM;EACd,IACA,wBAAwB,QAAQ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,cACL,OAAO,QAAQ,IAAI,IAAI,YACvB,CAAC,CAAC,IACJ;EACF,OAAO,IAAI,gBAAgB,KAAK,UAAU;GACxC,MAAM,QAAQ,aAAa,YAAY,EAAG,CAAC,CAAC,QAAQ;GACpD,MAAM,UAAU,MACb,OAAO,MAAM,CAAC,GAAG,MAAM,KAAK,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,CAC9C,QAAQ,EAAE,aAAa,KAAK,CAAC,CAAC,CAC9B,QAAQ;GACX,MAAM,QAAQ,SAAS,IAAI,OAAO,CAAC,CAAC,QAAQ;GAC5C,KAAK,cACH,UACA,OACA,KAAK,cACL,KACE,MAAM,OAAO,KAAK,aAAa,KAAK,KAAK,SAAS,GAAG,CAAC,CAAC,QAAQ,EAAE,aAAa,KAAK,CAAC,GACpF,OAAO,WAAW,KAAK,SAAS,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,QAAQ,IAAI,KAChE,GACA,CAAC,CAAC,IACJ;EACF,OACE,KAAK,cACH,WAAW,KAAK,UAAU,GAAG,GAC7B,UACA,KAAK,cACL,KAAA,GACA,CAAC,CAAC,IACJ;EAMF,MAAM,OAAO,SAAS;GACpB,KAAK,WAAW,IAAI,CAAC,CAAC,QAAQ;EAChC,CAAC,CAAC,CAAC;EACH,KAAK,WAAW,KAAK,SAAU,OAAO,IAAI;EAC1C,KAAK,iBAAiB,KAAK,eAAgB,OAAO,IAAI;CACxD;AACF"}
1
+ {"version":3,"file":"WindfoilMaterial.js","names":[],"sources":["../../src/windfoil/WindfoilMaterial.ts"],"sourcesContent":["import {\n createWindfoilCoverage,\n lazyFloat,\n windfoilVertexExtension,\n windfoilPixelBox,\n type WindfoilVertexClip,\n} from './coverage.js'\nimport { Node, type NodeBuilder, type StorageBufferNode, type UniformNode } from 'three/webgpu'\nimport {\n Fn,\n If,\n abs,\n attribute,\n clamp,\n dFdy,\n float,\n max,\n mix,\n step,\n uint,\n uniform,\n varying,\n varyingProperty,\n vec3,\n vec4,\n} from 'three/tsl'\n\nimport {\n GlyphTextMaterial,\n srgbAttributeToWorking,\n type GlyphTextMaterialOptions,\n type GlyphVertexExtension,\n} from '../text/GlyphTextMaterial.js'\nimport { resolveTextTone } from '../text/tone.js'\n\n/** Storage buffers retained by one Windfoil outline atlas. */\nexport interface WindfoilStorage {\n /**\n * Per-row SoA `[q1, q3] | [q2_0, q2_1]` xy-monotone quadratic pieces (`vec4f` default,\n * or `vec2f` fallback). Each row stores its pieces by descending x-maximum, followed by\n * the same pieces by ascending x-minimum.\n */\n readonly curves: StorageBufferNode<'vec4' | 'vec2'>\n /** Six uint entries per row: start, count|allLinear, density, x-min, x-max and split bits. */\n readonly rows: StorageBufferNode<'uint'>\n}\n\nexport interface WindfoilMaterialOptions extends WindfoilStorage, GlyphTextMaterialOptions {\n shadowCutoff?: number\n layered?: boolean\n paintFunctions?: {\n evaluatePaint(index: Node<'uint'>, point: Node<'vec2'>, foreground: Node<'vec4'>): Node<'vec4'>\n }\n}\n\n/** @internal Keeps alpha-blended beauty draws discard-free on TBDR GPUs while preserving mask discard on depth-writing, wireframe, opaque, and shadow passes. */\nexport function runBeautyClipDiffuseColor(\n material: {\n maskNode: Node | null\n maskShadowNode: Node | null\n colorNode: Node | null\n },\n builder: NodeBuilder,\n insideClip: Node<'bool'>,\n runSuper: () => void,\n): void {\n const mat = builder.material as {\n depthWrite?: boolean\n wireframe?: boolean\n transparent?: boolean\n isShadowPassMaterial?: boolean\n }\n const dropMask =\n mat.transparent !== false &&\n !mat.depthWrite &&\n !mat.wireframe &&\n !mat.isShadowPassMaterial &&\n material.maskNode !== material.maskShadowNode\n const savedMask = dropMask ? material.maskNode : null\n const savedColor = dropMask ? material.colorNode : null\n if (dropMask) {\n material.maskNode = null\n if (savedColor) {\n const color = savedColor as Node<'vec4'>\n material.colorNode = vec4(\n color.rgb,\n insideClip.select(color.a, 0).context({ uniformFlow: true }),\n )\n }\n }\n try {\n runSuper()\n } finally {\n if (dropMask) {\n material.maskNode = savedMask\n material.colorNode = savedColor\n }\n }\n}\n\nclass WindfoilClipSpaceNode extends Node {\n static readonly type = 'UltraWindfoilClipSpaceNode'\n\n constructor(\n readonly clipBox: { current?: WindfoilVertexClip },\n readonly fallback: Node,\n ) {\n super('vec4')\n }\n\n override setup(builder: NodeBuilder): Node {\n const clip = this.clipBox.current\n const mat = builder.material as { isShadowPassMaterial?: boolean; fog?: boolean }\n if (\n clip &&\n !mat.isShadowPassMaterial &&\n !((builder as { fogNode?: Node | null }).fogNode && mat.fog)\n ) {\n return clip.clip0.add(clip.colX.mul(clip.offset.x)).add(clip.colY.mul(clip.offset.y))\n }\n return this.fallback\n }\n}\n\n/** Analytic, atlas-free quadratic-outline text using the Windfoil coverage integral. */\nexport class WindfoilMaterial extends GlyphTextMaterial {\n readonly #sc: UniformNode<'float', number> = uniform(0.5)\n readonly #canFastClip: boolean\n readonly #clipBox: { current?: WindfoilVertexClip }\n\n get shadowCutoff(): UniformNode<'float', number> {\n return this.#sc\n }\n\n /** @internal */\n protected override copySubclassUniforms(target: this): void {\n target.shadowCutoff.value = this.#sc.value\n }\n\n /** @internal */\n override setupDiffuseColor(builder: NodeBuilder): void {\n runBeautyClipDiffuseColor(this, builder, this.insideClip, () => {\n super.setupDiffuseColor(builder)\n })\n }\n\n /**\n * Reuses `clip0 + colX * offset.x + colY * offset.y` from the skirt pass so\n * Three skips the extra `modelViewMatrix * positionLocal` and projection matrix\n * multiply when no custom `vertex`, `keepGlyph`, fog, or shadow pass overrides it.\n */\n override setupVertex(builder: NodeBuilder): Node {\n const mvp = super.setupVertex(builder)\n return this.#canFastClip ? new WindfoilClipSpaceNode(this.#clipBox, mvp) : mvp\n }\n\n constructor(options: WindfoilMaterialOptions) {\n const bounds = attribute<'vec4'>('windfoilBounds', 'vec4')\n const fragmentBounds = varying(bounds, 'vUltraWindfoilBounds').setInterpolation(\n 'flat',\n 'either',\n )\n // The band header's first row and row count, like the paint index below, are integers the\n // fragment truncates. Interpolated, an instance's constant can arrive a hair under itself\n // (Safari's relaxed math on Apple GPUs) and read the previous row: flat keeps them exact. Any\n // vertex of the glyph gives the same value, so `either` serves compatibility-mode devices.\n const band = varying(\n attribute<'vec4'>('windfoilBand', 'vec4'),\n 'vUltraWindfoilBand',\n ).setInterpolation('flat', 'either')\n const glyphPosition = varyingProperty('vec2', 'vUltraWindfoilPosition')\n const layer = options.layered ? attribute<'vec4'>('windfoilLayer', 'vec4') : null\n const paintVarying = layer\n ? varying(layer.w, 'vUltraWindfoilPaint').setInterpolation('flat', 'either')\n : null\n // A tone model that dilates the outline: each glyph's dilation in pixels, below zero from\n // the size where the model stops. Its em is the font size the instance carries in\n // `sdfMeta.z`, whose sign belongs to the size switch. An instance without one, and every\n // colour layer, reads as text of no size: the outline stays where it is.\n const dilation = resolveTextTone(options.tone)?.dilationPx\n ? varyingProperty('float', 'vUltraWindfoilDilation')\n : null\n const clipBox: { current?: WindfoilVertexClip } = {}\n const setClip = (clip: WindfoilVertexClip): void => {\n clipBox.current = clip\n }\n const extension: GlyphVertexExtension = dilation\n ? (...vertex) => {\n const meta = attribute<'vec3'>('sdfMeta', 'vec3')\n // Attribute nodes are shared by name, and the shared graph may have declared this\n // one two wide: its own identity keeps the third component.\n meta.getHash = () => String(meta.id)\n const em = abs(meta.z)\n // The tone's uniforms exist by the time a shader function first runs.\n return windfoilVertexExtension(\n bounds,\n glyphPosition,\n {\n law: this.tone!.dilation,\n em: layer ? em.mul(step(layer.w, 0.25)) : em,\n amount: dilation,\n },\n setClip,\n )(...vertex)\n }\n : windfoilVertexExtension(bounds, glyphPosition, undefined, setClip)\n super(options, extension, layer ? { index: layer.z, center: layer.xy } : undefined)\n this.#canFastClip = !options.vertex && !options.keepGlyph\n this.#clipBox = clipBox\n this.name = 'ultra-text TSL Windfoil text'\n this.shadowCutoff.value = Math.min(1, Math.max(0, options.shadowCutoff ?? 0.5))\n\n const { integrateFace, profileFace } = createWindfoilCoverage(options)\n const coverageOf = (grown: Node<'float'> | null): Node<'float'> =>\n Fn<Node<'float'>>(() => {\n // The integration box matches the pixel footprint's spread along each\n // outline axis: a box of width w has variance w²/12, as does the footprint\n // when w is the length of that axis's screen gradient. fwidth() would use\n // the footprint's bounding box, blurring rotated or sheared text by up to\n // √2 per axis. Axis-aligned text gets the same box either way.\n const dy = grown ? dFdy(glyphPosition) : undefined\n const pixel = windfoilPixelBox(glyphPosition, dy)\n let size = pixel\n let center: Node<'vec2'> = glyphPosition\n let area = pixel.x.mul(pixel.y)\n if (grown) {\n // A box 2d pixels larger, divided by one growth: a straight edge at x pixels from\n // the centre then covers clamp(0.5 + x + d), the exact coverage of the outline moved\n // out by d. Sampled d pixels lower on screen, edges facing down keep their place\n // and edges facing up rise by 2d. Empty pixels stay 0 and pixels inside the ink 1,\n // but where a corner faces down the box overhangs the ink on two sides: that pixel\n // row gets no dilation from the side, and at worst (1 + d) / (1 + 2d) of its ink.\n const amount = max(grown, 0).toConst()\n const growth = amount.mul(2).add(1).toConst()\n size = pixel.mul(growth).toConst()\n center = glyphPosition.sub(dy!.mul(amount)).toConst()\n area = area.mul(growth)\n }\n const integral = float(0).toVar('windfoilIntegral')\n // Glyphs of a few pixels use their ink profile, whatever the dilation.\n If(pixel.mul(3.7).greaterThanEqual(fragmentBounds.zw.sub(fragmentBounds.xy)).all(), () => {\n integral.assign(profileFace(band, fragmentBounds, center, size))\n }).Else(() => {\n integral.assign(integrateFace(band, fragmentBounds.y, center, size))\n })\n return clamp(abs(integral.div(area)), 0, 1)\n })()\n // The exact coverage: every shadow mask, and the beauty pass of the models that keep the\n // outline as it is.\n const coverage =\n dilation && !paintVarying ? lazyFloat(() => coverageOf(null)) : coverageOf(null)\n // Beauty coverage of foreground text ink, toned from the instance colour or from a fill's\n // own colour. Colour layers, paint and every shadow mask keep the exact coverage, and\n // with `tone: false` this is that same node: the graph has no trace of the conversion.\n const tone = this.tone\n // A toned graph reads the exact coverage more than once. One local keeps the integral in\n // one place; a conditional would evaluate it again in each of its branches.\n const exact = tone ? (dilation ? coverageOf(dilation) : coverage).toConst() : coverage\n // The model's table stops where its dilation does.\n const gate = dilation ? step(0, dilation) : undefined\n const inked = (ink?: Node<'vec3'>): Node<'float'> => this.toned(exact, ink, gate)\n // Layered geometry also carries solid colour layers, which stay exact.\n const foreground = (ink?: Node<'vec3'>): Node<'float'> =>\n tone && paintVarying ? mix(exact, inked(ink), step(paintVarying, 0.25)) : inked(ink)\n\n if (paintVarying && options.paintFunctions) {\n // `toning` false rebuilds the exact paint, whose alpha the shadow mask keeps.\n const painted = (toning: boolean): Node<'vec4'> =>\n Fn<Node<'vec4'>>(() => {\n const own = toning ? exact : coverage\n const result = (\n vec4(this.colorVarying.rgb, own).toVar() as unknown as {\n setAssignable(value: boolean): Node<'vec4'>\n }\n ).setAssignable(true)\n If(own.greaterThan(0), () => {\n If(paintVarying.greaterThanEqual(2), () => {\n const encoded = options.paintFunctions!.evaluatePaint(\n uint(paintVarying.sub(2)),\n glyphPosition,\n vec4(0),\n )\n result.assign(\n vec4(\n srgbAttributeToWorking(vec3(encoded.rgb.div(max(encoded.a, 1e-6)))),\n encoded.a.mul(own),\n ),\n )\n }).ElseIf(paintVarying.lessThan(0.5), () => {\n if (this.fillNode)\n result.assign(\n vec4(\n this.fillNode.rgb,\n (toning ? inked(this.fillNode.rgb) : own).mul(clamp(this.fillNode.a, 0, 1)),\n ),\n )\n else if (toning) result.assign(vec4(this.colorVarying.rgb, inked()))\n })\n })\n return result\n })()\n // A shadow pass reads the exact paint alone, so it evaluates one paint.\n const exactPaint = painted(false)\n this.applyCoverage(\n coverage,\n exactPaint.a,\n this.shadowCutoff,\n tone ? painted(true) : exactPaint,\n !!tone,\n )\n } else if (paintVarying && this.fillNode) {\n const solid = paintVarying.greaterThan(0.5).toConst()\n const opacity = solid\n .select(float(1), clamp(this.fillNode.a, 0, 1))\n .context({ uniformFlow: true })\n .toConst()\n const alpha = coverage.mul(opacity).toConst()\n this.applyCoverage(\n coverage,\n alpha,\n this.shadowCutoff,\n vec4(\n solid.select(this.colorVarying.rgb, this.fillNode.rgb).context({ uniformFlow: true }),\n tone ? foreground(this.fillNode.rgb).mul(opacity).toConst() : alpha,\n ),\n !!tone,\n )\n } else {\n this.applyCoverage(\n foreground(this.fillNode?.rgb),\n coverage,\n this.shadowCutoff,\n undefined,\n !!tone,\n )\n }\n // Clip before the analytic coverage loops. A logical AND on the final mask\n // alone materializes coverage first, even for fragments outside the block.\n // Keep the test separate from derivative-dependent coverage: discard retains\n // helper invocations for derivatives at the surviving clip edge.\n const clip = Fn(() => {\n this.insideClip.not().discard()\n })()\n this.maskNode = this.maskNode!.bypass(clip)\n this.maskShadowNode = this.maskShadowNode!.bypass(clip)\n }\n}\n"],"mappings":";;;;;;;AAwDA,SAAgB,0BACd,UAKA,SACA,YACA,UACM;CACN,MAAM,MAAM,QAAQ;CAMpB,MAAM,WACJ,IAAI,gBAAgB,SACpB,CAAC,IAAI,cACL,CAAC,IAAI,aACL,CAAC,IAAI,wBACL,SAAS,aAAa,SAAS;CACjC,MAAM,YAAY,WAAW,SAAS,WAAW;CACjD,MAAM,aAAa,WAAW,SAAS,YAAY;CACnD,IAAI,UAAU;EACZ,SAAS,WAAW;EACpB,IAAI,YAAY;GACd,MAAM,QAAQ;GACd,SAAS,YAAY,KACnB,MAAM,KACN,WAAW,OAAO,MAAM,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,aAAa,KAAK,CAAC,CAC7D;EACF;CACF;CACA,IAAI;EACF,SAAS;CACX,UAAU;EACR,IAAI,UAAU;GACZ,SAAS,WAAW;GACpB,SAAS,YAAY;EACvB;CACF;AACF;AAEA,IAAM,wBAAN,cAAoC,KAAK;CAI5B;CACA;CAJX,OAAgB,OAAO;CAEvB,YACE,SACA,UACA;EACA,MAAM,MAAM;EAHH,KAAA,UAAA;EACA,KAAA,WAAA;CAGX;CAEA,MAAe,SAA4B;EACzC,MAAM,OAAO,KAAK,QAAQ;EAC1B,MAAM,MAAM,QAAQ;EACpB,IACE,QACA,CAAC,IAA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,CAAC,CAAC,CAAC;EACH,KAAK,WAAW,KAAK,SAAU,OAAO,IAAI;EAC1C,KAAK,iBAAiB,KAAK,eAAgB,OAAO,IAAI;CACxD;AACF"}
@@ -53,7 +53,7 @@ function writeWindfoilCompositeGeometry(geometry, snapshot, glyphs, padding, ord
53
53
  cachedSnapshot = null;
54
54
  cachedGlyphs = null;
55
55
  const headers = scratchHeaders;
56
- let count = 0, maxSequence = 0, minZ = 0, maxZ = 0;
56
+ let count = 0, maxSequence = 0, minZ = 0, maxZ = 0, prevColor, pc0 = 0, pc1 = 0, pc2 = 0, pc3 = 0;
57
57
  const rectAttribute = geometry.getAttribute("sdfRect"), clipAttribute = geometry.getAttribute("sdfClip"), colorAttribute = geometry.getAttribute("sdfColor"), metaAttribute = geometry.getAttribute("sdfMeta"), boundsAttribute = geometry.getAttribute("windfoilBounds"), layersAttribute = geometry.getAttribute("windfoilLayers");
58
58
  const rects = rectAttribute.array, clips = clipAttribute.array, colors = colorAttribute.array, metadata = metaAttribute.array, bounds = boundsAttribute.array, layers = layersAttribute.array;
59
59
  const list = snapshot.glyphs;
@@ -75,10 +75,17 @@ function writeWindfoilCompositeGeometry(geometry, snapshot, glyphs, padding, ord
75
75
  clips[offset + 2] = clip[2];
76
76
  clips[offset + 3] = clip[3];
77
77
  const color = glyph.color;
78
- colors[offset] = byte(color[0]);
79
- colors[offset + 1] = byte(color[1]);
80
- colors[offset + 2] = byte(color[2]);
81
- colors[offset + 3] = byte(color[3]);
78
+ if (color !== prevColor) {
79
+ prevColor = color;
80
+ pc0 = byte(color[0]);
81
+ pc1 = byte(color[1]);
82
+ pc2 = byte(color[2]);
83
+ pc3 = byte(color[3]);
84
+ }
85
+ colors[offset] = pc0;
86
+ colors[offset + 1] = pc1;
87
+ colors[offset + 2] = pc2;
88
+ colors[offset + 3] = pc3;
82
89
  const metaOffset = count * 2, seq = glyph.sequence, z = glyph.z;
83
90
  metadata[metaOffset] = seq;
84
91
  metadata[metaOffset + 1] = z;
@@ -1 +1 @@
1
- {"version":3,"file":"compositeGeometry.js","names":[],"sources":["../../src/windfoil/compositeGeometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\nimport { byte, setBounds, setUnitQuad } from '../text/geometryUtils.js'\nimport type { DomLayoutSnapshot, WindfoilBoundingBox } from '../types.js'\n/** The snapshot fields composite geometry reads; shape handles pass instance layouts. */\nexport type WindfoilCompositeLayout = Pick<DomLayoutSnapshot, 'glyphs' | 'width' | 'height'>\nimport type { WindfoilGlyphHeader } from './preprocess.js'\nexport interface WindfoilCompositeHeader extends WindfoilGlyphHeader {\n readonly layerStart: number\n readonly layerCount: number\n}\nconst ATTRIBUTES = [\n ['sdfRect', 4],\n ['sdfClip', 4],\n ['sdfColor', 4],\n ['sdfMeta', 2],\n ['windfoilBounds', 4],\n ['windfoilLayers', 3],\n] as const\n/** Ink bounds after the optional outline clip; the composite quad and cell grid span it. */\nexport function windfoilCompositeBox(header: WindfoilGlyphHeader): WindfoilBoundingBox {\n const box = header.bbox,\n clip = header.clipBox\n return clip\n ? [\n Math.max(box[0], clip[0]),\n Math.max(box[1], clip[1]),\n Math.min(box[2], clip[2]),\n Math.min(box[3], clip[3]),\n ]\n : box\n}\nfunction drawable(header: WindfoilGlyphHeader | undefined): header is WindfoilGlyphHeader {\n if (!header?.monotonePieceCount) return false\n const box = header.bbox,\n clip = header.clipBox\n if (!clip) return box[0] < box[2] && box[1] < box[3]\n return (\n Math.max(box[0], clip[0]) < Math.min(box[2], clip[2]) &&\n Math.max(box[1], clip[1]) < Math.min(box[3], clip[3])\n )\n}\nlet cachedSnapshot: WindfoilCompositeLayout | null = null\nlet cachedGlyphs: ReadonlyMap<string, WindfoilCompositeHeader> | null = null\nlet scratchHeaders = new Array<WindfoilCompositeHeader | undefined>(256)\n\nfunction countInstances(\n snapshot: WindfoilCompositeLayout,\n glyphs: ReadonlyMap<string, WindfoilCompositeHeader>,\n): number {\n const list = snapshot.glyphs\n const len = list.length\n if (scratchHeaders.length < len)\n scratchHeaders = new Array<WindfoilCompositeHeader | undefined>(len)\n const headers = scratchHeaders\n let count = 0\n for (let i = 0; i < len; i++) {\n const h = glyphs.get(list[i]!.glyphKey)\n if (drawable(h)) {\n headers[i] = h\n count++\n } else {\n headers[i] = undefined\n }\n }\n cachedSnapshot = snapshot\n cachedGlyphs = glyphs\n return count\n}\nexport function windfoilCompositeContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: WindfoilCompositeLayout,\n glyphs: ReadonlyMap<string, WindfoilCompositeHeader>,\n): boolean {\n return countInstances(snapshot, glyphs) === geometry.instanceCount\n}\nfunction writeWindfoilCompositeGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: WindfoilCompositeLayout,\n glyphs: ReadonlyMap<string, WindfoilCompositeHeader>,\n padding: number,\n ordinals?: Float32Array,\n): number {\n if (cachedSnapshot !== snapshot || cachedGlyphs !== glyphs) {\n countInstances(snapshot, glyphs)\n }\n cachedSnapshot = null\n cachedGlyphs = null\n const headers = scratchHeaders\n let count = 0,\n maxSequence = 0,\n minZ = 0,\n maxZ = 0\n const rectAttribute = geometry.getAttribute('sdfRect') as InstancedBufferAttribute,\n clipAttribute = geometry.getAttribute('sdfClip') as InstancedBufferAttribute,\n colorAttribute = geometry.getAttribute('sdfColor') as InstancedBufferAttribute,\n metaAttribute = geometry.getAttribute('sdfMeta') as InstancedBufferAttribute,\n boundsAttribute = geometry.getAttribute('windfoilBounds') as InstancedBufferAttribute,\n layersAttribute = geometry.getAttribute('windfoilLayers') as InstancedBufferAttribute\n const rects = rectAttribute.array as Float32Array,\n clips = clipAttribute.array as Float32Array,\n colors = colorAttribute.array as Uint8Array,\n metadata = metaAttribute.array as Float32Array,\n bounds = boundsAttribute.array as Float32Array,\n layers = layersAttribute.array as Float32Array\n const list = snapshot.glyphs\n for (let index = 0, len = list.length; index < len; index++) {\n const header = headers[index]\n if (!header) continue\n const glyph = list[index]!\n const rawBox = header.bbox,\n clipBox = header.clipBox\n const b0 = clipBox ? Math.max(rawBox[0], clipBox[0]) : rawBox[0],\n b1 = clipBox ? Math.max(rawBox[1], clipBox[1]) : rawBox[1],\n b2 = clipBox ? Math.min(rawBox[2], clipBox[2]) : rawBox[2],\n b3 = clipBox ? Math.min(rawBox[3], clipBox[3]) : rawBox[3]\n const scale = glyph.fontSize / header.unitsPerEm,\n baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale),\n ox = glyph.originX\n const offset = count * 4\n rects[offset] = ox + b0 * scale\n rects[offset + 1] = baseline + b1 * scale\n rects[offset + 2] = ox + b2 * scale\n rects[offset + 3] = baseline + b3 * scale\n const clip = glyph.clip\n clips[offset] = clip[0]\n clips[offset + 1] = clip[1]\n clips[offset + 2] = clip[2]\n clips[offset + 3] = clip[3]\n const color = glyph.color\n colors[offset] = byte(color[0])\n colors[offset + 1] = byte(color[1])\n colors[offset + 2] = byte(color[2])\n colors[offset + 3] = byte(color[3])\n const metaOffset = count * 2,\n seq = glyph.sequence,\n z = glyph.z\n metadata[metaOffset] = seq\n metadata[metaOffset + 1] = z\n bounds[offset] = b0\n bounds[offset + 1] = b1\n bounds[offset + 2] = b2\n bounds[offset + 3] = b3\n const layerOffset = count * 3\n layers[layerOffset] = header.layerStart\n layers[layerOffset + 1] = clipBox ? -header.layerCount : header.layerCount\n layers[layerOffset + 2] = ordinals ? ordinals[index]! : (glyph.motionOrigin?.[2] ?? count)\n count++\n if (seq > maxSequence) maxSequence = seq\n if (z < minZ) minZ = z\n if (z > maxZ) maxZ = z\n }\n if (headers.length > 16384) scratchHeaders = new Array<WindfoilCompositeHeader | undefined>(256)\n if (count) {\n rectAttribute.needsUpdate = true\n clipAttribute.needsUpdate = true\n colorAttribute.needsUpdate = true\n metaAttribute.needsUpdate = true\n boundsAttribute.needsUpdate = true\n layersAttribute.needsUpdate = true\n }\n ;(geometry.userData['ultraGlyphRects'] as Float32Array).set(rects)\n setBounds(geometry, snapshot.width, snapshot.height, padding, minZ, maxZ)\n return maxSequence\n}\nexport function updateWindfoilCompositeGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: WindfoilCompositeLayout,\n glyphs: ReadonlyMap<string, WindfoilCompositeHeader>,\n padding: number,\n ordinals?: Float32Array,\n): number | null {\n if (!windfoilCompositeContentFits(geometry, snapshot, glyphs)) return null\n return writeWindfoilCompositeGeometry(geometry, snapshot, glyphs, padding, ordinals)\n}\n/** One quad per colour glyph. Clip boxes become analytic quad bounds. */\nexport function createWindfoilCompositeGeometry(\n snapshot: WindfoilCompositeLayout,\n glyphs: ReadonlyMap<string, WindfoilCompositeHeader>,\n padding: number,\n ordinals?: Float32Array,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n const geometry = new InstancedBufferGeometry(),\n count = countInstances(snapshot, glyphs)\n setUnitQuad(geometry)\n geometry.instanceCount = count\n geometry.name = 'ultra-text Windfoil colour glyph quads'\n for (const [name, size] of ATTRIBUTES)\n geometry.setAttribute(\n name,\n new InstancedBufferAttribute(\n name === 'sdfColor' ? new Uint8Array(count * size) : new Float32Array(count * size),\n size,\n name === 'sdfColor',\n ),\n )\n geometry.userData['ultraGlyphRects'] = new Float32Array(count * 4)\n return {\n geometry,\n maxSequence: writeWindfoilCompositeGeometry(geometry, snapshot, glyphs, padding, ordinals),\n }\n}\n"],"mappings":";;;AAUA,IAAM,aAAa;CACjB,CAAC,WAAW,CAAC;CACb,CAAC,WAAW,CAAC;CACb,CAAC,YAAY,CAAC;CACd,CAAC,WAAW,CAAC;CACb,CAAC,kBAAkB,CAAC;CACpB,CAAC,kBAAkB,CAAC;AACtB;;AAEA,SAAgB,qBAAqB,QAAkD;CACrF,MAAM,MAAM,OAAO,MACjB,OAAO,OAAO;CAChB,OAAO,OACH;EACE,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE;EACxB,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE;EACxB,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE;EACxB,KAAK,IAAI,IAAI,IAAI,KAAK,EAA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AAM,SAAS,YACzB,SAAS,aACP,MACA,IAAI,yBACF,SAAS,aAAa,IAAI,WAAW,QAAQ,IAAI,IAAI,IAAI,aAAa,QAAQ,IAAI,GAClF,MACA,SAAS,UACX,CACF;CACF,SAAS,SAAS,qBAAqB,IAAI,aAAa,QAAQ,CAAC;CACjE,OAAO;EACL;EACA,aAAa,+BAA+B,UAAU,UAAU,QAAQ,SAAS,QAAQ;CAC3F;AACF"}
1
+ {"version":3,"file":"compositeGeometry.js","names":[],"sources":["../../src/windfoil/compositeGeometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\nimport { byte, setBounds, setUnitQuad } from '../text/geometryUtils.js'\nimport type { DomLayoutSnapshot, WindfoilBoundingBox } from '../types.js'\n/** The snapshot fields composite geometry reads; shape handles pass instance layouts. */\nexport type WindfoilCompositeLayout = Pick<DomLayoutSnapshot, 'glyphs' | 'width' | 'height'>\nimport type { WindfoilGlyphHeader } from './preprocess.js'\nexport interface WindfoilCompositeHeader extends WindfoilGlyphHeader {\n readonly layerStart: number\n readonly layerCount: number\n}\nconst ATTRIBUTES = [\n ['sdfRect', 4],\n ['sdfClip', 4],\n ['sdfColor', 4],\n ['sdfMeta', 2],\n ['windfoilBounds', 4],\n ['windfoilLayers', 3],\n] as const\n/** Ink bounds after the optional outline clip; the composite quad and cell grid span it. */\nexport function windfoilCompositeBox(header: WindfoilGlyphHeader): WindfoilBoundingBox {\n const box = header.bbox,\n clip = header.clipBox\n return clip\n ? [\n Math.max(box[0], clip[0]),\n Math.max(box[1], clip[1]),\n Math.min(box[2], clip[2]),\n Math.min(box[3], clip[3]),\n ]\n : box\n}\nfunction drawable(header: WindfoilGlyphHeader | undefined): header is WindfoilGlyphHeader {\n if (!header?.monotonePieceCount) return false\n const box = header.bbox,\n clip = header.clipBox\n if (!clip) return box[0] < box[2] && box[1] < box[3]\n return (\n Math.max(box[0], clip[0]) < Math.min(box[2], clip[2]) &&\n Math.max(box[1], clip[1]) < Math.min(box[3], clip[3])\n )\n}\nlet cachedSnapshot: WindfoilCompositeLayout | null = null\nlet cachedGlyphs: ReadonlyMap<string, WindfoilCompositeHeader> | null = null\nlet scratchHeaders = new Array<WindfoilCompositeHeader | undefined>(256)\n\nfunction countInstances(\n snapshot: WindfoilCompositeLayout,\n glyphs: ReadonlyMap<string, WindfoilCompositeHeader>,\n): number {\n const list = snapshot.glyphs\n const len = list.length\n if (scratchHeaders.length < len)\n scratchHeaders = new Array<WindfoilCompositeHeader | undefined>(len)\n const headers = scratchHeaders\n let count = 0\n for (let i = 0; i < len; i++) {\n const h = glyphs.get(list[i]!.glyphKey)\n if (drawable(h)) {\n headers[i] = h\n count++\n } else {\n headers[i] = undefined\n }\n }\n cachedSnapshot = snapshot\n cachedGlyphs = glyphs\n return count\n}\nexport function windfoilCompositeContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: WindfoilCompositeLayout,\n glyphs: ReadonlyMap<string, WindfoilCompositeHeader>,\n): boolean {\n return countInstances(snapshot, glyphs) === geometry.instanceCount\n}\nfunction writeWindfoilCompositeGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: WindfoilCompositeLayout,\n glyphs: ReadonlyMap<string, WindfoilCompositeHeader>,\n padding: number,\n ordinals?: Float32Array,\n): number {\n if (cachedSnapshot !== snapshot || cachedGlyphs !== glyphs) {\n countInstances(snapshot, glyphs)\n }\n cachedSnapshot = null\n cachedGlyphs = null\n const headers = scratchHeaders\n let count = 0,\n maxSequence = 0,\n minZ = 0,\n maxZ = 0,\n prevColor: readonly [number, number, number, number] | undefined,\n pc0 = 0,\n pc1 = 0,\n pc2 = 0,\n pc3 = 0\n const rectAttribute = geometry.getAttribute('sdfRect') as InstancedBufferAttribute,\n clipAttribute = geometry.getAttribute('sdfClip') as InstancedBufferAttribute,\n colorAttribute = geometry.getAttribute('sdfColor') as InstancedBufferAttribute,\n metaAttribute = geometry.getAttribute('sdfMeta') as InstancedBufferAttribute,\n boundsAttribute = geometry.getAttribute('windfoilBounds') as InstancedBufferAttribute,\n layersAttribute = geometry.getAttribute('windfoilLayers') as InstancedBufferAttribute\n const rects = rectAttribute.array as Float32Array,\n clips = clipAttribute.array as Float32Array,\n colors = colorAttribute.array as Uint8Array,\n metadata = metaAttribute.array as Float32Array,\n bounds = boundsAttribute.array as Float32Array,\n layers = layersAttribute.array as Float32Array\n const list = snapshot.glyphs\n for (let index = 0, len = list.length; index < len; index++) {\n const header = headers[index]\n if (!header) continue\n const glyph = list[index]!\n const rawBox = header.bbox,\n clipBox = header.clipBox\n const b0 = clipBox ? Math.max(rawBox[0], clipBox[0]) : rawBox[0],\n b1 = clipBox ? Math.max(rawBox[1], clipBox[1]) : rawBox[1],\n b2 = clipBox ? Math.min(rawBox[2], clipBox[2]) : rawBox[2],\n b3 = clipBox ? Math.min(rawBox[3], clipBox[3]) : rawBox[3]\n const scale = glyph.fontSize / header.unitsPerEm,\n baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale),\n ox = glyph.originX\n const offset = count * 4\n rects[offset] = ox + b0 * scale\n rects[offset + 1] = baseline + b1 * scale\n rects[offset + 2] = ox + b2 * scale\n rects[offset + 3] = baseline + b3 * scale\n const clip = glyph.clip\n clips[offset] = clip[0]\n clips[offset + 1] = clip[1]\n clips[offset + 2] = clip[2]\n clips[offset + 3] = clip[3]\n const color = glyph.color\n if (color !== prevColor) {\n prevColor = color\n pc0 = byte(color[0])\n pc1 = byte(color[1])\n pc2 = byte(color[2])\n pc3 = byte(color[3])\n }\n colors[offset] = pc0\n colors[offset + 1] = pc1\n colors[offset + 2] = pc2\n colors[offset + 3] = pc3\n const metaOffset = count * 2,\n seq = glyph.sequence,\n z = glyph.z\n metadata[metaOffset] = seq\n metadata[metaOffset + 1] = z\n bounds[offset] = b0\n bounds[offset + 1] = b1\n bounds[offset + 2] = b2\n bounds[offset + 3] = b3\n const layerOffset = count * 3\n layers[layerOffset] = header.layerStart\n layers[layerOffset + 1] = clipBox ? -header.layerCount : header.layerCount\n layers[layerOffset + 2] = ordinals ? ordinals[index]! : (glyph.motionOrigin?.[2] ?? count)\n count++\n if (seq > maxSequence) maxSequence = seq\n if (z < minZ) minZ = z\n if (z > maxZ) maxZ = z\n }\n if (headers.length > 16384) scratchHeaders = new Array<WindfoilCompositeHeader | undefined>(256)\n if (count) {\n rectAttribute.needsUpdate = true\n clipAttribute.needsUpdate = true\n colorAttribute.needsUpdate = true\n metaAttribute.needsUpdate = true\n boundsAttribute.needsUpdate = true\n layersAttribute.needsUpdate = true\n }\n ;(geometry.userData['ultraGlyphRects'] as Float32Array).set(rects)\n setBounds(geometry, snapshot.width, snapshot.height, padding, minZ, maxZ)\n return maxSequence\n}\nexport function updateWindfoilCompositeGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: WindfoilCompositeLayout,\n glyphs: ReadonlyMap<string, WindfoilCompositeHeader>,\n padding: number,\n ordinals?: Float32Array,\n): number | null {\n if (!windfoilCompositeContentFits(geometry, snapshot, glyphs)) return null\n return writeWindfoilCompositeGeometry(geometry, snapshot, glyphs, padding, ordinals)\n}\n/** One quad per colour glyph. Clip boxes become analytic quad bounds. */\nexport function createWindfoilCompositeGeometry(\n snapshot: WindfoilCompositeLayout,\n glyphs: ReadonlyMap<string, WindfoilCompositeHeader>,\n padding: number,\n ordinals?: Float32Array,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n const geometry = new InstancedBufferGeometry(),\n count = countInstances(snapshot, glyphs)\n setUnitQuad(geometry)\n geometry.instanceCount = count\n geometry.name = 'ultra-text Windfoil colour glyph quads'\n for (const [name, size] of ATTRIBUTES)\n geometry.setAttribute(\n name,\n new InstancedBufferAttribute(\n name === 'sdfColor' ? new Uint8Array(count * size) : new Float32Array(count * size),\n size,\n name === 'sdfColor',\n ),\n )\n geometry.userData['ultraGlyphRects'] = new Float32Array(count * 4)\n return {\n geometry,\n maxSequence: writeWindfoilCompositeGeometry(geometry, snapshot, glyphs, padding, ordinals),\n }\n}\n"],"mappings":";;;AAUA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B,eAAe,cAAc;EAC7B,cAAc,cAAc;EAC5B,gBAAgB,cAAc;EAC9B,gBAAgB,cAAc;CAChC;CACC,SAAU,SAAS,kBAAkB,CAAkB,IAAI,KAAK;CACjE,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,SAAS,MAAM,IAAI;CACxE,OAAO;AACT;AACA,SAAgB,gCACd,UACA,UACA,QACA,SACA,UACe;CACf,IAAI,CAAC,6BAA6B,UAAU,UAAU,MAAM,GAAG,OAAO;CACtE,OAAO,+BAA+B,UAAU,UAAU,QAAQ,SAAS,QAAQ;AACrF;;AAEA,SAAgB,gCACd,UACA,QACA,SACA,UAC4D;CAC5D,MAAM,WAAW,IAAI,wBAAwB,GAC3C,QAAQ,eAAe,UAAU,MAAM;CACzC,YAAY,QAAQ;CACpB,SAAS,gBAAgB;CACzB,SAAS,OAAO;CAChB,KAAK,MAAM,CAAC,MAAM,SAAS,YACzB,SAAS,aACP,MACA,IAAI,yBACF,SAAS,aAAa,IAAI,WAAW,QAAQ,IAAI,IAAI,IAAI,aAAa,QAAQ,IAAI,GAClF,MACA,SAAS,UACX,CACF;CACF,SAAS,SAAS,qBAAqB,IAAI,aAAa,QAAQ,CAAC;CACjE,OAAO;EACL;EACA,aAAa,+BAA+B,UAAU,UAAU,QAAQ,SAAS,QAAQ;CAC3F;AACF"}
@@ -1,11 +1,19 @@
1
- import type { Node } from 'three/webgpu';
1
+ import { Node } from 'three/webgpu';
2
2
  import type { GlyphVertexExtension } from '../text/GlyphTextMaterial.js';
3
3
  import { windfoilKernelSkirt, type WindfoilDilation } from './skirt.js';
4
4
  import type { WindfoilStorage } from './WindfoilMaterial.js';
5
5
  export { windfoilKernelSkirt, type WindfoilDilation };
6
- export declare function windfoilVertexExtension(bounds: Node<'vec4'>, glyphPosition: Node<'vec2'>, dilation?: WindfoilDilation): GlyphVertexExtension;
6
+ export interface WindfoilVertexClip {
7
+ readonly clip0: Node<'vec4'>;
8
+ readonly colX: Node<'vec4'>;
9
+ readonly colY: Node<'vec4'>;
10
+ readonly offset: Node<'vec2'>;
11
+ }
12
+ export declare function windfoilVertexExtension(bounds: Node<'vec4'>, glyphPosition: Node<'vec2'>, dilation?: WindfoilDilation, onClip?: (clip: WindfoilVertexClip) => void): GlyphVertexExtension;
7
13
  export declare function createWindfoilCoverage(storage: WindfoilStorage): {
8
14
  integrateFace: import("three/tsl").FnNode<[import("three/webgpu").Vector4 | Node<"vec4">, number | Node<"float"> | Node<"uint">, import("three/webgpu").Vector2 | Node<"vec2">, import("three/webgpu").Vector2 | Node<"vec2">], Node<"float">>;
9
15
  profileFace: import("three/tsl").FnNode<[import("three/webgpu").Vector4 | Node<"vec4">, import("three/webgpu").Vector4 | Node<"vec4">, import("three/webgpu").Vector2 | Node<"vec2">, import("three/webgpu").Vector2 | Node<"vec2">], Node<"float">>;
10
16
  };
11
17
  export declare function windfoilPixelBox(glyphPosition: Node<'vec2'>, dy?: Node<'vec2'>): Node<'vec2'>;
18
+ /** Defers constructing a float subgraph (e.g. shadow coverage) until a builder actually evaluates it. */
19
+ export declare function lazyFloat(make: () => Node<'float'>): Node<'float'>;