@docyrus/animaguru 0.6.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/NOTICE.md +256 -0
- package/README.md +241 -0
- package/dist/animaguru.js +27338 -0
- package/package.json +37 -0
- package/skills/animaguru/SKILL.md +115 -0
- package/skills/animaguru-advertising/SKILL.md +25 -0
- package/skills/animaguru-advertising/references/brand-bumper.md +11 -0
- package/skills/animaguru-advertising/references/comparison.md +11 -0
- package/skills/animaguru-advertising/references/creator-testimonial.md +11 -0
- package/skills/animaguru-advertising/references/editorial-advertorial.md +11 -0
- package/skills/animaguru-advertising/references/game-reward.md +11 -0
- package/skills/animaguru-advertising/references/offer-promotion.md +11 -0
- package/skills/animaguru-advertising/references/product-launch.md +11 -0
- package/skills/animaguru-advertising/references/product-proof.md +11 -0
- package/skills/animaguru-analog-film-tape/SKILL.md +29 -0
- package/skills/animaguru-analog-film-tape/references/recipe.md +23 -0
- package/skills/animaguru-animated-data-visualization/SKILL.md +39 -0
- package/skills/animaguru-animated-data-visualization/references/data-contract.md +16 -0
- package/skills/animaguru-animated-data-visualization/references/variants.md +17 -0
- package/skills/animaguru-art-deco-motion/SKILL.md +29 -0
- package/skills/animaguru-art-deco-motion/references/recipe.md +22 -0
- package/skills/animaguru-ascii-crt/SKILL.md +29 -0
- package/skills/animaguru-ascii-crt/references/recipe.md +22 -0
- package/skills/animaguru-blueprint-drafting/SKILL.md +29 -0
- package/skills/animaguru-blueprint-drafting/references/recipe.md +22 -0
- package/skills/animaguru-cartoon-character-animation/SKILL.md +35 -0
- package/skills/animaguru-cartoon-character-animation/references/variants.md +17 -0
- package/skills/animaguru-cutout-animation/SKILL.md +33 -0
- package/skills/animaguru-cutout-animation/references/production-recipe.md +37 -0
- package/skills/animaguru-cutout-animation/references/variants.md +17 -0
- package/skills/animaguru-cutout-animation/references/visual-style.md +34 -0
- package/skills/animaguru-dark-tech-stage/SKILL.md +29 -0
- package/skills/animaguru-dark-tech-stage/references/recipe.md +23 -0
- package/skills/animaguru-diagram-formula-motion/SKILL.md +36 -0
- package/skills/animaguru-diagram-formula-motion/references/variants.md +17 -0
- package/skills/animaguru-engraved-relief-print/SKILL.md +29 -0
- package/skills/animaguru-engraved-relief-print/references/recipe.md +24 -0
- package/skills/animaguru-flat-vector-motion/SKILL.md +35 -0
- package/skills/animaguru-flat-vector-motion/references/variants.md +17 -0
- package/skills/animaguru-general-video/SKILL.md +20 -0
- package/skills/animaguru-general-video/references/ambient-loop.md +11 -0
- package/skills/animaguru-general-video/references/music-lyrics.md +11 -0
- package/skills/animaguru-general-video/references/short-film.md +11 -0
- package/skills/animaguru-general-video/references/titles-event.md +11 -0
- package/skills/animaguru-general-video/references/visual-essay.md +11 -0
- package/skills/animaguru-generative-light-signal/SKILL.md +29 -0
- package/skills/animaguru-generative-light-signal/references/recipe.md +23 -0
- package/skills/animaguru-glass-mosaic/SKILL.md +29 -0
- package/skills/animaguru-glass-mosaic/references/recipe.md +23 -0
- package/skills/animaguru-halftone-editorial/SKILL.md +29 -0
- package/skills/animaguru-halftone-editorial/references/recipe.md +23 -0
- package/skills/animaguru-holographic-scan/SKILL.md +29 -0
- package/skills/animaguru-holographic-scan/references/recipe.md +22 -0
- package/skills/animaguru-interface-motion/SKILL.md +36 -0
- package/skills/animaguru-interface-motion/references/screen-mapping.md +16 -0
- package/skills/animaguru-interface-motion/references/variants.md +17 -0
- package/skills/animaguru-isometric-worlds/SKILL.md +35 -0
- package/skills/animaguru-isometric-worlds/references/variants.md +17 -0
- package/skills/animaguru-kinetic-typography/SKILL.md +35 -0
- package/skills/animaguru-kinetic-typography/references/variants.md +17 -0
- package/skills/animaguru-miniature-diorama/SKILL.md +29 -0
- package/skills/animaguru-miniature-diorama/references/recipe.md +23 -0
- package/skills/animaguru-painterly-depth-animation/SKILL.md +35 -0
- package/skills/animaguru-painterly-depth-animation/references/variants.md +17 -0
- package/skills/animaguru-paper-popup/SKILL.md +29 -0
- package/skills/animaguru-paper-popup/references/recipe.md +22 -0
- package/skills/animaguru-photo-footage-editorial/SKILL.md +29 -0
- package/skills/animaguru-photo-footage-editorial/references/recipe.md +23 -0
- package/skills/animaguru-pixel-art-animation/SKILL.md +36 -0
- package/skills/animaguru-pixel-art-animation/references/variants.md +17 -0
- package/skills/animaguru-portal-zoom/SKILL.md +29 -0
- package/skills/animaguru-portal-zoom/references/recipe.md +21 -0
- package/skills/animaguru-risograph-print/SKILL.md +29 -0
- package/skills/animaguru-risograph-print/references/recipe.md +23 -0
- package/skills/animaguru-sand-drawing/SKILL.md +29 -0
- package/skills/animaguru-sand-drawing/references/recipe.md +21 -0
- package/skills/animaguru-shadow-theatre/SKILL.md +29 -0
- package/skills/animaguru-shadow-theatre/references/recipe.md +23 -0
- package/skills/animaguru-silkscreen-poster/SKILL.md +29 -0
- package/skills/animaguru-silkscreen-poster/references/recipe.md +22 -0
- package/skills/animaguru-stop-motion-objects/SKILL.md +29 -0
- package/skills/animaguru-stop-motion-objects/references/recipe.md +23 -0
- package/skills/animaguru-studio-product-reveal/SKILL.md +29 -0
- package/skills/animaguru-studio-product-reveal/references/recipe.md +23 -0
- package/skills/animaguru-video/SKILL.md +79 -0
- package/skills/animaguru-whiteboard-line-drawing/SKILL.md +34 -0
- package/skills/animaguru-whiteboard-line-drawing/references/variants.md +17 -0
- package/templates/video/AGENTS.md +34 -0
- package/templates/video/CLAUDE.md +19 -0
- package/templates/video/README.md +101 -0
- package/templates/video/VIDEO-STYLE-NOTICES.txt +54 -0
- package/templates/video/film.config.json +10 -0
- package/templates/video/gitignore +11 -0
- package/templates/video/index.html +14 -0
- package/templates/video/package.json +28 -0
- package/templates/video/public/brand/logo-mark.svg +5 -0
- package/templates/video/scripts/build.mjs +12 -0
- package/templates/video/scripts/export-html.mjs +12 -0
- package/templates/video/scripts/export-mp4.mjs +209 -0
- package/templates/video/scripts/html-export-plugin.mjs +35 -0
- package/templates/video/scripts/html-export.mjs +54 -0
- package/templates/video/scripts/install-example.mjs +32 -0
- package/templates/video/scripts/review-analysis.mjs +29 -0
- package/templates/video/scripts/review-audio.mjs +24 -0
- package/templates/video/scripts/review.mjs +37 -0
- package/templates/video/scripts/starter-film.sha256 +1 -0
- package/templates/video/shared/locales/en/export.json +10 -0
- package/templates/video/shared/locales/en/film.json +42 -0
- package/templates/video/shared/locales/en/player.json +31 -0
- package/templates/video/shared/locales/en/style-studies.json +168 -0
- package/templates/video/shared/locales/en/timeline.json +33 -0
- package/templates/video/src/assets.ts +4 -0
- package/templates/video/src/download.ts +27 -0
- package/templates/video/src/exporter.ts +70 -0
- package/templates/video/src/film-resources.ts +29 -0
- package/templates/video/src/film.ts +132 -0
- package/templates/video/src/main.ts +219 -0
- package/templates/video/src/resource-timeline.ts +193 -0
- package/templates/video/src/review.ts +50 -0
- package/templates/video/src/studies/film.ts +26 -0
- package/templates/video/src/studies/media.ts +46 -0
- package/templates/video/src/studies/model.ts +60 -0
- package/templates/video/src/studies/pixi-renderer.ts +121 -0
- package/templates/video/src/studies/scenes.ts +410 -0
- package/templates/video/src/studies/timing.ts +53 -0
- package/templates/video/src/studies/variants.ts +39 -0
- package/templates/video/src/style.css +111 -0
- package/templates/video/src/timeline-model.ts +55 -0
- package/templates/video/style-source-provenance.json +11 -0
- package/templates/video/tsconfig.json +15 -0
- package/templates/video/vite.config.mjs +9 -0
- package/vendor/pixijs-skills/LICENSE +21 -0
- package/vendor/pixijs-skills/provenance.json +79 -0
- package/vendor/pixijs-skills/skills/pixijs/SKILL.md +66 -0
- package/vendor/pixijs-skills/skills/pixijs/references/index.md +136 -0
- package/vendor/pixijs-skills/skills/pixijs-accessibility/SKILL.md +224 -0
- package/vendor/pixijs-skills/skills/pixijs-application/SKILL.md +293 -0
- package/vendor/pixijs-skills/skills/pixijs-application/references/application-options.md +314 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/SKILL.md +303 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/background.md +137 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/bundles.md +122 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/caching.md +143 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/compressed-textures.md +120 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/fonts.md +205 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/gif.md +171 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/manifests.md +175 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/progress.md +142 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/resolution.md +142 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/spritesheet.md +119 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/svg.md +132 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/video.md +158 -0
- package/vendor/pixijs-skills/skills/pixijs-blend-modes/SKILL.md +215 -0
- package/vendor/pixijs-skills/skills/pixijs-color/SKILL.md +299 -0
- package/vendor/pixijs-skills/skills/pixijs-core-concepts/SKILL.md +132 -0
- package/vendor/pixijs-skills/skills/pixijs-core-concepts/references/render-loop.md +216 -0
- package/vendor/pixijs-skills/skills/pixijs-core-concepts/references/renderers.md +287 -0
- package/vendor/pixijs-skills/skills/pixijs-create/SKILL.md +276 -0
- package/vendor/pixijs-skills/skills/pixijs-custom-rendering/SKILL.md +405 -0
- package/vendor/pixijs-skills/skills/pixijs-custom-rendering/references/advanced-gpu.md +244 -0
- package/vendor/pixijs-skills/skills/pixijs-custom-rendering/references/uniform-types.md +94 -0
- package/vendor/pixijs-skills/skills/pixijs-environments/SKILL.md +243 -0
- package/vendor/pixijs-skills/skills/pixijs-events/SKILL.md +387 -0
- package/vendor/pixijs-skills/skills/pixijs-filters/SKILL.md +300 -0
- package/vendor/pixijs-skills/skills/pixijs-html-source/SKILL.md +228 -0
- package/vendor/pixijs-skills/skills/pixijs-math/SKILL.md +489 -0
- package/vendor/pixijs-skills/skills/pixijs-migration-v8/SKILL.md +415 -0
- package/vendor/pixijs-skills/skills/pixijs-performance/SKILL.md +489 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-container/SKILL.md +345 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/SKILL.md +243 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/constructor-options.md +155 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/container-hierarchy.md +232 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/layers.md +145 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/masking.md +129 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/render-groups.md +140 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/scene-management.md +169 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/transforms.md +198 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-dom-container/SKILL.md +193 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-gif/SKILL.md +233 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-graphics/SKILL.md +576 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/SKILL.md +141 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-perspective.md +189 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-plane.md +159 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-rope.md +176 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-simple.md +144 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh.md +213 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-particle-container/SKILL.md +323 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/SKILL.md +120 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/animated-sprite.md +262 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/nineslice-sprite.md +202 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/sprite.md +181 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/tiling-sprite.md +216 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/SKILL.md +136 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/bitmap-text.md +232 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/html-text.md +192 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/split-bitmap-text.md +187 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/split-text.md +168 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/text.md +311 -0
- package/vendor/pixijs-skills/skills/pixijs-ticker/SKILL.md +292 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pixijs-create
|
|
3
|
+
description: "Use this skill when scaffolding a new PixiJS v8 project with the create-pixi CLI or adding PixiJS to an existing project. Covers npm/yarn/pnpm/bun create commands, interactive vs non-interactive flows, bundler vs creation template categories, available template presets (bundler-vite, bundler-webpack, bundler-esbuild, bundler-import-map, creation-web, framework-react, extension-default), Node version requirements, `npm install pixi.js` for existing projects, TypeScript 5/6/7 tsconfig setup (moduleResolution, @webgpu/types, @types/web), post-scaffold dev flow, and the Vite top-level-await production-build gotcha. Triggers on: create pixi.js, npm create, npm install pixi.js, scaffold, template, bundler-vite, bundler-webpack, creation-web, framework-react, new project, existing project, getting started, quick start, TypeScript, tsconfig, moduleResolution, @webgpu/types, @types/web, Cannot find name GPUTextureUsage."
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
`create pixi.js` is the official CLI for scaffolding a new PixiJS v8 project. Run it with any package manager (`npm`, `yarn`, `pnpm`, `bun`) and pick a template from the interactive menu, or pass `--template` to skip prompts. It writes a self-contained project folder; you then `cd` in, install dependencies, and run the dev script.
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
Scaffold a new project with interactive prompts:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm create pixi.js@latest
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or skip prompts by passing a project name and template:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm create pixi.js@latest my-game -- --template bundler-vite
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Then:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
cd my-game
|
|
27
|
+
npm install
|
|
28
|
+
npm run dev
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Requires Node.js 18+ or 20+. Some templates (notably `creation-web` and `framework-react`) may require a newer Node version; the package manager will warn if so.
|
|
32
|
+
|
|
33
|
+
### Adding PixiJS to an existing project
|
|
34
|
+
|
|
35
|
+
If you already have a bundler, framework, or project set up, skip the CLI and install the package directly:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install pixi.js
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then import from `pixi.js` and construct an `Application` as shown in `pixijs-application`. The CLI templates are a convenience for new projects; they don't add anything to the library that `npm install pixi.js` can't give you.
|
|
42
|
+
|
|
43
|
+
**Related skills:** `pixijs-application` (how the scaffolded `new Application()` + `app.init()` entry point works), `pixijs-core-concepts` (renderers and the render loop), `pixijs-scene-core-concepts` (scene graph fundamentals for the first things you'll add to the stage), `pixijs-assets` (loading textures, fonts, and bundles the template expects you to drop into `public/` or `src/assets/`).
|
|
44
|
+
|
|
45
|
+
## Core Patterns
|
|
46
|
+
|
|
47
|
+
### Choose a package manager
|
|
48
|
+
|
|
49
|
+
The command is the same shape for every package manager:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm create pixi.js@latest
|
|
53
|
+
yarn create pixi.js
|
|
54
|
+
pnpm create pixi.js
|
|
55
|
+
bun create pixi.js
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Under npm 7+ you must pass a `--` before CLI flags so npm doesn't consume them:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npm create pixi.js@latest my-game -- --template bundler-vite
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Yarn, pnpm, and bun don't need the extra separator:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
yarn create pixi.js my-game --template bundler-vite
|
|
68
|
+
pnpm create pixi.js my-game --template bundler-vite
|
|
69
|
+
bun create pixi.js my-game --template bundler-vite
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Use `.` as the project name to scaffold into the current directory.
|
|
73
|
+
|
|
74
|
+
### Interactive flow
|
|
75
|
+
|
|
76
|
+
Running with no arguments walks through prompts:
|
|
77
|
+
|
|
78
|
+
1. Project name (defaults to `pixi-project`).
|
|
79
|
+
2. Framework / template category.
|
|
80
|
+
3. Variant (TypeScript vs JavaScript where applicable).
|
|
81
|
+
4. Whether to install dependencies immediately (some runners).
|
|
82
|
+
|
|
83
|
+
At the end, the CLI prints the `cd` + install + dev commands for the manager you invoked it with.
|
|
84
|
+
|
|
85
|
+
### Non-interactive flow
|
|
86
|
+
|
|
87
|
+
Pass a project name and `--template` to skip all prompts. This is the form you want for scripts, CI, and quickstart docs:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npm create pixi.js@latest my-game -- --template bundler-vite
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Available template presets
|
|
94
|
+
|
|
95
|
+
Templates fall into two categories:
|
|
96
|
+
|
|
97
|
+
- **Bundler templates** (`bundler-*`): generic PixiJS setup wired up with your bundler of choice. Use one of these when you want to pick your own structure.
|
|
98
|
+
- **Creation templates** (`creation-*`): platform-tailored starters with extras already wired in (AssetPack, sound, UI, scene routing). Use one of these when you want batteries included.
|
|
99
|
+
- **Framework templates** (`framework-*`): PixiJS embedded inside a host framework like React.
|
|
100
|
+
- **Extension templates** (`extension-*`): scaffolding for building a reusable PixiJS package.
|
|
101
|
+
|
|
102
|
+
For most new projects, `bundler-vite` is the recommended starting point.
|
|
103
|
+
|
|
104
|
+
| Template | What you get |
|
|
105
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------------ |
|
|
106
|
+
| `bundler-vite` | Vite + TypeScript PixiJS project. The default first-stop template. |
|
|
107
|
+
| `bundler-vite-js` | Vite + plain JavaScript. |
|
|
108
|
+
| `bundler-webpack` | Webpack + TypeScript. |
|
|
109
|
+
| `bundler-webpack-js` | Webpack + plain JavaScript. |
|
|
110
|
+
| `bundler-esbuild` | esbuild + TypeScript. |
|
|
111
|
+
| `bundler-esbuild-js` | esbuild + plain JavaScript. |
|
|
112
|
+
| `bundler-import-map` | No-bundler setup using a browser import map (good for learning / demos). |
|
|
113
|
+
| `creation-web` | PixiJS Creation Engine web template with scene-based game scaffolding, AssetPack, sound, and UI integration. |
|
|
114
|
+
| `framework-react` | React + TypeScript + PixiJS via the `@pixi/react` package. |
|
|
115
|
+
| `framework-react-js` | React + plain JavaScript + PixiJS. |
|
|
116
|
+
| `extension-default` | Starter for building a reusable PixiJS extension/package. |
|
|
117
|
+
|
|
118
|
+
The live list is maintained in the `create-pixi` repo; run `npm create pixi.js@latest` without arguments to see the current menu if you need to confirm.
|
|
119
|
+
|
|
120
|
+
### Post-scaffold flow
|
|
121
|
+
|
|
122
|
+
Every template ships with the same three-step onboarding:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
cd my-game
|
|
126
|
+
npm install
|
|
127
|
+
npm run dev
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`npm run dev` starts the local dev server on the default port (Vite 5173, webpack 8080, etc.; the template's README has the exact number). Changes to `src/` hot-reload without reloading the whole page.
|
|
131
|
+
|
|
132
|
+
Other scripts every template exposes (names may vary slightly by preset):
|
|
133
|
+
|
|
134
|
+
- `npm run build`: produce a production build in `dist/`.
|
|
135
|
+
- `npm run preview` / `npm run serve`: serve the production build locally.
|
|
136
|
+
- `npm run lint`: run the template's configured linter if it ships one.
|
|
137
|
+
|
|
138
|
+
### Scaffolding into an existing directory
|
|
139
|
+
|
|
140
|
+
Use `.` as the project name to write into the current working directory. The CLI refuses to run if non-empty and conflicting files exist unless you confirm the prompt.
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
mkdir my-game
|
|
144
|
+
cd my-game
|
|
145
|
+
npm create pixi.js@latest . -- --template bundler-vite
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### TypeScript setup
|
|
149
|
+
|
|
150
|
+
PixiJS supports WebGPU, so its type declarations depend on the WebGPU types. Where those come from depends on your TypeScript version.
|
|
151
|
+
|
|
152
|
+
- **TypeScript 5:** no WebGPU types are built in, so PixiJS adds `@webgpu/types` for you. No additional setup required.
|
|
153
|
+
- **TypeScript 6 and 7:** the WebGPU types are built into the `"dom"` library, but some releases leave parts out, such as `GPUTextureUsage`. Use `@types/web`, which has the full set, in place of `"dom"`. Remove `@webgpu/types` from `types` if it's there, since it conflicts with the built-in types.
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npm install --save-dev @types/web
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
```json
|
|
160
|
+
{
|
|
161
|
+
"compilerOptions": {
|
|
162
|
+
"lib": ["esnext"],
|
|
163
|
+
"types": ["@types/web"]
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Next steps
|
|
169
|
+
|
|
170
|
+
After `npm run dev` starts, the template opens on a blank or bunny-sprite scene. The usual progression is:
|
|
171
|
+
|
|
172
|
+
1. Read `pixijs-application` to understand how the template's entry point constructs `new Application()` and calls `await app.init(...)`, how `app.stage` / `app.renderer` / `app.canvas` hang together, and how the ResizePlugin and TickerPlugin behave by default.
|
|
173
|
+
2. Read `pixijs-core-concepts` for the renderer and render-loop mental model.
|
|
174
|
+
3. Read `pixijs-scene-core-concepts` before adding your first non-trivial scene so you know the container-vs-leaf rule upfront.
|
|
175
|
+
4. Drop in textures via `pixijs-assets` once you're ready to load real art.
|
|
176
|
+
|
|
177
|
+
## Common Mistakes
|
|
178
|
+
|
|
179
|
+
### [HIGH] Missing `--` separator on npm 7+
|
|
180
|
+
|
|
181
|
+
Wrong:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
npm create pixi.js@latest my-game --template bundler-vite
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Correct:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
npm create pixi.js@latest my-game -- --template bundler-vite
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
npm 7+ consumes flags after the package spec unless you pass `--` to forward them. Without the separator, the CLI ignores `--template` and drops back to the interactive prompt. Yarn, pnpm, and bun don't need the separator.
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
### [MEDIUM] Running with an old Node version
|
|
197
|
+
|
|
198
|
+
PixiJS requires Node 18+ or 20+. Some templates (framework-react, creation-web) expect a newer Node for their tooling. Upgrade Node before re-running the CLI if you see an "engines" warning from your package manager.
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
### [MEDIUM] Top-level `await app.init()` broken in Vite production builds
|
|
202
|
+
|
|
203
|
+
On Vite versions `<=6.0.6`, top-level `await` works in dev but breaks in production builds, so a `bundler-vite` project that does this at module scope will fail after `npm run build`:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
const app = new Application();
|
|
207
|
+
await app.init({ resizeTo: window }); // broken at module top level in prod
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Wrap the init in an async IIFE instead:
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
(async () => {
|
|
214
|
+
const app = new Application();
|
|
215
|
+
await app.init({ resizeTo: window });
|
|
216
|
+
document.body.appendChild(app.canvas);
|
|
217
|
+
})();
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Upgrading Vite past 6.0.6 also resolves it, but the IIFE pattern is safe on every version and matches the PixiJS quick-start guide.
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
### [HIGH] Keeping `@webgpu/types` in `types` on TypeScript 6 or 7
|
|
224
|
+
|
|
225
|
+
Wrong:
|
|
226
|
+
|
|
227
|
+
```json
|
|
228
|
+
{
|
|
229
|
+
"compilerOptions": {
|
|
230
|
+
"types": ["@webgpu/types"]
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Correct: remove the `"@webgpu/types"` entry and keep any others.
|
|
236
|
+
|
|
237
|
+
TypeScript 6 and 7 declare the WebGPU types in their built-in `"dom"` library, so `@webgpu/types` declares them a second time. With `skipLibCheck: false` that produces dozens of conflicting-declaration errors inside `lib.dom.d.ts` and `@webgpu/types`. Keep it on TypeScript 5 only, where PixiJS loads it for you anyway.
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
### [MEDIUM] `Cannot find name 'GPUTextureUsage'` on TypeScript 6 or 7
|
|
241
|
+
|
|
242
|
+
Up to TypeScript 6.0.3 and 7.0.2, the built-in `"dom"` library has no WebGPU flag constants (`GPUBufferUsage`, `GPUColorWrite`, `GPUMapMode`, `GPUShaderStage`, `GPUTextureUsage`), so raw WebGPU code that uses them fails with `TS2552`. Adding `@webgpu/types` back only compiles with `skipLibCheck: true`, because it conflicts with the built-in types. Install `@types/web` 0.0.352 or later, drop `"dom"` from `lib`, and add `"@types/web"` to `types` alongside any existing entries, as shown in [TypeScript setup](#typescript-setup).
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
### [MEDIUM] `moduleResolution: "node"` breaks subpath imports
|
|
246
|
+
|
|
247
|
+
Wrong:
|
|
248
|
+
|
|
249
|
+
```json
|
|
250
|
+
{
|
|
251
|
+
"compilerOptions": {
|
|
252
|
+
"moduleResolution": "node"
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Correct:
|
|
258
|
+
|
|
259
|
+
```json
|
|
260
|
+
{
|
|
261
|
+
"compilerOptions": {
|
|
262
|
+
"module": "esnext",
|
|
263
|
+
"moduleResolution": "bundler"
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
`"node"` (also called `"node10"`) ignores the `exports` field in the PixiJS `package.json`, so `import 'pixi.js/advanced-blend-modes'` and other subpath imports don't resolve. TypeScript 6 reports `TS2882` for them and deprecates the setting (`TS5107`); TypeScript 7 removes it (`TS5108`). Use `"bundler"` if you use a bundler, or `"nodenext"` otherwise.
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
## API Reference
|
|
272
|
+
|
|
273
|
+
- [create-pixi on GitHub](https://github.com/pixijs/create-pixi)
|
|
274
|
+
- [create-pixi documentation site](https://pixijs.io/create-pixi/)
|
|
275
|
+
- [Application](https://pixijs.download/release/docs/app.Application.html.md): the class the generated entry point instantiates.
|
|
276
|
+
- [TypeScript guide](https://pixijs.download/release/docs/core-concepts-8.html.md): setup for TypeScript 5, 6, and 7.
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pixijs-custom-rendering
|
|
3
|
+
description: "Use this skill when writing custom shaders, uniforms, filters, batchers, or low-level draw code in PixiJS v8. Covers Shader.from({gl, gpu, resources}), GlProgram/GpuProgram, UniformGroup with typed uniforms (f32, vec2, mat4x4), UBO mode, textures as resources, TextureView for depth sampling, 3D and array textures (depth, arrayLayerCount, sampler3D, texture_3d), WebGPU storage textures (storage: true), WGSL override constants, custom bind group layouts (gpuLayout), partial buffer updates (Buffer.update), Geometry.vertexCount/indexCount, TexturePool scratch textures, State winding and culling (clockwiseFrontFace, cullMode), WebGPU render bundles, custom Filter via Filter.from, GLSL ES 3.0 conventions (finalColor), uBackTexture sampling, pixi.js/unsafe-eval for strict CSP, custom Batcher and InstructionPipe.destroyInstructionSet via extensions. Triggers on: Shader, GLSL, WGSL, uniform, custom shader, blendRequired, ShaderOverrides, bind group layout, depth texture, 3D texture, sampler3D, texture_3d, storage texture, getSize, indexCount, TexturePool, getOptimalTexture, destroyInstructionSet, beginBundle, executeBundle, RenderBundle."
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Custom shaders bind GLSL and WGSL programs to scene objects via `Shader.from({ gl, gpu, resources })`. Uniforms live in typed `UniformGroup`s, textures are passed as separate resources, and the same shader can target both WebGL and WebGPU.
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const uniforms = new UniformGroup({
|
|
13
|
+
uTime: { value: 0, type: "f32" },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const shader = Shader.from({
|
|
17
|
+
gl: { vertex: vertexSrc, fragment: fragmentSrc },
|
|
18
|
+
resources: { uniforms },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const geometry = new MeshGeometry({
|
|
22
|
+
positions: new Float32Array([0, 0, 100, 0, 100, 100, 0, 100]),
|
|
23
|
+
uvs: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
|
|
24
|
+
indices: new Uint32Array([0, 1, 2, 0, 2, 3]),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const mesh = new Mesh({ geometry, shader });
|
|
28
|
+
app.stage.addChild(mesh);
|
|
29
|
+
|
|
30
|
+
app.ticker.add(() => {
|
|
31
|
+
shader.resources.uniforms.uniforms.uTime = performance.now() / 1000;
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Related skills:** `pixijs-filters` (built-in filters), `pixijs-scene-mesh` (custom geometry), `pixijs-performance` (batch optimization), `pixijs-migration-v8` (shader API migration from v7).
|
|
36
|
+
|
|
37
|
+
## Core Patterns
|
|
38
|
+
|
|
39
|
+
### Dual-renderer shader (WebGL + WebGPU)
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { Shader, GlProgram, GpuProgram, UniformGroup } from "pixi.js";
|
|
43
|
+
|
|
44
|
+
const glVertex = `...`; // GLSL vertex (write `#version 300 es` yourself if you want WebGL2/GLSL ES 3.0)
|
|
45
|
+
const glFragment = `...`; // GLSL fragment
|
|
46
|
+
const wgslSource = `...`; // WGSL combined
|
|
47
|
+
|
|
48
|
+
const shader = Shader.from({
|
|
49
|
+
gl: { vertex: glVertex, fragment: glFragment },
|
|
50
|
+
gpu: {
|
|
51
|
+
// entryPoint names are arbitrary; they must match the @vertex / @fragment
|
|
52
|
+
// function names in your WGSL source. PixiJS ships examples using
|
|
53
|
+
// 'mainVert' / 'mainFrag' but `main` is equally valid.
|
|
54
|
+
vertex: { entryPoint: "mainVert", source: wgslSource },
|
|
55
|
+
fragment: { entryPoint: "mainFrag", source: wgslSource },
|
|
56
|
+
},
|
|
57
|
+
resources: {
|
|
58
|
+
myUniforms: new UniformGroup({
|
|
59
|
+
uColor: { value: new Float32Array([1, 0, 0, 1]), type: "vec4<f32>" },
|
|
60
|
+
uMatrix: { value: new Float32Array(16), type: "mat4x4<f32>" },
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
If only `gl` is provided, the shader works with WebGL only. If only `gpu` is provided, it works with WebGPU only. The `compatibleRenderers` bitmask is set automatically.
|
|
67
|
+
|
|
68
|
+
`GlProgram` does **not** auto-inject `#version 300 es`. If you write `#version 300 es` yourself, PixiJS preserves it and treats the shader as GLSL ES 3.0; otherwise it injects WebGL1 compat macros (`#define in varying`, `#define texture texture2D`) and runs the shader as WebGL1-style GLSL. `GlProgram` always injects a default precision (`highp` vertex, `mediump` fragment) and the program name. It also declares `highp` for sampler types GLSL ES 3.0 gives no default (`usampler2D`, `isampler2D`, `sampler2DArray`, `sampler3D`, and others), so you don't need a precision line for them; one you write yourself is kept. `sampler2D` and `samplerCube` keep their `lowp` default. For GLSL ES 3.0, use `in`/`out` instead of `attribute`/`varying`, `texture()` instead of `texture2D()`, and an `out vec4` instead of `gl_FragColor`.
|
|
69
|
+
|
|
70
|
+
### Textures as resources
|
|
71
|
+
|
|
72
|
+
Textures are resources, not uniforms. Pass the texture's `source` and `style` separately:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { Shader, UniformGroup, Texture, Assets } from "pixi.js";
|
|
76
|
+
|
|
77
|
+
const texture = await Assets.load("myImage.png");
|
|
78
|
+
|
|
79
|
+
const shader = Shader.from({
|
|
80
|
+
gl: { vertex: vertSrc, fragment: fragSrc },
|
|
81
|
+
resources: {
|
|
82
|
+
uTexture: texture.source,
|
|
83
|
+
uSampler: texture.source.style,
|
|
84
|
+
myUniforms: new UniformGroup({
|
|
85
|
+
uAlpha: { value: 1.0, type: "f32" },
|
|
86
|
+
}),
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Swap texture at runtime
|
|
91
|
+
shader.resources.uTexture = otherTexture.source;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Resources are a flat key-value map. The key must match the uniform/binding name in the shader source.
|
|
95
|
+
|
|
96
|
+
Resources can also be plain objects (auto-wrapped into `UniformGroup`):
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
const shader = Shader.from({
|
|
100
|
+
gl: { vertex: vertSrc, fragment: fragSrc },
|
|
101
|
+
resources: {
|
|
102
|
+
myUniforms: {
|
|
103
|
+
uTime: { value: 0, type: "f32" },
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### UBO mode (Uniform Buffer Objects)
|
|
110
|
+
|
|
111
|
+
UBO mode packs uniforms into a single GPU buffer. Required for WebGPU; optional (WebGL2+) for WebGL.
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { UniformGroup } from "pixi.js";
|
|
115
|
+
|
|
116
|
+
const ubo = new UniformGroup(
|
|
117
|
+
{
|
|
118
|
+
uProjection: { value: new Float32Array(16), type: "mat4x4<f32>" },
|
|
119
|
+
uAlpha: { value: 1.0, type: "f32" },
|
|
120
|
+
},
|
|
121
|
+
{ ubo: true, isStatic: true },
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// Must call update() manually when isStatic is true
|
|
125
|
+
ubo.uniforms.uAlpha = 0.5;
|
|
126
|
+
ubo.update();
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
UBO rules:
|
|
130
|
+
|
|
131
|
+
- Only `f32` and `i32` based types are supported (no `u32`). Matrices are float-only.
|
|
132
|
+
- Samplers/textures cannot go in a UBO.
|
|
133
|
+
- The UniformGroup name in resources must exactly match the UBO block name in the shader.
|
|
134
|
+
- Structure and order must exactly match the shader layout.
|
|
135
|
+
- UBO sync uses `new Function` under the hood. In strict-CSP environments (no `unsafe-eval`), import `pixi.js/unsafe-eval` once at startup to swap in the fallback sync path; without it, UBO-backed shaders (and therefore WebGPU) will throw on first use.
|
|
136
|
+
|
|
137
|
+
### Custom filter
|
|
138
|
+
|
|
139
|
+
`Filter.from({ gl, resources })` is the shorthand. Pass only a fragment shader; PixiJS supplies a default vertex shader that handles output frame positioning.
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { Filter } from "pixi.js";
|
|
143
|
+
|
|
144
|
+
const filter = Filter.from({
|
|
145
|
+
gl: {
|
|
146
|
+
fragment: `
|
|
147
|
+
in vec2 vTextureCoord;
|
|
148
|
+
out vec4 finalColor;
|
|
149
|
+
uniform sampler2D uTexture;
|
|
150
|
+
uniform float uStrength;
|
|
151
|
+
|
|
152
|
+
void main(void) {
|
|
153
|
+
vec4 color = texture(uTexture, vTextureCoord);
|
|
154
|
+
finalColor = mix(color, vec4(1.0 - color.rgb, color.a), uStrength);
|
|
155
|
+
}
|
|
156
|
+
`,
|
|
157
|
+
},
|
|
158
|
+
resources: {
|
|
159
|
+
filterUniforms: {
|
|
160
|
+
uStrength: { value: 0.5, type: "f32" },
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
filter.resources.filterUniforms.uniforms.uStrength = 1.0;
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
For a custom vertex shader, use `new Filter({ glProgram: new GlProgram({ vertex, fragment }), resources })`.
|
|
169
|
+
|
|
170
|
+
#### Filter shader conventions (GLSL ES 3.0)
|
|
171
|
+
|
|
172
|
+
- `in vec2 vTextureCoord;` instead of `varying vec2 vTextureCoord;`
|
|
173
|
+
- `out vec4 finalColor;` instead of `gl_FragColor`
|
|
174
|
+
- `texture(uTexture, uv)` instead of `texture2D(uTexture, uv)`
|
|
175
|
+
- The default vertex shader exposes `uInputSize`, `uOutputFrame`, `uOutputTexture` and helpers `filterVertexPosition()` / `filterTextureCoord()`
|
|
176
|
+
|
|
177
|
+
#### Sampling the render target behind the filter
|
|
178
|
+
|
|
179
|
+
Set `blendRequired: true` and sample `uBackTexture` in the fragment shader. PixiJS copies the destination pixels into that uniform before running the filter:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
const blendFilter = Filter.from({
|
|
183
|
+
gl: { fragment: blendFragSrc },
|
|
184
|
+
resources: { uniforms: { uAmount: { value: 0.5, type: "f32" } } },
|
|
185
|
+
blendRequired: true,
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Only enable `blendRequired` when you need it; it forces an extra GPU copy every frame.
|
|
190
|
+
|
|
191
|
+
### Updating uniforms at runtime
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
// Access the UniformGroup via resources
|
|
195
|
+
shader.resources.myUniforms.uniforms.uTime = performance.now() / 1000;
|
|
196
|
+
|
|
197
|
+
// For isStatic UBOs, call update() after changing values
|
|
198
|
+
shader.resources.myUniforms.update();
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Advanced GPU features
|
|
202
|
+
|
|
203
|
+
See [references/advanced-gpu.md](references/advanced-gpu.md) for full samples of:
|
|
204
|
+
|
|
205
|
+
- **Partial buffer and texture uploads**: `buffer.update(sizeInBytes, offsetInBytes)` uploads only the changed byte range; `bufferImageSource.update(startTexel, endTexel)` uploads only a texel range of a data texture.
|
|
206
|
+
- **Vertex and index counts, winding, culling**: `geometry.vertexCount` (replaces the deprecated `getSize()`), `geometry.indexCount` to draw a prefix of a shared index buffer, `state.clockwiseFrontFace` and `cullMode`.
|
|
207
|
+
- **WGSL override constants** (WebGPU): `Shader.from({ gpu, resources, overrides: { STEPS: 8 } })`; each distinct set compiles its own pipeline.
|
|
208
|
+
- **Custom bind group layouts** (WebGPU): generate the default with `generateGpuLayoutGroups(extractStructAndGroups(source))`, edit it, pass it as `gpuLayout`.
|
|
209
|
+
- **Depth sampling with `TextureView`** (WebGPU): bind `new TextureView(depth, { aspect: "depth-only" })` as a resource while the target's depth attachment is `depthReadOnly`.
|
|
210
|
+
- **Integer textures**: `BufferImageSource` with `rgba32uint` etc., `usampler2D`/`texelFetch` and `texture_2d<u32>`/`textureLoad`, `scaleMode: "nearest"`.
|
|
211
|
+
- **3D and array textures**: `depth` or `arrayLayerCount` on a `TextureSource`/`BufferImageSource`, sampled with `sampler3D`/`texture_3d<f32>` or `sampler2DArray`/`texture_2d_array<f32>`; they upload whole, and `renderer.render({ container, target: source, layer })` draws into one slice or layer.
|
|
212
|
+
- **Storage textures** (WebGPU): `storage: true` on a `TextureSource`, then `renderer.texture.getGpuSource(source).createView()` to write it from your own compute pass.
|
|
213
|
+
- **Render bundles** (WebGPU): record draws once with `encoder.beginBundle()` / `endBundle()` and replay with `executeBundle()` while `isBundleValid()` holds.
|
|
214
|
+
- **Pooled scratch textures**: `TexturePool.getOptimalTexture({ width, height, resolution, antialias })` and `returnTexture()`.
|
|
215
|
+
|
|
216
|
+
### Uniform type reference
|
|
217
|
+
|
|
218
|
+
See [references/uniform-types.md](references/uniform-types.md) for the complete table of supported types, their WGSL/GLSL equivalents, and value formats.
|
|
219
|
+
|
|
220
|
+
### Custom Batcher (extension-based)
|
|
221
|
+
|
|
222
|
+
The `Batcher` abstract class enables custom batching for specialized rendering. Subclass it and register via extensions:
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
import { Batcher, extensions, ExtensionType } from "pixi.js";
|
|
226
|
+
import type {
|
|
227
|
+
BatcherOptions,
|
|
228
|
+
BatchableMeshElement,
|
|
229
|
+
BatchableQuadElement,
|
|
230
|
+
Geometry,
|
|
231
|
+
Shader,
|
|
232
|
+
} from "pixi.js";
|
|
233
|
+
|
|
234
|
+
class MyBatcher extends Batcher {
|
|
235
|
+
public static extension = {
|
|
236
|
+
type: [ExtensionType.Batcher],
|
|
237
|
+
name: "my-batcher",
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
public name = "my-batcher";
|
|
241
|
+
protected vertexSize = 6; // floats per vertex
|
|
242
|
+
public geometry: Geometry;
|
|
243
|
+
public shader: Shader;
|
|
244
|
+
|
|
245
|
+
constructor(options: BatcherOptions) {
|
|
246
|
+
super(options);
|
|
247
|
+
// Initialize geometry and shader
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
public packAttributes(
|
|
251
|
+
element: BatchableMeshElement,
|
|
252
|
+
float32View: Float32Array,
|
|
253
|
+
uint32View: Uint32Array,
|
|
254
|
+
index: number,
|
|
255
|
+
textureId: number,
|
|
256
|
+
): void {
|
|
257
|
+
// Pack mesh vertex attributes into the batch buffer
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
public packQuadAttributes(
|
|
261
|
+
element: BatchableQuadElement,
|
|
262
|
+
float32View: Float32Array,
|
|
263
|
+
uint32View: Uint32Array,
|
|
264
|
+
index: number,
|
|
265
|
+
textureId: number,
|
|
266
|
+
): void {
|
|
267
|
+
// Pack quad vertex attributes into the batch buffer
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
extensions.add(MyBatcher);
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Elements reference the batcher by `batcherName`. The `BatchableElement` interface requires: `batcherName`, `texture`, `blendMode`, `indexSize`, `attributeSize`, `topology`, and `packAsQuad`.
|
|
275
|
+
|
|
276
|
+
A custom `InstructionPipe` that caches state per `InstructionSet` (the way `BatcherPipe` keeps its batchers) should implement `destroyInstructionSet(instructionSet)`. The renderer calls it when the owning render group is destroyed, so the cached GPU objects are released with it instead of leaking.
|
|
277
|
+
|
|
278
|
+
```ts
|
|
279
|
+
public destroyInstructionSet(instructionSet: InstructionSet): void {
|
|
280
|
+
this._cache[instructionSet.uid]?.destroy();
|
|
281
|
+
delete this._cache[instructionSet.uid];
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Common Mistakes
|
|
286
|
+
|
|
287
|
+
### [CRITICAL] Old Shader.from(vertex, fragment, uniforms) constructor
|
|
288
|
+
|
|
289
|
+
Wrong:
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
const shader = Shader.from(vertex, fragment, { uTime: 1 });
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Correct:
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
const shader = Shader.from({
|
|
299
|
+
gl: { vertex, fragment },
|
|
300
|
+
resources: {
|
|
301
|
+
uniforms: new UniformGroup({
|
|
302
|
+
uTime: { value: 1, type: "f32" },
|
|
303
|
+
}),
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
v8 requires an options object with `gl`/`gpu` programs and `resources`. The positional API was removed.
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
### [CRITICAL] UniformGroup without type annotation
|
|
312
|
+
|
|
313
|
+
Wrong:
|
|
314
|
+
|
|
315
|
+
```ts
|
|
316
|
+
new UniformGroup({ uTime: 1 });
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Correct:
|
|
320
|
+
|
|
321
|
+
```ts
|
|
322
|
+
new UniformGroup({ uTime: { value: 1, type: "f32" } });
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Every uniform requires an explicit `{ value, type }` pair. Omitting the type causes a runtime error: "Uniform type undefined is not supported."
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
### [HIGH] UBO with unsupported types or wrong structure
|
|
329
|
+
|
|
330
|
+
UBO mode supports `f32` and `i32` based types (scalars and vectors). `u32` is not in the supported `UniformGroup` type list and will throw. Matrices are float-only (`mat*<f32>`). Samplers cannot be placed in UBOs.
|
|
331
|
+
|
|
332
|
+
The struct name and field order must exactly match the shader's UBO declaration. Mismatches produce garbled rendering with no error.
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
### [HIGH] Putting textures in UniformGroup
|
|
336
|
+
|
|
337
|
+
Wrong:
|
|
338
|
+
|
|
339
|
+
```ts
|
|
340
|
+
new UniformGroup({
|
|
341
|
+
uTexture: { value: texture, type: "f32" },
|
|
342
|
+
});
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Correct:
|
|
346
|
+
|
|
347
|
+
```ts
|
|
348
|
+
const shader = Shader.from({
|
|
349
|
+
gl: { vertex, fragment },
|
|
350
|
+
resources: {
|
|
351
|
+
uTexture: texture.source,
|
|
352
|
+
uSampler: texture.source.style,
|
|
353
|
+
myUniforms: new UniformGroup({
|
|
354
|
+
uAlpha: { value: 1.0, type: "f32" },
|
|
355
|
+
}),
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
Textures are resources, not uniforms. Pass `texture.source` (TextureSource) and `texture.source.style` (TextureStyle) as top-level resource entries.
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
### [HIGH] Replaying a render bundle against a different render target
|
|
364
|
+
|
|
365
|
+
Wrong:
|
|
366
|
+
|
|
367
|
+
```ts
|
|
368
|
+
const bundle = encoder.endBundle();
|
|
369
|
+
// later, on every frame, regardless of what is bound
|
|
370
|
+
encoder.executeBundle(bundle);
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Correct:
|
|
374
|
+
|
|
375
|
+
```ts
|
|
376
|
+
if (!bundle || !encoder.isBundleValid(bundle)) {
|
|
377
|
+
bundle = record();
|
|
378
|
+
}
|
|
379
|
+
encoder.executeBundle(bundle);
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
A bundle bakes the attachments and winding of the pass it was recorded in, and the device it was recorded on. Replaying it under a different target either fails WebGPU validation for the whole frame or silently renders inside out; replaying it after a device loss is rejected outright.
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
### [MEDIUM] Reading Geometry.getSize()
|
|
386
|
+
|
|
387
|
+
`geometry.getSize()` is deprecated since 8.20.0 and logs a warning. Use `geometry.vertexCount`, which is cached and only recomputed when buffers or attributes change.
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
## API Reference
|
|
391
|
+
|
|
392
|
+
- [Shader](https://pixijs.download/release/docs/rendering.Shader.html.md)
|
|
393
|
+
- [GlProgram](https://pixijs.download/release/docs/rendering.GlProgram.html.md)
|
|
394
|
+
- [GpuProgram](https://pixijs.download/release/docs/rendering.GpuProgram.html.md)
|
|
395
|
+
- [UniformGroup](https://pixijs.download/release/docs/rendering.UniformGroup.html.md)
|
|
396
|
+
- [Filter](https://pixijs.download/release/docs/filters.Filter.html.md)
|
|
397
|
+
- [Batcher](https://pixijs.download/release/docs/rendering.Batcher.html.md)
|
|
398
|
+
- [BatcherPipe](https://pixijs.download/release/docs/rendering.BatcherPipe.html.md)
|
|
399
|
+
- [ShaderOverrides](https://pixijs.download/release/docs/rendering.ShaderOverrides.html.md)
|
|
400
|
+
- [TextureView](https://pixijs.download/release/docs/rendering.TextureView.html.md)
|
|
401
|
+
- [RenderTarget](https://pixijs.download/release/docs/rendering.RenderTarget.html.md)
|
|
402
|
+
- [GpuEncoderSystem](https://pixijs.download/release/docs/rendering.GpuEncoderSystem.html.md)
|
|
403
|
+
- [RenderBundle](https://pixijs.download/release/docs/rendering.RenderBundle.html.md)
|
|
404
|
+
- [Geometry](https://pixijs.download/release/docs/rendering.Geometry.html.md)
|
|
405
|
+
- [State](https://pixijs.download/release/docs/rendering.State.html.md)
|