@wolsok/loading-wave 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -12
- package/esm2022/index.js +1 -0
- package/esm2022/index.js.map +1 -1
- package/esm2022/lib/canvas-wave-renderer.js +34 -12
- package/esm2022/lib/canvas-wave-renderer.js.map +1 -1
- package/esm2022/lib/choose-wave-renderer.js +8 -3
- package/esm2022/lib/choose-wave-renderer.js.map +1 -1
- package/esm2022/lib/loading-wave-options.js +16 -2
- package/esm2022/lib/loading-wave-options.js.map +1 -1
- package/esm2022/lib/loading-wave.js +11 -3
- package/esm2022/lib/loading-wave.js.map +1 -1
- package/esm2022/lib/renderer.js.map +1 -1
- package/esm2022/lib/wave-model.js +33 -9
- package/esm2022/lib/wave-model.js.map +1 -1
- package/esm2022/lib/webgl/echo.js +5 -0
- package/esm2022/lib/webgl/echo.js.map +1 -0
- package/esm2022/lib/webgl/loading-wave-shader.js +1 -0
- package/esm2022/lib/webgl/loading-wave-shader.js.map +1 -0
- package/esm2022/lib/webgl/shader-program.js +235 -0
- package/esm2022/lib/webgl/shader-program.js.map +1 -0
- package/esm2022/lib/webgl/shaders/ripple.shader.js +110 -0
- package/esm2022/lib/webgl/shaders/ripple.shader.js.map +1 -0
- package/esm2022/lib/webgl/webgl-wave-renderer.js +102 -92
- package/esm2022/lib/webgl/webgl-wave-renderer.js.map +1 -1
- package/esm2022/shaders/lib/webgl/loading-wave-shader.js +1 -0
- package/esm2022/shaders/lib/webgl/loading-wave-shader.js.map +1 -0
- package/esm2022/shaders/lib/webgl/shaders/circuit-traces.shader.js +136 -0
- package/esm2022/shaders/lib/webgl/shaders/circuit-traces.shader.js.map +1 -0
- package/esm2022/shaders/lib/webgl/shaders/data-bus.shader.js +91 -0
- package/esm2022/shaders/lib/webgl/shaders/data-bus.shader.js.map +1 -0
- package/esm2022/shaders/lib/webgl/shaders/die-scan.shader.js +128 -0
- package/esm2022/shaders/lib/webgl/shaders/die-scan.shader.js.map +1 -0
- package/esm2022/shaders/lib/webgl/shaders/signal-trace.shader.js +89 -0
- package/esm2022/shaders/lib/webgl/shaders/signal-trace.shader.js.map +1 -0
- package/esm2022/shaders/lib/webgl/shaders/spark-front.shader.js +130 -0
- package/esm2022/shaders/lib/webgl/shaders/spark-front.shader.js.map +1 -0
- package/esm2022/shaders/shaders.js +12 -0
- package/esm2022/shaders/shaders.js.map +1 -0
- package/esm2022/shaders/wolsok-loading-wave-shaders.js +5 -0
- package/esm2022/shaders/wolsok-loading-wave-shaders.js.map +1 -0
- package/index.d.ts +3 -1
- package/lib/canvas-wave-renderer.d.ts +2 -0
- package/lib/choose-wave-renderer.d.ts +3 -0
- package/lib/loading-wave-options.d.ts +24 -4
- package/lib/loading-wave.d.ts +3 -3
- package/lib/renderer.d.ts +5 -0
- package/lib/wave-model.d.ts +17 -6
- package/lib/webgl/echo.d.ts +4 -0
- package/lib/webgl/loading-wave-shader.d.ts +20 -0
- package/lib/webgl/shader-program.d.ts +33 -0
- package/lib/webgl/shaders/ripple.shader.d.ts +10 -0
- package/lib/webgl/webgl-wave-renderer.d.ts +18 -7
- package/package.json +5 -1
- package/shaders/lib/webgl/loading-wave-shader.d.ts +20 -0
- package/shaders/lib/webgl/shaders/circuit-traces.shader.d.ts +12 -0
- package/shaders/lib/webgl/shaders/data-bus.shader.d.ts +10 -0
- package/shaders/lib/webgl/shaders/die-scan.shader.d.ts +10 -0
- package/shaders/lib/webgl/shaders/signal-trace.shader.d.ts +10 -0
- package/shaders/lib/webgl/shaders/spark-front.shader.d.ts +8 -0
- package/shaders/shaders.d.ts +5 -0
- package/shaders/wolsok-loading-wave-shaders.d.ts +5 -0
- package/esm2022/lib/webgl/wave-shaders.js +0 -114
- package/esm2022/lib/webgl/wave-shaders.js.map +0 -1
- package/lib/webgl/wave-shaders.d.ts +0 -14
|
@@ -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 @@
|
|
|
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"]}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { LoadingWaveDirective } from './lib/loading-wave.directive';
|
|
2
2
|
export { DEFAULT_LOADING_WAVE_OPTIONS, LOADING_WAVE_OPTIONS, provideLoadingWave, } from './lib/loading-wave-options';
|
|
3
|
-
export type { AfterLoading, LoadingWaveOptions, WaveRendererPreference, } from './lib/loading-wave-options';
|
|
3
|
+
export type { AfterLoading, LoadingWaveOptions, ResolvedLoadingWaveOptions, WaveRendererPreference, } from './lib/loading-wave-options';
|
|
4
4
|
export type { WaveRendererKind } from './lib/renderer';
|
|
5
|
+
export type { LoadingWaveShader, ShaderUniforms, ShaderUniformValue, } from './lib/webgl/loading-wave-shader';
|
|
6
|
+
export { rippleShader } from './lib/webgl/shaders/ripple.shader';
|
|
@@ -19,6 +19,8 @@ export declare class CanvasWaveRenderer implements WaveRenderer {
|
|
|
19
19
|
resize(geometry: WaveGeometry, pixelRatio: number): void;
|
|
20
20
|
draw(frame: WaveFrame): void;
|
|
21
21
|
setLook(look: WaveLook): void;
|
|
22
|
+
/** a 2D canvas runs no shader */
|
|
23
|
+
setShaderUniforms(): void;
|
|
22
24
|
dispose(): void;
|
|
23
25
|
/** draws every dot at rest in one path, returns the lit ones */
|
|
24
26
|
private drawRestingDots;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { WaveRendererPreference } from './loading-wave-options';
|
|
2
2
|
import type { WaveLook, WaveRenderer } from './renderer';
|
|
3
|
+
import type { LoadingWaveShader } from './webgl/loading-wave-shader';
|
|
3
4
|
/** counts the waves that hold a WebGL context */
|
|
4
5
|
export declare class GpuContextBudget {
|
|
5
6
|
private readonly max;
|
|
@@ -13,6 +14,8 @@ export declare const PAGE_GPU_BUDGET: GpuContextBudget;
|
|
|
13
14
|
export interface ChooseWaveRendererParams {
|
|
14
15
|
readonly preference: WaveRendererPreference;
|
|
15
16
|
readonly look: WaveLook;
|
|
17
|
+
/** what the WebGL renderer draws with */
|
|
18
|
+
readonly shader: LoadingWaveShader;
|
|
16
19
|
/** a new, detached canvas for each renderer tried */
|
|
17
20
|
readonly createCanvas: () => HTMLCanvasElement;
|
|
18
21
|
/** the WebGL renderer lost its context; swap it for a 2D one */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InjectionToken, Provider } from '@angular/core';
|
|
2
|
+
import type { LoadingWaveShader } from './webgl/loading-wave-shader';
|
|
2
3
|
/** what the dots do once loading ended */
|
|
3
4
|
export type AfterLoading = 'hide' | 'keep';
|
|
4
5
|
/** which renderer draws the wave */
|
|
@@ -15,6 +16,11 @@ export interface LoadingWaveOptions {
|
|
|
15
16
|
readonly dotSize: number;
|
|
16
17
|
/** any CSS colour; unset, the dots take the host's `currentColor` */
|
|
17
18
|
readonly color?: string;
|
|
19
|
+
/**
|
|
20
|
+
* any CSS colour for the lit dots and the wave itself; unset, they take
|
|
21
|
+
* the dots' colour
|
|
22
|
+
*/
|
|
23
|
+
readonly accentColor?: string;
|
|
18
24
|
/** how long one sweep of the wave across the element takes, in ms */
|
|
19
25
|
readonly sweepMs: number;
|
|
20
26
|
/**
|
|
@@ -23,13 +29,27 @@ export interface LoadingWaveOptions {
|
|
|
23
29
|
* that fails. `'canvas'` never uses WebGL.
|
|
24
30
|
*/
|
|
25
31
|
readonly renderer: WaveRendererPreference;
|
|
32
|
+
/**
|
|
33
|
+
* 0 (a straight front) to 1 (a half circle): how far the wave front's ends
|
|
34
|
+
* lag its middle, as a share of `min(height / 2, width)`; 0.5 when unset
|
|
35
|
+
*/
|
|
36
|
+
readonly frontRoundness?: number;
|
|
37
|
+
/**
|
|
38
|
+
* the fragment shader the WebGL renderer draws with: a built-in one
|
|
39
|
+
* (`rippleShader`) or one's own; unset, `rippleShader`. The 2D canvas
|
|
40
|
+
* always draws the dot wave.
|
|
41
|
+
*/
|
|
42
|
+
readonly shader?: LoadingWaveShader;
|
|
26
43
|
}
|
|
27
|
-
|
|
44
|
+
/** options with every default filled in, as the wave runs with them */
|
|
45
|
+
export type ResolvedLoadingWaveOptions = LoadingWaveOptions & Required<Pick<LoadingWaveOptions, 'frontRoundness' | 'shader'>>;
|
|
46
|
+
export declare const DEFAULT_LOADING_WAVE_OPTIONS: ResolvedLoadingWaveOptions;
|
|
28
47
|
export declare const LOADING_WAVE_OPTIONS: InjectionToken<LoadingWaveOptions>;
|
|
29
48
|
/** sets app-wide defaults; the directive's own options still win */
|
|
30
49
|
export declare function provideLoadingWave(options: Partial<LoadingWaveOptions>): Provider;
|
|
31
50
|
/**
|
|
32
|
-
* Merges `overrides` into `defaults`, ignoring `undefined` values
|
|
33
|
-
* replacing sizes and durations that are no positive finite number
|
|
51
|
+
* Merges `overrides` into `defaults`, ignoring `undefined` values,
|
|
52
|
+
* replacing sizes and durations that are no positive finite number and
|
|
53
|
+
* clamping the front's roundness into 0 to 1.
|
|
34
54
|
*/
|
|
35
|
-
export declare function resolveLoadingWaveOptions(defaults: LoadingWaveOptions, overrides?: Partial<LoadingWaveOptions>):
|
|
55
|
+
export declare function resolveLoadingWaveOptions(defaults: LoadingWaveOptions, overrides?: Partial<LoadingWaveOptions>): ResolvedLoadingWaveOptions;
|
package/lib/loading-wave.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ResolvedLoadingWaveOptions } from './loading-wave-options';
|
|
2
2
|
import type { WaveRendererKind } from './renderer';
|
|
3
3
|
import type { WaveEnvironment } from './wave-environment';
|
|
4
4
|
/**
|
|
@@ -25,14 +25,14 @@ export declare class LoadingWave {
|
|
|
25
25
|
private loading;
|
|
26
26
|
private disconnects;
|
|
27
27
|
private hostStyle?;
|
|
28
|
-
constructor(host: HTMLElement, options:
|
|
28
|
+
constructor(host: HTMLElement, options: ResolvedLoadingWaveOptions, env: WaveEnvironment, onRendererChange?: (kind: WaveRendererKind | null) => void);
|
|
29
29
|
setLoading(loading: boolean): void;
|
|
30
30
|
/**
|
|
31
31
|
* applies new options: look, spacing and speed in place; a new renderer or
|
|
32
32
|
* `afterLoading` starts a running effect over, and resting dots stay where
|
|
33
33
|
* the new options keep them
|
|
34
34
|
*/
|
|
35
|
-
setOptions(options:
|
|
35
|
+
setOptions(options: ResolvedLoadingWaveOptions): void;
|
|
36
36
|
dispose(): void;
|
|
37
37
|
private mount;
|
|
38
38
|
private unmount;
|
package/lib/renderer.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ShaderUniforms } from './webgl/loading-wave-shader';
|
|
1
2
|
import type { WaveGeometry } from './wave-model';
|
|
2
3
|
export type WaveRendererKind = 'webgl' | 'canvas';
|
|
3
4
|
/** a colour channel by channel, each 0 to 255 */
|
|
@@ -15,6 +16,8 @@ export interface WaveLook {
|
|
|
15
16
|
/** diameter of a dot at rest, in CSS pixels */
|
|
16
17
|
readonly dotSize: number;
|
|
17
18
|
readonly color: Rgb;
|
|
19
|
+
/** the colour lit dots and the wave take; the dots' colour when unset */
|
|
20
|
+
readonly accent?: Rgb;
|
|
18
21
|
}
|
|
19
22
|
/** what one frame shows */
|
|
20
23
|
export interface WaveFrame {
|
|
@@ -42,6 +45,8 @@ export interface WaveRenderer {
|
|
|
42
45
|
draw(frame: WaveFrame): void;
|
|
43
46
|
/** changes the dots' look, say after the theme changed the host's colour */
|
|
44
47
|
setLook(look: WaveLook): void;
|
|
48
|
+
/** changes the values of a shader's own uniforms; only WebGL has any */
|
|
49
|
+
setShaderUniforms(uniforms: ShaderUniforms | undefined): void;
|
|
45
50
|
/** frees what the renderer holds; the canvas stays where it is */
|
|
46
51
|
dispose(): void;
|
|
47
52
|
}
|
package/lib/wave-model.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The loading wave as pure math, shared by the 2D canvas renderer and
|
|
3
|
-
* mirrored by the WebGL
|
|
3
|
+
* mirrored by the WebGL shaders' header (`webgl/shader-program.ts`).
|
|
4
4
|
*
|
|
5
|
-
* The wave front is an arc of a circle whose centre lies
|
|
6
|
-
* element, at mid-height: a ripple from off-screen.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* The wave front is an arc of a circle whose centre lies left of the
|
|
6
|
+
* element, at mid-height: a ripple from off-screen. How round it is
|
|
7
|
+
* (`frontRoundness`) sets the circle's radius. Its radius grows at an even
|
|
8
|
+
* speed, so the front sweeps from the left edge until the lit tail behind
|
|
9
|
+
* it has left the element at every row, then starts again.
|
|
9
10
|
* Every length is in CSS pixels, every time in milliseconds.
|
|
10
11
|
*/
|
|
12
|
+
/**
|
|
13
|
+
* How round the front is by default: its ends lag its middle by half of
|
|
14
|
+
* `min(height / 2, width)`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const DEFAULT_FRONT_ROUNDNESS = 0.5;
|
|
11
17
|
/** how lit a dot stays once the front passed it, as in the video */
|
|
12
18
|
export declare const AFTERGLOW = 0.45;
|
|
13
19
|
/** share of a sweep after which a passed dot's afterglow starts to fade */
|
|
@@ -42,6 +48,11 @@ export interface WaveGeometry {
|
|
|
42
48
|
export interface WaveGeometryOptions {
|
|
43
49
|
readonly dotSpacing: number;
|
|
44
50
|
readonly sweepMs: number;
|
|
51
|
+
/**
|
|
52
|
+
* 0 (a straight front) to 1: how far the front's ends lag its middle, as a
|
|
53
|
+
* share of `min(height / 2, width)`; `DEFAULT_FRONT_ROUNDNESS` when unset
|
|
54
|
+
*/
|
|
55
|
+
readonly frontRoundness?: number;
|
|
45
56
|
}
|
|
46
57
|
export interface Point {
|
|
47
58
|
readonly x: number;
|
|
@@ -51,7 +62,7 @@ export interface Displacement {
|
|
|
51
62
|
readonly dx: number;
|
|
52
63
|
readonly dy: number;
|
|
53
64
|
}
|
|
54
|
-
export declare function waveGeometry(width: number, height: number, { dotSpacing: askedSpacing, sweepMs }: WaveGeometryOptions): WaveGeometry;
|
|
65
|
+
export declare function waveGeometry(width: number, height: number, { dotSpacing: askedSpacing, sweepMs, frontRoundness, }: WaveGeometryOptions): WaveGeometry;
|
|
55
66
|
/** the share of the current sweep that has passed, 0 up to (not including) 1 */
|
|
56
67
|
export declare function sweepPhase(geometry: WaveGeometry, elapsedMs: number): number;
|
|
57
68
|
/** the front's radius at the time `elapsedMs` */
|
|
@@ -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
|
+
}
|