matrix-rain-webgpu 1.0.0-beta.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/LICENSE +21 -0
- package/README.md +82 -0
- package/dist/gpu/atlas/bindings.d.ts +9 -0
- package/dist/gpu/atlas/build-sdf-atlas.d.ts +6 -0
- package/dist/gpu/atlas/glyph-set.d.ts +3 -0
- package/dist/gpu/feature-detect.d.ts +1 -0
- package/dist/gpu/material/hash.d.ts +3 -0
- package/dist/gpu/material/palette.d.ts +6 -0
- package/dist/gpu/pipelines/blit.d.ts +11 -0
- package/dist/gpu/pipelines/bloom.d.ts +19 -0
- package/dist/gpu/pipelines/compute-step.d.ts +6 -0
- package/dist/gpu/pipelines/crt.d.ts +4 -0
- package/dist/gpu/pipelines/render-glyphs.d.ts +5 -0
- package/dist/gpu/render-graph.d.ts +31 -0
- package/dist/gpu/schemas/column.d.ts +8 -0
- package/dist/gpu/schemas/uniforms.d.ts +14 -0
- package/dist/hooks/use-matrix-rain-renderer.d.ts +21 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3231 -0
- package/dist/matrix-rain.d.ts +7 -0
- package/dist/types.d.ts +95 -0
- package/package.json +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fabrizio Duroni
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# matrix-rain-webgpu
|
|
2
|
+
|
|
3
|
+
[](https://github.com/chicio/matrix-rain-webgpu/actions/workflows/deploy.yml)
|
|
4
|
+
|
|
5
|
+
> A Matrix-style "digital rain" background effect for React, rendered on the GPU with WebGPU via [TypeGPU](https://docs.swmansion.com/TypeGPU/). GPU-driven simulation, signed-distance-field glyphs, depth parallax, bloom, and a CRT post-process.
|
|
6
|
+
|
|
7
|
+
**▶ Live demo & full documentation: https://chicio.github.io/matrix-rain-webgpu/**
|
|
8
|
+
|
|
9
|
+
It powers the animated background on [fabrizioduroni.it](https://www.fabrizioduroni.it). Requires a WebGPU-capable browser (recent Chrome / Edge / Safari / Firefox).
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install matrix-rain-webgpu react react-dom typegpu @typegpu/react @typegpu/noise
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`react`/`react-dom` (v19) and `typegpu`/`@typegpu/react`/`@typegpu/noise` (v0.11) are
|
|
18
|
+
peer dependencies — they must resolve to a single instance in your app, so you install
|
|
19
|
+
them yourself. The shaders are pre-compiled at publish time, so you do **not** need any
|
|
20
|
+
TypeGPU build plugin.
|
|
21
|
+
|
|
22
|
+
> **Module resolution:** the published types target bundler-style resolution
|
|
23
|
+
> (`moduleResolution: "bundler"` / `"node"`), which is what Vite, Next.js, and most React
|
|
24
|
+
> setups use. Strict `"node16"`/`"nodenext"` resolution isn't supported yet.
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
The component renders a `<canvas>` that fills its positioned parent and ignores pointer events:
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { MatrixRainWebGPU } from 'matrix-rain-webgpu';
|
|
32
|
+
|
|
33
|
+
export function Background() {
|
|
34
|
+
return (
|
|
35
|
+
<div style={{ position: 'relative', width: '100%', height: '100dvh' }}>
|
|
36
|
+
<MatrixRainWebGPU />
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Everything is optional and grouped — omit for defaults, pass an object to tune, or `false` to disable an effect:
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
<MatrixRainWebGPU rain={{ fontSize: 24 }} bloom={{ intensity: 2 }} crt={false} />
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
WebGPU isn't available everywhere; gate on `isWebGPUSupported()` and render your own fallback when it's missing:
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { MatrixRainWebGPU, isWebGPUSupported } from 'matrix-rain-webgpu';
|
|
52
|
+
|
|
53
|
+
return isWebGPUSupported() ? <MatrixRainWebGPU /> : <My2DFallback />;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Documentation
|
|
57
|
+
|
|
58
|
+
Full docs live on the site — including the interactive playground:
|
|
59
|
+
|
|
60
|
+
- **[Getting started](https://chicio.github.io/matrix-rain-webgpu/overview/getting-started/)** & **[Public API](https://chicio.github.io/matrix-rain-webgpu/usage/public-api/)** — install, props, recipes.
|
|
61
|
+
- **[Architecture](https://chicio.github.io/matrix-rain-webgpu/architecture/pipeline-overview/)** — how the pieces connect.
|
|
62
|
+
- **[How it works](https://chicio.github.io/matrix-rain-webgpu/how-it-works/glyph-rendering/)** — per-component deep dives, with the computer-graphics concepts and the math.
|
|
63
|
+
- **[Playground](https://chicio.github.io/matrix-rain-webgpu/playground/)** — the live demo with every knob exposed.
|
|
64
|
+
|
|
65
|
+
## Local development
|
|
66
|
+
|
|
67
|
+
This repo is two packages: the publishable library at the root (`src/`) and the docs + demo site (`docs/`, an Astro + Starlight app).
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
# Library — typecheck + lint/format
|
|
71
|
+
npm install
|
|
72
|
+
npm run types
|
|
73
|
+
npm run check
|
|
74
|
+
|
|
75
|
+
# Docs + demo site (Astro)
|
|
76
|
+
npm --prefix docs install
|
|
77
|
+
npm --prefix docs run dev
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Author
|
|
81
|
+
|
|
82
|
+
Built by [Fabrizio Duroni](https://www.fabrizioduroni.it). If you enjoy it, a visit to the site is the best way to support the work. Also don't foget to star this repository :star:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isWebGPUSupported: () => boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { d, type TgpuRoot } from 'typegpu';
|
|
2
|
+
export declare const blitBindings: import("typegpu").TgpuBindGroupLayout<{
|
|
3
|
+
source: {
|
|
4
|
+
texture: d.WgslTexture2d<d.F32>;
|
|
5
|
+
};
|
|
6
|
+
sampler: {
|
|
7
|
+
sampler: "filtering";
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
10
|
+
export declare function createBlitPipeline(root: TgpuRoot): import("typegpu").TgpuRenderPipeline<d.Vec4f>;
|
|
11
|
+
export type BlitPipeline = ReturnType<typeof createBlitPipeline>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { d, type TgpuRoot, type TgpuUniform } from 'typegpu';
|
|
2
|
+
import { Uniforms } from '../schemas/uniforms';
|
|
3
|
+
export declare function createExtractPipeline(root: TgpuRoot, uniforms: TgpuUniform<typeof Uniforms>, format: GPUTextureFormat): import("typegpu").TgpuRenderPipeline<d.Vec4f>;
|
|
4
|
+
export type ExtractPipeline = ReturnType<typeof createExtractPipeline>;
|
|
5
|
+
export declare function createBlurPipeline(root: TgpuRoot, uniforms: TgpuUniform<typeof Uniforms>, format: GPUTextureFormat, direction: readonly [number, number]): import("typegpu").TgpuRenderPipeline<d.Vec4f>;
|
|
6
|
+
export type BlurPipeline = ReturnType<typeof createBlurPipeline>;
|
|
7
|
+
export declare const combineBindings: import("typegpu").TgpuBindGroupLayout<{
|
|
8
|
+
scene: {
|
|
9
|
+
texture: d.WgslTexture2d<d.F32>;
|
|
10
|
+
};
|
|
11
|
+
bloom: {
|
|
12
|
+
texture: d.WgslTexture2d<d.F32>;
|
|
13
|
+
};
|
|
14
|
+
sampler: {
|
|
15
|
+
sampler: "filtering";
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
export declare function createCombinePipeline(root: TgpuRoot, uniforms: TgpuUniform<typeof Uniforms>, format: GPUTextureFormat): import("typegpu").TgpuRenderPipeline<d.Vec4f>;
|
|
19
|
+
export type CombinePipeline = ReturnType<typeof createCombinePipeline>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { d, type TgpuMutable, type TgpuRoot, type TgpuUniform } from 'typegpu';
|
|
2
|
+
import { Column } from '../schemas/column';
|
|
3
|
+
import { Uniforms } from '../schemas/uniforms';
|
|
4
|
+
export declare const COMPUTE_STEP_WORKGROUP_SIZE = 64;
|
|
5
|
+
export declare function createComputeStepPipeline(root: TgpuRoot, columns: TgpuMutable<d.WgslArray<typeof Column>>, uniforms: TgpuUniform<typeof Uniforms>): import("typegpu").TgpuComputePipeline;
|
|
6
|
+
export type ComputeStepPipeline = ReturnType<typeof createComputeStepPipeline>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { d, type TgpuRoot, type TgpuUniform } from 'typegpu';
|
|
2
|
+
import { Uniforms } from '../schemas/uniforms';
|
|
3
|
+
export declare function createCrtPipeline(root: TgpuRoot, uniforms: TgpuUniform<typeof Uniforms>): import("typegpu").TgpuRenderPipeline<d.Vec4f>;
|
|
4
|
+
export type CrtPipeline = ReturnType<typeof createCrtPipeline>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { d, type TgpuMutable, type TgpuRoot, type TgpuUniform } from 'typegpu';
|
|
2
|
+
import { Column } from '../schemas/column';
|
|
3
|
+
import { Uniforms } from '../schemas/uniforms';
|
|
4
|
+
export declare function createRenderGlyphsPipeline(root: TgpuRoot, columns: TgpuMutable<d.WgslArray<typeof Column>>, uniforms: TgpuUniform<typeof Uniforms>, format: GPUTextureFormat): import("typegpu").TgpuRenderPipeline<d.Vec4f>;
|
|
5
|
+
export type RenderGlyphsPipeline = ReturnType<typeof createRenderGlyphsPipeline>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type TgpuRoot } from 'typegpu';
|
|
2
|
+
import type { SdfAtlas } from './atlas/build-sdf-atlas';
|
|
3
|
+
import type { BloomConfig, CrtConfig, ParallaxConfig } from '../types';
|
|
4
|
+
export type CreateRenderGraphArgs = {
|
|
5
|
+
root: TgpuRoot;
|
|
6
|
+
ctx: GPUCanvasContext;
|
|
7
|
+
atlas: SdfAtlas;
|
|
8
|
+
cellSize: number;
|
|
9
|
+
density: number;
|
|
10
|
+
stepRate: number;
|
|
11
|
+
tailRange: [number, number];
|
|
12
|
+
bloom: BloomConfig;
|
|
13
|
+
crt: CrtConfig;
|
|
14
|
+
parallax: ParallaxConfig;
|
|
15
|
+
};
|
|
16
|
+
export type RenderGraph = {
|
|
17
|
+
resize: (width: number, height: number) => void;
|
|
18
|
+
step: (deltaSeconds: number, elapsedSeconds: number) => void;
|
|
19
|
+
settle: () => void;
|
|
20
|
+
render: () => void;
|
|
21
|
+
setDensity: (density: number) => void;
|
|
22
|
+
setStepRate: (stepRate: number) => void;
|
|
23
|
+
setTailRange: (range: [number, number]) => void;
|
|
24
|
+
setBloom: (config: BloomConfig) => void;
|
|
25
|
+
setCrt: (config: CrtConfig) => void;
|
|
26
|
+
setParallax: (config: ParallaxConfig) => void;
|
|
27
|
+
regenerate: () => void;
|
|
28
|
+
getColumnCount: () => number;
|
|
29
|
+
dispose: () => void;
|
|
30
|
+
};
|
|
31
|
+
export declare function createRenderGraph(args: CreateRenderGraphArgs): RenderGraph;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { d } from 'typegpu';
|
|
2
|
+
export declare const Uniforms: d.WgslStruct<{
|
|
3
|
+
time: d.F32;
|
|
4
|
+
stepProgress: d.F32;
|
|
5
|
+
resolution: d.Vec2f;
|
|
6
|
+
cellSize: d.F32;
|
|
7
|
+
density: d.F32;
|
|
8
|
+
depthDim: d.F32;
|
|
9
|
+
bloomThreshold: d.F32;
|
|
10
|
+
bloomIntensity: d.F32;
|
|
11
|
+
headEmission: d.F32;
|
|
12
|
+
scanlineStrength: d.F32;
|
|
13
|
+
aberration: d.F32;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import type { BloomConfig, CrtConfig, ParallaxConfig } from '../types';
|
|
3
|
+
type UseMatrixRainRendererArgs = {
|
|
4
|
+
ctxRef: RefObject<GPUCanvasContext | null>;
|
|
5
|
+
cellSize: number;
|
|
6
|
+
density: number;
|
|
7
|
+
stepRate: number;
|
|
8
|
+
tailRange: [number, number];
|
|
9
|
+
bloom: BloomConfig;
|
|
10
|
+
crt: CrtConfig;
|
|
11
|
+
parallax: ParallaxConfig;
|
|
12
|
+
paused: boolean;
|
|
13
|
+
onError?: ((err: Error) => void) | undefined;
|
|
14
|
+
};
|
|
15
|
+
export type MatrixRainRenderer = {
|
|
16
|
+
tick: (deltaSeconds: number, elapsedSeconds: number) => void;
|
|
17
|
+
regenerate: () => void;
|
|
18
|
+
columnCount: number;
|
|
19
|
+
};
|
|
20
|
+
export declare function useMatrixRainRenderer(args: UseMatrixRainRendererArgs): MatrixRainRenderer;
|
|
21
|
+
export {};
|
package/dist/index.d.ts
ADDED