@brochington/shader-backgrounds 0.1.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/.github/workflows/deploy-demo-to-pages.yml +63 -0
- package/PLUGINS.md +269 -0
- package/README.md +159 -0
- package/demo.js +1044 -0
- package/index.html +194 -0
- package/package.json +23 -0
- package/src/index.ts +5 -0
- package/src/lib/components/web-component.ts +198 -0
- package/src/lib/core/ShaderCanvas.ts +235 -0
- package/src/lib/core/types.ts +26 -0
- package/src/lib/plugins/AuroraWavesPlugin.ts +128 -0
- package/src/lib/plugins/CausticsPlugin.ts +128 -0
- package/src/lib/plugins/ContourLinesPlugin.ts +148 -0
- package/src/lib/plugins/DreamyBokehPlugin.ts +191 -0
- package/src/lib/plugins/GradientPlugin.ts +445 -0
- package/src/lib/plugins/GrainyFogPlugin.ts +139 -0
- package/src/lib/plugins/InkWashPlugin.ts +182 -0
- package/src/lib/plugins/LiquidOrbPlugin.ts +140 -0
- package/src/lib/plugins/RetroGridPlugin.ts +77 -0
- package/src/lib/plugins/SoftStarfieldPlugin.ts +156 -0
- package/src/lib/plugins/StainedGlassPlugin.ts +261 -0
- package/src/lib/plugins/index.ts +11 -0
- package/tsconfig.json +26 -0
- package/vite.config.ts +19 -0
- package/vite.demo.config.ts +13 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
name: Deploy demo to GitHub Pages
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, master]
|
|
6
|
+
workflow_dispatch: {}
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
pages: write
|
|
11
|
+
id-token: write
|
|
12
|
+
|
|
13
|
+
concurrency:
|
|
14
|
+
group: pages
|
|
15
|
+
cancel-in-progress: true
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
build:
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
steps:
|
|
21
|
+
- name: Checkout
|
|
22
|
+
uses: actions/checkout@v4
|
|
23
|
+
|
|
24
|
+
- name: Setup Node
|
|
25
|
+
uses: actions/setup-node@v4
|
|
26
|
+
with:
|
|
27
|
+
node-version: 20
|
|
28
|
+
cache: npm
|
|
29
|
+
|
|
30
|
+
- name: Install
|
|
31
|
+
run: npm ci
|
|
32
|
+
|
|
33
|
+
- name: Build demo
|
|
34
|
+
run: |
|
|
35
|
+
# For project pages, assets must be rooted at `/<repo>/...`.
|
|
36
|
+
# For user/organization pages (`<owner>.github.io`), the base is `/`.
|
|
37
|
+
if [[ "${{ github.event.repository.name }}" == *.github.io ]]; then
|
|
38
|
+
export BASE_PATH="/"
|
|
39
|
+
else
|
|
40
|
+
export BASE_PATH="/${{ github.event.repository.name }}/"
|
|
41
|
+
fi
|
|
42
|
+
npm run build:demo
|
|
43
|
+
|
|
44
|
+
- name: Setup Pages
|
|
45
|
+
uses: actions/configure-pages@v5
|
|
46
|
+
|
|
47
|
+
- name: Upload artifact
|
|
48
|
+
uses: actions/upload-pages-artifact@v3
|
|
49
|
+
with:
|
|
50
|
+
path: dist-demo
|
|
51
|
+
|
|
52
|
+
deploy:
|
|
53
|
+
runs-on: ubuntu-latest
|
|
54
|
+
needs: build
|
|
55
|
+
environment:
|
|
56
|
+
name: github-pages
|
|
57
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
58
|
+
steps:
|
|
59
|
+
- name: Deploy to GitHub Pages
|
|
60
|
+
id: deployment
|
|
61
|
+
uses: actions/deploy-pages@v4
|
|
62
|
+
|
|
63
|
+
|
package/PLUGINS.md
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# Built-in Plugins
|
|
2
|
+
|
|
3
|
+
This document describes configuration options for all built-in plugins exported from `shader-backgrounds`.
|
|
4
|
+
|
|
5
|
+
General notes:
|
|
6
|
+
|
|
7
|
+
- Colors are CSS color strings parsed by OGL `Color` (commonly hex like `#rrggbb`).
|
|
8
|
+
- `speed` values generally scale animation time (higher = faster).
|
|
9
|
+
- `grainAmount` adds subtle noise to reduce color banding; keep it low for backgrounds.
|
|
10
|
+
|
|
11
|
+
## `GradientPlugin` (`name = "gradient-points"`)
|
|
12
|
+
|
|
13
|
+
Creates a smooth multi-point gradient using inverse-distance weighting. Supports animated color cycling and optional motion for each point.
|
|
14
|
+
|
|
15
|
+
Constructor:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
new GradientPlugin(points: GradientPoint[], options?: GradientPluginOptions)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### `GradientPoint`
|
|
22
|
+
|
|
23
|
+
- **`x: number`**: point X in range `[-1, 1]`.
|
|
24
|
+
- **`y: number`**: point Y in range `[-1, 1]`.
|
|
25
|
+
- **`colors: string[]`**: list of colors to cycle through (length 1 means static).
|
|
26
|
+
- **`speed?: number`**: color cycle speed multiplier. Default `1.0`.
|
|
27
|
+
- **`motion?: GradientMotion`**: optional motion configuration.
|
|
28
|
+
|
|
29
|
+
### `GradientPluginOptions`
|
|
30
|
+
|
|
31
|
+
- **`defaultMotion?: GradientMotion`**: defaults applied to points that omit `motion`.
|
|
32
|
+
|
|
33
|
+
### `GradientMotion`
|
|
34
|
+
|
|
35
|
+
- **`mode?: "none" | "path" | "random"`**: default `"none"`.
|
|
36
|
+
- **`path?: Array<{ x: number; y: number }>`**: waypoints for `"path"` mode.
|
|
37
|
+
- **`duration?: number`**: seconds to move from start to target. Default `3.0`.
|
|
38
|
+
- **`easing?: "linear" | "smoothstep" | "easeInOutQuad" | "easeInOutCubic"`**: default `"smoothstep"`.
|
|
39
|
+
- **`bounds?: Partial<{ minX: number; maxX: number; minY: number; maxY: number }>`**: clamp / random range; defaults to `[-1..1]` for both axes.
|
|
40
|
+
- **`randomRadius?: number`**: `"random"` mode only. If > 0, choose targets within this radius around the point’s base position.
|
|
41
|
+
|
|
42
|
+
Limits:
|
|
43
|
+
|
|
44
|
+
- Max points: **16** (extra points are truncated).
|
|
45
|
+
|
|
46
|
+
## `GrainyFogPlugin` (`name = "grainy-fog"`)
|
|
47
|
+
|
|
48
|
+
Animated fog-like noise with two primary colors blended over a background.
|
|
49
|
+
|
|
50
|
+
Constructor:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
new GrainyFogPlugin(config: GrainyFogConfig)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### `GrainyFogConfig`
|
|
57
|
+
|
|
58
|
+
- **`firstColor: string`**
|
|
59
|
+
- **`secondColor: string`**
|
|
60
|
+
- **`backgroundColor: string`**
|
|
61
|
+
- **`grainAmount?: number`**: default `0.12`.
|
|
62
|
+
- **`speed?: number`**: default `1.0`.
|
|
63
|
+
- **`scale?: number`**: noise scale. Default `2.25`.
|
|
64
|
+
- **`octaves?: number`**: `1..6`. Default `4`.
|
|
65
|
+
- **`lacunarity?: number`**: default `2.0`.
|
|
66
|
+
- **`gain?: number`**: default `0.5`.
|
|
67
|
+
- **`contrast?: number`**: default `1.25`.
|
|
68
|
+
|
|
69
|
+
## `RetroGridPlugin` (`name = "retro-grid"`)
|
|
70
|
+
|
|
71
|
+
Retro-futuristic perspective floor grid.
|
|
72
|
+
|
|
73
|
+
Constructor:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
new RetroGridPlugin(config: RetroGridConfig)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### `RetroGridConfig`
|
|
80
|
+
|
|
81
|
+
- **`gridColor: string`**
|
|
82
|
+
- **`backgroundColor: string`**
|
|
83
|
+
- **`speed?: number`**: default `1.0`.
|
|
84
|
+
|
|
85
|
+
## `LiquidOrbPlugin` (`name = "liquid-orb"`)
|
|
86
|
+
|
|
87
|
+
Metaball-like “goo” blobs simulated on the CPU and rendered as an SDF in the shader.
|
|
88
|
+
|
|
89
|
+
Constructor:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
new LiquidOrbPlugin(config: LiquidOrbConfig)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### `LiquidOrbConfig`
|
|
96
|
+
|
|
97
|
+
- **`color: string`**
|
|
98
|
+
- **`backgroundColor: string`**
|
|
99
|
+
- **`count?: number`**: number of blobs. Default `5`. Max `20`.
|
|
100
|
+
- **`speed?: number`**: motion speed multiplier. Default `0.5`.
|
|
101
|
+
- **`gooeyness?: number`**: smooth-min blending factor. Default `0.3`.
|
|
102
|
+
- **`edgeSoftness?: number`**: edge softness / AA amount. Default `0.02`.
|
|
103
|
+
|
|
104
|
+
## `CausticsPlugin` (`name = "caustics"`)
|
|
105
|
+
|
|
106
|
+
Stylized light-caustics pattern with controllable sharpness and distortion.
|
|
107
|
+
|
|
108
|
+
Constructor:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
new CausticsPlugin(config: CausticsConfig)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### `CausticsConfig`
|
|
115
|
+
|
|
116
|
+
- **`color: string`**: caustics light color.
|
|
117
|
+
- **`backgroundColor: string`**
|
|
118
|
+
- **`intensity?: number`**: brightness multiplier. Default `1.0`.
|
|
119
|
+
- **`speed?: number`**: default `0.5`.
|
|
120
|
+
- **`scale?: number`**: default `2.2`.
|
|
121
|
+
- **`distortion?: number`**: `0..2`. Default `0.9`.
|
|
122
|
+
- **`sharpness?: number`**: `0.5..6` typical. Default `3.2`.
|
|
123
|
+
- **`antiAlias?: number`**: `0..2`. Default `1.0` (higher = smoother).
|
|
124
|
+
|
|
125
|
+
## `AuroraWavesPlugin` (`name = "aurora-waves"`)
|
|
126
|
+
|
|
127
|
+
Soft aurora ribbons over a dark background.
|
|
128
|
+
|
|
129
|
+
Constructor:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
new AuroraWavesPlugin(config: AuroraWavesConfig)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### `AuroraWavesConfig`
|
|
136
|
+
|
|
137
|
+
- **`backgroundColor: string`**
|
|
138
|
+
- **`color1: string`**
|
|
139
|
+
- **`color2: string`**
|
|
140
|
+
- **`intensity?: number`**: default `0.9`.
|
|
141
|
+
- **`speed?: number`**: default `0.6`.
|
|
142
|
+
- **`scale?: number`**: default `1.6`.
|
|
143
|
+
- **`grainAmount?: number`**: default `0.05`.
|
|
144
|
+
|
|
145
|
+
## `SoftStarfieldPlugin` (`name = "soft-starfield"`)
|
|
146
|
+
|
|
147
|
+
Starfield with background gradient and a subtle nebula layer.
|
|
148
|
+
|
|
149
|
+
Constructor:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
new SoftStarfieldPlugin(config: SoftStarfieldConfig)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### `SoftStarfieldConfig`
|
|
156
|
+
|
|
157
|
+
- **`backgroundBottom: string`**
|
|
158
|
+
- **`backgroundTop: string`**
|
|
159
|
+
- **`starColor?: string`**: default `#ffffff`.
|
|
160
|
+
- **`density?: number`**: star density multiplier. Default `1.0`.
|
|
161
|
+
- **`size?: number`**: star size multiplier. Default `1.0`.
|
|
162
|
+
- **`twinkle?: number`**: default `0.35`.
|
|
163
|
+
- **`nebulaColor?: string`**: default `#6a5cff`.
|
|
164
|
+
- **`nebula?: number`**: nebula strength. Default `0.35`.
|
|
165
|
+
- **`speed?: number`**: default `0.2`.
|
|
166
|
+
- **`grainAmount?: number`**: default `0.04`.
|
|
167
|
+
|
|
168
|
+
## `ContourLinesPlugin` (`name = "contour-lines"`)
|
|
169
|
+
|
|
170
|
+
Topographic contour lines with controllable density, glow, and warp.
|
|
171
|
+
|
|
172
|
+
Constructor:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
new ContourLinesPlugin(config: ContourLinesConfig)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### `ContourLinesConfig`
|
|
179
|
+
|
|
180
|
+
- **`backgroundColor: string`**
|
|
181
|
+
- **`lineColor: string`**
|
|
182
|
+
- **`accentColor?: string`**: default is derived from `lineColor`.
|
|
183
|
+
- **`density?: number`**: default `12`.
|
|
184
|
+
- **`thickness?: number`**: default `0.075`.
|
|
185
|
+
- **`warp?: number`**: default `0.9`.
|
|
186
|
+
- **`speed?: number`**: default `0.35`.
|
|
187
|
+
- **`glow?: number`**: default `0.35`.
|
|
188
|
+
- **`grainAmount?: number`**: default `0.04`.
|
|
189
|
+
|
|
190
|
+
## `DreamyBokehPlugin` (`name = "dreamy-bokeh"`)
|
|
191
|
+
|
|
192
|
+
Soft bokeh highlights over a gradient. Designed to stay low-distraction as a background.
|
|
193
|
+
|
|
194
|
+
Constructor:
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
new DreamyBokehPlugin(config: DreamyBokehConfig)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### `DreamyBokehConfig`
|
|
201
|
+
|
|
202
|
+
- **`backgroundBottom: string`**
|
|
203
|
+
- **`backgroundTop: string`**
|
|
204
|
+
- **`colorA?: string`**: default `#ffd1f3`.
|
|
205
|
+
- **`colorB?: string`**: default `#8be9ff`.
|
|
206
|
+
- **`colorC?: string`**: default `#b7ff9b`.
|
|
207
|
+
- **`density?: number`**: `0..3`. Default `1.0`.
|
|
208
|
+
- **`size?: number`**: `0.5..2` typical. Default `1.0`.
|
|
209
|
+
- **`blur?: number`**: `0.5..2.5` typical. Default `1.0`.
|
|
210
|
+
- **`speed?: number`**: default `0.25`.
|
|
211
|
+
- **`vignette?: number`**: `0..1`. Default `0.35`.
|
|
212
|
+
- **`grainAmount?: number`**: default `0.03`.
|
|
213
|
+
|
|
214
|
+
## `InkWashPlugin` (`name = "ink-wash"`)
|
|
215
|
+
|
|
216
|
+
Animated ink diffusion on paper with optional granulation and vignette.
|
|
217
|
+
|
|
218
|
+
Constructor:
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
new InkWashPlugin(config: InkWashConfig)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### `InkWashConfig`
|
|
225
|
+
|
|
226
|
+
- **`paperColor: string`**
|
|
227
|
+
- **`inkColor: string`**
|
|
228
|
+
- **`scale?: number`**: default `1.4`.
|
|
229
|
+
- **`speed?: number`**: default `0.18`.
|
|
230
|
+
- **`flow?: number`**: default `0.85`.
|
|
231
|
+
- **`contrast?: number`**: default `1.15`.
|
|
232
|
+
- **`granulation?: number`**: default `0.35`.
|
|
233
|
+
- **`vignette?: number`**: `0..1`. Default `0.35`.
|
|
234
|
+
- **`grainAmount?: number`**: default `0.03`.
|
|
235
|
+
|
|
236
|
+
## `StainedGlassPlugin` (`name = "stained-glass"`)
|
|
237
|
+
|
|
238
|
+
Voronoi mosaic “stained glass” pattern with lead lines, edge glow, and layout variation controls.
|
|
239
|
+
|
|
240
|
+
Constructor:
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
new StainedGlassPlugin(config: StainedGlassConfig)
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### `StainedGlassConfig`
|
|
247
|
+
|
|
248
|
+
- **`backgroundColor: string`**
|
|
249
|
+
- **`leadColor?: string`**: default `#0b0b10`.
|
|
250
|
+
- **`colorA?: string`**: default `#38bdf8`.
|
|
251
|
+
- **`colorB?: string`**: default `#a78bfa`.
|
|
252
|
+
- **`colorC?: string`**: default `#fb7185`.
|
|
253
|
+
- **`colorD?: string`**: default `#fbbf24`.
|
|
254
|
+
- **`scale?: number`**: cell scale. Default `3.2`.
|
|
255
|
+
- **`variant?: 0 | 1 | 2`**: default `0`.
|
|
256
|
+
- `0`: classic
|
|
257
|
+
- `1`: crystal (anisotropic)
|
|
258
|
+
- `2`: radial-ish twist
|
|
259
|
+
- **`seed?: number`**: default `0` (change to get a new layout).
|
|
260
|
+
- **`jitter?: number`**: `0..1`. Default `1.0` (regular -> random).
|
|
261
|
+
- **`rotation?: number`**: radians. Default `0`.
|
|
262
|
+
- **`edgeWidth?: number`**: lead line thickness. Default `0.08`.
|
|
263
|
+
- **`edgeSharpness?: number`**: higher = crisper lines. Default `1.25`.
|
|
264
|
+
- **`edgeGlow?: number`**: default `0.45`.
|
|
265
|
+
- **`distortion?: number`**: default `0.55`.
|
|
266
|
+
- **`speed?: number`**: default `0.12`.
|
|
267
|
+
- **`grainAmount?: number`**: default `0.02`.
|
|
268
|
+
|
|
269
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# shader-backgrounds
|
|
2
|
+
|
|
3
|
+
Small shader-based background library built on [OGL](https://github.com/oframe/ogl). It provides:
|
|
4
|
+
|
|
5
|
+
- A lightweight plugin interface (`ShaderPlugin`)
|
|
6
|
+
- A canvas renderer (`ShaderCanvas`)
|
|
7
|
+
- A web component (`<shader-background>`) for easy page backgrounds
|
|
8
|
+
- A set of built-in background plugins
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @brochington/shader-backgrounds
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quick start (Web Component)
|
|
17
|
+
|
|
18
|
+
Import the package once to register the custom element, then assign a plugin instance.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import '@brochington/shader-backgrounds';
|
|
22
|
+
import { SoftStarfieldPlugin } from '@brochington/shader-backgrounds';
|
|
23
|
+
|
|
24
|
+
const el = document.querySelector('shader-background') as any;
|
|
25
|
+
el.plugin = new SoftStarfieldPlugin({
|
|
26
|
+
backgroundBottom: '#040512',
|
|
27
|
+
backgroundTop: '#0b1630',
|
|
28
|
+
starColor: '#ffffff',
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
HTML:
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
<shader-background style="position:fixed; inset:0; z-index:-1;"></shader-background>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Web component API
|
|
39
|
+
|
|
40
|
+
- **`plugin: ShaderPlugin`**: set the active plugin (recreates the renderer).
|
|
41
|
+
- **`renderScale: number`**: internal render resolution multiplier (0.1..2.0).
|
|
42
|
+
- **`singleRender: boolean`**: if true, render once (manual) instead of animating.
|
|
43
|
+
- **`render()`**: triggers a render when `singleRender === true`.
|
|
44
|
+
- **Attributes**
|
|
45
|
+
- **`render-scale="0.5"`**: same as `renderScale`.
|
|
46
|
+
- **`single-render`** or **`single-render="true"`**: same as `singleRender`.
|
|
47
|
+
|
|
48
|
+
Styling the internal canvas from outside the shadow root:
|
|
49
|
+
|
|
50
|
+
```css
|
|
51
|
+
shader-background::part(canvas) {
|
|
52
|
+
filter: blur(10px) saturate(1.15);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Quick start (ShaderCanvas)
|
|
57
|
+
|
|
58
|
+
Use this if you want to manage the `<canvas>` yourself.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { ShaderCanvas, CausticsPlugin } from '@brochington/shader-backgrounds';
|
|
62
|
+
|
|
63
|
+
const canvas = document.querySelector('canvas')!;
|
|
64
|
+
const plugin = new CausticsPlugin({
|
|
65
|
+
color: '#b9fff7',
|
|
66
|
+
backgroundColor: '#031028',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const engine = new ShaderCanvas(canvas, plugin, {
|
|
70
|
+
renderScale: 1.0, // internal buffer scale
|
|
71
|
+
pixelRatio: 1.0, // additional multiplier (clamped 0.1..4.0)
|
|
72
|
+
singleRender: false,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
engine.start();
|
|
76
|
+
// engine.resize() is available if you manage sizing yourself.
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Built-in plugins
|
|
80
|
+
|
|
81
|
+
See `PLUGINS.md` for full configuration details for each plugin.
|
|
82
|
+
|
|
83
|
+
Available exports:
|
|
84
|
+
|
|
85
|
+
- `GradientPlugin`
|
|
86
|
+
- `GrainyFogPlugin`
|
|
87
|
+
- `RetroGridPlugin`
|
|
88
|
+
- `LiquidOrbPlugin`
|
|
89
|
+
- `CausticsPlugin`
|
|
90
|
+
- `AuroraWavesPlugin`
|
|
91
|
+
- `SoftStarfieldPlugin`
|
|
92
|
+
- `ContourLinesPlugin`
|
|
93
|
+
- `DreamyBokehPlugin`
|
|
94
|
+
- `InkWashPlugin`
|
|
95
|
+
- `StainedGlassPlugin`
|
|
96
|
+
|
|
97
|
+
## Writing your own plugin
|
|
98
|
+
|
|
99
|
+
Implement the `ShaderPlugin` interface from `src/lib/core/types.ts`:
|
|
100
|
+
|
|
101
|
+
- **`name`**: unique identifier.
|
|
102
|
+
- **`fragmentShader`**: GLSL fragment shader string.
|
|
103
|
+
- **`uniforms`**: object of `{ value }` entries (OGL wraps these).
|
|
104
|
+
- Optional hooks: **`onInit(gl, program)`**, **`onRender(dtMs, totalTimeSeconds)`**, **`onResize(width, height)`**
|
|
105
|
+
|
|
106
|
+
The engine always provides these uniforms:
|
|
107
|
+
|
|
108
|
+
- **`uTime`**: elapsed time in seconds.
|
|
109
|
+
- **`uResolution`**: display resolution in CSS pixels (`vec2(width, height)`), suitable for aspect-correct math.
|
|
110
|
+
|
|
111
|
+
### Minimal example plugin
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import type { ShaderPlugin } from '@brochington/shader-backgrounds';
|
|
115
|
+
|
|
116
|
+
export class SolidColorPlugin implements ShaderPlugin {
|
|
117
|
+
name = 'solid-color';
|
|
118
|
+
|
|
119
|
+
fragmentShader = /* glsl */ `
|
|
120
|
+
precision highp float;
|
|
121
|
+
uniform vec3 uColor;
|
|
122
|
+
void main() {
|
|
123
|
+
gl_FragColor = vec4(uColor, 1.0);
|
|
124
|
+
}
|
|
125
|
+
`;
|
|
126
|
+
|
|
127
|
+
uniforms = {
|
|
128
|
+
uColor: { value: [0.10, 0.12, 0.18] },
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Notes and conventions
|
|
134
|
+
|
|
135
|
+
- **Time units**: `onRender` receives `dt` in milliseconds. `uTime` and `totalTime` are seconds.
|
|
136
|
+
- **Uniform arrays**: for GLSL `uniform vec3 uData[N]`, pass an array of triplets like `[[x,y,z], ...]` (not a packed `Float32Array`).
|
|
137
|
+
- **Aspect correction**: typical pattern is:
|
|
138
|
+
- `float aspect = uResolution.x / uResolution.y;`
|
|
139
|
+
- `vec2 p = (vUv - 0.5) * vec2(aspect, 1.0);`
|
|
140
|
+
- **Derivatives / antialiasing**: if you use `fwidth`, include:
|
|
141
|
+
- `#ifdef GL_OES_standard_derivatives` / `#extension GL_OES_standard_derivatives : enable`
|
|
142
|
+
|
|
143
|
+
## Repository development
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
npm install
|
|
147
|
+
npm run dev # run demo via Vite
|
|
148
|
+
npm run build # generate dist bundles + .d.ts
|
|
149
|
+
npm run preview # preview Vite build
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Demo (GitHub Pages)
|
|
153
|
+
|
|
154
|
+
This repo’s demo (`index.html` + `demo.js`) can be deployed to GitHub Pages via GitHub Actions.
|
|
155
|
+
|
|
156
|
+
- **Build the demo site**: `npm run build:demo` (outputs `dist-demo/`)
|
|
157
|
+
- **Workflow**: `.github/workflows/deploy-demo-to-pages.yml`
|
|
158
|
+
|
|
159
|
+
|