@wolsok/loading-wave 0.0.1 → 0.0.2

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 (40) hide show
  1. package/README.md +113 -12
  2. package/esm2022/index.js +1 -0
  3. package/esm2022/index.js.map +1 -1
  4. package/esm2022/lib/canvas-wave-renderer.js +34 -12
  5. package/esm2022/lib/canvas-wave-renderer.js.map +1 -1
  6. package/esm2022/lib/choose-wave-renderer.js +8 -3
  7. package/esm2022/lib/choose-wave-renderer.js.map +1 -1
  8. package/esm2022/lib/loading-wave-options.js +16 -2
  9. package/esm2022/lib/loading-wave-options.js.map +1 -1
  10. package/esm2022/lib/loading-wave.js +11 -3
  11. package/esm2022/lib/loading-wave.js.map +1 -1
  12. package/esm2022/lib/renderer.js.map +1 -1
  13. package/esm2022/lib/wave-model.js +33 -9
  14. package/esm2022/lib/wave-model.js.map +1 -1
  15. package/esm2022/lib/webgl/echo.js +5 -0
  16. package/esm2022/lib/webgl/echo.js.map +1 -0
  17. package/esm2022/lib/webgl/loading-wave-shader.js +1 -0
  18. package/esm2022/lib/webgl/loading-wave-shader.js.map +1 -0
  19. package/esm2022/lib/webgl/shader-program.js +227 -0
  20. package/esm2022/lib/webgl/shader-program.js.map +1 -0
  21. package/esm2022/lib/webgl/shaders/ripple.shader.js +110 -0
  22. package/esm2022/lib/webgl/shaders/ripple.shader.js.map +1 -0
  23. package/esm2022/lib/webgl/webgl-wave-renderer.js +102 -92
  24. package/esm2022/lib/webgl/webgl-wave-renderer.js.map +1 -1
  25. package/index.d.ts +3 -1
  26. package/lib/canvas-wave-renderer.d.ts +2 -0
  27. package/lib/choose-wave-renderer.d.ts +3 -0
  28. package/lib/loading-wave-options.d.ts +24 -4
  29. package/lib/loading-wave.d.ts +3 -3
  30. package/lib/renderer.d.ts +5 -0
  31. package/lib/wave-model.d.ts +17 -6
  32. package/lib/webgl/echo.d.ts +4 -0
  33. package/lib/webgl/loading-wave-shader.d.ts +20 -0
  34. package/lib/webgl/shader-program.d.ts +33 -0
  35. package/lib/webgl/shaders/ripple.shader.d.ts +10 -0
  36. package/lib/webgl/webgl-wave-renderer.d.ts +18 -7
  37. package/package.json +1 -1
  38. package/esm2022/lib/webgl/wave-shaders.js +0 -114
  39. package/esm2022/lib/webgl/wave-shaders.js.map +0 -1
  40. package/lib/webgl/wave-shaders.d.ts +0 -14
@@ -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;