instantshader 0.6.1 → 0.8.0
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 +42 -18
- package/dist/index.d.ts +28 -1
- package/dist/index.js +1360 -184
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
# instantshader
|
|
4
4
|
|
|
5
|
-
Animated WebGL gradient shaders with zero dependencies. Mount a live
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Animated WebGL gradient shaders with zero dependencies. Mount a live gradient
|
|
6
|
+
into any element, draw dither, pixelate, halftone, ASCII or tint effects over
|
|
7
|
+
it or over your own image, or render single frames for export. Built by
|
|
8
|
+
[InstantGradient](https://instantgradient.com/app).
|
|
9
9
|
|
|
10
10
|
## Install
|
|
11
11
|
|
|
@@ -33,13 +33,17 @@ tree-shake away.
|
|
|
33
33
|
|
|
34
34
|
| Shader | Look | Params |
|
|
35
35
|
| --- | --- | --- |
|
|
36
|
-
| `flow` |
|
|
37
|
-
| `beam` | One wide beam of soft light
|
|
38
|
-
| `bloom` | A fan of huge
|
|
39
|
-
| `halo` | An eclipse:
|
|
40
|
-
| `strata` | Stacked cut-paper sheets, one per palette step, each casting a soft shadow on the one below. `ridges` and `stretch`
|
|
41
|
-
| `dune` | Overlapping crests rolling across the frame
|
|
42
|
-
| `whorl` | A
|
|
36
|
+
| `flow` | Swirling fluid currents. Colour masses travel in soft eddies with bright edges and calm open space between them. | `scale`, `curl`, `drift`, `openness`, `grain` |
|
|
37
|
+
| `beam` | One wide beam of soft light across a near-black frame. The palette runs along the beam, with thin brighter filaments inside it. | `scale`, `width`, `glow`, `angle`, `grain` |
|
|
38
|
+
| `bloom` | A fan of huge soft petals rising from the bottom edge. The palette forms scalloped bands from a hot core out to a dark background, with thin creases between the petals. | `scale`, `petals`, `pinch`, `bend`, `sway`, `colorflow`, `grain` |
|
|
39
|
+
| `halo` | An eclipse: a dark disc with a bright rim and a corona of streamers, the palette wrapped around the ring. `x` / `y` place the disc; the default sinks it below the frame for a glowing horizon. | `radius`, `x`, `y`, `glow`, `crescent`, `flares`, `grain` |
|
|
40
|
+
| `strata` | Stacked cut-paper sheets, one per palette step, each casting a soft shadow on the one below. `ridges` and `stretch` turn round islands into spines or long bands. | `scale`, `layers`, `warp`, `ridges`, `stretch`, `depth`, `blend`, `angle`, `grain` |
|
|
41
|
+
| `dune` | Overlapping crests rolling across the frame. Each has a crisp top edge and fades out below it. | `layers`, `swell`, `waves`, `fade`, `soft`, `angle`, `grain` |
|
|
42
|
+
| `whorl` | A spiral of curved blades, each with a sharp leading edge and a soft fade behind it. `x` / `y` place the centre anywhere, including off-frame. | `blades`, `twist`, `depth`, `scale`, `wobble`, `x`, `y`, `grain` |
|
|
43
|
+
| `silk` | Satin folds lit from one side, with a sheen that streaks along the threads. | `scale`, `folds`, `depth`, `warp`, `sheen`, `light`, `grain` |
|
|
44
|
+
| `nacre` | Glassy liquid folds whose colour shifts to the neighbouring palette colours on every slope, like mother of pearl. | `scale`, `flow`, `crease`, `depth`, `iridescence`, `light`, `grain` |
|
|
45
|
+
| `burst` | Thin grainy rays out of one point, from a dark tunnel to a white-hot star, straight or twisted into a pinwheel. | `rays`, `sharp`, `glow`, `twist`, `x`, `y`, `grain` |
|
|
46
|
+
| `glint` | Small spinning shards streaming along a curved current on dark, each edge fringed with colour. | `size`, `density`, `bend`, `angle`, `speed`, `grain` |
|
|
43
47
|
|
|
44
48
|
Previews of every look, with full param ranges, are in the
|
|
45
49
|
[repository README](https://github.com/ugolbck/instantshader#readme).
|
|
@@ -66,8 +70,17 @@ the whole registry (importing either pulls every shader).
|
|
|
66
70
|
## Effects
|
|
67
71
|
|
|
68
72
|
An effect redraws a picture: a shader's output, or an image, canvas or video
|
|
69
|
-
frame you supply.
|
|
70
|
-
`ascii`.
|
|
73
|
+
frame you supply. Five are included: `pixelate`, `dither`, `halftone`,
|
|
74
|
+
`ascii` and `tint`.
|
|
75
|
+
|
|
76
|
+
- Halftone and ASCII draw shapes or characters over the picture. `ground`
|
|
77
|
+
picks what is under them: the picture, or a flat `paper` colour.
|
|
78
|
+
- `blend` (`normal`, `multiply`, `screen`, `overlay`, `softLight`,
|
|
79
|
+
`colorDodge`) and `opacity` set how an effect mixes with what is below.
|
|
80
|
+
Pixelate and dither at `blend: "normal"` and `opacity: 1` replace the
|
|
81
|
+
picture.
|
|
82
|
+
- Tint recolours whatever is below it by brightness, in two colours or along
|
|
83
|
+
the palette.
|
|
71
84
|
|
|
72
85
|
```ts
|
|
73
86
|
import { mountStack, bloom, dither } from "instantshader";
|
|
@@ -75,14 +88,23 @@ import { mountStack, bloom, dither } from "instantshader";
|
|
|
75
88
|
mountStack(el, {
|
|
76
89
|
source: { kind: "generator", shader: bloom },
|
|
77
90
|
colors: ["#140f30", "#9c2168", "#eb6a4e", "#fcd87c"],
|
|
78
|
-
effects: [{ effect: dither, params: { pattern: "blueNoise", colorMode: "palette", levels: 4 } }],
|
|
91
|
+
effects: [{ effect: dither, params: { pattern: "blueNoise", colorMode: "palette", levels: 4, blend: "normal", opacity: 1 } }],
|
|
79
92
|
loopSeconds: 30,
|
|
80
93
|
});
|
|
81
94
|
```
|
|
82
95
|
|
|
83
96
|
For an image, the source is `{ kind: "media", media: img }` with an optional
|
|
84
97
|
`fit` of `"cover"` (default) or `"contain"`. `effects` is a list, bottom
|
|
85
|
-
layer first
|
|
98
|
+
layer first, and each effect works on everything below it:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
effects: [
|
|
102
|
+
{ effect: halftone, params: { shape: "dot", size: 16 } },
|
|
103
|
+
{ effect: tint, params: { mode: "palette", amount: 0.6 } },
|
|
104
|
+
],
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
A layer with `enabled: false` is skipped. `mountStack` returns the `mountGradient` handle plus
|
|
86
108
|
`setSource`, `setSourceParams`, `setEffects`, `setEffectParams(index, params)`,
|
|
87
109
|
`refreshMedia()` and `getGridInfo()`. `renderStackFrame` renders one frame to
|
|
88
110
|
a detached canvas and `createStackRenderer` is the seekable renderer for
|
|
@@ -140,7 +162,7 @@ Notes:
|
|
|
140
162
|
translating in a straight line through a noise field that tiles, and it
|
|
141
163
|
covers exactly one tile per cycle, so a short loop flows fast and a long
|
|
142
164
|
one flows slowly. The hand-tuned drift rate corresponds to a period around
|
|
143
|
-
60
|
|
165
|
+
60 to 90s; below ~30s the currents move noticeably faster than the look was
|
|
144
166
|
designed for. Compensate with `speed` rather than by shortening the loop.
|
|
145
167
|
- **`beam` freezes its width swell below ~29s.** Its natural cycle is ~57s and
|
|
146
168
|
cannot be squeezed into a short loop without becoming a throb, so under that
|
|
@@ -151,7 +173,9 @@ Notes:
|
|
|
151
173
|
shorter than about half its own period, so below ~10s the wander is the only
|
|
152
174
|
thing left moving. `colorflow` is unaffected. It always fits at least one
|
|
153
175
|
full cycle into the loop, flowing faster on a short one.
|
|
154
|
-
- `halo`, `dune` and `whorl` always complete at least one full cycle of
|
|
155
|
-
main motion per loop, so a short loop simply runs them faster.
|
|
176
|
+
- `halo`, `dune` and `whorl` always complete at least one full cycle of
|
|
177
|
+
their main motion per loop, so a short loop simply runs them faster.
|
|
178
|
+
`burst` never turns; its rays stream outward one tile per loop. `glint`
|
|
179
|
+
travels one pattern period per loop, half a period under 12 s.
|
|
156
180
|
- Any loop necessarily revisits the same state every N seconds; a long period
|
|
157
181
|
is what buys the impression of never repeating.
|
package/dist/index.d.ts
CHANGED
|
@@ -251,6 +251,18 @@ type EffectDef = {
|
|
|
251
251
|
lattice?: (params: Record<string, ParamValue>) => {
|
|
252
252
|
angle: number;
|
|
253
253
|
};
|
|
254
|
+
/**
|
|
255
|
+
* The draw stage also reads the layer below at frame size, as
|
|
256
|
+
* `uniform sampler2D u_picture`, for effects that draw over the picture
|
|
257
|
+
* rather than replacing it (halftone's image ground). Shape sizes and
|
|
258
|
+
* colours still come from the cell buffer; only the backdrop is per
|
|
259
|
+
* pixel. A function returns a blur in reference px applied to that
|
|
260
|
+
* picture (0 = none), or null when this configuration does not read the
|
|
261
|
+
* picture, so the stack skips rendering it.
|
|
262
|
+
*/
|
|
263
|
+
picture?: true | ((params: Record<string, ParamValue>) => {
|
|
264
|
+
blur: number;
|
|
265
|
+
} | null);
|
|
254
266
|
fragment: string;
|
|
255
267
|
};
|
|
256
268
|
textures?: EffectTexture[];
|
|
@@ -340,6 +352,18 @@ declare const dune: ShaderDef;
|
|
|
340
352
|
//#region src/shaders/whorl.d.ts
|
|
341
353
|
declare const whorl: ShaderDef;
|
|
342
354
|
//#endregion
|
|
355
|
+
//#region src/shaders/silk.d.ts
|
|
356
|
+
declare const silk: ShaderDef;
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/shaders/nacre.d.ts
|
|
359
|
+
declare const nacre: ShaderDef;
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/shaders/burst.d.ts
|
|
362
|
+
declare const burst: ShaderDef;
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region src/shaders/glint.d.ts
|
|
365
|
+
declare const glint: ShaderDef;
|
|
366
|
+
//#endregion
|
|
343
367
|
//#region src/effects/pixelate.d.ts
|
|
344
368
|
declare const pixelate: EffectDef;
|
|
345
369
|
//#endregion
|
|
@@ -352,6 +376,9 @@ declare const halftone: EffectDef;
|
|
|
352
376
|
//#region src/effects/ascii.d.ts
|
|
353
377
|
declare const ascii: EffectDef;
|
|
354
378
|
//#endregion
|
|
379
|
+
//#region src/effects/tint.d.ts
|
|
380
|
+
declare const tint: EffectDef;
|
|
381
|
+
//#endregion
|
|
355
382
|
//#region src/registry.d.ts
|
|
356
383
|
declare const shaders: readonly ShaderDef[];
|
|
357
384
|
declare function getShader(id: string): ShaderDef | undefined;
|
|
@@ -473,4 +500,4 @@ declare function gridFor(width: number, height: number, cell: [number, number],
|
|
|
473
500
|
*/
|
|
474
501
|
declare function buildPaletteRamp(colors: string[]): Uint8Array;
|
|
475
502
|
//#endregion
|
|
476
|
-
export { type BoolParamDef, type ColorParamDef, type EffectDef, type EffectLayer, type EffectParamDef, type EffectTexture, type EnumParamDef, type FloatParamDef, type GeneratorDef, type Grid, type GridInfo, type MountHandle, type MountOptions, type ParamDef, type ParamValue, type RenderFrameResult, type Renderer, type RendererOptions, type ShaderDef, type Source, type StackHandle, type StackMountOptions, type StackOptions, type StackRenderer, type TextureData, type TextureEnv, ascii, beam, bloom, buildPaletteRamp, createRenderer, createStackRenderer, dither, dune, effects, flow, getEffect, getShader, gridFor, halftone, halo, mountGradient, mountStack, pixelate, renderGradientFrame, renderStackFrame, shaders, strata, whorl };
|
|
503
|
+
export { type BoolParamDef, type ColorParamDef, type EffectDef, type EffectLayer, type EffectParamDef, type EffectTexture, type EnumParamDef, type FloatParamDef, type GeneratorDef, type Grid, type GridInfo, type MountHandle, type MountOptions, type ParamDef, type ParamValue, type RenderFrameResult, type Renderer, type RendererOptions, type ShaderDef, type Source, type StackHandle, type StackMountOptions, type StackOptions, type StackRenderer, type TextureData, type TextureEnv, ascii, beam, bloom, buildPaletteRamp, burst, createRenderer, createStackRenderer, dither, dune, effects, flow, getEffect, getShader, glint, gridFor, halftone, halo, mountGradient, mountStack, nacre, pixelate, renderGradientFrame, renderStackFrame, shaders, silk, strata, tint, whorl };
|