@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,33 @@
|
|
|
1
|
+
import type { LoadingWaveShader } from './loading-wave-shader';
|
|
2
|
+
/** the shaders did not compile or link on this GPU */
|
|
3
|
+
export declare class WaveShaderError extends Error {
|
|
4
|
+
readonly name = "WaveShaderError";
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The uniforms the lib sets for every shader. `ws_bufferSize` and `ws_dots`
|
|
8
|
+
* are for `main` only.
|
|
9
|
+
*/
|
|
10
|
+
export declare const STANDARD_UNIFORMS: readonly ["ws_size", "ws_bufferSize", "ws_pixel", "ws_spacing", "ws_dotSize", "ws_color", "ws_accent", "ws_center", "ws_frontRadius", "ws_echoRadius", "ws_travel", "ws_falloff", "ws_rise", "ws_tail", "ws_maxPush", "ws_phase", "ws_time", "ws_previousSweep", "ws_wave", "ws_dots"];
|
|
11
|
+
export type StandardUniform = (typeof STANDARD_UNIFORMS)[number];
|
|
12
|
+
/** one triangle that covers the whole canvas, no vertex buffer needed */
|
|
13
|
+
export declare 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";
|
|
14
|
+
/**
|
|
15
|
+
* What every fragment shader starts with: the uniforms and helpers of the
|
|
16
|
+
* contract (`LoadingWaveShader`). The `WS_*` constants mirror the
|
|
17
|
+
* TypeScript ones (`renderer.ts`, `wave-model.ts`, `echo.ts`);
|
|
18
|
+
* `shader-constants.spec.ts` keeps them equal. Kept a plain literal, so a
|
|
19
|
+
* bundler can tell it has no side effects.
|
|
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, 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
|
+
/**
|
|
23
|
+
* What every fragment shader ends with: maps the drawing buffer onto the
|
|
24
|
+
* host in CSS pixels (y down), calls `wsShade` and fades it by `ws_dots`.
|
|
25
|
+
*/
|
|
26
|
+
export declare 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";
|
|
27
|
+
/** the whole fragment shader for a `LoadingWaveShader` */
|
|
28
|
+
export declare function assembleFragment(shader: LoadingWaveShader): string;
|
|
29
|
+
/**
|
|
30
|
+
* The program of the full-canvas triangle and the shader's fragment.
|
|
31
|
+
* @throws WaveShaderError when it does not compile or link on this GPU
|
|
32
|
+
*/
|
|
33
|
+
export declare function linkWaveProgram(gl: WebGL2RenderingContext, shader: LoadingWaveShader): WebGLProgram;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LoadingWaveShader } from '../loading-wave-shader';
|
|
2
|
+
/**
|
|
3
|
+
* The default look on the GPU: the wave as a ripple running through water
|
|
4
|
+
* over the dot grid. The crests (front and echo) are a height field; the
|
|
5
|
+
* dots are seen through its slope (refraction), shaded as small beads lit
|
|
6
|
+
* from the crest ahead of them, and bloom in the accent colour; the water
|
|
7
|
+
* itself shows as a faint body with a glossy sheen on the crests' slopes.
|
|
8
|
+
* Drawn over the host's background, so it reads in light and dark themes.
|
|
9
|
+
*/
|
|
10
|
+
export declare const rippleShader: LoadingWaveShader;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { WaveFrame, WaveLook, WaveRenderer } from '../renderer';
|
|
2
2
|
import { WaveGeometry } from '../wave-model';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
3
|
+
import type { LoadingWaveShader, ShaderUniforms } from './loading-wave-shader';
|
|
4
|
+
import { WaveShaderError } from './shader-program';
|
|
5
|
+
export { WaveShaderError };
|
|
7
6
|
export interface WebGlWaveRendererHooks {
|
|
8
7
|
/** the browser took the GPU context away; the renderer draws no more */
|
|
9
8
|
readonly onContextLost: () => void;
|
|
@@ -11,8 +10,9 @@ export interface WebGlWaveRendererHooks {
|
|
|
11
10
|
readonly onDispose?: () => void;
|
|
12
11
|
}
|
|
13
12
|
/**
|
|
14
|
-
* Draws the wave with a WebGL2 fragment shader
|
|
15
|
-
*
|
|
13
|
+
* Draws the wave with a WebGL2 fragment shader (`LoadingWaveShader`) over a
|
|
14
|
+
* full-canvas triangle, setting the contract's `ws_*` uniforms and the
|
|
15
|
+
* shader's own each frame.
|
|
16
16
|
*/
|
|
17
17
|
export declare class WebGlWaveRenderer implements WaveRenderer {
|
|
18
18
|
readonly canvas: HTMLCanvasElement;
|
|
@@ -22,12 +22,16 @@ export declare class WebGlWaveRenderer implements WaveRenderer {
|
|
|
22
22
|
readonly kind = "webgl";
|
|
23
23
|
private readonly program;
|
|
24
24
|
private readonly uniforms;
|
|
25
|
+
private readonly ownLocations;
|
|
26
|
+
private ownUniforms;
|
|
27
|
+
/** uniforms `setShaderUniforms` left out, set to 0 on the next draw */
|
|
28
|
+
private pendingResets;
|
|
25
29
|
private geometry?;
|
|
26
30
|
private lost;
|
|
27
31
|
private disposed;
|
|
28
32
|
private readonly handleContextLost;
|
|
29
33
|
/** @throws WaveShaderError when the shaders fail on this GPU */
|
|
30
|
-
constructor(canvas: HTMLCanvasElement, gl: WebGL2RenderingContext, look: WaveLook, hooks: WebGlWaveRendererHooks);
|
|
34
|
+
constructor(canvas: HTMLCanvasElement, gl: WebGL2RenderingContext, look: WaveLook, shader: LoadingWaveShader, hooks: WebGlWaveRendererHooks);
|
|
31
35
|
/**
|
|
32
36
|
* A WebGL2 context, or `null` where the browser offers none. With
|
|
33
37
|
* `hardwareOnly` also `null` where it would render on the CPU (no GPU, a
|
|
@@ -37,8 +41,15 @@ export declare class WebGlWaveRenderer implements WaveRenderer {
|
|
|
37
41
|
resize(geometry: WaveGeometry, pixelRatio: number): void;
|
|
38
42
|
draw(frame: WaveFrame): void;
|
|
39
43
|
setLook(look: WaveLook): void;
|
|
44
|
+
/**
|
|
45
|
+
* a uniform the new values leave out goes back to 0, the value GLSL gives
|
|
46
|
+
* every uniform before it is set
|
|
47
|
+
*/
|
|
48
|
+
setShaderUniforms(uniforms: ShaderUniforms | undefined): void;
|
|
40
49
|
dispose(): void;
|
|
41
50
|
private setUniforms;
|
|
51
|
+
/** where the shader's own uniform lives, looked up once per name */
|
|
52
|
+
private ownLocation;
|
|
42
53
|
}
|
|
43
54
|
/**
|
|
44
55
|
* The echo's radius, trailing the front by `ECHO_LAG` of a sweep; negative,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wolsok/loading-wave",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
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';
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { FRONT_LINE_ALPHA, LIT_ALPHA, LIT_GROWTH, REST_ALPHA, } from '../renderer';
|
|
2
|
-
import { AFTERGLOW, AFTERGLOW_FADE_START } from '../wave-model';
|
|
3
|
-
/** strength of the echo ripple trailing the front, times the main front's */
|
|
4
|
-
export const ECHO_STRENGTH = 0.4;
|
|
5
|
-
/** the echo trails the front by this share of a sweep */
|
|
6
|
-
export const ECHO_LAG = 1 / 3;
|
|
7
|
-
/** opacity of the glow around a dot right behind the front */
|
|
8
|
-
const GLOW_ALPHA = 0.18;
|
|
9
|
-
/** width of the glow, in dot spacings */
|
|
10
|
-
const GLOW_SPACINGS = 0.18;
|
|
11
|
-
const glsl = (value) => value.toFixed(5);
|
|
12
|
-
/** one triangle that covers the whole canvas, no vertex buffer needed */
|
|
13
|
-
export const WAVE_VERTEX_SHADER = `#version 300 es
|
|
14
|
-
void main() {
|
|
15
|
-
vec2 corner = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
|
|
16
|
-
gl_Position = vec4(corner * 2.0 - 1.0, 0.0, 1.0);
|
|
17
|
-
}
|
|
18
|
-
`;
|
|
19
|
-
/**
|
|
20
|
-
* The wave model of `wave-model.ts` (front glow, afterglow, push) per pixel, for every dot of the 3 × 3
|
|
21
|
-
* cells around it: brightness, growth and push behind the front, plus what
|
|
22
|
-
* the 2D canvas cannot afford: a glow around lit dots and an echo ripple
|
|
23
|
-
* trailing the front. Lengths are in CSS pixels, y grows downwards as in CSS.
|
|
24
|
-
* A negative `u_echoRadius` shows no echo, as before the echo's first sweep.
|
|
25
|
-
*/
|
|
26
|
-
export const WAVE_FRAGMENT_SHADER = `#version 300 es
|
|
27
|
-
precision highp float;
|
|
28
|
-
|
|
29
|
-
uniform vec2 u_size;
|
|
30
|
-
uniform vec2 u_bufferSize;
|
|
31
|
-
uniform float u_spacing;
|
|
32
|
-
uniform float u_dotSize;
|
|
33
|
-
uniform vec3 u_color;
|
|
34
|
-
uniform vec2 u_center;
|
|
35
|
-
uniform float u_frontRadius;
|
|
36
|
-
uniform float u_echoRadius;
|
|
37
|
-
uniform float u_travel;
|
|
38
|
-
uniform float u_previousSweep;
|
|
39
|
-
uniform float u_falloff;
|
|
40
|
-
uniform float u_rise;
|
|
41
|
-
uniform float u_maxPush;
|
|
42
|
-
uniform float u_wave;
|
|
43
|
-
uniform float u_dots;
|
|
44
|
-
|
|
45
|
-
out vec4 outColor;
|
|
46
|
-
|
|
47
|
-
const float REST_ALPHA = ${glsl(REST_ALPHA)};
|
|
48
|
-
const float LIT_ALPHA = ${glsl(LIT_ALPHA)};
|
|
49
|
-
const float LIT_GROWTH = ${glsl(LIT_GROWTH)};
|
|
50
|
-
const float FRONT_LINE_ALPHA = ${glsl(FRONT_LINE_ALPHA)};
|
|
51
|
-
const float ECHO_STRENGTH = ${glsl(ECHO_STRENGTH)};
|
|
52
|
-
const float GLOW_ALPHA = ${glsl(GLOW_ALPHA)};
|
|
53
|
-
const float GLOW_SPACINGS = ${glsl(GLOW_SPACINGS)};
|
|
54
|
-
const float AFTERGLOW = ${glsl(AFTERGLOW)};
|
|
55
|
-
const float AFTERGLOW_FADE_START = ${glsl(AFTERGLOW_FADE_START)};
|
|
56
|
-
|
|
57
|
-
float frontGlow(float behind) {
|
|
58
|
-
return smoothstep(-u_rise, 0.0, behind) * exp(-max(behind, 0.0) / u_falloff);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
float afterglow(float behind) {
|
|
62
|
-
if (behind < 0.0 && u_previousSweep < 0.5) {
|
|
63
|
-
return 0.0;
|
|
64
|
-
}
|
|
65
|
-
float sincePassed = (behind >= 0.0 ? behind : behind + u_travel) / u_travel;
|
|
66
|
-
return AFTERGLOW * (1.0 - smoothstep(AFTERGLOW_FADE_START, 1.0, sincePassed));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
float pushAt(float behind) {
|
|
70
|
-
if (behind <= 0.0) {
|
|
71
|
-
return 0.0;
|
|
72
|
-
}
|
|
73
|
-
float scaled = behind / u_falloff;
|
|
74
|
-
return u_maxPush * scaled * exp(1.0 - scaled);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
void main() {
|
|
78
|
-
// the drawing buffer may be smaller than asked for: map it onto the host
|
|
79
|
-
vec2 cssPerPixel = u_size / u_bufferSize;
|
|
80
|
-
vec2 point = vec2(gl_FragCoord.x, u_bufferSize.y - gl_FragCoord.y) * cssPerPixel;
|
|
81
|
-
vec2 cell = floor(point / u_spacing);
|
|
82
|
-
float antialias = 0.5 * cssPerPixel.x;
|
|
83
|
-
float glowWidth = GLOW_SPACINGS * u_spacing;
|
|
84
|
-
float alpha = 0.0;
|
|
85
|
-
for (int row = -1; row <= 1; row++) {
|
|
86
|
-
for (int column = -1; column <= 1; column++) {
|
|
87
|
-
vec2 center = (cell + vec2(float(column), float(row)) + 0.5) * u_spacing;
|
|
88
|
-
if (center.x < 0.0 || center.y < 0.0 || center.x >= u_size.x || center.y >= u_size.y) {
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
vec2 fromWaveCenter = center - u_center;
|
|
92
|
-
float waveDistance = length(fromWaveCenter);
|
|
93
|
-
float behindFront = u_frontRadius - waveDistance;
|
|
94
|
-
float behindEcho = u_echoRadius - waveDistance;
|
|
95
|
-
float fronts = frontGlow(behindFront) + ECHO_STRENGTH * frontGlow(behindEcho);
|
|
96
|
-
float lit = u_wave * clamp(max(fronts, afterglow(behindFront)), 0.0, 1.0);
|
|
97
|
-
float push = u_wave * (pushAt(behindFront) + ECHO_STRENGTH * pushAt(behindEcho));
|
|
98
|
-
vec2 dotCenter = center + push * fromWaveCenter / waveDistance;
|
|
99
|
-
float radius = 0.5 * u_dotSize * (1.0 + LIT_GROWTH * lit);
|
|
100
|
-
float fromDot = length(point - dotCenter);
|
|
101
|
-
float core = 1.0 - smoothstep(radius - antialias, radius + antialias, fromDot);
|
|
102
|
-
// only the fronts glow, the afterglow stays calm
|
|
103
|
-
float glow = GLOW_ALPHA * u_wave * clamp(fronts, 0.0, 1.0)
|
|
104
|
-
* exp(-fromDot * fromDot / (2.0 * glowWidth * glowWidth));
|
|
105
|
-
alpha += core * (REST_ALPHA + (LIT_ALPHA - REST_ALPHA) * lit) + glow;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
float fromFront = abs(length(point - u_center) - u_frontRadius);
|
|
109
|
-
alpha += FRONT_LINE_ALPHA * u_wave * (1.0 - smoothstep(0.0, cssPerPixel.x, fromFront));
|
|
110
|
-
alpha = clamp(alpha, 0.0, 1.0) * u_dots;
|
|
111
|
-
outColor = vec4(u_color * alpha, alpha);
|
|
112
|
-
}
|
|
113
|
-
`;
|
|
114
|
-
//# sourceMappingURL=wave-shaders.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wave-shaders.js","sourceRoot":"","sources":["../../../../../../../libs/public/ws-loading-wave/src/lib/webgl/wave-shaders.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAEhE,6EAA6E;AAC7E,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AACjC,yDAAyD;AACzD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC;AAC9B,8DAA8D;AAC9D,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,yCAAyC;AACzC,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B,MAAM,IAAI,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAEzD,yEAAyE;AACzE,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;CAKjC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;2BAqBT,IAAI,CAAC,UAAU,CAAC;0BACjB,IAAI,CAAC,SAAS,CAAC;2BACd,IAAI,CAAC,UAAU,CAAC;iCACV,IAAI,CAAC,gBAAgB,CAAC;8BACzB,IAAI,CAAC,aAAa,CAAC;2BACtB,IAAI,CAAC,UAAU,CAAC;8BACb,IAAI,CAAC,aAAa,CAAC;0BACvB,IAAI,CAAC,SAAS,CAAC;qCACJ,IAAI,CAAC,oBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0D9D,CAAC","sourcesContent":["import {\n FRONT_LINE_ALPHA,\n LIT_ALPHA,\n LIT_GROWTH,\n REST_ALPHA,\n} from '../renderer';\nimport { AFTERGLOW, AFTERGLOW_FADE_START } from '../wave-model';\n\n/** strength of the echo ripple trailing the front, times the main front's */\nexport const ECHO_STRENGTH = 0.4;\n/** the echo trails the front by this share of a sweep */\nexport const ECHO_LAG = 1 / 3;\n/** opacity of the glow around a dot right behind the front */\nconst GLOW_ALPHA = 0.18;\n/** width of the glow, in dot spacings */\nconst GLOW_SPACINGS = 0.18;\n\nconst glsl = (value: number): string => value.toFixed(5);\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 * The wave model of `wave-model.ts` (front glow, afterglow, push) per pixel, for every dot of the 3 × 3\n * cells around it: brightness, growth and push behind the front, plus what\n * the 2D canvas cannot afford: a glow around lit dots and an echo ripple\n * trailing the front. Lengths are in CSS pixels, y grows downwards as in CSS.\n * A negative `u_echoRadius` shows no echo, as before the echo's first sweep.\n */\nexport const WAVE_FRAGMENT_SHADER = `#version 300 es\nprecision highp float;\n\nuniform vec2 u_size;\nuniform vec2 u_bufferSize;\nuniform float u_spacing;\nuniform float u_dotSize;\nuniform vec3 u_color;\nuniform vec2 u_center;\nuniform float u_frontRadius;\nuniform float u_echoRadius;\nuniform float u_travel;\nuniform float u_previousSweep;\nuniform float u_falloff;\nuniform float u_rise;\nuniform float u_maxPush;\nuniform float u_wave;\nuniform float u_dots;\n\nout vec4 outColor;\n\nconst float REST_ALPHA = ${glsl(REST_ALPHA)};\nconst float LIT_ALPHA = ${glsl(LIT_ALPHA)};\nconst float LIT_GROWTH = ${glsl(LIT_GROWTH)};\nconst float FRONT_LINE_ALPHA = ${glsl(FRONT_LINE_ALPHA)};\nconst float ECHO_STRENGTH = ${glsl(ECHO_STRENGTH)};\nconst float GLOW_ALPHA = ${glsl(GLOW_ALPHA)};\nconst float GLOW_SPACINGS = ${glsl(GLOW_SPACINGS)};\nconst float AFTERGLOW = ${glsl(AFTERGLOW)};\nconst float AFTERGLOW_FADE_START = ${glsl(AFTERGLOW_FADE_START)};\n\nfloat frontGlow(float behind) {\n return smoothstep(-u_rise, 0.0, behind) * exp(-max(behind, 0.0) / u_falloff);\n}\n\nfloat afterglow(float behind) {\n if (behind < 0.0 && u_previousSweep < 0.5) {\n return 0.0;\n }\n float sincePassed = (behind >= 0.0 ? behind : behind + u_travel) / u_travel;\n return AFTERGLOW * (1.0 - smoothstep(AFTERGLOW_FADE_START, 1.0, sincePassed));\n}\n\nfloat pushAt(float behind) {\n if (behind <= 0.0) {\n return 0.0;\n }\n float scaled = behind / u_falloff;\n return u_maxPush * scaled * exp(1.0 - scaled);\n}\n\nvoid main() {\n // the drawing buffer may be smaller than asked for: map it onto the host\n vec2 cssPerPixel = u_size / u_bufferSize;\n vec2 point = vec2(gl_FragCoord.x, u_bufferSize.y - gl_FragCoord.y) * cssPerPixel;\n vec2 cell = floor(point / u_spacing);\n float antialias = 0.5 * cssPerPixel.x;\n float glowWidth = GLOW_SPACINGS * u_spacing;\n float alpha = 0.0;\n for (int row = -1; row <= 1; row++) {\n for (int column = -1; column <= 1; column++) {\n vec2 center = (cell + vec2(float(column), float(row)) + 0.5) * u_spacing;\n if (center.x < 0.0 || center.y < 0.0 || center.x >= u_size.x || center.y >= u_size.y) {\n continue;\n }\n vec2 fromWaveCenter = center - u_center;\n float waveDistance = length(fromWaveCenter);\n float behindFront = u_frontRadius - waveDistance;\n float behindEcho = u_echoRadius - waveDistance;\n float fronts = frontGlow(behindFront) + ECHO_STRENGTH * frontGlow(behindEcho);\n float lit = u_wave * clamp(max(fronts, afterglow(behindFront)), 0.0, 1.0);\n float push = u_wave * (pushAt(behindFront) + ECHO_STRENGTH * pushAt(behindEcho));\n vec2 dotCenter = center + push * fromWaveCenter / waveDistance;\n float radius = 0.5 * u_dotSize * (1.0 + LIT_GROWTH * lit);\n float fromDot = length(point - dotCenter);\n float core = 1.0 - smoothstep(radius - antialias, radius + antialias, fromDot);\n // only the fronts glow, the afterglow stays calm\n float glow = GLOW_ALPHA * u_wave * clamp(fronts, 0.0, 1.0)\n * exp(-fromDot * fromDot / (2.0 * glowWidth * glowWidth));\n alpha += core * (REST_ALPHA + (LIT_ALPHA - REST_ALPHA) * lit) + glow;\n }\n }\n float fromFront = abs(length(point - u_center) - u_frontRadius);\n alpha += FRONT_LINE_ALPHA * u_wave * (1.0 - smoothstep(0.0, cssPerPixel.x, fromFront));\n alpha = clamp(alpha, 0.0, 1.0) * u_dots;\n outColor = vec4(u_color * alpha, alpha);\n}\n`;\n"]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/** strength of the echo ripple trailing the front, times the main front's */
|
|
2
|
-
export declare const ECHO_STRENGTH = 0.4;
|
|
3
|
-
/** the echo trails the front by this share of a sweep */
|
|
4
|
-
export declare const ECHO_LAG: number;
|
|
5
|
-
/** one triangle that covers the whole canvas, no vertex buffer needed */
|
|
6
|
-
export declare 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";
|
|
7
|
-
/**
|
|
8
|
-
* The wave model of `wave-model.ts` (front glow, afterglow, push) per pixel, for every dot of the 3 × 3
|
|
9
|
-
* cells around it: brightness, growth and push behind the front, plus what
|
|
10
|
-
* the 2D canvas cannot afford: a glow around lit dots and an echo ripple
|
|
11
|
-
* trailing the front. Lengths are in CSS pixels, y grows downwards as in CSS.
|
|
12
|
-
* A negative `u_echoRadius` shows no echo, as before the echo's first sweep.
|
|
13
|
-
*/
|
|
14
|
-
export declare const WAVE_FRAGMENT_SHADER: string;
|