@wolsok/loading-wave 0.0.1 → 0.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 (64) hide show
  1. package/README.md +146 -12
  2. package/esm2022/index.js +1 -0
  3. package/esm2022/index.js.map +1 -1
  4. package/esm2022/lib/canvas-wave-renderer.js +34 -12
  5. package/esm2022/lib/canvas-wave-renderer.js.map +1 -1
  6. package/esm2022/lib/choose-wave-renderer.js +8 -3
  7. package/esm2022/lib/choose-wave-renderer.js.map +1 -1
  8. package/esm2022/lib/loading-wave-options.js +16 -2
  9. package/esm2022/lib/loading-wave-options.js.map +1 -1
  10. package/esm2022/lib/loading-wave.js +11 -3
  11. package/esm2022/lib/loading-wave.js.map +1 -1
  12. package/esm2022/lib/renderer.js.map +1 -1
  13. package/esm2022/lib/wave-model.js +33 -9
  14. package/esm2022/lib/wave-model.js.map +1 -1
  15. package/esm2022/lib/webgl/echo.js +5 -0
  16. package/esm2022/lib/webgl/echo.js.map +1 -0
  17. package/esm2022/lib/webgl/loading-wave-shader.js +1 -0
  18. package/esm2022/lib/webgl/loading-wave-shader.js.map +1 -0
  19. package/esm2022/lib/webgl/shader-program.js +235 -0
  20. package/esm2022/lib/webgl/shader-program.js.map +1 -0
  21. package/esm2022/lib/webgl/shaders/ripple.shader.js +110 -0
  22. package/esm2022/lib/webgl/shaders/ripple.shader.js.map +1 -0
  23. package/esm2022/lib/webgl/webgl-wave-renderer.js +102 -92
  24. package/esm2022/lib/webgl/webgl-wave-renderer.js.map +1 -1
  25. package/esm2022/shaders/lib/webgl/loading-wave-shader.js +1 -0
  26. package/esm2022/shaders/lib/webgl/loading-wave-shader.js.map +1 -0
  27. package/esm2022/shaders/lib/webgl/shaders/circuit-traces.shader.js +136 -0
  28. package/esm2022/shaders/lib/webgl/shaders/circuit-traces.shader.js.map +1 -0
  29. package/esm2022/shaders/lib/webgl/shaders/data-bus.shader.js +91 -0
  30. package/esm2022/shaders/lib/webgl/shaders/data-bus.shader.js.map +1 -0
  31. package/esm2022/shaders/lib/webgl/shaders/die-scan.shader.js +128 -0
  32. package/esm2022/shaders/lib/webgl/shaders/die-scan.shader.js.map +1 -0
  33. package/esm2022/shaders/lib/webgl/shaders/signal-trace.shader.js +89 -0
  34. package/esm2022/shaders/lib/webgl/shaders/signal-trace.shader.js.map +1 -0
  35. package/esm2022/shaders/lib/webgl/shaders/spark-front.shader.js +130 -0
  36. package/esm2022/shaders/lib/webgl/shaders/spark-front.shader.js.map +1 -0
  37. package/esm2022/shaders/shaders.js +12 -0
  38. package/esm2022/shaders/shaders.js.map +1 -0
  39. package/esm2022/shaders/wolsok-loading-wave-shaders.js +5 -0
  40. package/esm2022/shaders/wolsok-loading-wave-shaders.js.map +1 -0
  41. package/index.d.ts +3 -1
  42. package/lib/canvas-wave-renderer.d.ts +2 -0
  43. package/lib/choose-wave-renderer.d.ts +3 -0
  44. package/lib/loading-wave-options.d.ts +24 -4
  45. package/lib/loading-wave.d.ts +3 -3
  46. package/lib/renderer.d.ts +5 -0
  47. package/lib/wave-model.d.ts +17 -6
  48. package/lib/webgl/echo.d.ts +4 -0
  49. package/lib/webgl/loading-wave-shader.d.ts +20 -0
  50. package/lib/webgl/shader-program.d.ts +33 -0
  51. package/lib/webgl/shaders/ripple.shader.d.ts +10 -0
  52. package/lib/webgl/webgl-wave-renderer.d.ts +18 -7
  53. package/package.json +5 -1
  54. package/shaders/lib/webgl/loading-wave-shader.d.ts +20 -0
  55. package/shaders/lib/webgl/shaders/circuit-traces.shader.d.ts +12 -0
  56. package/shaders/lib/webgl/shaders/data-bus.shader.d.ts +10 -0
  57. package/shaders/lib/webgl/shaders/die-scan.shader.d.ts +10 -0
  58. package/shaders/lib/webgl/shaders/signal-trace.shader.d.ts +10 -0
  59. package/shaders/lib/webgl/shaders/spark-front.shader.d.ts +8 -0
  60. package/shaders/shaders.d.ts +5 -0
  61. package/shaders/wolsok-loading-wave-shaders.d.ts +5 -0
  62. package/esm2022/lib/webgl/wave-shaders.js +0 -114
  63. package/esm2022/lib/webgl/wave-shaders.js.map +0 -1
  64. package/lib/webgl/wave-shaders.d.ts +0 -14
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../../../../../libs/public/ws-loading-wave/src/lib/renderer.ts"],"names":[],"mappings":"AAaA,sDAAsD;AACtD,MAAM,UAAU,WAAW,CAAC,KAAgB,EAAE,KAAU;IACtD,OAAO,KAAK,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;AACzC,CAAC;AAmBD,mDAAmD;AACnD,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC;AAC/B,8CAA8C;AAC9C,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAC;AAC7B,oEAAoE;AACpE,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC;AAC9B,8CAA8C;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAerC,4EAA4E;AAC5E,MAAM,UAAU,UAAU,CACxB,MAAyB,EACzB,QAAsB,EACtB,UAAkB;IAElB,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC;IACpE,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import type { WaveGeometry } from './wave-model';\n\nexport type WaveRendererKind = 'webgl' | 'canvas';\n\n/** a colour channel by channel, each 0 to 255 */\nexport interface Rgb {\n readonly r: number;\n readonly g: number;\n readonly b: number;\n /** the colour's own opacity, 0 to 1; 1 when unset */\n readonly alpha?: number;\n}\n\n/** the frame's grid opacity times the colour's own */\nexport function dotsOpacity(frame: WaveFrame, color: Rgb): number {\n return frame.dots * (color.alpha ?? 1);\n}\n\n/** how the dots look, the same in both renderers */\nexport interface WaveLook {\n /** diameter of a dot at rest, in CSS pixels */\n readonly dotSize: number;\n readonly color: Rgb;\n}\n\n/** what one frame shows */\nexport interface WaveFrame {\n /** time since the wave started, drives where the front is */\n readonly elapsedMs: number;\n /** strength of the wave, 0 (no wave) to 1, for fading it in and out */\n readonly wave: number;\n /** opacity of the whole dot grid, 0 to 1, for fading it in and out */\n readonly dots: number;\n}\n\n/** opacity of a dot at rest, times the colour's */\nexport const REST_ALPHA = 0.22;\n/** opacity of a dot right behind the front */\nexport const LIT_ALPHA = 0.9;\n/** how much a dot right behind the front grows, 0.8 = 80% larger */\nexport const LIT_GROWTH = 0.8;\n/** opacity of the hairline along the front */\nexport const FRONT_LINE_ALPHA = 0.14;\n\n/** draws the dot grid and the wave into its own canvas */\nexport interface WaveRenderer {\n readonly kind: WaveRendererKind;\n readonly canvas: HTMLCanvasElement;\n /** sizes the canvas to the geometry at the given device pixel ratio */\n resize(geometry: WaveGeometry, pixelRatio: number): void;\n draw(frame: WaveFrame): void;\n /** changes the dots' look, say after the theme changed the host's colour */\n setLook(look: WaveLook): void;\n /** frees what the renderer holds; the canvas stays where it is */\n dispose(): void;\n}\n\n/** sets the canvas's backing store to the CSS size times the pixel ratio */\nexport function sizeCanvas(\n canvas: HTMLCanvasElement,\n geometry: WaveGeometry,\n pixelRatio: number\n): void {\n canvas.width = Math.max(1, Math.round(geometry.width * pixelRatio));\n canvas.height = Math.max(1, Math.round(geometry.height * pixelRatio));\n}\n"]}
1
+ {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../../../../../libs/public/ws-loading-wave/src/lib/renderer.ts"],"names":[],"mappings":"AAcA,sDAAsD;AACtD,MAAM,UAAU,WAAW,CAAC,KAAgB,EAAE,KAAU;IACtD,OAAO,KAAK,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;AACzC,CAAC;AAqBD,mDAAmD;AACnD,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC;AAC/B,8CAA8C;AAC9C,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAC;AAC7B,oEAAoE;AACpE,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC;AAC9B,8CAA8C;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAiBrC,4EAA4E;AAC5E,MAAM,UAAU,UAAU,CACxB,MAAyB,EACzB,QAAsB,EACtB,UAAkB;IAElB,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC;IACpE,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import type { ShaderUniforms } from './webgl/loading-wave-shader';\nimport type { WaveGeometry } from './wave-model';\n\nexport type WaveRendererKind = 'webgl' | 'canvas';\n\n/** a colour channel by channel, each 0 to 255 */\nexport interface Rgb {\n readonly r: number;\n readonly g: number;\n readonly b: number;\n /** the colour's own opacity, 0 to 1; 1 when unset */\n readonly alpha?: number;\n}\n\n/** the frame's grid opacity times the colour's own */\nexport function dotsOpacity(frame: WaveFrame, color: Rgb): number {\n return frame.dots * (color.alpha ?? 1);\n}\n\n/** how the dots look, the same in both renderers */\nexport interface WaveLook {\n /** diameter of a dot at rest, in CSS pixels */\n readonly dotSize: number;\n readonly color: Rgb;\n /** the colour lit dots and the wave take; the dots' colour when unset */\n readonly accent?: Rgb;\n}\n\n/** what one frame shows */\nexport interface WaveFrame {\n /** time since the wave started, drives where the front is */\n readonly elapsedMs: number;\n /** strength of the wave, 0 (no wave) to 1, for fading it in and out */\n readonly wave: number;\n /** opacity of the whole dot grid, 0 to 1, for fading it in and out */\n readonly dots: number;\n}\n\n/** opacity of a dot at rest, times the colour's */\nexport const REST_ALPHA = 0.22;\n/** opacity of a dot right behind the front */\nexport const LIT_ALPHA = 0.9;\n/** how much a dot right behind the front grows, 0.8 = 80% larger */\nexport const LIT_GROWTH = 0.8;\n/** opacity of the hairline along the front */\nexport const FRONT_LINE_ALPHA = 0.14;\n\n/** draws the dot grid and the wave into its own canvas */\nexport interface WaveRenderer {\n readonly kind: WaveRendererKind;\n readonly canvas: HTMLCanvasElement;\n /** sizes the canvas to the geometry at the given device pixel ratio */\n resize(geometry: WaveGeometry, pixelRatio: number): void;\n draw(frame: WaveFrame): void;\n /** changes the dots' look, say after the theme changed the host's colour */\n setLook(look: WaveLook): void;\n /** changes the values of a shader's own uniforms; only WebGL has any */\n setShaderUniforms(uniforms: ShaderUniforms | undefined): void;\n /** frees what the renderer holds; the canvas stays where it is */\n dispose(): void;\n}\n\n/** sets the canvas's backing store to the CSS size times the pixel ratio */\nexport function sizeCanvas(\n canvas: HTMLCanvasElement,\n geometry: WaveGeometry,\n pixelRatio: number\n): void {\n canvas.width = Math.max(1, Math.round(geometry.width * pixelRatio));\n canvas.height = Math.max(1, Math.round(geometry.height * pixelRatio));\n}\n"]}
@@ -1,15 +1,25 @@
1
1
  /**
2
2
  * The loading wave as pure math, shared by the 2D canvas renderer and
3
- * mirrored by the WebGL shader (`webgl/wave-shaders.ts`).
3
+ * mirrored by the WebGL shaders' header (`webgl/shader-program.ts`).
4
4
  *
5
- * The wave front is an arc of a circle whose centre lies far left of the
6
- * element, at mid-height: a ripple from off-screen. Its radius grows at an
7
- * even speed, so the front sweeps from the left edge until the lit tail
8
- * behind it has left the element at every row, then starts again.
5
+ * The wave front is an arc of a circle whose centre lies left of the
6
+ * element, at mid-height: a ripple from off-screen. How round it is
7
+ * (`frontRoundness`) sets the circle's radius. Its radius grows at an even
8
+ * speed, so the front sweeps from the left edge until the lit tail behind
9
+ * it has left the element at every row, then starts again.
9
10
  * Every length is in CSS pixels, every time in milliseconds.
10
11
  */
11
- /** how far the circle's centre lies left of the element, times its larger side */
12
- const CENTER_DISTANCE = 1.5;
12
+ /**
13
+ * How round the front is by default: its ends lag its middle by half of
14
+ * `min(height / 2, width)`.
15
+ */
16
+ export const DEFAULT_FRONT_ROUNDNESS = 0.5;
17
+ /**
18
+ * The largest radius of the front's circle, times the element's larger
19
+ * side: a straight front (`frontRoundness` 0) gets this one, which keeps the
20
+ * shader's floats exact.
21
+ */
22
+ const MAX_RADIUS_SIDES = 50;
13
23
  /** distance behind the front over which a dot dims to 1/e, in dot spacings */
14
24
  const FALLOFF_SPACINGS = 1.5;
15
25
  /** how lit a dot stays once the front passed it, as in the video */
@@ -27,9 +37,9 @@ const TAIL_SPACINGS = 4;
27
37
  export const MAX_DOTS = 20_000;
28
38
  /** the farthest a lit dot is pushed along the wave, in dot spacings */
29
39
  const MAX_PUSH_SPACINGS = 0.15;
30
- export function waveGeometry(width, height, { dotSpacing: askedSpacing, sweepMs }) {
40
+ export function waveGeometry(width, height, { dotSpacing: askedSpacing, sweepMs, frontRoundness = DEFAULT_FRONT_ROUNDNESS, }) {
31
41
  const dotSpacing = spacingWithinDotLimit(width, height, askedSpacing);
32
- const distance = CENTER_DISTANCE * Math.max(width, height, dotSpacing);
42
+ const distance = frontCircleRadius(width, height, dotSpacing, frontRoundness);
33
43
  const tail = TAIL_SPACINGS * dotSpacing;
34
44
  const endRadius = Math.hypot(distance + width + tail, height / 2);
35
45
  return {
@@ -48,6 +58,20 @@ export function waveGeometry(width, height, { dotSpacing: askedSpacing, sweepMs
48
58
  maxPush: MAX_PUSH_SPACINGS * dotSpacing,
49
59
  };
50
60
  }
61
+ /**
62
+ * The radius of the circle whose arc across the element's height lags at
63
+ * its ends by the sagitta `frontRoundness × min(height / 2, width)`:
64
+ * `R = (a² + s²) / (2s)` with `a = height / 2`, capped for a straight front.
65
+ */
66
+ function frontCircleRadius(width, height, dotSpacing, frontRoundness) {
67
+ const maxRadius = MAX_RADIUS_SIDES * Math.max(width, height, dotSpacing);
68
+ const halfHeight = height / 2;
69
+ const sagitta = frontRoundness * Math.min(halfHeight, width);
70
+ if (sagitta <= 0) {
71
+ return maxRadius;
72
+ }
73
+ return Math.min(maxRadius, (halfHeight * halfHeight + sagitta * sagitta) / (2 * sagitta));
74
+ }
51
75
  /** how many dots a grid of this spacing holds, rows times columns */
52
76
  function dotCount(width, height, spacing) {
53
77
  const along = (length) => length <= 0 ? 0 : Math.max(0, Math.ceil(length / spacing - 0.5));
@@ -1 +1 @@
1
- {"version":3,"file":"wave-model.js","sourceRoot":"","sources":["../../../../../../libs/public/ws-loading-wave/src/lib/wave-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,kFAAkF;AAClF,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,8EAA8E;AAC9E,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,oEAAoE;AACpE,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC;AAC9B,2EAA2E;AAC3E,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AACzC,8EAA8E;AAC9E,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,kEAAkE;AAClE,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC/B,uEAAuE;AACvE,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAwC/B,MAAM,UAAU,YAAY,CAC1B,KAAa,EACb,MAAc,EACd,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAuB;IAE1D,MAAM,UAAU,GAAG,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;IACtE,MAAM,QAAQ,GAAG,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IACvE,MAAM,I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H,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["/**\n * The loading wave as pure math, shared by the 2D canvas renderer and\n * mirrored by the WebGL shader (`webgl/wave-shaders.ts`).\n *\n * The wave front is an arc of a circle whose centre lies far left of the\n * element, at mid-height: a ripple from off-screen. Its radius grows at an\n * even speed, so the front sweeps from the left edge until the lit tail\n * behind it has left the element at every row, then starts again.\n * Every length is in CSS pixels, every time in milliseconds.\n */\n\n/** how far the circle's centre lies left of the element, times its larger side */\nconst CENTER_DISTANCE = 1.5;\n/** distance behind the front over which a dot dims to 1/e, in dot spacings */\nconst FALLOFF_SPACINGS = 1.5;\n/** how lit a dot stays once the front passed it, as in the video */\nexport const AFTERGLOW = 0.45;\n/** share of a sweep after which a passed dot's afterglow starts to fade */\nexport const AFTERGLOW_FADE_START = 0.45;\n/** distance ahead of the front over which a dot lights up, in dot spacings */\nconst RISE_SPACINGS = 0.25;\n/** length of the bright tail behind the front, in dot spacings */\nconst TAIL_SPACINGS = 4;\n/**\n * The most dots a grid holds: a tiny spacing on a large host is widened\n * rather than creating millions of dots each frame.\n */\nexport const MAX_DOTS = 20_000;\n/** the farthest a lit dot is pushed along the wave, in dot spacings */\nconst MAX_PUSH_SPACINGS = 0.15;\n\nexport interface WaveGeometry {\n readonly width: number;\n readonly height: number;\n readonly dotSpacing: number;\n readonly sweepMs: number;\n readonly centerX: number;\n readonly centerY: number;\n /** the front's radius at the start of a sweep: it touches the left edge */\n readonly startRadius: number;\n /** the front's radius at the end of a sweep: the tail left every row */\n readonly endRadius: number;\n /** how far the front's radius grows in one sweep */\n readonly travel: number;\n /** distance behind the front over which a dot dims to 1/e */\n readonly falloff: number;\n /** distance ahead of the front over which a dot lights up */\n readonly rise: number;\n /** length of the lit tail behind the front */\n readonly tail: number;\n /** the farthest a lit dot is pushed along the wave */\n readonly maxPush: number;\n}\n\nexport interface WaveGeometryOptions {\n readonly dotSpacing: number;\n readonly sweepMs: number;\n}\n\nexport interface Point {\n readonly x: number;\n readonly y: number;\n}\n\nexport interface Displacement {\n readonly dx: number;\n readonly dy: number;\n}\n\nexport function waveGeometry(\n width: number,\n height: number,\n { dotSpacing: askedSpacing, sweepMs }: WaveGeometryOptions\n): WaveGeometry {\n const dotSpacing = spacingWithinDotLimit(width, height, askedSpacing);\n const distance = CENTER_DISTANCE * Math.max(width, height, dotSpacing);\n const tail = TAIL_SPACINGS * dotSpacing;\n const endRadius = Math.hypot(distance + width + tail, height / 2);\n return {\n width,\n height,\n dotSpacing,\n sweepMs,\n centerX: -distance,\n centerY: height / 2,\n startRadius: distance,\n endRadius,\n travel: endRadius - distance,\n falloff: FALLOFF_SPACINGS * dotSpacing,\n rise: RISE_SPACINGS * dotSpacing,\n tail,\n maxPush: MAX_PUSH_SPACINGS * dotSpacing,\n };\n}\n\n/** how many dots a grid of this spacing holds, rows times columns */\nfunction dotCount(width: number, height: number, spacing: number): number {\n const along = (length: number) =>\n length <= 0 ? 0 : Math.max(0, Math.ceil(length / spacing - 0.5));\n return along(width) * along(height);\n}\n\n/** the asked spacing, widened until the grid holds at most `MAX_DOTS` */\nfunction spacingWithinDotLimit(\n width: number,\n height: number,\n askedSpacing: number\n): number {\n let spacing = Math.max(askedSpacing, Math.sqrt((width * height) / MAX_DOTS));\n // the rows and columns round up: widen a little more where they still do\n while (dotCount(width, height, spacing) > MAX_DOTS) {\n spacing *= 1.01;\n }\n return spacing;\n}\n\n/** the share of the current sweep that has passed, 0 up to (not including) 1 */\nexport function sweepPhase(geometry: WaveGeometry, elapsedMs: number): number {\n const { sweepMs } = geometry;\n return (((elapsedMs % sweepMs) + sweepMs) % sweepMs) / sweepMs;\n}\n\n/** the front's radius at the time `elapsedMs` */\nexport function frontRadius(geometry: WaveGeometry, elapsedMs: number): number {\n return (\n geometry.startRadius + geometry.travel * sweepPhase(geometry, elapsedMs)\n );\n}\n\n/** how far the dot lies behind the front: negative ahead of it */\nfunction distanceBehindFront(\n x: number,\n y: number,\n elapsedMs: number,\n geometry: WaveGeometry\n): number {\n const fromCenter = Math.hypot(x - geometry.centerX, y - geometry.centerY);\n return frontRadius(geometry, elapsedMs) - fromCenter;\n}\n\nfunction smoothstep(edge0: number, edge1: number, value: number): number {\n const t = Math.min(1, Math.max(0, (value - edge0) / (edge1 - edge0)));\n return t * t * (3 - 2 * t);\n}\n\n/**\n * The bright part of the wave: 1 right behind the front, dimming\n * exponentially further behind, 0 ahead of it.\n */\nfunction frontGlow(behind: number, geometry: WaveGeometry): number {\n return (\n smoothstep(-geometry.rise, 0, behind) *\n Math.exp(-Math.max(behind, 0) / geometry.falloff)\n );\n}\n\n/** whether a sweep went before this one, whose afterglow and echo show */\nexport function hasPreviousSweep(\n geometry: WaveGeometry,\n elapsedMs: number\n): boolean {\n return elapsedMs >= geometry.sweepMs;\n}\n\n/**\n * What stays lit once the front passed: `AFTERGLOW` for the first part of a\n * sweep, then fading out until the next front arrives. Ahead of the front a\n * dot still glows from the sweep before, if there was one.\n */\nfunction afterglow(\n behind: number,\n geometry: WaveGeometry,\n elapsedMs: number\n): number {\n if (behind < 0 && !hasPreviousSweep(geometry, elapsedMs)) {\n return 0;\n }\n const sincePassed =\n (behind >= 0 ? behind : behind + geometry.travel) / geometry.travel;\n return AFTERGLOW * (1 - smoothstep(AFTERGLOW_FADE_START, 1, sincePassed));\n}\n\n/**\n * How much the wave lights the dot at `(x, y)`: 1 right behind the front,\n * dimming over a few spacings to the afterglow of the dots it passed, which\n * fades out again until the next front comes. On the first sweep nothing\n * ahead of the front is lit.\n */\nexport function waveIntensity(\n x: number,\n y: number,\n elapsedMs: number,\n geometry: WaveGeometry\n): number {\n const behind = distanceBehindFront(x, y, elapsedMs, geometry);\n return Math.max(\n frontGlow(behind, geometry),\n afterglow(behind, geometry, elapsedMs)\n );\n}\n\n/**\n * How far the wave pushes the dot at `(x, y)` away from the circle's centre:\n * nothing at rest, most at one falloff behind the front.\n */\nexport function dotDisplacement(\n x: number,\n y: number,\n elapsedMs: number,\n geometry: WaveGeometry\n): Displacement {\n const behind = distanceBehindFront(x, y, elapsedMs, geometry);\n if (behind <= 0) {\n return { dx: 0, dy: 0 };\n }\n const scaled = behind / geometry.falloff;\n const push = geometry.maxPush * scaled * Math.exp(1 - scaled);\n const toX = x - geometry.centerX;\n const toY = y - geometry.centerY;\n const length = Math.hypot(toX, toY);\n return { dx: (push * toX) / length, dy: (push * toY) / length };\n}\n\n/** the centres of the grid's dots, row by row, each centred in its cell */\nexport function dotCenters({\n width,\n height,\n dotSpacing,\n}: Pick<WaveGeometry, 'width' | 'height' | 'dotSpacing'>): Point[] {\n const centers: Point[] = [];\n // an empty host has no dots, however small the spacing\n if (width <= 0 || height <= 0) {\n return centers;\n }\n for (let y = dotSpacing / 2; y < height; y += dotSpacing) {\n for (let x = dotSpacing / 2; x < width; x += dotSpacing) {\n centers.push({ x, y });\n }\n }\n return centers;\n}\n"]}
1
+ {"version":3,"file":"wave-model.js","sourceRoot":"","sources":["../../../../../../libs/public/ws-loading-wave/src/lib/wave-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAC3C;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,8EAA8E;AAC9E,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,oEAAoE;AACpE,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC;AAC9B,2EAA2E;AAC3E,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AACzC,8EAA8E;AAC9E,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,kEAAkE;AAClE,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC/B,uEAAuE;AACvE,MAAM,iBAAiB,GAAG,IAAI,CAAC;AA6C/B,MAAM,UAAU,YAAY,CAC1B,KAAa,EACb,MAAc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M,GAAG,GAAG,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC;IACjC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACpC,OAAO,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,MAAM,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,MAAM,EAAE,CAAC;AAClE,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,UAAU,CAAC,EACzB,KAAK,EACL,MAAM,EACN,UAAU,GAC4C;IACtD,MAAM,OAAO,GAAY,EAAE,CAAC;IAC5B,uDAAuD;IACvD,IAAI,KAAK,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,KAAK,IAAI,CAAC,GAAG,UAAU,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC;QACzD,KAAK,IAAI,CAAC,GAAG,UAAU,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC;YACxD,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["/**\n * The loading wave as pure math, shared by the 2D canvas renderer and\n * mirrored by the WebGL shaders' header (`webgl/shader-program.ts`).\n *\n * The wave front is an arc of a circle whose centre lies left of the\n * element, at mid-height: a ripple from off-screen. How round it is\n * (`frontRoundness`) sets the circle's radius. Its radius grows at an even\n * speed, so the front sweeps from the left edge until the lit tail behind\n * it has left the element at every row, then starts again.\n * Every length is in CSS pixels, every time in milliseconds.\n */\n\n/**\n * How round the front is by default: its ends lag its middle by half of\n * `min(height / 2, width)`.\n */\nexport const DEFAULT_FRONT_ROUNDNESS = 0.5;\n/**\n * The largest radius of the front's circle, times the element's larger\n * side: a straight front (`frontRoundness` 0) gets this one, which keeps the\n * shader's floats exact.\n */\nconst MAX_RADIUS_SIDES = 50;\n/** distance behind the front over which a dot dims to 1/e, in dot spacings */\nconst FALLOFF_SPACINGS = 1.5;\n/** how lit a dot stays once the front passed it, as in the video */\nexport const AFTERGLOW = 0.45;\n/** share of a sweep after which a passed dot's afterglow starts to fade */\nexport const AFTERGLOW_FADE_START = 0.45;\n/** distance ahead of the front over which a dot lights up, in dot spacings */\nconst RISE_SPACINGS = 0.25;\n/** length of the bright tail behind the front, in dot spacings */\nconst TAIL_SPACINGS = 4;\n/**\n * The most dots a grid holds: a tiny spacing on a large host is widened\n * rather than creating millions of dots each frame.\n */\nexport const MAX_DOTS = 20_000;\n/** the farthest a lit dot is pushed along the wave, in dot spacings */\nconst MAX_PUSH_SPACINGS = 0.15;\n\nexport interface WaveGeometry {\n readonly width: number;\n readonly height: number;\n readonly dotSpacing: number;\n readonly sweepMs: number;\n readonly centerX: number;\n readonly centerY: number;\n /** the front's radius at the start of a sweep: it touches the left edge */\n readonly startRadius: number;\n /** the front's radius at the end of a sweep: the tail left every row */\n readonly endRadius: number;\n /** how far the front's radius grows in one sweep */\n readonly travel: number;\n /** distance behind the front over which a dot dims to 1/e */\n readonly falloff: number;\n /** distance ahead of the front over which a dot lights up */\n readonly rise: number;\n /** length of the lit tail behind the front */\n readonly tail: number;\n /** the farthest a lit dot is pushed along the wave */\n readonly maxPush: number;\n}\n\nexport interface WaveGeometryOptions {\n readonly dotSpacing: number;\n readonly sweepMs: number;\n /**\n * 0 (a straight front) to 1: how far the front's ends lag its middle, as a\n * share of `min(height / 2, width)`; `DEFAULT_FRONT_ROUNDNESS` when unset\n */\n readonly frontRoundness?: number;\n}\n\nexport interface Point {\n readonly x: number;\n readonly y: number;\n}\n\nexport interface Displacement {\n readonly dx: number;\n readonly dy: number;\n}\n\nexport function waveGeometry(\n width: number,\n height: number,\n {\n dotSpacing: askedSpacing,\n sweepMs,\n frontRoundness = DEFAULT_FRONT_ROUNDNESS,\n }: WaveGeometryOptions\n): WaveGeometry {\n const dotSpacing = spacingWithinDotLimit(width, height, askedSpacing);\n const distance = frontCircleRadius(width, height, dotSpacing, frontRoundness);\n const tail = TAIL_SPACINGS * dotSpacing;\n const endRadius = Math.hypot(distance + width + tail, height / 2);\n return {\n width,\n height,\n dotSpacing,\n sweepMs,\n centerX: -distance,\n centerY: height / 2,\n startRadius: distance,\n endRadius,\n travel: endRadius - distance,\n falloff: FALLOFF_SPACINGS * dotSpacing,\n rise: RISE_SPACINGS * dotSpacing,\n tail,\n maxPush: MAX_PUSH_SPACINGS * dotSpacing,\n };\n}\n\n/**\n * The radius of the circle whose arc across the element's height lags at\n * its ends by the sagitta `frontRoundness × min(height / 2, width)`:\n * `R = (a² + s²) / (2s)` with `a = height / 2`, capped for a straight front.\n */\nfunction frontCircleRadius(\n width: number,\n height: number,\n dotSpacing: number,\n frontRoundness: number\n): number {\n const maxRadius = MAX_RADIUS_SIDES * Math.max(width, height, dotSpacing);\n const halfHeight = height / 2;\n const sagitta = frontRoundness * Math.min(halfHeight, width);\n if (sagitta <= 0) {\n return maxRadius;\n }\n return Math.min(\n maxRadius,\n (halfHeight * halfHeight + sagitta * sagitta) / (2 * sagitta)\n );\n}\n\n/** how many dots a grid of this spacing holds, rows times columns */\nfunction dotCount(width: number, height: number, spacing: number): number {\n const along = (length: number) =>\n length <= 0 ? 0 : Math.max(0, Math.ceil(length / spacing - 0.5));\n return along(width) * along(height);\n}\n\n/** the asked spacing, widened until the grid holds at most `MAX_DOTS` */\nfunction spacingWithinDotLimit(\n width: number,\n height: number,\n askedSpacing: number\n): number {\n let spacing = Math.max(askedSpacing, Math.sqrt((width * height) / MAX_DOTS));\n // the rows and columns round up: widen a little more where they still do\n while (dotCount(width, height, spacing) > MAX_DOTS) {\n spacing *= 1.01;\n }\n return spacing;\n}\n\n/** the share of the current sweep that has passed, 0 up to (not including) 1 */\nexport function sweepPhase(geometry: WaveGeometry, elapsedMs: number): number {\n const { sweepMs } = geometry;\n return (((elapsedMs % sweepMs) + sweepMs) % sweepMs) / sweepMs;\n}\n\n/** the front's radius at the time `elapsedMs` */\nexport function frontRadius(geometry: WaveGeometry, elapsedMs: number): number {\n return (\n geometry.startRadius + geometry.travel * sweepPhase(geometry, elapsedMs)\n );\n}\n\n/** how far the dot lies behind the front: negative ahead of it */\nfunction distanceBehindFront(\n x: number,\n y: number,\n elapsedMs: number,\n geometry: WaveGeometry\n): number {\n const fromCenter = Math.hypot(x - geometry.centerX, y - geometry.centerY);\n return frontRadius(geometry, elapsedMs) - fromCenter;\n}\n\nfunction smoothstep(edge0: number, edge1: number, value: number): number {\n const t = Math.min(1, Math.max(0, (value - edge0) / (edge1 - edge0)));\n return t * t * (3 - 2 * t);\n}\n\n/**\n * The bright part of the wave: 1 right behind the front, dimming\n * exponentially further behind, 0 ahead of it.\n */\nfunction frontGlow(behind: number, geometry: WaveGeometry): number {\n return (\n smoothstep(-geometry.rise, 0, behind) *\n Math.exp(-Math.max(behind, 0) / geometry.falloff)\n );\n}\n\n/** whether a sweep went before this one, whose afterglow and echo show */\nexport function hasPreviousSweep(\n geometry: WaveGeometry,\n elapsedMs: number\n): boolean {\n return elapsedMs >= geometry.sweepMs;\n}\n\n/**\n * What stays lit once the front passed: `AFTERGLOW` for the first part of a\n * sweep, then fading out until the next front arrives. Ahead of the front a\n * dot still glows from the sweep before, if there was one.\n */\nfunction afterglow(\n behind: number,\n geometry: WaveGeometry,\n elapsedMs: number\n): number {\n if (behind < 0 && !hasPreviousSweep(geometry, elapsedMs)) {\n return 0;\n }\n const sincePassed =\n (behind >= 0 ? behind : behind + geometry.travel) / geometry.travel;\n return AFTERGLOW * (1 - smoothstep(AFTERGLOW_FADE_START, 1, sincePassed));\n}\n\n/**\n * How much the wave lights the dot at `(x, y)`: 1 right behind the front,\n * dimming over a few spacings to the afterglow of the dots it passed, which\n * fades out again until the next front comes. On the first sweep nothing\n * ahead of the front is lit.\n */\nexport function waveIntensity(\n x: number,\n y: number,\n elapsedMs: number,\n geometry: WaveGeometry\n): number {\n const behind = distanceBehindFront(x, y, elapsedMs, geometry);\n return Math.max(\n frontGlow(behind, geometry),\n afterglow(behind, geometry, elapsedMs)\n );\n}\n\n/**\n * How far the wave pushes the dot at `(x, y)` away from the circle's centre:\n * nothing at rest, most at one falloff behind the front.\n */\nexport function dotDisplacement(\n x: number,\n y: number,\n elapsedMs: number,\n geometry: WaveGeometry\n): Displacement {\n const behind = distanceBehindFront(x, y, elapsedMs, geometry);\n if (behind <= 0) {\n return { dx: 0, dy: 0 };\n }\n const scaled = behind / geometry.falloff;\n const push = geometry.maxPush * scaled * Math.exp(1 - scaled);\n const toX = x - geometry.centerX;\n const toY = y - geometry.centerY;\n const length = Math.hypot(toX, toY);\n return { dx: (push * toX) / length, dy: (push * toY) / length };\n}\n\n/** the centres of the grid's dots, row by row, each centred in its cell */\nexport function dotCenters({\n width,\n height,\n dotSpacing,\n}: Pick<WaveGeometry, 'width' | 'height' | 'dotSpacing'>): Point[] {\n const centers: Point[] = [];\n // an empty host has no dots, however small the spacing\n if (width <= 0 || height <= 0) {\n return centers;\n }\n for (let y = dotSpacing / 2; y < height; y += dotSpacing) {\n for (let x = dotSpacing / 2; x < width; x += dotSpacing) {\n centers.push({ x, y });\n }\n }\n return centers;\n}\n"]}
@@ -0,0 +1,5 @@
1
+ /** strength of the echo ripple trailing the front, times the main front's */
2
+ export const ECHO_STRENGTH = 0.4;
3
+ /** the echo trails the front by this share of a sweep */
4
+ export const ECHO_LAG = 1 / 3;
5
+ //# sourceMappingURL=echo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"echo.js","sourceRoot":"","sources":["../../../../../../../libs/public/ws-loading-wave/src/lib/webgl/echo.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AACjC,yDAAyD;AACzD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC","sourcesContent":["/** strength of the echo ripple trailing the front, times the main front's */\nexport const ECHO_STRENGTH = 0.4;\n/** the echo trails the front by this share of a sweep */\nexport const ECHO_LAG = 1 / 3;\n"]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=loading-wave-shader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loading-wave-shader.js","sourceRoot":"","sources":["../../../../../../../libs/public/ws-loading-wave/src/lib/webgl/loading-wave-shader.ts"],"names":[],"mappings":"","sourcesContent":["/** a uniform's value: a `float`, or the components of a `vec2` to `vec4` */\nexport type ShaderUniformValue =\n | number\n | readonly [number]\n | readonly [number, number]\n | readonly [number, number, number]\n | readonly [number, number, number, number];\n\n/** values of the uniforms a fragment declares itself, by their GLSL name */\nexport type ShaderUniforms = Readonly<Record<string, ShaderUniformValue>>;\n\n/**\n * A fragment shader for the loading wave's WebGL renderer.\n *\n * `fragment` is GLSL ES 3.00 that defines `vec4 wsShade(vec2 point)`: the\n * straight (not premultiplied) colour and opacity at `point`, in CSS pixels\n * from the host's top left corner. The lib puts the `ws_*` uniforms and\n * helpers before it and a `main` after it (see the README), so the fragment\n * holds neither `#version` nor `main`. At `ws_wave == 0` it draws its resting\n * state, without `ws_time`: that is what `afterLoading: 'keep'` leaves and\n * what `prefers-reduced-motion` shows.\n */\nexport interface LoadingWaveShader {\n readonly fragment: string;\n /** values of uniforms the fragment declares itself; never `ws_*` ones */\n readonly uniforms?: ShaderUniforms;\n}\n"]}
@@ -0,0 +1,235 @@
1
+ /** the shaders did not compile or link on this GPU */
2
+ export class WaveShaderError extends Error {
3
+ constructor() {
4
+ super(...arguments);
5
+ this.name = 'WaveShaderError';
6
+ }
7
+ }
8
+ /**
9
+ * The uniforms the lib sets for every shader. `ws_bufferSize` and `ws_dots`
10
+ * are for `main` only.
11
+ */
12
+ export const STANDARD_UNIFORMS = [
13
+ 'ws_size',
14
+ 'ws_bufferSize',
15
+ 'ws_pixel',
16
+ 'ws_spacing',
17
+ 'ws_dotSize',
18
+ 'ws_color',
19
+ 'ws_accent',
20
+ 'ws_center',
21
+ 'ws_frontRadius',
22
+ 'ws_echoRadius',
23
+ 'ws_travel',
24
+ 'ws_falloff',
25
+ 'ws_rise',
26
+ 'ws_tail',
27
+ 'ws_maxPush',
28
+ 'ws_phase',
29
+ 'ws_time',
30
+ 'ws_previousSweep',
31
+ 'ws_wave',
32
+ 'ws_dots',
33
+ ];
34
+ /** one triangle that covers the whole canvas, no vertex buffer needed */
35
+ export const WAVE_VERTEX_SHADER = `#version 300 es
36
+ void main() {
37
+ vec2 corner = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
38
+ gl_Position = vec4(corner * 2.0 - 1.0, 0.0, 1.0);
39
+ }
40
+ `;
41
+ /**
42
+ * What every fragment shader starts with: the uniforms and helpers of the
43
+ * contract (`LoadingWaveShader`). The `WS_*` constants mirror the
44
+ * TypeScript ones (`renderer.ts`, `wave-model.ts`, `echo.ts`);
45
+ * `shader-constants.spec.ts` keeps them equal. Kept a plain literal, so a
46
+ * bundler can tell it has no side effects.
47
+ */
48
+ export const WAVE_SHADER_HEADER = `#version 300 es
49
+ precision highp float;
50
+
51
+ uniform vec2 ws_size;
52
+ uniform vec2 ws_bufferSize;
53
+ uniform float ws_pixel;
54
+ uniform float ws_spacing;
55
+ uniform float ws_dotSize;
56
+ uniform vec4 ws_color;
57
+ uniform vec4 ws_accent;
58
+ uniform vec2 ws_center;
59
+ uniform float ws_frontRadius;
60
+ uniform float ws_echoRadius;
61
+ uniform float ws_travel;
62
+ uniform float ws_falloff;
63
+ uniform float ws_rise;
64
+ uniform float ws_tail;
65
+ uniform float ws_maxPush;
66
+ uniform float ws_phase;
67
+ uniform float ws_time;
68
+ uniform float ws_previousSweep;
69
+ uniform float ws_wave;
70
+ uniform float ws_dots;
71
+
72
+ const float WS_REST_ALPHA = 0.22;
73
+ const float WS_LIT_ALPHA = 0.9;
74
+ const float WS_LIT_GROWTH = 0.8;
75
+ const float WS_FRONT_LINE_ALPHA = 0.14;
76
+ const float WS_AFTERGLOW = 0.45;
77
+ const float WS_AFTERGLOW_FADE_START = 0.45;
78
+ const float WS_ECHO_STRENGTH = 0.4;
79
+
80
+ /** how far p lies behind the front: negative ahead of it */
81
+ float ws_behindFront(vec2 p) {
82
+ return ws_frontRadius - length(p - ws_center);
83
+ }
84
+
85
+ /** how far p lies behind the echo; far ahead of it while there is none */
86
+ float ws_behindEcho(vec2 p) {
87
+ return ws_echoRadius < 0.0 ? -1.0e6 : ws_echoRadius - length(p - ws_center);
88
+ }
89
+
90
+ /** the bright part right behind a front: 1 there, dimming behind, 0 ahead */
91
+ float ws_frontGlow(float behind) {
92
+ return smoothstep(-ws_rise, 0.0, behind) * exp(-max(behind, 0.0) / ws_falloff);
93
+ }
94
+
95
+ /** what stays lit once the front passed, fading until the next one comes */
96
+ float ws_afterglow(float behind) {
97
+ if (behind < 0.0 && ws_previousSweep < 0.5) {
98
+ return 0.0;
99
+ }
100
+ float sincePassed = (behind >= 0.0 ? behind : behind + ws_travel) / ws_travel;
101
+ return WS_AFTERGLOW * (1.0 - smoothstep(WS_AFTERGLOW_FADE_START, 1.0, sincePassed));
102
+ }
103
+
104
+ /** the wave's light at p, 0 to 1, already scaled by ws_wave */
105
+ float ws_waveIntensity(vec2 p) {
106
+ float behind = ws_behindFront(p);
107
+ return ws_wave * max(ws_frontGlow(behind), ws_afterglow(behind));
108
+ }
109
+
110
+ /** the echo's front glow at p, scaled by its strength and ws_wave */
111
+ float ws_echoGlow(vec2 p) {
112
+ return ws_wave * WS_ECHO_STRENGTH * ws_frontGlow(ws_behindEcho(p));
113
+ }
114
+
115
+ /** a stable pseudo-random number in [0, 1) per p, say per grid cell */
116
+ float ws_hash(vec2 p) {
117
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
118
+ p3 += dot(p3, p3.yzx + 33.33);
119
+ return fract((p3.x + p3.y) * p3.z);
120
+ }
121
+
122
+ /** two stable pseudo-random numbers in [0, 1) per p */
123
+ vec2 ws_hash2(vec2 p) {
124
+ vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
125
+ p3 += dot(p3, p3.yzx + 33.33);
126
+ return fract((p3.xx + p3.yz) * p3.zy);
127
+ }
128
+
129
+ /** the grid cell p lies in */
130
+ vec2 ws_cell(vec2 p) {
131
+ return floor(p / ws_spacing);
132
+ }
133
+
134
+ /** the centre of a grid cell, where its dot sits */
135
+ vec2 ws_cellCenter(vec2 cell) {
136
+ return (cell + 0.5) * ws_spacing;
137
+ }
138
+
139
+ /** anti-aliased coverage, 0 to 1, of a band of the given width at a distance from its middle */
140
+ float ws_band(float away, float width) {
141
+ float edge = 0.5 * ws_pixel;
142
+ return 1.0 - smoothstep(0.5 * width - edge, 0.5 * width + edge, away);
143
+ }
144
+
145
+ /** anti-aliased coverage of a disk at p, 0 to 1 */
146
+ float ws_dotDisk(vec2 p, vec2 center, float radius) {
147
+ return ws_band(length(p - center), 2.0 * radius);
148
+ }
149
+
150
+ /** the distance from p to the segment from a to b */
151
+ float ws_segmentDistance(vec2 p, vec2 a, vec2 b) {
152
+ vec2 ab = b - a;
153
+ float along = clamp(dot(p - a, ab) / max(dot(ab, ab), 1.0e-6), 0.0, 1.0);
154
+ return length(p - a - ab * along);
155
+ }
156
+
157
+ /** anti-aliased coverage of a line of the given width along a segment */
158
+ float ws_segment(vec2 p, vec2 a, vec2 b, float width) {
159
+ return ws_band(ws_segmentDistance(p, a, b), width);
160
+ }
161
+
162
+ /** the dots' colour mixed towards the accent by lit, 0 to 1 */
163
+ vec4 ws_ink(float lit) {
164
+ return mix(ws_color, ws_accent, clamp(lit, 0.0, 1.0));
165
+ }
166
+ `;
167
+ /**
168
+ * What every fragment shader ends with: maps the drawing buffer onto the
169
+ * host in CSS pixels (y down), calls `wsShade` and fades it by `ws_dots`.
170
+ */
171
+ export const WAVE_SHADER_MAIN = `
172
+ out vec4 ws_outColor;
173
+
174
+ void main() {
175
+ // the drawing buffer may be smaller than asked for: map it onto the host
176
+ vec2 cssPerPixel = ws_size / ws_bufferSize;
177
+ vec2 point = vec2(gl_FragCoord.x, ws_bufferSize.y - gl_FragCoord.y) * cssPerPixel;
178
+ vec4 shade = clamp(wsShade(point), 0.0, 1.0);
179
+ float alpha = shade.a * ws_dots;
180
+ ws_outColor = vec4(shade.rgb * alpha, alpha);
181
+ }
182
+ `;
183
+ /** the whole fragment shader for a `LoadingWaveShader` */
184
+ export function assembleFragment(shader) {
185
+ // `#line 1`: the GPU's compile log counts the shader's own lines
186
+ return `${WAVE_SHADER_HEADER}\n#line 1\n${shader.fragment}\n${WAVE_SHADER_MAIN}`;
187
+ }
188
+ function compileShader(gl, type, source) {
189
+ const shader = gl.createShader(type);
190
+ if (shader == null) {
191
+ throw new WaveShaderError('could not create a shader');
192
+ }
193
+ gl.shaderSource(shader, source);
194
+ gl.compileShader(shader);
195
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
196
+ const log = gl.getShaderInfoLog(shader);
197
+ gl.deleteShader(shader);
198
+ throw new WaveShaderError(`shader did not compile: ${log}`);
199
+ }
200
+ return shader;
201
+ }
202
+ /**
203
+ * The program of the full-canvas triangle and the shader's fragment.
204
+ * @throws WaveShaderError when it does not compile or link on this GPU
205
+ */
206
+ export function linkWaveProgram(gl, shader) {
207
+ const vertex = compileShader(gl, gl.VERTEX_SHADER, WAVE_VERTEX_SHADER);
208
+ let fragment;
209
+ try {
210
+ fragment = compileShader(gl, gl.FRAGMENT_SHADER, assembleFragment(shader));
211
+ }
212
+ catch (error) {
213
+ gl.deleteShader(vertex);
214
+ throw error;
215
+ }
216
+ const program = gl.createProgram();
217
+ if (program == null) {
218
+ gl.deleteShader(vertex);
219
+ gl.deleteShader(fragment);
220
+ throw new WaveShaderError('could not create a program');
221
+ }
222
+ gl.attachShader(program, vertex);
223
+ gl.attachShader(program, fragment);
224
+ gl.linkProgram(program);
225
+ // the program keeps what it needs
226
+ gl.deleteShader(vertex);
227
+ gl.deleteShader(fragment);
228
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
229
+ const log = gl.getProgramInfoLog(program);
230
+ gl.deleteProgram(program);
231
+ throw new WaveShaderError(`shaders did not link: ${log}`);
232
+ }
233
+ return program;
234
+ }
235
+ //# sourceMappingURL=shader-program.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shader-program.js","sourceRoot":"","sources":["../../../../../../../libs/public/ws-loading-wave/src/lib/webgl/shader-program.ts"],"names":[],"mappings":"AAEA,sDAAsD;AACtD,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAA1C;;QAC2B,SAAI,GAAG,iBAAiB,CAAC;IACpD,CAAC;CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,SAAS;IACT,eAAe;IACf,UAAU;IACV,YAAY;IACZ,YAAY;IACZ,UAAU;IACV,WAAW;IACX,WAAW;IACX,gBAAgB;IAChB,eAAe;IACf,WAAW;IACX,YAAY;IACZ,SAAS;IACT,SAAS;IACT,YAAY;IACZ,UAAU;IACV,SAAS;IACT,kBAAkB;IAClB,SAAS;IACT,SAAS;CACD,CAAC;AAIX,yEAAyE;AACzE,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;CAKjC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsHjC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;CAW/B,CAAC;AAEF,0DAA0D;AAC1D,MAAM,UAAU,gBAAgB,CAAC,MAAyB;IACxD,iEAAiE;IACjE,OAAO,GAAG,kBAAkB,cAAc,MAAM,CAAC,QAAQ,KAAK,gBAAgB,EAAE,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AM,CAAC,CAAC;QACxB,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC1B,MAAM,IAAI,eAAe,CAAC,4BAA4B,CAAC,CAAC;IAC1D,CAAC;IACD,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACjC,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACnC,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACxB,kCAAkC;IAClC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACxB,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC1B,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC;QACrD,MAAM,GAAG,GAAG,EAAE,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC1C,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC1B,MAAM,IAAI,eAAe,CAAC,yBAAyB,GAAG,EAAE,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { LoadingWaveShader } from './loading-wave-shader';\n\n/** the shaders did not compile or link on this GPU */\nexport class WaveShaderError extends Error {\n public override readonly name = 'WaveShaderError';\n}\n\n/**\n * The uniforms the lib sets for every shader. `ws_bufferSize` and `ws_dots`\n * are for `main` only.\n */\nexport const STANDARD_UNIFORMS = [\n 'ws_size',\n 'ws_bufferSize',\n 'ws_pixel',\n 'ws_spacing',\n 'ws_dotSize',\n 'ws_color',\n 'ws_accent',\n 'ws_center',\n 'ws_frontRadius',\n 'ws_echoRadius',\n 'ws_travel',\n 'ws_falloff',\n 'ws_rise',\n 'ws_tail',\n 'ws_maxPush',\n 'ws_phase',\n 'ws_time',\n 'ws_previousSweep',\n 'ws_wave',\n 'ws_dots',\n] as const;\n\nexport type StandardUniform = (typeof STANDARD_UNIFORMS)[number];\n\n/** one triangle that covers the whole canvas, no vertex buffer needed */\nexport const WAVE_VERTEX_SHADER = `#version 300 es\nvoid main() {\n vec2 corner = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\n gl_Position = vec4(corner * 2.0 - 1.0, 0.0, 1.0);\n}\n`;\n\n/**\n * What every fragment shader starts with: the uniforms and helpers of the\n * contract (`LoadingWaveShader`). The `WS_*` constants mirror the\n * TypeScript ones (`renderer.ts`, `wave-model.ts`, `echo.ts`);\n * `shader-constants.spec.ts` keeps them equal. Kept a plain literal, so a\n * bundler can tell it has no side effects.\n */\nexport const WAVE_SHADER_HEADER = `#version 300 es\nprecision highp float;\n\nuniform vec2 ws_size;\nuniform vec2 ws_bufferSize;\nuniform float ws_pixel;\nuniform float ws_spacing;\nuniform float ws_dotSize;\nuniform vec4 ws_color;\nuniform vec4 ws_accent;\nuniform vec2 ws_center;\nuniform float ws_frontRadius;\nuniform float ws_echoRadius;\nuniform float ws_travel;\nuniform float ws_falloff;\nuniform float ws_rise;\nuniform float ws_tail;\nuniform float ws_maxPush;\nuniform float ws_phase;\nuniform float ws_time;\nuniform float ws_previousSweep;\nuniform float ws_wave;\nuniform float ws_dots;\n\nconst float WS_REST_ALPHA = 0.22;\nconst float WS_LIT_ALPHA = 0.9;\nconst float WS_LIT_GROWTH = 0.8;\nconst float WS_FRONT_LINE_ALPHA = 0.14;\nconst float WS_AFTERGLOW = 0.45;\nconst float WS_AFTERGLOW_FADE_START = 0.45;\nconst float WS_ECHO_STRENGTH = 0.4;\n\n/** how far p lies behind the front: negative ahead of it */\nfloat ws_behindFront(vec2 p) {\n return ws_frontRadius - length(p - ws_center);\n}\n\n/** how far p lies behind the echo; far ahead of it while there is none */\nfloat ws_behindEcho(vec2 p) {\n return ws_echoRadius < 0.0 ? -1.0e6 : ws_echoRadius - length(p - ws_center);\n}\n\n/** the bright part right behind a front: 1 there, dimming behind, 0 ahead */\nfloat ws_frontGlow(float behind) {\n return smoothstep(-ws_rise, 0.0, behind) * exp(-max(behind, 0.0) / ws_falloff);\n}\n\n/** what stays lit once the front passed, fading until the next one comes */\nfloat ws_afterglow(float behind) {\n if (behind < 0.0 && ws_previousSweep < 0.5) {\n return 0.0;\n }\n float sincePassed = (behind >= 0.0 ? behind : behind + ws_travel) / ws_travel;\n return WS_AFTERGLOW * (1.0 - smoothstep(WS_AFTERGLOW_FADE_START, 1.0, sincePassed));\n}\n\n/** the wave's light at p, 0 to 1, already scaled by ws_wave */\nfloat ws_waveIntensity(vec2 p) {\n float behind = ws_behindFront(p);\n return ws_wave * max(ws_frontGlow(behind), ws_afterglow(behind));\n}\n\n/** the echo's front glow at p, scaled by its strength and ws_wave */\nfloat ws_echoGlow(vec2 p) {\n return ws_wave * WS_ECHO_STRENGTH * ws_frontGlow(ws_behindEcho(p));\n}\n\n/** a stable pseudo-random number in [0, 1) per p, say per grid cell */\nfloat ws_hash(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * 0.1031);\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n}\n\n/** two stable pseudo-random numbers in [0, 1) per p */\nvec2 ws_hash2(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.xx + p3.yz) * p3.zy);\n}\n\n/** the grid cell p lies in */\nvec2 ws_cell(vec2 p) {\n return floor(p / ws_spacing);\n}\n\n/** the centre of a grid cell, where its dot sits */\nvec2 ws_cellCenter(vec2 cell) {\n return (cell + 0.5) * ws_spacing;\n}\n\n/** anti-aliased coverage, 0 to 1, of a band of the given width at a distance from its middle */\nfloat ws_band(float away, float width) {\n float edge = 0.5 * ws_pixel;\n return 1.0 - smoothstep(0.5 * width - edge, 0.5 * width + edge, away);\n}\n\n/** anti-aliased coverage of a disk at p, 0 to 1 */\nfloat ws_dotDisk(vec2 p, vec2 center, float radius) {\n return ws_band(length(p - center), 2.0 * radius);\n}\n\n/** the distance from p to the segment from a to b */\nfloat ws_segmentDistance(vec2 p, vec2 a, vec2 b) {\n vec2 ab = b - a;\n float along = clamp(dot(p - a, ab) / max(dot(ab, ab), 1.0e-6), 0.0, 1.0);\n return length(p - a - ab * along);\n}\n\n/** anti-aliased coverage of a line of the given width along a segment */\nfloat ws_segment(vec2 p, vec2 a, vec2 b, float width) {\n return ws_band(ws_segmentDistance(p, a, b), width);\n}\n\n/** the dots' colour mixed towards the accent by lit, 0 to 1 */\nvec4 ws_ink(float lit) {\n return mix(ws_color, ws_accent, clamp(lit, 0.0, 1.0));\n}\n`;\n\n/**\n * What every fragment shader ends with: maps the drawing buffer onto the\n * host in CSS pixels (y down), calls `wsShade` and fades it by `ws_dots`.\n */\nexport const WAVE_SHADER_MAIN = `\nout vec4 ws_outColor;\n\nvoid main() {\n // the drawing buffer may be smaller than asked for: map it onto the host\n vec2 cssPerPixel = ws_size / ws_bufferSize;\n vec2 point = vec2(gl_FragCoord.x, ws_bufferSize.y - gl_FragCoord.y) * cssPerPixel;\n vec4 shade = clamp(wsShade(point), 0.0, 1.0);\n float alpha = shade.a * ws_dots;\n ws_outColor = vec4(shade.rgb * alpha, alpha);\n}\n`;\n\n/** the whole fragment shader for a `LoadingWaveShader` */\nexport function assembleFragment(shader: LoadingWaveShader): string {\n // `#line 1`: the GPU's compile log counts the shader's own lines\n return `${WAVE_SHADER_HEADER}\\n#line 1\\n${shader.fragment}\\n${WAVE_SHADER_MAIN}`;\n}\n\nfunction compileShader(\n gl: WebGL2RenderingContext,\n type: number,\n source: string\n): WebGLShader {\n const shader = gl.createShader(type);\n if (shader == null) {\n throw new WaveShaderError('could not create a shader');\n }\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n const log = gl.getShaderInfoLog(shader);\n gl.deleteShader(shader);\n throw new WaveShaderError(`shader did not compile: ${log}`);\n }\n return shader;\n}\n\n/**\n * The program of the full-canvas triangle and the shader's fragment.\n * @throws WaveShaderError when it does not compile or link on this GPU\n */\nexport function linkWaveProgram(\n gl: WebGL2RenderingContext,\n shader: LoadingWaveShader\n): WebGLProgram {\n const vertex = compileShader(gl, gl.VERTEX_SHADER, WAVE_VERTEX_SHADER);\n let fragment: WebGLShader;\n try {\n fragment = compileShader(gl, gl.FRAGMENT_SHADER, assembleFragment(shader));\n } catch (error) {\n gl.deleteShader(vertex);\n throw error;\n }\n const program = gl.createProgram();\n if (program == null) {\n gl.deleteShader(vertex);\n gl.deleteShader(fragment);\n throw new WaveShaderError('could not create a program');\n }\n gl.attachShader(program, vertex);\n gl.attachShader(program, fragment);\n gl.linkProgram(program);\n // the program keeps what it needs\n gl.deleteShader(vertex);\n gl.deleteShader(fragment);\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n const log = gl.getProgramInfoLog(program);\n gl.deleteProgram(program);\n throw new WaveShaderError(`shaders did not link: ${log}`);\n }\n return program;\n}\n"]}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * The default look on the GPU: the wave as a ripple running through water
3
+ * over the dot grid. The crests (front and echo) are a height field; the
4
+ * dots are seen through its slope (refraction), shaded as small beads lit
5
+ * from the crest ahead of them, and bloom in the accent colour; the water
6
+ * itself shows as a faint body with a glossy sheen on the crests' slopes.
7
+ * Drawn over the host's background, so it reads in light and dark themes.
8
+ */
9
+ export const rippleShader = {
10
+ fragment: `
11
+ const float RIPPLE_GROWTH = 1.4;
12
+ const float GLOW_ALPHA = 0.18;
13
+ const float GLOW_SPACINGS = 0.18;
14
+ const float BLOOM_ALPHA = 0.08;
15
+ const float BLOOM_SPACINGS = 0.55;
16
+ const float REFRACTION = 2.0;
17
+ const float BODY_ALPHA = 0.05;
18
+ const float SHEEN_ALPHA = 0.35;
19
+ const float GLINT_ALPHA = 0.9;
20
+
21
+ /* the water's height: a crest of 1 behind the front, a lower one behind the echo */
22
+ float rippleHeight(vec2 p) {
23
+ return ws_wave * (ws_frontGlow(ws_behindFront(p))
24
+ + WS_ECHO_STRENGTH * ws_frontGlow(ws_behindEcho(p)));
25
+ }
26
+
27
+ /* the height's slope along the wave's direction, per CSS pixel */
28
+ float rippleSlope(vec2 p, vec2 direction) {
29
+ return 0.5 * (rippleHeight(p + direction) - rippleHeight(p - direction));
30
+ }
31
+
32
+ /* the unit vector from the wave's centre towards p */
33
+ vec2 outwardAt(vec2 p) {
34
+ vec2 outward = p - ws_center;
35
+ return outward / max(length(outward), 1.0e-3);
36
+ }
37
+
38
+ vec4 wsShade(vec2 point) {
39
+ vec3 color = vec3(0.0);
40
+ float alpha = 0.0;
41
+ vec2 cell = ws_cell(point);
42
+ float glowWidth = GLOW_SPACINGS * ws_spacing;
43
+ float bloomWidth = BLOOM_SPACINGS * ws_spacing;
44
+ for (int row = -1; row <= 1; row++) {
45
+ for (int column = -1; column <= 1; column++) {
46
+ vec2 center = ws_cellCenter(cell + vec2(float(column), float(row)));
47
+ if (any(lessThan(center, vec2(0.0))) || any(greaterThanEqual(center, ws_size))) {
48
+ continue;
49
+ }
50
+ vec2 direction = outwardAt(center);
51
+ float crest = clamp(rippleHeight(center), 0.0, 1.0);
52
+ float lit = clamp(max(crest, ws_waveIntensity(center)), 0.0, 1.0);
53
+ // seen through the ripple's slope, the dot shifts
54
+ float slope = clamp(rippleSlope(center, direction) * ws_falloff, -1.0, 1.0);
55
+ vec2 dotCenter = center - direction * REFRACTION * ws_maxPush * slope;
56
+ float radius = 0.5 * ws_dotSize * (1.0 + RIPPLE_GROWTH * lit);
57
+ float core = ws_dotDisk(point, dotCenter, radius);
58
+ // a bead: a small sphere lit from the crest, which rides with the front
59
+ // outside the disk the normal stays on its rim, so pow() gets a base in [0, 1]
60
+ vec2 local = (point - dotCenter) / radius;
61
+ local /= max(1.0, length(local));
62
+ vec3 normal = vec3(local, sqrt(max(0.0, 1.0 - dot(local, local))));
63
+ float towardsCrest = ws_behindFront(center) >= 0.0 ? 1.0 : -1.0;
64
+ vec3 light = normalize(vec3(direction * 0.8 * towardsCrest, 0.6));
65
+ float diffuse = clamp(dot(normal, light), 0.0, 1.0);
66
+ float glint = pow(clamp(dot(normal, normalize(light + vec3(0.0, 0.0, 1.0))), 0.0, 1.0), 18.0);
67
+ vec4 ink = ws_ink(lit);
68
+ float bead = core * ink.a
69
+ * (WS_REST_ALPHA + (WS_LIT_ALPHA - WS_REST_ALPHA) * lit)
70
+ * mix(1.0, 0.45 + 0.75 * diffuse, lit);
71
+ color += ink.rgb * bead;
72
+ alpha += bead;
73
+ float shine = core * lit * glint * GLINT_ALPHA * ws_accent.a;
74
+ color += mix(ws_accent.rgb, vec3(1.0), 0.35) * shine;
75
+ alpha += shine;
76
+ // only the crests bloom, the afterglow stays calm; the bloom ends
77
+ // within the 3 x 3 cells drawn, or their seams would show
78
+ float fromDot = length(point - dotCenter);
79
+ float inWindow = 1.0 - smoothstep(0.6 * ws_spacing, ws_spacing, fromDot);
80
+ float glow = ws_accent.a * crest * (
81
+ GLOW_ALPHA * exp(-fromDot * fromDot / (2.0 * glowWidth * glowWidth))
82
+ + BLOOM_ALPHA * crest * inWindow
83
+ * exp(-fromDot * fromDot / (2.0 * bloomWidth * bloomWidth)));
84
+ color += ws_accent.rgb * glow;
85
+ alpha += glow;
86
+ }
87
+ }
88
+ // the water: a faint body and a glossy sheen where a crest's slope faces the light
89
+ vec2 direction = outwardAt(point);
90
+ float height = rippleHeight(point);
91
+ float slope = rippleSlope(point, direction) * ws_falloff;
92
+ vec3 surface = normalize(vec3(-direction * slope * 0.8, 1.0));
93
+ vec3 sun = normalize(vec3(-0.45, -0.55, 0.7));
94
+ float sheen = pow(clamp(dot(surface, normalize(sun + vec3(0.0, 0.0, 1.0))), 0.0, 1.0), 60.0);
95
+ float fromMiddle = (point.y - ws_center.y) / max(0.5 * ws_size.y, 1.0);
96
+ float middle = 1.0 - 0.5 * fromMiddle * fromMiddle;
97
+ float water = ws_accent.a * middle
98
+ * (BODY_ALPHA * height + SHEEN_ALPHA * sheen * smoothstep(0.0, 0.2, height));
99
+ color += ws_accent.rgb * water;
100
+ alpha += water;
101
+ // a soft crest line where the hairline of the 2D canvas runs
102
+ float behind = ws_behindFront(point) / max(ws_rise, ws_pixel);
103
+ float crestLine = ws_accent.a * WS_FRONT_LINE_ALPHA * ws_wave * exp(-behind * behind);
104
+ color += ws_accent.rgb * crestLine;
105
+ alpha += crestLine;
106
+ return alpha <= 0.0 ? vec4(0.0) : vec4(color / alpha, min(alpha, 1.0));
107
+ }
108
+ `,
109
+ };
110
+ //# sourceMappingURL=ripple.shader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ripple.shader.js","sourceRoot":"","sources":["../../../../../../../../libs/public/ws-loading-wave/src/lib/webgl/shaders/ripple.shader.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAsB;IAC7C,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkGX;CACA,CAAC","sourcesContent":["import type { LoadingWaveShader } from '../loading-wave-shader';\n\n/**\n * The default look on the GPU: the wave as a ripple running through water\n * over the dot grid. The crests (front and echo) are a height field; the\n * dots are seen through its slope (refraction), shaded as small beads lit\n * from the crest ahead of them, and bloom in the accent colour; the water\n * itself shows as a faint body with a glossy sheen on the crests' slopes.\n * Drawn over the host's background, so it reads in light and dark themes.\n */\nexport const rippleShader: LoadingWaveShader = {\n fragment: `\nconst float RIPPLE_GROWTH = 1.4;\nconst float GLOW_ALPHA = 0.18;\nconst float GLOW_SPACINGS = 0.18;\nconst float BLOOM_ALPHA = 0.08;\nconst float BLOOM_SPACINGS = 0.55;\nconst float REFRACTION = 2.0;\nconst float BODY_ALPHA = 0.05;\nconst float SHEEN_ALPHA = 0.35;\nconst float GLINT_ALPHA = 0.9;\n\n/* the water's height: a crest of 1 behind the front, a lower one behind the echo */\nfloat rippleHeight(vec2 p) {\n return ws_wave * (ws_frontGlow(ws_behindFront(p))\n + WS_ECHO_STRENGTH * ws_frontGlow(ws_behindEcho(p)));\n}\n\n/* the height's slope along the wave's direction, per CSS pixel */\nfloat rippleSlope(vec2 p, vec2 direction) {\n return 0.5 * (rippleHeight(p + direction) - rippleHeight(p - direction));\n}\n\n/* the unit vector from the wave's centre towards p */\nvec2 outwardAt(vec2 p) {\n vec2 outward = p - ws_center;\n return outward / max(length(outward), 1.0e-3);\n}\n\nvec4 wsShade(vec2 point) {\n vec3 color = vec3(0.0);\n float alpha = 0.0;\n vec2 cell = ws_cell(point);\n float glowWidth = GLOW_SPACINGS * ws_spacing;\n float bloomWidth = BLOOM_SPACINGS * ws_spacing;\n for (int row = -1; row <= 1; row++) {\n for (int column = -1; column <= 1; column++) {\n vec2 center = ws_cellCenter(cell + vec2(float(column), float(row)));\n if (any(lessThan(center, vec2(0.0))) || any(greaterThanEqual(center, ws_size))) {\n continue;\n }\n vec2 direction = outwardAt(center);\n float crest = clamp(rippleHeight(center), 0.0, 1.0);\n float lit = clamp(max(crest, ws_waveIntensity(center)), 0.0, 1.0);\n // seen through the ripple's slope, the dot shifts\n float slope = clamp(rippleSlope(center, direction) * ws_falloff, -1.0, 1.0);\n vec2 dotCenter = center - direction * REFRACTION * ws_maxPush * slope;\n float radius = 0.5 * ws_dotSize * (1.0 + RIPPLE_GROWTH * lit);\n float core = ws_dotDisk(point, dotCenter, radius);\n // a bead: a small sphere lit from the crest, which rides with the front\n // outside the disk the normal stays on its rim, so pow() gets a base in [0, 1]\n vec2 local = (point - dotCenter) / radius;\n local /= max(1.0, length(local));\n vec3 normal = vec3(local, sqrt(max(0.0, 1.0 - dot(local, local))));\n float towardsCrest = ws_behindFront(center) >= 0.0 ? 1.0 : -1.0;\n vec3 light = normalize(vec3(direction * 0.8 * towardsCrest, 0.6));\n float diffuse = clamp(dot(normal, light), 0.0, 1.0);\n float glint = pow(clamp(dot(normal, normalize(light + vec3(0.0, 0.0, 1.0))), 0.0, 1.0), 18.0);\n vec4 ink = ws_ink(lit);\n float bead = core * ink.a\n * (WS_REST_ALPHA + (WS_LIT_ALPHA - WS_REST_ALPHA) * lit)\n * mix(1.0, 0.45 + 0.75 * diffuse, lit);\n color += ink.rgb * bead;\n alpha += bead;\n float shine = core * lit * glint * GLINT_ALPHA * ws_accent.a;\n color += mix(ws_accent.rgb, vec3(1.0), 0.35) * shine;\n alpha += shine;\n // only the crests bloom, the afterglow stays calm; the bloom ends\n // within the 3 x 3 cells drawn, or their seams would show\n float fromDot = length(point - dotCenter);\n float inWindow = 1.0 - smoothstep(0.6 * ws_spacing, ws_spacing, fromDot);\n float glow = ws_accent.a * crest * (\n GLOW_ALPHA * exp(-fromDot * fromDot / (2.0 * glowWidth * glowWidth))\n + BLOOM_ALPHA * crest * inWindow\n * exp(-fromDot * fromDot / (2.0 * bloomWidth * bloomWidth)));\n color += ws_accent.rgb * glow;\n alpha += glow;\n }\n }\n // the water: a faint body and a glossy sheen where a crest's slope faces the light\n vec2 direction = outwardAt(point);\n float height = rippleHeight(point);\n float slope = rippleSlope(point, direction) * ws_falloff;\n vec3 surface = normalize(vec3(-direction * slope * 0.8, 1.0));\n vec3 sun = normalize(vec3(-0.45, -0.55, 0.7));\n float sheen = pow(clamp(dot(surface, normalize(sun + vec3(0.0, 0.0, 1.0))), 0.0, 1.0), 60.0);\n float fromMiddle = (point.y - ws_center.y) / max(0.5 * ws_size.y, 1.0);\n float middle = 1.0 - 0.5 * fromMiddle * fromMiddle;\n float water = ws_accent.a * middle\n * (BODY_ALPHA * height + SHEEN_ALPHA * sheen * smoothstep(0.0, 0.2, height));\n color += ws_accent.rgb * water;\n alpha += water;\n // a soft crest line where the hairline of the 2D canvas runs\n float behind = ws_behindFront(point) / max(ws_rise, ws_pixel);\n float crestLine = ws_accent.a * WS_FRONT_LINE_ALPHA * ws_wave * exp(-behind * behind);\n color += ws_accent.rgb * crestLine;\n alpha += crestLine;\n return alpha <= 0.0 ? vec4(0.0) : vec4(color / alpha, min(alpha, 1.0));\n}\n`,\n};\n"]}