@wolsok/loading-wave 0.0.2 → 0.0.4

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 (29) hide show
  1. package/README.md +48 -15
  2. package/esm2022/lib/webgl/shader-program.js +15 -7
  3. package/esm2022/lib/webgl/shader-program.js.map +1 -1
  4. package/esm2022/shaders/lib/webgl/loading-wave-shader.js +1 -0
  5. package/esm2022/shaders/lib/webgl/loading-wave-shader.js.map +1 -0
  6. package/esm2022/shaders/lib/webgl/shaders/circuit-traces.shader.js +136 -0
  7. package/esm2022/shaders/lib/webgl/shaders/circuit-traces.shader.js.map +1 -0
  8. package/esm2022/shaders/lib/webgl/shaders/data-bus.shader.js +91 -0
  9. package/esm2022/shaders/lib/webgl/shaders/data-bus.shader.js.map +1 -0
  10. package/esm2022/shaders/lib/webgl/shaders/die-scan.shader.js +128 -0
  11. package/esm2022/shaders/lib/webgl/shaders/die-scan.shader.js.map +1 -0
  12. package/esm2022/shaders/lib/webgl/shaders/signal-trace.shader.js +89 -0
  13. package/esm2022/shaders/lib/webgl/shaders/signal-trace.shader.js.map +1 -0
  14. package/esm2022/shaders/lib/webgl/shaders/spark-front.shader.js +130 -0
  15. package/esm2022/shaders/lib/webgl/shaders/spark-front.shader.js.map +1 -0
  16. package/esm2022/shaders/shaders.js +12 -0
  17. package/esm2022/shaders/shaders.js.map +1 -0
  18. package/esm2022/shaders/wolsok-loading-wave-shaders.js +5 -0
  19. package/esm2022/shaders/wolsok-loading-wave-shaders.js.map +1 -0
  20. package/lib/webgl/shader-program.d.ts +1 -1
  21. package/package.json +5 -1
  22. package/shaders/lib/webgl/loading-wave-shader.d.ts +20 -0
  23. package/shaders/lib/webgl/shaders/circuit-traces.shader.d.ts +12 -0
  24. package/shaders/lib/webgl/shaders/data-bus.shader.d.ts +10 -0
  25. package/shaders/lib/webgl/shaders/die-scan.shader.d.ts +10 -0
  26. package/shaders/lib/webgl/shaders/signal-trace.shader.d.ts +10 -0
  27. package/shaders/lib/webgl/shaders/spark-front.shader.d.ts +8 -0
  28. package/shaders/shaders.d.ts +5 -0
  29. package/shaders/wolsok-loading-wave-shaders.d.ts +5 -0
package/README.md CHANGED
@@ -10,8 +10,10 @@ Try it in the [playground](https://angularexamples.wolsok.de/loadingWavePlaygrou
10
10
  - **One directive**, a boolean input: `[wsLoadingWave]="loading()"`.
11
11
  - **On the GPU where there is one:** a WebGL2 shader draws the wave as a
12
12
  ripple through water: the dots refract through its slope, shine as small
13
- lit beads and bloom, and an echo trails the front. Or bring your own
14
- fragment shader (see [Shaders](#shaders)).
13
+ lit beads and bloom, and an echo trails the front. Or pick one of five
14
+ built-in shaders (circuit traces, a data bus, a chip powering up, an
15
+ oscilloscope, electric arcs), or bring your own fragment shader (see
16
+ [Shaders](#shaders)).
15
17
  - **Everywhere else on a 2D canvas:** without a GPU (or when the browser
16
18
  would render WebGL on the CPU), when the shader fails, when more than 8
17
19
  waves run on one page or when the GPU context is lost.
@@ -104,6 +106,35 @@ On the GPU the wave is drawn by a fragment shader, `rippleShader` unless
104
106
  you pass another one as `shader`. The 2D canvas fallback always draws the
105
107
  dot wave.
106
108
 
109
+ ### Built-in shaders
110
+
111
+ Beside `rippleShader` (from `@wolsok/loading-wave`, the default) five
112
+ built-in shaders come from the secondary entry point
113
+ `@wolsok/loading-wave/shaders`, so an app loads only those it imports. Each
114
+ runs from left to right with the front, on the dot grid's spacing, and lies
115
+ faintly at rest:
116
+
117
+ | Shader | Looks like |
118
+ | --------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
119
+ | `circuitTracesShader` | a printed circuit board: the front energises copper traces, current pulses with comet tails run on them |
120
+ | `dataBusShader` | a logic analyser: buses of lanes whose bits idle dim ahead of the front and flip and stream behind it, the front a clock edge |
121
+ | `dieScanShader` | a chip powering up: blocks with micro patterns flicker on as the front reaches them, their rails glow |
122
+ | `signalTraceShader` | an oscilloscope: square-wave signals drawn by the front with a phosphor head and a decaying trail |
123
+ | `sparkFrontShader` | electric arcs: the front as a crackling bolt whose branches strike the dots near it |
124
+
125
+ ```ts
126
+ import { circuitTracesShader } from '@wolsok/loading-wave/shaders';
127
+ ```
128
+
129
+ ```html
130
+ <section
131
+ [wsLoadingWave]="loading()"
132
+ [wsLoadingWaveOptions]="{ shader: circuitTracesShader }"
133
+ >
134
+ ```
135
+
136
+ ### Your own shader
137
+
107
138
  ```ts
108
139
  import { LoadingWaveShader } from '@wolsok/loading-wave';
109
140
 
@@ -174,23 +205,25 @@ with alpha, not by adding light, and it reads in light and dark themes.
174
205
  | `ws_previousSweep` | `float` | 1 once a sweep went before, else 0 |
175
206
  | `ws_wave` | `float` | the wave's strength, 0 to 1 (fades in and out, 0 at rest) |
176
207
 
177
- | Helper | Gives |
178
- | ---------------------------------------------------------------------- | ------------------------------------------------------------------ |
179
- | `float ws_behindFront(vec2 p)` | how far `p` lies behind the front, negative ahead of it |
180
- | `float ws_waveIntensity(vec2 p)` | the wave's light at `p`, 0 to 1, scaled by `ws_wave` |
181
- | `float ws_echoGlow(vec2 p)` | the echo's light at `p` |
182
- | `float ws_behindEcho(vec2 p)` | how far `p` lies behind the echo, far negative while there is none |
183
- | `float ws_frontGlow(float behind)`, `float ws_afterglow(float behind)` | the two parts of `ws_waveIntensity` |
184
- | `vec2 ws_cell(vec2 p)`, `vec2 ws_cellCenter(vec2 cell)` | the grid cell of `p` and where its dot sits |
185
- | `float ws_dotDisk(vec2 p, vec2 center, float radius)` | anti-aliased coverage of a disk |
186
- | `float ws_segment(vec2 p, vec2 a, vec2 b, float width)` | anti-aliased coverage of a line |
187
- | `float ws_hash(vec2 p)`, `vec2 ws_hash2(vec2 p)` | stable pseudo-random numbers in [0, 1), say per cell |
188
- | `vec4 ws_ink(float lit)` | the dots' colour mixed towards the accent |
208
+ | Helper | Gives |
209
+ | ---------------------------------------------------------------------- | -------------------------------------------------------------------- |
210
+ | `float ws_behindFront(vec2 p)` | how far `p` lies behind the front, negative ahead of it |
211
+ | `float ws_waveIntensity(vec2 p)` | the wave's light at `p`, 0 to 1, scaled by `ws_wave` |
212
+ | `float ws_echoGlow(vec2 p)` | the echo's light at `p` |
213
+ | `float ws_behindEcho(vec2 p)` | how far `p` lies behind the echo, far negative while there is none |
214
+ | `float ws_frontGlow(float behind)`, `float ws_afterglow(float behind)` | the two parts of `ws_waveIntensity` |
215
+ | `vec2 ws_cell(vec2 p)`, `vec2 ws_cellCenter(vec2 cell)` | the grid cell of `p` and where its dot sits |
216
+ | `float ws_dotDisk(vec2 p, vec2 center, float radius)` | anti-aliased coverage of a disk |
217
+ | `float ws_segment(vec2 p, vec2 a, vec2 b, float width)` | anti-aliased coverage of a line |
218
+ | `float ws_segmentDistance(vec2 p, vec2 a, vec2 b)` | the distance from `p` to a segment |
219
+ | `float ws_band(float away, float width)` | anti-aliased coverage of a band of `width` at `away` from its middle |
220
+ | `float ws_hash(vec2 p)`, `vec2 ws_hash2(vec2 p)` | stable pseudo-random numbers in [0, 1), say per cell |
221
+ | `vec4 ws_ink(float lit)` | the dots' colour mixed towards the accent |
189
222
 
190
223
  The constants `WS_REST_ALPHA`, `WS_LIT_ALPHA`, `WS_LIT_GROWTH`,
191
224
  `WS_FRONT_LINE_ALPHA`, `WS_AFTERGLOW`, `WS_AFTERGLOW_FADE_START` and
192
225
  `WS_ECHO_STRENGTH` give the
193
- dot wave's own look. `rippleShader`'s source is a fuller example.
226
+ dot wave's own look. The built-in shaders' sources are fuller examples.
194
227
 
195
228
  ## License
196
229
 
@@ -136,19 +136,27 @@ vec2 ws_cellCenter(vec2 cell) {
136
136
  return (cell + 0.5) * ws_spacing;
137
137
  }
138
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
+
139
145
  /** anti-aliased coverage of a disk at p, 0 to 1 */
140
146
  float ws_dotDisk(vec2 p, vec2 center, float radius) {
141
- float edge = 0.5 * ws_pixel;
142
- return 1.0 - smoothstep(radius - edge, radius + edge, length(p - center));
147
+ return ws_band(length(p - center), 2.0 * radius);
143
148
  }
144
149
 
145
- /** anti-aliased coverage of a line of the given width along a segment */
146
- float ws_segment(vec2 p, vec2 a, vec2 b, float width) {
150
+ /** the distance from p to the segment from a to b */
151
+ float ws_segmentDistance(vec2 p, vec2 a, vec2 b) {
147
152
  vec2 ab = b - a;
148
153
  float along = clamp(dot(p - a, ab) / max(dot(ab, ab), 1.0e-6), 0.0, 1.0);
149
- float away = length(p - a - ab * along);
150
- float edge = 0.5 * ws_pixel;
151
- return 1.0 - smoothstep(0.5 * width - edge, 0.5 * width + edge, away);
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);
152
160
  }
153
161
 
154
162
  /** the dots' colour mixed towards the accent by lit, 0 to 1 */
@@ -1 +1 @@
1
- {"version":3,"file":"shader-program.js","sourceRoot":"","sources":["../../../../../../../libs/public/ws-loading-wave/src/lib/webgl/shader-program.ts"],"names":[],"mappings":"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","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 of a disk at p, 0 to 1 */\nfloat ws_dotDisk(vec2 p, vec2 center, float radius) {\n float edge = 0.5 * ws_pixel;\n return 1.0 - smoothstep(radius - edge, radius + edge, length(p - center));\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 vec2 ab = b - a;\n float along = clamp(dot(p - a, ab) / max(dot(ab, ab), 1.0e-6), 0.0, 1.0);\n float away = length(p - a - ab * along);\n float edge = 0.5 * ws_pixel;\n return 1.0 - smoothstep(0.5 * width - edge, 0.5 * width + edge, away);\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"]}
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,CAAC;AACnF,CAAC;AAED,SAAS,aAAa,CACpB,EAA0B,EAC1B,IAAY,EACZ,MAAc;IAEd,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,eAAe,CAAC,2BAA2B,CAAC,CAAC;IACzD,CAAC;IACD,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACzB,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC;QACtD,MAAM,GAAG,GAAG,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QACxC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QACxB,MAAM,IAAI,eAAe,CAAC,2BAA2B,GAAG,EAAE,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,EAA0B,EAC1B,MAAyB;IAEzB,MAAM,MAAM,GAAG,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;IACvE,IAAI,QAAqB,CAAC;IAC1B,IAAI,CAAC;QACH,QAAQ,GAAG,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7E,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QACxB,MAAM,KAAK,CAAC;IACd,CAAC;IACD,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC;IACnC,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,EAAE,CAAC,YAAY,CAAC,MAAM,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 @@
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,136 @@
1
+ /**
2
+ * A printed circuit board: each grid cell leads a copper trace on to the
3
+ * right, now and then jogging a row up or down at 45° within a pair of rows,
4
+ * so the cells join into traces running left to right, with the dots as
5
+ * solder points and some of them pads. Ahead of the front the board lies
6
+ * dark; behind it the traces light up in the accent colour and current
7
+ * pulses, bright packets with comet tails, run on along them at a speed per
8
+ * pair of rows (a differential pair, so a pulse runs on through a jog),
9
+ * flashing the pads they pass, then die out in the afterglow.
10
+ */
11
+ export const circuitTracesShader = {
12
+ fragment: `
13
+ const float TRACE_WIDTH = 0.07;
14
+ const float TRACE_REST_ALPHA = 0.12;
15
+ const float TRACE_LIT_ALPHA = 0.6;
16
+ const float PAD_RADIUS = 0.17;
17
+ const float PAD_HOLE = 0.45;
18
+ const float PAD_CHANCE = 0.35;
19
+ const float PAD_RING_ALPHA = 0.7;
20
+ const float PAD_FLASH = 1.5;
21
+ const float PULSE_GLOW_WIDTH = 0.2;
22
+ const float PULSE_ALPHA = 0.9;
23
+ const float PULSE_HEAD_GLOW = 0.5;
24
+ const float PULSE_HEAD_EDGE = 0.15;
25
+ const float PULSE_PERIOD_SPACINGS = 7.0;
26
+ const float PULSE_TAIL_SPACINGS = 1.6;
27
+ const float PULSE_SPEED_SPACINGS = 9.0;
28
+ const float PULSE_SPEED_SPREAD = 0.6;
29
+ const float PULSE_WHITENING = 0.4;
30
+ const float JOG_CHANCE = 0.4;
31
+ const float GAP_CHANCE = 0.1;
32
+
33
+ /* the pair of rows a row belongs to; traces jog only within a pair */
34
+ float rowPair(float row) {
35
+ return floor(row * 0.5);
36
+ }
37
+
38
+ /*
39
+ * Where the trace leaving a cell goes: 0 a gap, 1 straight on to the right,
40
+ * 2 a jog a row down, -2 a jog a row up. In a pair only the top row jogs
41
+ * down or the bottom row jogs up at a column, so no traces cross.
42
+ */
43
+ float traceKind(vec2 cell) {
44
+ if (ws_hash(cell + vec2(17.0, 3.0)) < GAP_CHANCE) {
45
+ return 0.0;
46
+ }
47
+ float pair = rowPair(cell.y);
48
+ bool top = cell.y - 2.0 * pair < 0.5;
49
+ float jog = ws_hash(vec2(cell.x, pair) + vec2(5.0, 41.0));
50
+ if (jog < 0.5 * JOG_CHANCE) {
51
+ return top ? 2.0 : 1.0;
52
+ }
53
+ if (jog < JOG_CHANCE) {
54
+ return top ? 1.0 : -2.0;
55
+ }
56
+ return 1.0;
57
+ }
58
+
59
+ /* where the trace leaving a cell ends: the next column's centre, maybe a row off */
60
+ vec2 traceEnd(vec2 cell, float kind) {
61
+ float rows = kind > 1.5 ? 1.0 : (kind < -1.5 ? -1.0 : 0.0);
62
+ return ws_cellCenter(cell + vec2(1.0, rows));
63
+ }
64
+
65
+ /* how far x lies behind the head of a pair's current pulse, 0 up to one period */
66
+ float behindPulse(float x, float pair) {
67
+ float speed = PULSE_SPEED_SPACINGS * ws_spacing
68
+ * (1.0 - 0.5 * PULSE_SPEED_SPREAD + PULSE_SPEED_SPREAD * ws_hash(vec2(pair, 7.0)));
69
+ float period = PULSE_PERIOD_SPACINGS * ws_spacing;
70
+ return mod(ws_time * speed - x + ws_hash(vec2(pair, 13.0)) * period, period);
71
+ }
72
+
73
+ /* a pulse's brightness: 1 at its head, a comet tail behind it */
74
+ float comet(float behind) {
75
+ float period = PULSE_PERIOD_SPACINGS * ws_spacing;
76
+ return exp(-behind / (PULSE_TAIL_SPACINGS * ws_spacing))
77
+ * smoothstep(0.0, PULSE_HEAD_EDGE * ws_spacing, period - behind);
78
+ }
79
+
80
+ vec4 wsShade(vec2 point) {
81
+ vec2 cell = ws_cell(point);
82
+ float traceWidth = max(TRACE_WIDTH * ws_spacing, 1.5 * ws_pixel);
83
+ float glowWidth = PULSE_GLOW_WIDTH * ws_spacing;
84
+ float nearest = 1.0e6;
85
+ float tracePair = rowPair(cell.y);
86
+ for (int row = -1; row <= 1; row++) {
87
+ for (int column = -1; column <= 0; column++) {
88
+ vec2 from = cell + vec2(float(column), float(row));
89
+ float kind = traceKind(from);
90
+ if (kind == 0.0) {
91
+ continue;
92
+ }
93
+ float away = ws_segmentDistance(point, ws_cellCenter(from), traceEnd(from, kind));
94
+ if (away < nearest) {
95
+ nearest = away;
96
+ tracePair = rowPair(from.y);
97
+ }
98
+ }
99
+ }
100
+ float trace = ws_band(nearest, traceWidth);
101
+ float lit = ws_waveIntensity(point);
102
+ float behind = behindPulse(point.x, tracePair);
103
+ float current = lit * comet(behind);
104
+ // the head glows round, off the trace too
105
+ float toHead = min(behind, PULSE_PERIOD_SPACINGS * ws_spacing - behind);
106
+ float headGlow = lit * exp(-(toHead * toHead + nearest * nearest) / (2.0 * glowWidth * glowWidth));
107
+ vec4 ink = ws_ink(lit);
108
+ float copper = trace * ink.a * mix(TRACE_REST_ALPHA, TRACE_LIT_ALPHA, lit);
109
+ float pulse = ws_accent.a * PULSE_ALPHA * max(current * trace, PULSE_HEAD_GLOW * headGlow);
110
+
111
+ // every dot of the grid is a solder point; some are pads, a copper ring around it
112
+ vec2 padCenter = ws_cellCenter(cell);
113
+ bool onGrid = all(lessThan(padCenter, ws_size));
114
+ float padLit = ws_waveIntensity(padCenter);
115
+ // a passing pulse makes the pad flash brighter than the wave alone
116
+ float flash = clamp(padLit * (1.0 + PAD_FLASH * comet(behindPulse(padCenter.x, rowPair(cell.y)))), 0.0, 1.0);
117
+ float padRadius = max(PAD_RADIUS * ws_spacing, 0.75 * ws_dotSize + ws_pixel);
118
+ float ring = ws_hash(cell + vec2(29.0, 11.0)) < PAD_CHANCE
119
+ ? ws_dotDisk(point, padCenter, padRadius)
120
+ * (1.0 - ws_dotDisk(point, padCenter, PAD_HOLE * padRadius))
121
+ : 0.0;
122
+ float pad = onGrid ? max(PAD_RING_ALPHA * ring, ws_dotDisk(point, padCenter, 0.5 * ws_dotSize)) : 0.0;
123
+ vec4 padInk = ws_ink(flash);
124
+ float padAlpha = pad * padInk.a * mix(WS_REST_ALPHA, 1.0, flash);
125
+
126
+ // the pad sits on top of the trace, the pulse on top of both
127
+ float alpha = padAlpha + (1.0 - padAlpha) * copper;
128
+ vec3 color = padInk.rgb * padAlpha + ink.rgb * (1.0 - padAlpha) * copper;
129
+ vec3 hot = mix(ws_accent.rgb, vec3(1.0), PULSE_WHITENING * current);
130
+ color = color * (1.0 - pulse) + hot * pulse;
131
+ alpha = alpha * (1.0 - pulse) + pulse;
132
+ return alpha <= 0.0 ? vec4(0.0) : vec4(color / alpha, alpha);
133
+ }
134
+ `,
135
+ };
136
+ //# sourceMappingURL=circuit-traces.shader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circuit-traces.shader.js","sourceRoot":"","sources":["../../../../../../../../../libs/public/ws-loading-wave/src/lib/webgl/shaders/circuit-traces.shader.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAsB;IACpD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0HX;CACA,CAAC","sourcesContent":["import type { LoadingWaveShader } from '../loading-wave-shader';\n\n/**\n * A printed circuit board: each grid cell leads a copper trace on to the\n * right, now and then jogging a row up or down at 45° within a pair of rows,\n * so the cells join into traces running left to right, with the dots as\n * solder points and some of them pads. Ahead of the front the board lies\n * dark; behind it the traces light up in the accent colour and current\n * pulses, bright packets with comet tails, run on along them at a speed per\n * pair of rows (a differential pair, so a pulse runs on through a jog),\n * flashing the pads they pass, then die out in the afterglow.\n */\nexport const circuitTracesShader: LoadingWaveShader = {\n fragment: `\nconst float TRACE_WIDTH = 0.07;\nconst float TRACE_REST_ALPHA = 0.12;\nconst float TRACE_LIT_ALPHA = 0.6;\nconst float PAD_RADIUS = 0.17;\nconst float PAD_HOLE = 0.45;\nconst float PAD_CHANCE = 0.35;\nconst float PAD_RING_ALPHA = 0.7;\nconst float PAD_FLASH = 1.5;\nconst float PULSE_GLOW_WIDTH = 0.2;\nconst float PULSE_ALPHA = 0.9;\nconst float PULSE_HEAD_GLOW = 0.5;\nconst float PULSE_HEAD_EDGE = 0.15;\nconst float PULSE_PERIOD_SPACINGS = 7.0;\nconst float PULSE_TAIL_SPACINGS = 1.6;\nconst float PULSE_SPEED_SPACINGS = 9.0;\nconst float PULSE_SPEED_SPREAD = 0.6;\nconst float PULSE_WHITENING = 0.4;\nconst float JOG_CHANCE = 0.4;\nconst float GAP_CHANCE = 0.1;\n\n/* the pair of rows a row belongs to; traces jog only within a pair */\nfloat rowPair(float row) {\n return floor(row * 0.5);\n}\n\n/*\n * Where the trace leaving a cell goes: 0 a gap, 1 straight on to the right,\n * 2 a jog a row down, -2 a jog a row up. In a pair only the top row jogs\n * down or the bottom row jogs up at a column, so no traces cross.\n */\nfloat traceKind(vec2 cell) {\n if (ws_hash(cell + vec2(17.0, 3.0)) < GAP_CHANCE) {\n return 0.0;\n }\n float pair = rowPair(cell.y);\n bool top = cell.y - 2.0 * pair < 0.5;\n float jog = ws_hash(vec2(cell.x, pair) + vec2(5.0, 41.0));\n if (jog < 0.5 * JOG_CHANCE) {\n return top ? 2.0 : 1.0;\n }\n if (jog < JOG_CHANCE) {\n return top ? 1.0 : -2.0;\n }\n return 1.0;\n}\n\n/* where the trace leaving a cell ends: the next column's centre, maybe a row off */\nvec2 traceEnd(vec2 cell, float kind) {\n float rows = kind > 1.5 ? 1.0 : (kind < -1.5 ? -1.0 : 0.0);\n return ws_cellCenter(cell + vec2(1.0, rows));\n}\n\n/* how far x lies behind the head of a pair's current pulse, 0 up to one period */\nfloat behindPulse(float x, float pair) {\n float speed = PULSE_SPEED_SPACINGS * ws_spacing\n * (1.0 - 0.5 * PULSE_SPEED_SPREAD + PULSE_SPEED_SPREAD * ws_hash(vec2(pair, 7.0)));\n float period = PULSE_PERIOD_SPACINGS * ws_spacing;\n return mod(ws_time * speed - x + ws_hash(vec2(pair, 13.0)) * period, period);\n}\n\n/* a pulse's brightness: 1 at its head, a comet tail behind it */\nfloat comet(float behind) {\n float period = PULSE_PERIOD_SPACINGS * ws_spacing;\n return exp(-behind / (PULSE_TAIL_SPACINGS * ws_spacing))\n * smoothstep(0.0, PULSE_HEAD_EDGE * ws_spacing, period - behind);\n}\n\nvec4 wsShade(vec2 point) {\n vec2 cell = ws_cell(point);\n float traceWidth = max(TRACE_WIDTH * ws_spacing, 1.5 * ws_pixel);\n float glowWidth = PULSE_GLOW_WIDTH * ws_spacing;\n float nearest = 1.0e6;\n float tracePair = rowPair(cell.y);\n for (int row = -1; row <= 1; row++) {\n for (int column = -1; column <= 0; column++) {\n vec2 from = cell + vec2(float(column), float(row));\n float kind = traceKind(from);\n if (kind == 0.0) {\n continue;\n }\n float away = ws_segmentDistance(point, ws_cellCenter(from), traceEnd(from, kind));\n if (away < nearest) {\n nearest = away;\n tracePair = rowPair(from.y);\n }\n }\n }\n float trace = ws_band(nearest, traceWidth);\n float lit = ws_waveIntensity(point);\n float behind = behindPulse(point.x, tracePair);\n float current = lit * comet(behind);\n // the head glows round, off the trace too\n float toHead = min(behind, PULSE_PERIOD_SPACINGS * ws_spacing - behind);\n float headGlow = lit * exp(-(toHead * toHead + nearest * nearest) / (2.0 * glowWidth * glowWidth));\n vec4 ink = ws_ink(lit);\n float copper = trace * ink.a * mix(TRACE_REST_ALPHA, TRACE_LIT_ALPHA, lit);\n float pulse = ws_accent.a * PULSE_ALPHA * max(current * trace, PULSE_HEAD_GLOW * headGlow);\n\n // every dot of the grid is a solder point; some are pads, a copper ring around it\n vec2 padCenter = ws_cellCenter(cell);\n bool onGrid = all(lessThan(padCenter, ws_size));\n float padLit = ws_waveIntensity(padCenter);\n // a passing pulse makes the pad flash brighter than the wave alone\n float flash = clamp(padLit * (1.0 + PAD_FLASH * comet(behindPulse(padCenter.x, rowPair(cell.y)))), 0.0, 1.0);\n float padRadius = max(PAD_RADIUS * ws_spacing, 0.75 * ws_dotSize + ws_pixel);\n float ring = ws_hash(cell + vec2(29.0, 11.0)) < PAD_CHANCE\n ? ws_dotDisk(point, padCenter, padRadius)\n * (1.0 - ws_dotDisk(point, padCenter, PAD_HOLE * padRadius))\n : 0.0;\n float pad = onGrid ? max(PAD_RING_ALPHA * ring, ws_dotDisk(point, padCenter, 0.5 * ws_dotSize)) : 0.0;\n vec4 padInk = ws_ink(flash);\n float padAlpha = pad * padInk.a * mix(WS_REST_ALPHA, 1.0, flash);\n\n // the pad sits on top of the trace, the pulse on top of both\n float alpha = padAlpha + (1.0 - padAlpha) * copper;\n vec3 color = padInk.rgb * padAlpha + ink.rgb * (1.0 - padAlpha) * copper;\n vec3 hot = mix(ws_accent.rgb, vec3(1.0), PULSE_WHITENING * current);\n color = color * (1.0 - pulse) + hot * pulse;\n alpha = alpha * (1.0 - pulse) + pulse;\n return alpha <= 0.0 ? vec4(0.0) : vec4(color / alpha, alpha);\n}\n`,\n};\n"]}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * A logic analyser: the grid's rows are the lanes of buses, four to six
3
+ * lanes each with a gap between buses, now and then a whole bus bending a
4
+ * lane down and back. Each lane carries bits, a short dash for a zero and a
5
+ * long one for a one. Ahead of the front they idle dim and still; the front
6
+ * is a clock edge: behind it the bits flip, brighten and stream on to the
7
+ * right at a speed per bus.
8
+ */
9
+ export const dataBusShader = {
10
+ fragment: `
11
+ // a bus and its bend take at most BLOCK_ROWS - 1 rows: one row stays a gap
12
+ const float BLOCK_ROWS = 8.0;
13
+ const float MIN_LANES = 4.0;
14
+ const float MAX_LANES = BLOCK_ROWS - 2.0;
15
+ const float STRETCH_COLUMNS = 6.0;
16
+ const float BEND_CHANCE = 0.35;
17
+ const float LANE_ALPHA = 0.07;
18
+ const float LANE_LIT_ALPHA = 0.3;
19
+ const float LANE_WIDTH_DOTS = 0.5;
20
+ const float IDLE_ALPHA = 0.5;
21
+ const float CLOCKED_THRESHOLD = 0.02;
22
+ const float BIT_GROWTH = 0.6;
23
+ const float SPEED_SPACINGS = 3.0;
24
+ const float SPEED_SPREAD = 0.8;
25
+ const float ZERO_LENGTH = 0.25;
26
+ const float ONE_LENGTH = 0.7;
27
+
28
+ /* 1 where a bus is bent a lane down at the start of a stretch of columns, else 0 */
29
+ float bentAt(float block, float stretch) {
30
+ return ws_hash(vec2(block, stretch) + vec2(3.0, 71.0)) < BEND_CHANCE ? 1.0 : 0.0;
31
+ }
32
+
33
+ /*
34
+ * How many rows a bus is shifted down at x, 0 to 1. A bend runs at 45° over
35
+ * the first column of a stretch, from the last stretch's shift to this one's.
36
+ */
37
+ float busShift(float block, float x) {
38
+ float stretchLength = STRETCH_COLUMNS * ws_spacing;
39
+ float stretch = floor(x / stretchLength);
40
+ float into = (x - stretch * stretchLength) / ws_spacing;
41
+ float before = bentAt(block, stretch - 1.0);
42
+ float now = bentAt(block, stretch);
43
+ return mix(before, now, clamp(into - 0.5, 0.0, 1.0));
44
+ }
45
+
46
+ /* the coverage of a bit dash of the given length, centred in its slot, round-capped */
47
+ float bitDash(float along, float across, float dashLength, float radius) {
48
+ float halfLength = 0.5 * dashLength * ws_spacing;
49
+ float fromMiddle = abs(along - 0.5 * ws_spacing);
50
+ float away = length(vec2(max(fromMiddle - halfLength, 0.0), across));
51
+ return ws_band(away, 2.0 * radius);
52
+ }
53
+
54
+ vec4 wsShade(vec2 point) {
55
+ float blockHeight = BLOCK_ROWS * ws_spacing;
56
+ float block = floor(point.y / blockHeight);
57
+ float lanes = MIN_LANES + floor(ws_hash(vec2(block, 5.0)) * (MAX_LANES - MIN_LANES + 1.0));
58
+ float shift = busShift(block, point.x);
59
+ float local = point.y - block * blockHeight - shift * ws_spacing;
60
+ float lane = floor(local / ws_spacing);
61
+ float laneCenter = point.y - local + (lane + 0.5) * ws_spacing;
62
+ // no lane outside the lanes of the bus or cut by the host's bottom edge
63
+ if (lane < 0.0 || lane >= lanes || laneCenter >= ws_size.y) {
64
+ return vec4(0.0);
65
+ }
66
+ // a bent stretch runs at 45°: measure across the lane, not straight down
67
+ float slope = abs(busShift(block, point.x + 0.5 * ws_pixel) - busShift(block, point.x - 0.5 * ws_pixel))
68
+ * ws_spacing / ws_pixel;
69
+ float across = abs(local - (lane + 0.5) * ws_spacing) / sqrt(1.0 + slope * slope);
70
+ float laneId = block * BLOCK_ROWS + lane;
71
+
72
+ float lit = ws_waveIntensity(point);
73
+ bool clocked = lit > CLOCKED_THRESHOLD;
74
+ float speed = clocked ? SPEED_SPACINGS * ws_spacing * (1.0 - 0.5 * SPEED_SPREAD + SPEED_SPREAD * ws_hash(vec2(block, 9.0))) : 0.0;
75
+ float streamed = point.x - (clocked ? ws_time * speed : 0.0);
76
+ float slot = floor(streamed / ws_spacing);
77
+ float along = streamed - slot * ws_spacing;
78
+ float one = step(0.5, ws_hash(vec2(laneId, slot) + (clocked ? vec2(113.0, 17.0) : vec2(0.0))));
79
+ float radius = 0.5 * ws_dotSize * (1.0 + BIT_GROWTH * lit);
80
+ float bit = bitDash(along, across, mix(ZERO_LENGTH, ONE_LENGTH, one), radius);
81
+ float wire = ws_band(across, LANE_WIDTH_DOTS * ws_dotSize);
82
+
83
+ vec4 ink = ws_ink(lit);
84
+ float bitAlpha = bit * ink.a * mix(WS_REST_ALPHA * IDLE_ALPHA, WS_LIT_ALPHA, lit);
85
+ float wireAlpha = wire * ink.a * mix(LANE_ALPHA, LANE_LIT_ALPHA, lit);
86
+ float alpha = bitAlpha + (1.0 - bitAlpha) * wireAlpha;
87
+ return alpha <= 0.0 ? vec4(0.0) : vec4(ink.rgb, alpha);
88
+ }
89
+ `,
90
+ };
91
+ //# sourceMappingURL=data-bus.shader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-bus.shader.js","sourceRoot":"","sources":["../../../../../../../../../libs/public/ws-loading-wave/src/lib/webgl/shaders/data-bus.shader.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAsB;IAC9C,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+EX;CACA,CAAC","sourcesContent":["import type { LoadingWaveShader } from '../loading-wave-shader';\n\n/**\n * A logic analyser: the grid's rows are the lanes of buses, four to six\n * lanes each with a gap between buses, now and then a whole bus bending a\n * lane down and back. Each lane carries bits, a short dash for a zero and a\n * long one for a one. Ahead of the front they idle dim and still; the front\n * is a clock edge: behind it the bits flip, brighten and stream on to the\n * right at a speed per bus.\n */\nexport const dataBusShader: LoadingWaveShader = {\n fragment: `\n// a bus and its bend take at most BLOCK_ROWS - 1 rows: one row stays a gap\nconst float BLOCK_ROWS = 8.0;\nconst float MIN_LANES = 4.0;\nconst float MAX_LANES = BLOCK_ROWS - 2.0;\nconst float STRETCH_COLUMNS = 6.0;\nconst float BEND_CHANCE = 0.35;\nconst float LANE_ALPHA = 0.07;\nconst float LANE_LIT_ALPHA = 0.3;\nconst float LANE_WIDTH_DOTS = 0.5;\nconst float IDLE_ALPHA = 0.5;\nconst float CLOCKED_THRESHOLD = 0.02;\nconst float BIT_GROWTH = 0.6;\nconst float SPEED_SPACINGS = 3.0;\nconst float SPEED_SPREAD = 0.8;\nconst float ZERO_LENGTH = 0.25;\nconst float ONE_LENGTH = 0.7;\n\n/* 1 where a bus is bent a lane down at the start of a stretch of columns, else 0 */\nfloat bentAt(float block, float stretch) {\n return ws_hash(vec2(block, stretch) + vec2(3.0, 71.0)) < BEND_CHANCE ? 1.0 : 0.0;\n}\n\n/*\n * How many rows a bus is shifted down at x, 0 to 1. A bend runs at 45° over\n * the first column of a stretch, from the last stretch's shift to this one's.\n */\nfloat busShift(float block, float x) {\n float stretchLength = STRETCH_COLUMNS * ws_spacing;\n float stretch = floor(x / stretchLength);\n float into = (x - stretch * stretchLength) / ws_spacing;\n float before = bentAt(block, stretch - 1.0);\n float now = bentAt(block, stretch);\n return mix(before, now, clamp(into - 0.5, 0.0, 1.0));\n}\n\n/* the coverage of a bit dash of the given length, centred in its slot, round-capped */\nfloat bitDash(float along, float across, float dashLength, float radius) {\n float halfLength = 0.5 * dashLength * ws_spacing;\n float fromMiddle = abs(along - 0.5 * ws_spacing);\n float away = length(vec2(max(fromMiddle - halfLength, 0.0), across));\n return ws_band(away, 2.0 * radius);\n}\n\nvec4 wsShade(vec2 point) {\n float blockHeight = BLOCK_ROWS * ws_spacing;\n float block = floor(point.y / blockHeight);\n float lanes = MIN_LANES + floor(ws_hash(vec2(block, 5.0)) * (MAX_LANES - MIN_LANES + 1.0));\n float shift = busShift(block, point.x);\n float local = point.y - block * blockHeight - shift * ws_spacing;\n float lane = floor(local / ws_spacing);\n float laneCenter = point.y - local + (lane + 0.5) * ws_spacing;\n // no lane outside the lanes of the bus or cut by the host's bottom edge\n if (lane < 0.0 || lane >= lanes || laneCenter >= ws_size.y) {\n return vec4(0.0);\n }\n // a bent stretch runs at 45°: measure across the lane, not straight down\n float slope = abs(busShift(block, point.x + 0.5 * ws_pixel) - busShift(block, point.x - 0.5 * ws_pixel))\n * ws_spacing / ws_pixel;\n float across = abs(local - (lane + 0.5) * ws_spacing) / sqrt(1.0 + slope * slope);\n float laneId = block * BLOCK_ROWS + lane;\n\n float lit = ws_waveIntensity(point);\n bool clocked = lit > CLOCKED_THRESHOLD;\n float speed = clocked ? SPEED_SPACINGS * ws_spacing * (1.0 - 0.5 * SPEED_SPREAD + SPEED_SPREAD * ws_hash(vec2(block, 9.0))) : 0.0;\n float streamed = point.x - (clocked ? ws_time * speed : 0.0);\n float slot = floor(streamed / ws_spacing);\n float along = streamed - slot * ws_spacing;\n float one = step(0.5, ws_hash(vec2(laneId, slot) + (clocked ? vec2(113.0, 17.0) : vec2(0.0))));\n float radius = 0.5 * ws_dotSize * (1.0 + BIT_GROWTH * lit);\n float bit = bitDash(along, across, mix(ZERO_LENGTH, ONE_LENGTH, one), radius);\n float wire = ws_band(across, LANE_WIDTH_DOTS * ws_dotSize);\n\n vec4 ink = ws_ink(lit);\n float bitAlpha = bit * ink.a * mix(WS_REST_ALPHA * IDLE_ALPHA, WS_LIT_ALPHA, lit);\n float wireAlpha = wire * ink.a * mix(LANE_ALPHA, LANE_LIT_ALPHA, lit);\n float alpha = bitAlpha + (1.0 - bitAlpha) * wireAlpha;\n return alpha <= 0.0 ? vec4(0.0) : vec4(ink.rgb, alpha);\n}\n`,\n};\n"]}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * A chip powering up: the element is cut along the grid's lines into blocks
3
+ * by a hashed recursive split, large cores and small cells with rails
4
+ * between them, each block filled with a micro pattern on the dot pitch
5
+ * (dots, stripes, a hatch or cells). The front powers the die on: a block
6
+ * flickers on as the front reaches its left edge, its rails and pattern
7
+ * light up in the accent colour, and it keeps a low afterglow.
8
+ */
9
+ export const dieScanShader = {
10
+ fragment: `
11
+ const int SPLIT_LEVELS = 5;
12
+ const float MIN_BLOCK_CELLS = 2.0;
13
+ const float LEAF_CHANCE = 0.3;
14
+ const float INSET_SPACINGS = 0.3;
15
+ const float RAIL_WIDTH = 0.08;
16
+ const float RAIL_REST_ALPHA = 0.14;
17
+ const float RAIL_LIT_ALPHA = 0.75;
18
+ const float FILL_ALPHA = 0.07;
19
+ const float PATTERN_REST_ALPHA = 0.6;
20
+ const float LINE_WIDTH = 0.06;
21
+ const float FLICKER_SPACINGS = 1.5;
22
+ const float FLICKERS_PER_SECOND = 24.0;
23
+ const float FLICKER_OFF_CHANCE = 0.35;
24
+ const float PATTERN_KINDS = 4.0;
25
+ const float STRIPE_ALPHA = 0.6;
26
+ const float HATCH_ALPHA = 0.5;
27
+ const float CELL_SQUARE_SPACINGS = 0.3;
28
+
29
+ /*
30
+ * The block, in cells (min in xy, max in zw), that a point lies in: the
31
+ * grid is split again and again across its longer side at a hashed cell line.
32
+ */
33
+ vec4 dieBlock(vec2 point) {
34
+ vec2 cells = point / ws_spacing;
35
+ vec4 box = vec4(0.0, 0.0, ceil(ws_size / ws_spacing));
36
+ for (int level = 0; level < SPLIT_LEVELS; level++) {
37
+ vec2 extent = box.zw - box.xy;
38
+ float seed = ws_hash(box.xy * 7.0 + box.zw * 13.0 + float(level));
39
+ bool across = extent.x >= extent.y;
40
+ float span = across ? extent.x : extent.y;
41
+ if (span < 2.0 * MIN_BLOCK_CELLS || (level >= 2 && seed < LEAF_CHANCE)) {
42
+ break;
43
+ }
44
+ float cut = floor(mix(MIN_BLOCK_CELLS, span - MIN_BLOCK_CELLS, ws_hash(box.zw + box.xy * 3.0 + 0.5)) + 0.5);
45
+ if (across) {
46
+ float x = box.x + cut;
47
+ box = cells.x < x ? vec4(box.xy, x, box.w) : vec4(x, box.y, box.zw);
48
+ } else {
49
+ float y = box.y + cut;
50
+ box = cells.y < y ? vec4(box.x, box.y, box.z, y) : vec4(box.x, y, box.zw);
51
+ }
52
+ }
53
+ return box;
54
+ }
55
+
56
+ /*
57
+ * How far p lies inside its block from the block's inner edges, in CSS
58
+ * pixels; the host's own edges count as far away, so no rail runs there.
59
+ */
60
+ float toInnerEdge(vec2 p, vec4 box) {
61
+ vec2 low = box.xy * ws_spacing;
62
+ vec2 high = min(box.zw * ws_spacing, ws_size);
63
+ vec2 fromLow = p - low + 1.0e6 * vec2(lessThanEqual(box.xy, vec2(0.0)));
64
+ vec2 toHigh = high - p + 1.0e6 * vec2(greaterThanEqual(high, ws_size));
65
+ return min(min(fromLow.x, fromLow.y), min(toHigh.x, toHigh.y));
66
+ }
67
+
68
+ /*
69
+ * A block's micro pattern at p, 0 to 1: dots, stripes, a hatch or cells,
70
+ * kept off the rails by the inset. Dots sit where the grid has them, whole.
71
+ */
72
+ float microPattern(vec2 p, vec4 box, float kind) {
73
+ float inset = INSET_SPACINGS * ws_spacing;
74
+ float edge = 0.5 * ws_pixel;
75
+ float inside = smoothstep(inset - edge, inset + edge, toInnerEdge(p, box));
76
+ vec2 center = ws_cellCenter(ws_cell(p));
77
+ bool dotShown = all(lessThan(center, ws_size)) && toInnerEdge(center, box) >= inset;
78
+ float dotCover = dotShown ? ws_dotDisk(p, center, 0.5 * ws_dotSize) : 0.0;
79
+ float lineWidth = max(LINE_WIDTH * ws_spacing, ws_pixel);
80
+ float lines = 0.0;
81
+ if (kind < 1.0) {
82
+ lines = 0.0;
83
+ } else if (kind < 2.0) {
84
+ lines = STRIPE_ALPHA * ws_band(abs(p.y - center.y), lineWidth);
85
+ } else if (kind < 3.0) {
86
+ // 45° lines through the dots, measured across them
87
+ float diagonal = (p.x + p.y) / ws_spacing;
88
+ float away = abs(fract(diagonal) - 0.5) * ws_spacing * inversesqrt(2.0);
89
+ lines = HATCH_ALPHA * ws_band(away, lineWidth);
90
+ } else {
91
+ vec2 fromCenter = abs(p - center);
92
+ float square = abs(max(fromCenter.x, fromCenter.y) - CELL_SQUARE_SPACINGS * ws_spacing);
93
+ lines = STRIPE_ALPHA * ws_band(square, lineWidth);
94
+ }
95
+ return max(dotCover, inside * lines);
96
+ }
97
+
98
+ vec4 wsShade(vec2 point) {
99
+ vec4 box = dieBlock(point);
100
+ vec2 low = box.xy * ws_spacing;
101
+ vec2 high = min(box.zw * ws_spacing, ws_size);
102
+ float blockSeed = ws_hash(box.xy * 5.0 + box.zw * 11.0);
103
+
104
+ // the block powers on when the front reaches the middle of its left edge
105
+ vec2 anchor = vec2(low.x, 0.5 * (low.y + high.y));
106
+ float power = ws_waveIntensity(anchor);
107
+ float sinceReached = ws_behindFront(anchor);
108
+ if (sinceReached >= 0.0 && sinceReached < FLICKER_SPACINGS * ws_spacing) {
109
+ float flickerFrame = floor(ws_time * FLICKERS_PER_SECOND);
110
+ power *= step(FLICKER_OFF_CHANCE, ws_hash(vec2(blockSeed * 97.0, flickerFrame)));
111
+ }
112
+
113
+ // rails run along the block's inner edges, half on each side
114
+ float rail = ws_band(toInnerEdge(point, box), 2.0 * max(RAIL_WIDTH * ws_spacing, ws_pixel));
115
+ float pattern = microPattern(point, box, floor(blockSeed * PATTERN_KINDS));
116
+
117
+ vec4 ink = ws_ink(power);
118
+ float railAlpha = rail * ink.a * mix(RAIL_REST_ALPHA, RAIL_LIT_ALPHA, power);
119
+ float patternAlpha = pattern * ink.a * mix(WS_REST_ALPHA * PATTERN_REST_ALPHA, WS_LIT_ALPHA, power);
120
+ float fill = FILL_ALPHA * power * ws_accent.a;
121
+ float alpha = max(railAlpha, patternAlpha);
122
+ vec3 color = ink.rgb * alpha + ws_accent.rgb * fill * (1.0 - alpha);
123
+ alpha += fill * (1.0 - alpha);
124
+ return alpha <= 0.0 ? vec4(0.0) : vec4(color / alpha, alpha);
125
+ }
126
+ `,
127
+ };
128
+ //# sourceMappingURL=die-scan.shader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"die-scan.shader.js","sourceRoot":"","sources":["../../../../../../../../../libs/public/ws-loading-wave/src/lib/webgl/shaders/die-scan.shader.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAsB;IAC9C,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoHX;CACA,CAAC","sourcesContent":["import type { LoadingWaveShader } from '../loading-wave-shader';\n\n/**\n * A chip powering up: the element is cut along the grid's lines into blocks\n * by a hashed recursive split, large cores and small cells with rails\n * between them, each block filled with a micro pattern on the dot pitch\n * (dots, stripes, a hatch or cells). The front powers the die on: a block\n * flickers on as the front reaches its left edge, its rails and pattern\n * light up in the accent colour, and it keeps a low afterglow.\n */\nexport const dieScanShader: LoadingWaveShader = {\n fragment: `\nconst int SPLIT_LEVELS = 5;\nconst float MIN_BLOCK_CELLS = 2.0;\nconst float LEAF_CHANCE = 0.3;\nconst float INSET_SPACINGS = 0.3;\nconst float RAIL_WIDTH = 0.08;\nconst float RAIL_REST_ALPHA = 0.14;\nconst float RAIL_LIT_ALPHA = 0.75;\nconst float FILL_ALPHA = 0.07;\nconst float PATTERN_REST_ALPHA = 0.6;\nconst float LINE_WIDTH = 0.06;\nconst float FLICKER_SPACINGS = 1.5;\nconst float FLICKERS_PER_SECOND = 24.0;\nconst float FLICKER_OFF_CHANCE = 0.35;\nconst float PATTERN_KINDS = 4.0;\nconst float STRIPE_ALPHA = 0.6;\nconst float HATCH_ALPHA = 0.5;\nconst float CELL_SQUARE_SPACINGS = 0.3;\n\n/*\n * The block, in cells (min in xy, max in zw), that a point lies in: the\n * grid is split again and again across its longer side at a hashed cell line.\n */\nvec4 dieBlock(vec2 point) {\n vec2 cells = point / ws_spacing;\n vec4 box = vec4(0.0, 0.0, ceil(ws_size / ws_spacing));\n for (int level = 0; level < SPLIT_LEVELS; level++) {\n vec2 extent = box.zw - box.xy;\n float seed = ws_hash(box.xy * 7.0 + box.zw * 13.0 + float(level));\n bool across = extent.x >= extent.y;\n float span = across ? extent.x : extent.y;\n if (span < 2.0 * MIN_BLOCK_CELLS || (level >= 2 && seed < LEAF_CHANCE)) {\n break;\n }\n float cut = floor(mix(MIN_BLOCK_CELLS, span - MIN_BLOCK_CELLS, ws_hash(box.zw + box.xy * 3.0 + 0.5)) + 0.5);\n if (across) {\n float x = box.x + cut;\n box = cells.x < x ? vec4(box.xy, x, box.w) : vec4(x, box.y, box.zw);\n } else {\n float y = box.y + cut;\n box = cells.y < y ? vec4(box.x, box.y, box.z, y) : vec4(box.x, y, box.zw);\n }\n }\n return box;\n}\n\n/*\n * How far p lies inside its block from the block's inner edges, in CSS\n * pixels; the host's own edges count as far away, so no rail runs there.\n */\nfloat toInnerEdge(vec2 p, vec4 box) {\n vec2 low = box.xy * ws_spacing;\n vec2 high = min(box.zw * ws_spacing, ws_size);\n vec2 fromLow = p - low + 1.0e6 * vec2(lessThanEqual(box.xy, vec2(0.0)));\n vec2 toHigh = high - p + 1.0e6 * vec2(greaterThanEqual(high, ws_size));\n return min(min(fromLow.x, fromLow.y), min(toHigh.x, toHigh.y));\n}\n\n/*\n * A block's micro pattern at p, 0 to 1: dots, stripes, a hatch or cells,\n * kept off the rails by the inset. Dots sit where the grid has them, whole.\n */\nfloat microPattern(vec2 p, vec4 box, float kind) {\n float inset = INSET_SPACINGS * ws_spacing;\n float edge = 0.5 * ws_pixel;\n float inside = smoothstep(inset - edge, inset + edge, toInnerEdge(p, box));\n vec2 center = ws_cellCenter(ws_cell(p));\n bool dotShown = all(lessThan(center, ws_size)) && toInnerEdge(center, box) >= inset;\n float dotCover = dotShown ? ws_dotDisk(p, center, 0.5 * ws_dotSize) : 0.0;\n float lineWidth = max(LINE_WIDTH * ws_spacing, ws_pixel);\n float lines = 0.0;\n if (kind < 1.0) {\n lines = 0.0;\n } else if (kind < 2.0) {\n lines = STRIPE_ALPHA * ws_band(abs(p.y - center.y), lineWidth);\n } else if (kind < 3.0) {\n // 45° lines through the dots, measured across them\n float diagonal = (p.x + p.y) / ws_spacing;\n float away = abs(fract(diagonal) - 0.5) * ws_spacing * inversesqrt(2.0);\n lines = HATCH_ALPHA * ws_band(away, lineWidth);\n } else {\n vec2 fromCenter = abs(p - center);\n float square = abs(max(fromCenter.x, fromCenter.y) - CELL_SQUARE_SPACINGS * ws_spacing);\n lines = STRIPE_ALPHA * ws_band(square, lineWidth);\n }\n return max(dotCover, inside * lines);\n}\n\nvec4 wsShade(vec2 point) {\n vec4 box = dieBlock(point);\n vec2 low = box.xy * ws_spacing;\n vec2 high = min(box.zw * ws_spacing, ws_size);\n float blockSeed = ws_hash(box.xy * 5.0 + box.zw * 11.0);\n\n // the block powers on when the front reaches the middle of its left edge\n vec2 anchor = vec2(low.x, 0.5 * (low.y + high.y));\n float power = ws_waveIntensity(anchor);\n float sinceReached = ws_behindFront(anchor);\n if (sinceReached >= 0.0 && sinceReached < FLICKER_SPACINGS * ws_spacing) {\n float flickerFrame = floor(ws_time * FLICKERS_PER_SECOND);\n power *= step(FLICKER_OFF_CHANCE, ws_hash(vec2(blockSeed * 97.0, flickerFrame)));\n }\n\n // rails run along the block's inner edges, half on each side\n float rail = ws_band(toInnerEdge(point, box), 2.0 * max(RAIL_WIDTH * ws_spacing, ws_pixel));\n float pattern = microPattern(point, box, floor(blockSeed * PATTERN_KINDS));\n\n vec4 ink = ws_ink(power);\n float railAlpha = rail * ink.a * mix(RAIL_REST_ALPHA, RAIL_LIT_ALPHA, power);\n float patternAlpha = pattern * ink.a * mix(WS_REST_ALPHA * PATTERN_REST_ALPHA, WS_LIT_ALPHA, power);\n float fill = FILL_ALPHA * power * ws_accent.a;\n float alpha = max(railAlpha, patternAlpha);\n vec3 color = ink.rgb * alpha + ws_accent.rgb * fill * (1.0 - alpha);\n alpha += fill * (1.0 - alpha);\n return alpha <= 0.0 ? vec4(0.0) : vec4(color / alpha, alpha);\n}\n`,\n};\n"]}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * An oscilloscope: the dot grid is the graticule, and up to three digital
3
+ * signals (square waves of hashed bits, the last a clock) run across it on
4
+ * its rows. The front draws them as it sweeps: a bright phosphor head where
5
+ * it crosses a signal, a decaying trail behind it and a slight bloom; at
6
+ * rest the signals lie faint. The sparest of the circuits, good on small
7
+ * hosts.
8
+ */
9
+ export const signalTraceShader = {
10
+ fragment: `
11
+ const int MAX_SIGNALS = 3;
12
+ const float ROWS_PER_SIGNAL = 3.0;
13
+ const float SWING_SPACINGS = 1.0;
14
+ const float LINE_WIDTH = 0.09;
15
+ const float TRACE_REST_ALPHA = 0.12;
16
+ const float HEAD_SPACINGS = 0.5;
17
+ const float HEAD_ALPHA = 0.8;
18
+ const float BLOOM_SPACINGS = 0.35;
19
+ const float BLOOM_ALPHA = 0.25;
20
+ const float PHOSPHOR_WHITENING = 0.5;
21
+
22
+ /* a signal's level in a column, 0 low or 1 high: hashed bits, the last signal a clock */
23
+ float signalLevel(float signal, float lastSignal, float column) {
24
+ if (signal >= lastSignal) {
25
+ return mod(column, 2.0);
26
+ }
27
+ return step(0.5, ws_hash(vec2(signal * 31.0 + 7.0, column)));
28
+ }
29
+
30
+ /* the distance from p to the nearest signal */
31
+ float toSignals(vec2 p) {
32
+ float rows = floor(ws_size.y / ws_spacing);
33
+ float signals = clamp(floor(rows / ROWS_PER_SIGNAL), 1.0, float(MAX_SIGNALS));
34
+ float swing = SWING_SPACINGS * ws_spacing;
35
+ // a column runs from one dot to the next, so the edges stand on the dots
36
+ float column = floor(p.x / ws_spacing - 0.5);
37
+ float edgeX = (column + 0.5) * ws_spacing;
38
+ float nearest = 1.0e6;
39
+ for (int index = 0; index < MAX_SIGNALS; index++) {
40
+ float signal = float(index);
41
+ if (signal >= signals) {
42
+ break;
43
+ }
44
+ // spread over the rows, both lines on rows of dots
45
+ float row = floor((signal + 1.0) * rows / (signals + 1.0));
46
+ float low = ws_cellCenter(vec2(0.0, row)).y;
47
+ float high = low - swing;
48
+ float level = signalLevel(signal, signals - 1.0, column);
49
+ nearest = min(nearest, abs(p.y - mix(low, high, level)));
50
+ if (signalLevel(signal, signals - 1.0, column - 1.0) != level) {
51
+ nearest = min(nearest, ws_segmentDistance(p, vec2(edgeX, low), vec2(edgeX, high)));
52
+ }
53
+ if (signalLevel(signal, signals - 1.0, column + 1.0) != level) {
54
+ nearest = min(nearest, ws_segmentDistance(p, vec2(edgeX + ws_spacing, low), vec2(edgeX + ws_spacing, high)));
55
+ }
56
+ }
57
+ return nearest;
58
+ }
59
+
60
+ vec4 wsShade(vec2 point) {
61
+ float away = toSignals(point);
62
+ float lineWidth = max(LINE_WIDTH * ws_spacing, 1.5 * ws_pixel);
63
+ float line = ws_band(away, lineWidth);
64
+
65
+ float lit = ws_waveIntensity(point);
66
+ float behind = ws_behindFront(point) / (HEAD_SPACINGS * ws_spacing);
67
+ float head = ws_wave * exp(-behind * behind);
68
+ float bloomWidth = BLOOM_SPACINGS * ws_spacing;
69
+ float bloom = lit * exp(-away * away / (2.0 * bloomWidth * bloomWidth));
70
+
71
+ vec2 center = ws_cellCenter(ws_cell(point));
72
+ float graticule = all(lessThan(center, ws_size))
73
+ ? ws_dotDisk(point, center, 0.5 * ws_dotSize) * ws_color.a * WS_REST_ALPHA
74
+ : 0.0;
75
+
76
+ vec4 ink = ws_ink(lit);
77
+ float trace = line * ink.a * mix(TRACE_REST_ALPHA, WS_LIT_ALPHA, lit);
78
+ float glow = ws_accent.a * (BLOOM_ALPHA * bloom + HEAD_ALPHA * head * line);
79
+ float alpha = graticule + (1.0 - graticule) * trace;
80
+ vec3 color = ws_color.rgb * graticule + ink.rgb * (1.0 - graticule) * trace;
81
+ // the phosphor head burns lighter than the trace behind it
82
+ vec3 phosphor = mix(ws_accent.rgb, vec3(1.0), PHOSPHOR_WHITENING * head);
83
+ color = color * (1.0 - glow) + phosphor * glow;
84
+ alpha = alpha * (1.0 - glow) + glow;
85
+ return alpha <= 0.0 ? vec4(0.0) : vec4(color / alpha, alpha);
86
+ }
87
+ `,
88
+ };
89
+ //# sourceMappingURL=signal-trace.shader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal-trace.shader.js","sourceRoot":"","sources":["../../../../../../../../../libs/public/ws-loading-wave/src/lib/webgl/shaders/signal-trace.shader.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAsB;IAClD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6EX;CACA,CAAC","sourcesContent":["import type { LoadingWaveShader } from '../loading-wave-shader';\n\n/**\n * An oscilloscope: the dot grid is the graticule, and up to three digital\n * signals (square waves of hashed bits, the last a clock) run across it on\n * its rows. The front draws them as it sweeps: a bright phosphor head where\n * it crosses a signal, a decaying trail behind it and a slight bloom; at\n * rest the signals lie faint. The sparest of the circuits, good on small\n * hosts.\n */\nexport const signalTraceShader: LoadingWaveShader = {\n fragment: `\nconst int MAX_SIGNALS = 3;\nconst float ROWS_PER_SIGNAL = 3.0;\nconst float SWING_SPACINGS = 1.0;\nconst float LINE_WIDTH = 0.09;\nconst float TRACE_REST_ALPHA = 0.12;\nconst float HEAD_SPACINGS = 0.5;\nconst float HEAD_ALPHA = 0.8;\nconst float BLOOM_SPACINGS = 0.35;\nconst float BLOOM_ALPHA = 0.25;\nconst float PHOSPHOR_WHITENING = 0.5;\n\n/* a signal's level in a column, 0 low or 1 high: hashed bits, the last signal a clock */\nfloat signalLevel(float signal, float lastSignal, float column) {\n if (signal >= lastSignal) {\n return mod(column, 2.0);\n }\n return step(0.5, ws_hash(vec2(signal * 31.0 + 7.0, column)));\n}\n\n/* the distance from p to the nearest signal */\nfloat toSignals(vec2 p) {\n float rows = floor(ws_size.y / ws_spacing);\n float signals = clamp(floor(rows / ROWS_PER_SIGNAL), 1.0, float(MAX_SIGNALS));\n float swing = SWING_SPACINGS * ws_spacing;\n // a column runs from one dot to the next, so the edges stand on the dots\n float column = floor(p.x / ws_spacing - 0.5);\n float edgeX = (column + 0.5) * ws_spacing;\n float nearest = 1.0e6;\n for (int index = 0; index < MAX_SIGNALS; index++) {\n float signal = float(index);\n if (signal >= signals) {\n break;\n }\n // spread over the rows, both lines on rows of dots\n float row = floor((signal + 1.0) * rows / (signals + 1.0));\n float low = ws_cellCenter(vec2(0.0, row)).y;\n float high = low - swing;\n float level = signalLevel(signal, signals - 1.0, column);\n nearest = min(nearest, abs(p.y - mix(low, high, level)));\n if (signalLevel(signal, signals - 1.0, column - 1.0) != level) {\n nearest = min(nearest, ws_segmentDistance(p, vec2(edgeX, low), vec2(edgeX, high)));\n }\n if (signalLevel(signal, signals - 1.0, column + 1.0) != level) {\n nearest = min(nearest, ws_segmentDistance(p, vec2(edgeX + ws_spacing, low), vec2(edgeX + ws_spacing, high)));\n }\n }\n return nearest;\n}\n\nvec4 wsShade(vec2 point) {\n float away = toSignals(point);\n float lineWidth = max(LINE_WIDTH * ws_spacing, 1.5 * ws_pixel);\n float line = ws_band(away, lineWidth);\n\n float lit = ws_waveIntensity(point);\n float behind = ws_behindFront(point) / (HEAD_SPACINGS * ws_spacing);\n float head = ws_wave * exp(-behind * behind);\n float bloomWidth = BLOOM_SPACINGS * ws_spacing;\n float bloom = lit * exp(-away * away / (2.0 * bloomWidth * bloomWidth));\n\n vec2 center = ws_cellCenter(ws_cell(point));\n float graticule = all(lessThan(center, ws_size))\n ? ws_dotDisk(point, center, 0.5 * ws_dotSize) * ws_color.a * WS_REST_ALPHA\n : 0.0;\n\n vec4 ink = ws_ink(lit);\n float trace = line * ink.a * mix(TRACE_REST_ALPHA, WS_LIT_ALPHA, lit);\n float glow = ws_accent.a * (BLOOM_ALPHA * bloom + HEAD_ALPHA * head * line);\n float alpha = graticule + (1.0 - graticule) * trace;\n vec3 color = ws_color.rgb * graticule + ink.rgb * (1.0 - graticule) * trace;\n // the phosphor head burns lighter than the trace behind it\n vec3 phosphor = mix(ws_accent.rgb, vec3(1.0), PHOSPHOR_WHITENING * head);\n color = color * (1.0 - glow) + phosphor * glow;\n alpha = alpha * (1.0 - glow) + glow;\n return alpha <= 0.0 ? vec4(0.0) : vec4(color / alpha, alpha);\n}\n`,\n};\n"]}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Electric arcs: the front is a crackling bolt, an arc thrown off the front
3
+ * line by noise that changes several times a second, whose branches jump to
4
+ * the dots near it. A struck dot sparks hot and keeps the afterglow. The
5
+ * loudest of the built-in shaders.
6
+ */
7
+ export const sparkFrontShader = {
8
+ fragment: `
9
+ const float FRAMES_PER_SECOND = 14.0;
10
+ const float WANDER_SPACINGS = 0.9;
11
+ const float BOLT_WIDTH = 0.07;
12
+ const float BOLT_GLOW_SPACINGS = 0.45;
13
+ const float BOLT_GLOW_ALPHA = 0.4;
14
+ const float STRIKE_CHANCE = 0.3;
15
+ // a branch, kink and width included, stays within the 3 x 3 cells drawn
16
+ const float REACH_SPACINGS = 1.2;
17
+ const float BRANCH_KINK_SPACINGS = 0.35;
18
+ const float DOT_GROWTH = 1.0;
19
+ const float SPARK_GROWTH = 1.4;
20
+ const float SPARK_WHITENING = 0.7;
21
+ const float BRANCH_WIDTH = 0.6;
22
+ const float COARSE_WANDER_SPACINGS = 2.5;
23
+ const float FINE_WANDER_SPACINGS = 0.7;
24
+ const float FINE_WANDER_SHARE = 0.35;
25
+ const vec3 LUMA = vec3(0.299, 0.587, 0.114);
26
+
27
+ /* smooth value noise along t, 0 to 1, a new curve per frame */
28
+ float frameNoise(float t, float frame) {
29
+ float index = floor(t);
30
+ float into = fract(t);
31
+ float eased = into * into * (3.0 - 2.0 * into);
32
+ return mix(ws_hash(vec2(index, frame)), ws_hash(vec2(index + 1.0, frame)), eased);
33
+ }
34
+
35
+ /*
36
+ * Where p lies around the wave's centre: the arc length to it on the circle
37
+ * the front starts on, about its height from the middle near the front. Every
38
+ * point on a line from the centre has the same, so the bolt is one curve.
39
+ */
40
+ float arcAround(vec2 p) {
41
+ return atan(p.y - ws_center.y, p.x - ws_center.x) * -ws_center.x;
42
+ }
43
+
44
+ /* how far the bolt lies behind the front at an arc length, in CSS pixels: a coarse and a fine wander */
45
+ float boltOffset(float arc, float frame) {
46
+ float coarse = frameNoise(arc / (COARSE_WANDER_SPACINGS * ws_spacing), frame);
47
+ float fine = frameNoise(arc / (FINE_WANDER_SPACINGS * ws_spacing), frame + 17.0);
48
+ float wander = mix(coarse, fine, FINE_WANDER_SHARE);
49
+ return WANDER_SPACINGS * ws_spacing * (2.0 * wander - 1.0);
50
+ }
51
+
52
+ /* where the bolt crosses the line from the wave's centre through p */
53
+ vec2 boltPointToward(vec2 p, float frame) {
54
+ vec2 outward = normalize(p - ws_center);
55
+ return ws_center + outward * (ws_frontRadius - boltOffset(arcAround(p), frame));
56
+ }
57
+
58
+ /*
59
+ * The colour a spark burns in: lighter than the accent where the dots are
60
+ * light, so over a dark background, and the accent itself over a light one.
61
+ */
62
+ vec3 sparkColor() {
63
+ float dotsLight = step(0.5, dot(ws_color.rgb, LUMA));
64
+ return mix(ws_accent.rgb, vec3(1.0), SPARK_WHITENING * dotsLight);
65
+ }
66
+
67
+ vec4 wsShade(vec2 point) {
68
+ float frame = floor(ws_time * FRAMES_PER_SECOND);
69
+ vec3 spark = sparkColor();
70
+
71
+ // the bolt: its core measured across it, so its steep stretches keep their
72
+ // width; its glow along the front, so a sharp bend throws no smear
73
+ float arc = arcAround(point);
74
+ float offset = boltOffset(arc, frame);
75
+ float slope = boltOffset(arc + 0.5, frame) - boltOffset(arc - 0.5, frame);
76
+ float along = abs(ws_behindFront(point) - offset);
77
+ float away = along / sqrt(1.0 + slope * slope);
78
+ float boltWidth = max(BOLT_WIDTH * ws_spacing, 1.5 * ws_pixel);
79
+ float glowWidth = BOLT_GLOW_SPACINGS * ws_spacing;
80
+ float bolt = ws_wave * ws_band(away, boltWidth);
81
+ float boltGlow = ws_wave * BOLT_GLOW_ALPHA * exp(-along * along / (2.0 * glowWidth * glowWidth));
82
+
83
+ // the dots, and the branches the bolt throws to those it strikes
84
+ vec2 cell = ws_cell(point);
85
+ float dots = 0.0;
86
+ vec3 dotColor = vec3(0.0);
87
+ float branches = 0.0;
88
+ for (int row = -1; row <= 1; row++) {
89
+ for (int column = -1; column <= 1; column++) {
90
+ vec2 neighbour = cell + vec2(float(column), float(row));
91
+ vec2 center = ws_cellCenter(neighbour);
92
+ if (any(lessThan(center, vec2(0.0))) || any(greaterThanEqual(center, ws_size))) {
93
+ continue;
94
+ }
95
+ vec2 target = boltPointToward(center, frame);
96
+ bool inReach = length(target - center) < REACH_SPACINGS * ws_spacing;
97
+ float struck = ws_wave * step(ws_hash(neighbour + vec2(frame * 0.37, 5.0)), STRIKE_CHANCE)
98
+ * (inReach ? 1.0 : 0.0);
99
+ if (struck > 0.0) {
100
+ vec2 across = normalize(vec2(target.y - center.y, center.x - target.x) + vec2(1.0e-4));
101
+ vec2 kink = 0.5 * (center + target)
102
+ + across * BRANCH_KINK_SPACINGS * ws_spacing * (ws_hash(neighbour + frame) - 0.5);
103
+ float branch = max(ws_segment(point, center, kink, BRANCH_WIDTH * boltWidth),
104
+ ws_segment(point, kink, target, BRANCH_WIDTH * boltWidth));
105
+ branches = max(branches, struck * branch);
106
+ }
107
+ float lit = ws_waveIntensity(center);
108
+ float radius = 0.5 * ws_dotSize * (1.0 + DOT_GROWTH * lit + SPARK_GROWTH * struck);
109
+ float core = ws_dotDisk(point, center, radius);
110
+ vec4 ink = ws_ink(lit);
111
+ float dotAlpha = core * ink.a * mix(WS_REST_ALPHA, WS_LIT_ALPHA, max(lit, struck));
112
+ vec3 color = mix(ink.rgb, spark, struck);
113
+ dotColor = dotColor * (1.0 - dotAlpha) + color * dotAlpha;
114
+ dots = dots + (1.0 - dots) * dotAlpha;
115
+ }
116
+ }
117
+
118
+ float glow = ws_accent.a * boltGlow;
119
+ float hot = ws_accent.a * max(bolt, branches);
120
+ vec3 color = dotColor;
121
+ float alpha = dots;
122
+ color = color * (1.0 - glow) + ws_accent.rgb * glow;
123
+ alpha = alpha * (1.0 - glow) + glow;
124
+ color = color * (1.0 - hot) + spark * hot;
125
+ alpha = alpha * (1.0 - hot) + hot;
126
+ return alpha <= 0.0 ? vec4(0.0) : vec4(color / alpha, alpha);
127
+ }
128
+ `,
129
+ };
130
+ //# sourceMappingURL=spark-front.shader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spark-front.shader.js","sourceRoot":"","sources":["../../../../../../../../../libs/public/ws-loading-wave/src/lib/webgl/shaders/spark-front.shader.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAsB;IACjD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwHX;CACA,CAAC","sourcesContent":["import type { LoadingWaveShader } from '../loading-wave-shader';\n\n/**\n * Electric arcs: the front is a crackling bolt, an arc thrown off the front\n * line by noise that changes several times a second, whose branches jump to\n * the dots near it. A struck dot sparks hot and keeps the afterglow. The\n * loudest of the built-in shaders.\n */\nexport const sparkFrontShader: LoadingWaveShader = {\n fragment: `\nconst float FRAMES_PER_SECOND = 14.0;\nconst float WANDER_SPACINGS = 0.9;\nconst float BOLT_WIDTH = 0.07;\nconst float BOLT_GLOW_SPACINGS = 0.45;\nconst float BOLT_GLOW_ALPHA = 0.4;\nconst float STRIKE_CHANCE = 0.3;\n// a branch, kink and width included, stays within the 3 x 3 cells drawn\nconst float REACH_SPACINGS = 1.2;\nconst float BRANCH_KINK_SPACINGS = 0.35;\nconst float DOT_GROWTH = 1.0;\nconst float SPARK_GROWTH = 1.4;\nconst float SPARK_WHITENING = 0.7;\nconst float BRANCH_WIDTH = 0.6;\nconst float COARSE_WANDER_SPACINGS = 2.5;\nconst float FINE_WANDER_SPACINGS = 0.7;\nconst float FINE_WANDER_SHARE = 0.35;\nconst vec3 LUMA = vec3(0.299, 0.587, 0.114);\n\n/* smooth value noise along t, 0 to 1, a new curve per frame */\nfloat frameNoise(float t, float frame) {\n float index = floor(t);\n float into = fract(t);\n float eased = into * into * (3.0 - 2.0 * into);\n return mix(ws_hash(vec2(index, frame)), ws_hash(vec2(index + 1.0, frame)), eased);\n}\n\n/*\n * Where p lies around the wave's centre: the arc length to it on the circle\n * the front starts on, about its height from the middle near the front. Every\n * point on a line from the centre has the same, so the bolt is one curve.\n */\nfloat arcAround(vec2 p) {\n return atan(p.y - ws_center.y, p.x - ws_center.x) * -ws_center.x;\n}\n\n/* how far the bolt lies behind the front at an arc length, in CSS pixels: a coarse and a fine wander */\nfloat boltOffset(float arc, float frame) {\n float coarse = frameNoise(arc / (COARSE_WANDER_SPACINGS * ws_spacing), frame);\n float fine = frameNoise(arc / (FINE_WANDER_SPACINGS * ws_spacing), frame + 17.0);\n float wander = mix(coarse, fine, FINE_WANDER_SHARE);\n return WANDER_SPACINGS * ws_spacing * (2.0 * wander - 1.0);\n}\n\n/* where the bolt crosses the line from the wave's centre through p */\nvec2 boltPointToward(vec2 p, float frame) {\n vec2 outward = normalize(p - ws_center);\n return ws_center + outward * (ws_frontRadius - boltOffset(arcAround(p), frame));\n}\n\n/*\n * The colour a spark burns in: lighter than the accent where the dots are\n * light, so over a dark background, and the accent itself over a light one.\n */\nvec3 sparkColor() {\n float dotsLight = step(0.5, dot(ws_color.rgb, LUMA));\n return mix(ws_accent.rgb, vec3(1.0), SPARK_WHITENING * dotsLight);\n}\n\nvec4 wsShade(vec2 point) {\n float frame = floor(ws_time * FRAMES_PER_SECOND);\n vec3 spark = sparkColor();\n\n // the bolt: its core measured across it, so its steep stretches keep their\n // width; its glow along the front, so a sharp bend throws no smear\n float arc = arcAround(point);\n float offset = boltOffset(arc, frame);\n float slope = boltOffset(arc + 0.5, frame) - boltOffset(arc - 0.5, frame);\n float along = abs(ws_behindFront(point) - offset);\n float away = along / sqrt(1.0 + slope * slope);\n float boltWidth = max(BOLT_WIDTH * ws_spacing, 1.5 * ws_pixel);\n float glowWidth = BOLT_GLOW_SPACINGS * ws_spacing;\n float bolt = ws_wave * ws_band(away, boltWidth);\n float boltGlow = ws_wave * BOLT_GLOW_ALPHA * exp(-along * along / (2.0 * glowWidth * glowWidth));\n\n // the dots, and the branches the bolt throws to those it strikes\n vec2 cell = ws_cell(point);\n float dots = 0.0;\n vec3 dotColor = vec3(0.0);\n float branches = 0.0;\n for (int row = -1; row <= 1; row++) {\n for (int column = -1; column <= 1; column++) {\n vec2 neighbour = cell + vec2(float(column), float(row));\n vec2 center = ws_cellCenter(neighbour);\n if (any(lessThan(center, vec2(0.0))) || any(greaterThanEqual(center, ws_size))) {\n continue;\n }\n vec2 target = boltPointToward(center, frame);\n bool inReach = length(target - center) < REACH_SPACINGS * ws_spacing;\n float struck = ws_wave * step(ws_hash(neighbour + vec2(frame * 0.37, 5.0)), STRIKE_CHANCE)\n * (inReach ? 1.0 : 0.0);\n if (struck > 0.0) {\n vec2 across = normalize(vec2(target.y - center.y, center.x - target.x) + vec2(1.0e-4));\n vec2 kink = 0.5 * (center + target)\n + across * BRANCH_KINK_SPACINGS * ws_spacing * (ws_hash(neighbour + frame) - 0.5);\n float branch = max(ws_segment(point, center, kink, BRANCH_WIDTH * boltWidth),\n ws_segment(point, kink, target, BRANCH_WIDTH * boltWidth));\n branches = max(branches, struck * branch);\n }\n float lit = ws_waveIntensity(center);\n float radius = 0.5 * ws_dotSize * (1.0 + DOT_GROWTH * lit + SPARK_GROWTH * struck);\n float core = ws_dotDisk(point, center, radius);\n vec4 ink = ws_ink(lit);\n float dotAlpha = core * ink.a * mix(WS_REST_ALPHA, WS_LIT_ALPHA, max(lit, struck));\n vec3 color = mix(ink.rgb, spark, struck);\n dotColor = dotColor * (1.0 - dotAlpha) + color * dotAlpha;\n dots = dots + (1.0 - dots) * dotAlpha;\n }\n }\n\n float glow = ws_accent.a * boltGlow;\n float hot = ws_accent.a * max(bolt, branches);\n vec3 color = dotColor;\n float alpha = dots;\n color = color * (1.0 - glow) + ws_accent.rgb * glow;\n alpha = alpha * (1.0 - glow) + glow;\n color = color * (1.0 - hot) + spark * hot;\n alpha = alpha * (1.0 - hot) + hot;\n return alpha <= 0.0 ? vec4(0.0) : vec4(color / alpha, alpha);\n}\n`,\n};\n"]}
@@ -0,0 +1,12 @@
1
+ /*
2
+ * Public API Surface of @wolsok/loading-wave/shaders: the built-in shaders
3
+ * beside the default. A secondary entry point of their own, so an app that
4
+ * shares the lib's main entry (Native Federation bundles an entry whole)
5
+ * loads none of them until it imports one.
6
+ */
7
+ export { circuitTracesShader } from './lib/webgl/shaders/circuit-traces.shader';
8
+ export { dataBusShader } from './lib/webgl/shaders/data-bus.shader';
9
+ export { dieScanShader } from './lib/webgl/shaders/die-scan.shader';
10
+ export { signalTraceShader } from './lib/webgl/shaders/signal-trace.shader';
11
+ export { sparkFrontShader } from './lib/webgl/shaders/spark-front.shader';
12
+ //# sourceMappingURL=shaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shaders.js","sourceRoot":"","sources":["../../../../../../libs/public/ws-loading-wave/src/shaders.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC","sourcesContent":["/*\n * Public API Surface of @wolsok/loading-wave/shaders: the built-in shaders\n * beside the default. A secondary entry point of their own, so an app that\n * shares the lib's main entry (Native Federation bundles an entry whole)\n * loads none of them until it imports one.\n */\nexport { circuitTracesShader } from './lib/webgl/shaders/circuit-traces.shader';\nexport { dataBusShader } from './lib/webgl/shaders/data-bus.shader';\nexport { dieScanShader } from './lib/webgl/shaders/die-scan.shader';\nexport { signalTraceShader } from './lib/webgl/shaders/signal-trace.shader';\nexport { sparkFrontShader } from './lib/webgl/shaders/spark-front.shader';\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ export * from './shaders';
5
+ //# sourceMappingURL=wolsok-loading-wave-shaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wolsok-loading-wave-shaders.js","sourceRoot":"","sources":["../../../../../../libs/public/ws-loading-wave/src/wolsok-loading-wave-shaders.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC","sourcesContent":["/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './shaders';\n"]}
@@ -18,7 +18,7 @@ export declare const WAVE_VERTEX_SHADER = "#version 300 es\nvoid main() {\n vec
18
18
  * `shader-constants.spec.ts` keeps them equal. Kept a plain literal, so a
19
19
  * bundler can tell it has no side effects.
20
20
  */
21
- export declare 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 of a disk at p, 0 to 1 */\nfloat ws_dotDisk(vec2 p, vec2 center, float radius) {\n float edge = 0.5 * ws_pixel;\n return 1.0 - smoothstep(radius - edge, radius + edge, length(p - center));\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 vec2 ab = b - a;\n float along = clamp(dot(p - a, ab) / max(dot(ab, ab), 1.0e-6), 0.0, 1.0);\n float away = length(p - a - ab * along);\n float edge = 0.5 * ws_pixel;\n return 1.0 - smoothstep(0.5 * width - edge, 0.5 * width + edge, away);\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";
21
+ export declare 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";
22
22
  /**
23
23
  * What every fragment shader ends with: maps the drawing buffer onto the
24
24
  * host in CSS pixels (y down), calls `wsShade` and fades it by `ws_dots`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wolsok/loading-wave",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "An Angular directive that lays a calm loading wave of lit dots behind any element, on the GPU with a 2D canvas fallback",
5
5
  "bugs": {
6
6
  "url": "https://github.com/WolfSoko/wol-sok-mono/issues"
@@ -40,6 +40,10 @@
40
40
  ".": {
41
41
  "types": "./wolsok-loading-wave.d.ts",
42
42
  "default": "./esm2022/wolsok-loading-wave.js"
43
+ },
44
+ "./shaders": {
45
+ "types": "./shaders/wolsok-loading-wave-shaders.d.ts",
46
+ "default": "./esm2022/shaders/wolsok-loading-wave-shaders.js"
43
47
  }
44
48
  },
45
49
  "sideEffects": false,
@@ -0,0 +1,20 @@
1
+ /** a uniform's value: a `float`, or the components of a `vec2` to `vec4` */
2
+ export type ShaderUniformValue = number | readonly [number] | readonly [number, number] | readonly [number, number, number] | readonly [number, number, number, number];
3
+ /** values of the uniforms a fragment declares itself, by their GLSL name */
4
+ export type ShaderUniforms = Readonly<Record<string, ShaderUniformValue>>;
5
+ /**
6
+ * A fragment shader for the loading wave's WebGL renderer.
7
+ *
8
+ * `fragment` is GLSL ES 3.00 that defines `vec4 wsShade(vec2 point)`: the
9
+ * straight (not premultiplied) colour and opacity at `point`, in CSS pixels
10
+ * from the host's top left corner. The lib puts the `ws_*` uniforms and
11
+ * helpers before it and a `main` after it (see the README), so the fragment
12
+ * holds neither `#version` nor `main`. At `ws_wave == 0` it draws its resting
13
+ * state, without `ws_time`: that is what `afterLoading: 'keep'` leaves and
14
+ * what `prefers-reduced-motion` shows.
15
+ */
16
+ export interface LoadingWaveShader {
17
+ readonly fragment: string;
18
+ /** values of uniforms the fragment declares itself; never `ws_*` ones */
19
+ readonly uniforms?: ShaderUniforms;
20
+ }
@@ -0,0 +1,12 @@
1
+ import type { LoadingWaveShader } from '../loading-wave-shader';
2
+ /**
3
+ * A printed circuit board: each grid cell leads a copper trace on to the
4
+ * right, now and then jogging a row up or down at 45° within a pair of rows,
5
+ * so the cells join into traces running left to right, with the dots as
6
+ * solder points and some of them pads. Ahead of the front the board lies
7
+ * dark; behind it the traces light up in the accent colour and current
8
+ * pulses, bright packets with comet tails, run on along them at a speed per
9
+ * pair of rows (a differential pair, so a pulse runs on through a jog),
10
+ * flashing the pads they pass, then die out in the afterglow.
11
+ */
12
+ export declare const circuitTracesShader: LoadingWaveShader;
@@ -0,0 +1,10 @@
1
+ import type { LoadingWaveShader } from '../loading-wave-shader';
2
+ /**
3
+ * A logic analyser: the grid's rows are the lanes of buses, four to six
4
+ * lanes each with a gap between buses, now and then a whole bus bending a
5
+ * lane down and back. Each lane carries bits, a short dash for a zero and a
6
+ * long one for a one. Ahead of the front they idle dim and still; the front
7
+ * is a clock edge: behind it the bits flip, brighten and stream on to the
8
+ * right at a speed per bus.
9
+ */
10
+ export declare const dataBusShader: LoadingWaveShader;
@@ -0,0 +1,10 @@
1
+ import type { LoadingWaveShader } from '../loading-wave-shader';
2
+ /**
3
+ * A chip powering up: the element is cut along the grid's lines into blocks
4
+ * by a hashed recursive split, large cores and small cells with rails
5
+ * between them, each block filled with a micro pattern on the dot pitch
6
+ * (dots, stripes, a hatch or cells). The front powers the die on: a block
7
+ * flickers on as the front reaches its left edge, its rails and pattern
8
+ * light up in the accent colour, and it keeps a low afterglow.
9
+ */
10
+ export declare const dieScanShader: LoadingWaveShader;
@@ -0,0 +1,10 @@
1
+ import type { LoadingWaveShader } from '../loading-wave-shader';
2
+ /**
3
+ * An oscilloscope: the dot grid is the graticule, and up to three digital
4
+ * signals (square waves of hashed bits, the last a clock) run across it on
5
+ * its rows. The front draws them as it sweeps: a bright phosphor head where
6
+ * it crosses a signal, a decaying trail behind it and a slight bloom; at
7
+ * rest the signals lie faint. The sparest of the circuits, good on small
8
+ * hosts.
9
+ */
10
+ export declare const signalTraceShader: LoadingWaveShader;
@@ -0,0 +1,8 @@
1
+ import type { LoadingWaveShader } from '../loading-wave-shader';
2
+ /**
3
+ * Electric arcs: the front is a crackling bolt, an arc thrown off the front
4
+ * line by noise that changes several times a second, whose branches jump to
5
+ * the dots near it. A struck dot sparks hot and keeps the afterglow. The
6
+ * loudest of the built-in shaders.
7
+ */
8
+ export declare const sparkFrontShader: LoadingWaveShader;
@@ -0,0 +1,5 @@
1
+ export { circuitTracesShader } from './lib/webgl/shaders/circuit-traces.shader';
2
+ export { dataBusShader } from './lib/webgl/shaders/data-bus.shader';
3
+ export { dieScanShader } from './lib/webgl/shaders/die-scan.shader';
4
+ export { signalTraceShader } from './lib/webgl/shaders/signal-trace.shader';
5
+ export { sparkFrontShader } from './lib/webgl/shaders/spark-front.shader';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ /// <amd-module name="@wolsok/loading-wave/shaders" />
5
+ export * from './shaders';