A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
docs: update post-processing and scenes guides
esengine7d9c8fc9d6a3
diff --git a/docs/astro/src/content/docs/guides/post-processing.mdx b/docs/astro/src/content/docs/guides/post-processing.mdxindex 843a20d73..d518706c0 100644--- a/docs/astro/src/content/docs/guides/post-processing.mdx+++ b/docs/astro/src/content/docs/guides/post-processing.mdx@@ -1,80 +1,141 @@---title: Post-Processing-description: Full-screen post-processing effects pipeline in ESEngine+description: Per-camera post-processing effects pipeline in ESEngine---import { Aside } from '@astrojs/starlight/components';-The PostProcess API applies full-screen shader effects after the scene is rendered. Chain multiple passes to create blur, vignette, grayscale, chromatic aberration, or custom effects.+The PostProcess API applies full-screen shader effects after each camera renders. Effects are managed through **PostProcessStack** objects that can be bound to individual cameras, allowing different cameras to have different effects.-## Initialization--Initialize the pipeline with your canvas dimensions:+## Quick Start```typescriptimport { PostProcess } from 'esengine';-PostProcess.init(canvas.width, canvas.height);+// Create an effect stack+const fx = PostProcess.createStack();+fx.addPass('bloom', PostProcess.createBloom());+fx.setUniform('bloom', 'u_threshold', 0.8);+fx.setUniform('bloom', 'u_intensity', 1.5);++// Bind to a camera entity+PostProcess.bind(cameraEntity, fx);```-<Aside type="note">- `PostProcess.begin()` and `PostProcess.end()` are called by the engine internally. You only need to configure passes and uniforms.+## PostProcessStack++A `PostProcessStack` is a reusable effect chain. Create one, add passes, and bind it to one or more cameras:++```typescript+const fx = PostProcess.createStack();++// Add effects (execute in order)+fx.addPass('blur', PostProcess.createBlur());+fx.addPass('vignette', PostProcess.createVignette());++// Configure uniforms+fx.setUniform('blur', 'u_intensity', 3.0);+fx.setUniform('vignette', 'u_intensity', 0.8);+fx.setUniform('vignette', 'u_softness', 0.3);++// Bind to camera — effects apply immediately+PostProcess.bind(cameraEntity, fx);+```++<Aside type="tip">+ Multiple cameras can share the same stack. Modifying the stack affects all cameras that reference it.</Aside>-## Adding Passes+### Stack Methods-Create a built-in effect shader and add it as a named pass:+| Method | Description |+|--------|-------------|+| `addPass(name, shader)` | Append a named pass |+| `removePass(name)` | Remove a pass by name |+| `setEnabled(name, enabled)` | Enable or disable a pass |+| `setUniform(pass, name, value)` | Set a float uniform |+| `setUniformVec4(pass, name, value)` | Set a vec4 uniform |+| `setAllPassesEnabled(enabled)` | Enable or disable all passes at once |+| `passCount` | Total number of passes |+| `enabledPassCount` | Number of enabled passes |+| `destroy()` | Destroy the stack (auto-unbinds all cameras) |++## Camera Binding```typescript-const blurShader = PostProcess.createBlur();-PostProcess.addPass('blur', blurShader);-PostProcess.setUniform('blur', 'u_intensity', 2.0);+// Bind a stack to a camera+PostProcess.bind(cameraEntity, fx);++// Query the current stack+const stack = PostProcess.getStack(cameraEntity); // null if none++// Unbind (camera renders without effects)+PostProcess.unbind(cameraEntity);```-Passes execute in the order they are added. Each pass reads the output of the previous pass as `u_texture`.+<Aside type="note">+ Each camera can have at most one stack. Binding a new stack replaces the previous one.+</Aside>## Built-in Effects| Method | Effect | Uniforms ||--------|--------|----------|-| `createBlur()` | Gaussian blur | `u_intensity` (float) — blur spread, `u_resolution` (vec2) — auto |-| `createVignette()` | Darkened edges | `u_intensity` (float) — radius, `u_softness` (float) — falloff |-| `createGrayscale()` | Desaturation | `u_intensity` (float, 0–1) — blend ratio |-| `createChromaticAberration()` | RGB channel offset | `u_intensity` (float) — offset amount, `u_resolution` (vec2) — auto |+| `createBloom()` | Bright-pixel glow | `u_threshold` — brightness cutoff, `u_intensity` — glow strength, `u_radius` — blur spread |+| `createBlur()` | Gaussian blur | `u_intensity` — blur spread |+| `createVignette()` | Darkened edges | `u_intensity` — radius, `u_softness` — falloff |+| `createGrayscale()` | Desaturation | `u_intensity` (0–1) — blend ratio |+| `createChromaticAberration()` | RGB channel offset | `u_intensity` — offset amount |<Aside type="tip">- `u_resolution` is set automatically by the engine. You only need to set the other uniforms.+ `u_resolution` is set automatically by the engine for effects that use it.</Aside>+### Bloom++Extracts bright pixels, blurs them, and adds them back. Good for glowing lights and HDR-like effects:++```typescript+const fx = PostProcess.createStack();+fx.addPass('bloom', PostProcess.createBloom());+fx.setUniform('bloom', 'u_threshold', 0.8); // brightness cutoff+fx.setUniform('bloom', 'u_intensity', 1.5); // glow strength+fx.setUniform('bloom', 'u_radius', 4.0); // blur spread+PostProcess.bind(cameraEntity, fx);+```+### Blur9-tap Gaussian blur. Higher `u_intensity` increases the blur spread:```typescript-const blur = PostProcess.createBlur();-PostProcess.addPass('blur', blur);-PostProcess.setUniform('blur', 'u_intensity', 3.0);+const fx = PostProcess.createStack();+fx.addPass('blur', PostProcess.createBlur());+fx.setUniform('blur', 'u_intensity', 3.0);+PostProcess.bind(cameraEntity, fx);```### Vignette-Darkens the screen edges. `u_intensity` controls the radius, `u_softness` controls the falloff:+Darkens the screen edges:```typescript-const vignette = PostProcess.createVignette();-PostProcess.addPass('vignette', vignette);-PostProcess.setUniform('vignette', 'u_intensity', 0.8);-PostProcess.setUniform('vignette', 'u_softness', 0.4);+const fx = PostProcess.createStack();+fx.addPass('vignette', PostProcess.createVignette());+fx.setUniform('vignette', 'u_intensity', 0.8);+fx.setUniform('vignette', 'u_softness', 0.4);+PostProcess.bind(cameraEntity, fx);```### Grayscale-Blends between the original color and grayscale. `u_intensity` of `1.0` is fully gray:+Blends between the original color and grayscale:```typescript-const gray = PostProcess.createGrayscale();-PostProcess.addPass('grayscale', gray);-PostProcess.setUniform('grayscale', 'u_intensity', 1.0);+const fx = PostProcess.createStack();+fx.addPass('grayscale', PostProcess.createGrayscale());+fx.setUniform('grayscale', 'u_intensity', 1.0); // fully gray+PostProcess.bind(cameraEntity, fx);```### Chromatic Aberration@@ -82,58 +143,31 @@ PostProcess.setUniform('grayscale', 'u_intensity', 1.0);Offsets the R and B channels for a lens distortion look:```typescript-const ca = PostProcess.createChromaticAberration();-PostProcess.addPass('chromatic', ca);-PostProcess.setUniform('chromatic', 'u_intensity', 2.0);+const fx = PostProcess.createStack();+fx.addPass('chromatic', PostProcess.createChromaticAberration());+fx.setUniform('chromatic', 'u_intensity', 2.0);+PostProcess.bind(cameraEntity, fx);```-## Pass Management--```typescript-PostProcess.setEnabled('blur', false); // disable a pass-PostProcess.setEnabled('blur', true); // re-enable-PostProcess.removePass('blur'); // remove entirely-const count = PostProcess.getPassCount(); // number of passes-```+## Editor Workflow-## Setting Uniforms+Add a **PostProcessVolume** component to a Camera entity in the editor to configure effects visually:-```typescript-PostProcess.setUniform('blur', 'u_intensity', 5.0);-PostProcess.setUniformVec4('custom', 'u_tint', { x: 1, y: 0.8, z: 0.6, w: 1 });-```+1. Select the Camera entity in the Hierarchy+2. **Add Component** → **PostProcessVolume**+3. Click **Add Effect** and choose from the built-in effects+4. Adjust parameters with the sliders-## Bypass Mode--When no passes are active, bypass the pipeline to skip FBO overhead:--```typescript-PostProcess.setBypass(true); // render directly to screen-PostProcess.setBypass(false); // use the pipeline--const bypassed = PostProcess.isBypassed();-```--## Window Resize--Update framebuffer dimensions when the canvas resizes:--```typescript-window.addEventListener('resize', () => {- PostProcess.resize(canvas.width, canvas.height);-});-```+Effects are visible in both the Scene View and the Game View. The component data is saved with the scene file.## Custom Pass-Write a custom fragment shader and add it as a pass. The vertex shader is a fixed full-screen quad — you only write the fragment shader:+Write a custom fragment shader. The vertex shader uses a fixed full-screen quad — you only write the fragment shader:```typescriptimport { Material, PostProcess } from 'esengine';const invertShader = Material.createShader(- // vertex shader is provided internally for post-process,- // but createShader needs both — use the same pattern:`#version 300 esprecision highp float;layout(location = 0) in vec2 a_position;@@ -156,8 +190,10 @@ const invertShader = Material.createShader(}`);-PostProcess.addPass('invert', invertShader);-PostProcess.setUniform('invert', 'u_intensity', 1.0);+const fx = PostProcess.createStack();+fx.addPass('invert', invertShader);+fx.setUniform('invert', 'u_intensity', 1.0);+PostProcess.bind(cameraEntity, fx);```See [Materials & Shaders](/microes/guides/materials/) for more on writing shaders.@@ -169,38 +205,50 @@ Enable blur and grayscale when the game is paused:```typescriptimport { PostProcess } from 'esengine';-const blurShader = PostProcess.createBlur();-const grayShader = PostProcess.createGrayscale();-PostProcess.addPass('pause-blur', blurShader);-PostProcess.addPass('pause-gray', grayShader);-PostProcess.setEnabled('pause-blur', false);-PostProcess.setEnabled('pause-gray', false);+const pauseFx = PostProcess.createStack();+pauseFx.addPass('blur', PostProcess.createBlur());+pauseFx.addPass('gray', PostProcess.createGrayscale());+pauseFx.setAllPassesEnabled(false);++PostProcess.bind(cameraEntity, pauseFx);function setPaused(paused: boolean) {- PostProcess.setEnabled('pause-blur', paused);- PostProcess.setEnabled('pause-gray', paused);- PostProcess.setUniform('pause-blur', 'u_intensity', 4.0);- PostProcess.setUniform('pause-gray', 'u_intensity', 0.6);+ pauseFx.setAllPassesEnabled(paused);+ pauseFx.setUniform('blur', 'u_intensity', 4.0);+ pauseFx.setUniform('gray', 'u_intensity', 0.6);}```-## Full API Reference+## Example: Different Effects per Camera++```typescript+// Main camera — bloom + vignette+const mainFx = PostProcess.createStack();+mainFx.addPass('bloom', PostProcess.createBloom());+mainFx.addPass('vignette', PostProcess.createVignette());+mainFx.setUniform('bloom', 'u_threshold', 0.7);+mainFx.setUniform('vignette', 'u_intensity', 0.6);+PostProcess.bind(mainCamera, mainFx);++// Minimap camera — grayscale+const minimapFx = PostProcess.createStack();+minimapFx.addPass('gray', PostProcess.createGrayscale());+minimapFx.setUniform('gray', 'u_intensity', 0.5);+PostProcess.bind(minimapCamera, minimapFx);+```++## Lifecycle| Method | Description ||--------|-------------|-| `PostProcess.init(width, height)` | Initialize the pipeline |+| `PostProcess.createStack()` | Create a new effect stack |+| `PostProcess.bind(camera, stack)` | Bind a stack to a camera |+| `PostProcess.unbind(camera)` | Unbind the stack from a camera |+| `PostProcess.getStack(camera)` | Get the bound stack (or null) |+| `PostProcess.init(width, height)` | Initialize the pipeline (called automatically) || `PostProcess.shutdown()` | Shut down the pipeline |-| `PostProcess.resize(width, height)` | Update framebuffer size |-| `PostProcess.addPass(name, shader)` | Add a named pass |-| `PostProcess.removePass(name)` | Remove a pass |-| `PostProcess.setEnabled(name, enabled)` | Enable or disable a pass |-| `PostProcess.isEnabled(name)` | Check if a pass is enabled |-| `PostProcess.setUniform(pass, name, value)` | Set a float uniform |-| `PostProcess.setUniformVec4(pass, name, value)` | Set a vec4 uniform |-| `PostProcess.getPassCount()` | Get the number of passes |-| `PostProcess.isInitialized()` | Check if the pipeline is active |-| `PostProcess.setBypass(bypass)` | Enable or disable bypass mode |-| `PostProcess.isBypassed()` | Check bypass state |+| `PostProcess.resize(width, height)` | Update framebuffer size (called automatically) |+| `PostProcess.createBloom()` | Create a bloom effect shader || `PostProcess.createBlur()` | Create a blur effect shader || `PostProcess.createVignette()` | Create a vignette effect shader || `PostProcess.createGrayscale()` | Create a grayscale effect shader |diff --git a/docs/astro/src/content/docs/guides/scenes.mdx b/docs/astro/src/content/docs/guides/scenes.mdxindex 4f61c7af2..ce6ac9414 100644--- a/docs/astro/src/content/docs/guides/scenes.mdx+++ b/docs/astro/src/content/docs/guides/scenes.mdx@@ -40,6 +40,10 @@ In the editor, scenes are loaded automatically — you only write scripts that dAfter building your project, the engine automatically loads the scene, resolves all referenced assets (textures, materials, Spine), and creates a default camera if none exists. You don't need to handle scene loading manually.+<Aside type="tip">+ Scene files (`.esscene`) created in the editor are **embedded directly into the build output** as data. You do not need to specify file paths or worry about deployment URLs — the build system handles everything. The `path` field in `SceneConfig` is only needed for advanced use cases like loading scenes from a remote server at runtime.+</Aside>+## Finding Entities### By Name@@ -149,7 +153,23 @@ addSystem(defineSystem(## Registering Scenes-Scenes are managed in the editor — create `.scene` files and configure them in the project settings. For advanced use cases, you can register scenes programmatically in a `setup` function:+### Editor Workflow (Recommended)++Most projects manage scenes entirely through the editor:++1. Right-click in the **Content Browser** → **Create** → **Scene** to create a `.esscene` file (default location: `assets/scenes/main.esscene`)+2. Open **Build Settings** and add the scenes you want to include in the build+3. Build the project — the build system reads each `.esscene` file, extracts its name, and **embeds the scene data directly** into the build output++At runtime, the engine automatically registers and loads these embedded scenes. **You don't need to write any scene loading code or specify any file paths.**++<Aside type="note">+ When the project is built, the `.esscene` file at `assets/scenes/main.esscene` becomes a scene named `"main"`. The file path is only used at build time — it is not a runtime URL.+</Aside>++### Programmatic Registration++For multi-scene projects that need scene switching, custom systems, or setup/cleanup callbacks, register scenes in a `setup` function. You still don't need `path` — the build system handles data embedding:```typescriptimport { SceneManager, Schedule, type App } from 'esengine';@@ -159,7 +179,6 @@ export function setup(app: App) {mgr.register({name: 'menu',- path: '/scenes/menu.json',systems: [{ schedule: Schedule.Update, system: menuUpdateSystem },],@@ -171,15 +190,25 @@ export function setup(app: App) {},});- mgr.register({ name: 'game', path: '/scenes/game.json' });+ mgr.register({ name: 'game' });mgr.setInitial('menu');}```-Instead of specifying a file path with `path`, you can pass scene data directly via `data`. This is useful for procedurally generated or in-memory scenes:+<Aside type="tip">+ The `name` must match the scene file name without extension. For example, `assets/scenes/menu.esscene` → `name: 'menu'`.+</Aside>++<Aside type="tip">+ Systems registered in `systems` are automatically wrapped as scene-scoped systems and only run while that scene's status is `running`.+</Aside>++### Inline Scene Data++You can pass scene data directly via `data` for procedurally generated or in-memory scenes:```typescript-app.registerScene({+mgr.register({name: 'procedural',data: {version: '1.0',@@ -192,8 +221,27 @@ app.registerScene({});```-<Aside type="tip">- Systems registered in `systems` are automatically wrapped as scene-scoped systems and only run while that scene's status is `running`.+### Loading from URL (Advanced)++For advanced use cases — such as loading scenes from a CDN or hot-reloading during development — use the `path` field to specify a URL:++```typescript+mgr.register({+ name: 'menu',+ path: '/scenes/menu.json',+});+```++Path resolution rules:++| Path format | Resolves to | Example |+|-------------|-------------|---------|+| Starts with `/` | Absolute path from site root | `/scenes/menu.json` → `/scenes/menu.json` |+| Starts with `http://` or `https://` | Full URL, used as-is | `https://cdn.example.com/scenes/menu.json` |+| Relative path | Prepended with `AssetServer.baseUrl` | `scenes/menu.json` → `{baseUrl}/scenes/menu.json` |++<Aside type="caution">+ `path` is a **runtime URL**, not a project file path. Do not put your `.esscene` file path here (e.g. `assets/scenes/main.esscene`). For editor-built projects, scene data is already embedded — you don't need `path` at all.</Aside>## Switching Scenesdiff --git a/docs/astro/src/content/docs/zh/guides/post-processing.mdx b/docs/astro/src/content/docs/zh/guides/post-processing.mdxindex 5342a051c..76a2b5d3f 100644--- a/docs/astro/src/content/docs/zh/guides/post-processing.mdx+++ b/docs/astro/src/content/docs/zh/guides/post-processing.mdx@@ -1,132 +1,168 @@---title: 后处理效果-description: ESEngine 全屏后处理效果管线+description: ESEngine 逐相机后处理效果管线---import { Aside } from '@astrojs/starlight/components';-PostProcess API 在场景渲染完成后应用全屏着色器效果。可以链式添加多个 pass 来实现模糊、暗角、灰度、色差等效果。+PostProcess API 在每个相机渲染完成后应用全屏着色器效果。效果通过 **PostProcessStack** 对象管理,可以绑定到不同的相机,让每个相机拥有不同的效果。-## 初始化--使用画布尺寸初始化管线:+## 快速开始```typescriptimport { PostProcess } from 'esengine';-PostProcess.init(canvas.width, canvas.height);+// 创建效果栈+const fx = PostProcess.createStack();+fx.addPass('bloom', PostProcess.createBloom());+fx.setUniform('bloom', 'u_threshold', 0.8);+fx.setUniform('bloom', 'u_intensity', 1.5);++// 绑定到相机实体+PostProcess.bind(cameraEntity, fx);```-<Aside type="note">- `PostProcess.begin()` 和 `PostProcess.end()` 由引擎内部调用。你只需配置 pass 和 uniform。+## PostProcessStack++`PostProcessStack` 是可复用的效果链。创建一个 Stack,添加 pass,然后绑定到一个或多个相机:++```typescript+const fx = PostProcess.createStack();++// 添加效果(按顺序执行)+fx.addPass('blur', PostProcess.createBlur());+fx.addPass('vignette', PostProcess.createVignette());++// 配置 uniform+fx.setUniform('blur', 'u_intensity', 3.0);+fx.setUniform('vignette', 'u_intensity', 0.8);+fx.setUniform('vignette', 'u_softness', 0.3);++// 绑定到相机 — 效果立即生效+PostProcess.bind(cameraEntity, fx);+```++<Aside type="tip">+ 多个相机可以共享同一个 Stack。修改 Stack 会影响所有引用它的相机。</Aside>-## 添加 Pass+### Stack 方法-创建内置效果着色器并添加为命名 pass:+| 方法 | 说明 |+|------|------|+| `addPass(name, shader)` | 追加一个命名 pass |+| `removePass(name)` | 按名称移除 pass |+| `setEnabled(name, enabled)` | 启用或禁用 pass |+| `setUniform(pass, name, value)` | 设置 float uniform |+| `setUniformVec4(pass, name, value)` | 设置 vec4 uniform |+| `setAllPassesEnabled(enabled)` | 一次性启用或禁用所有 pass |+| `passCount` | pass 总数 |+| `enabledPassCount` | 已启用的 pass 数 |+| `destroy()` | 销毁 Stack(自动解绑所有相机) |++## 相机绑定```typescript-const blurShader = PostProcess.createBlur();-PostProcess.addPass('blur', blurShader);-PostProcess.setUniform('blur', 'u_intensity', 2.0);+// 绑定 Stack 到相机+PostProcess.bind(cameraEntity, fx);++// 查询当前 Stack+const stack = PostProcess.getStack(cameraEntity); // 无绑定时返回 null++// 解绑(相机不再应用效果)+PostProcess.unbind(cameraEntity);```-Pass 按添加顺序执行。每个 pass 读取前一个 pass 的输出作为 `u_texture`。+<Aside type="note">+ 每个相机最多绑定一个 Stack。绑定新的 Stack 会替换之前的。+</Aside>## 内置效果| 方法 | 效果 | Uniform ||------|------|---------|-| `createBlur()` | 高斯模糊 | `u_intensity` (float) — 模糊扩散, `u_resolution` (vec2) — 自动 |-| `createVignette()` | 暗角 | `u_intensity` (float) — 半径, `u_softness` (float) — 衰减 |-| `createGrayscale()` | 灰度 | `u_intensity` (float, 0–1) — 混合比例 |-| `createChromaticAberration()` | 色差 | `u_intensity` (float) — 偏移量, `u_resolution` (vec2) — 自动 |+| `createBloom()` | 亮像素辉光 | `u_threshold` — 亮度截断, `u_intensity` — 辉光强度, `u_radius` — 模糊扩散 |+| `createBlur()` | 高斯模糊 | `u_intensity` — 模糊扩散 |+| `createVignette()` | 暗角 | `u_intensity` — 半径, `u_softness` — 衰减 |+| `createGrayscale()` | 去饱和 | `u_intensity` (0–1) — 混合比例 |+| `createChromaticAberration()` | RGB 通道偏移 | `u_intensity` — 偏移量 |<Aside type="tip">- `u_resolution` 由引擎自动设置,你只需设置其他 uniform。+ `u_resolution` 由引擎自动设置,无需手动配置。</Aside>-### 模糊+### 辉光 (Bloom)-9 次采样高斯模糊。`u_intensity` 越大模糊越强:+提取亮像素、模糊后叠加回原图。适合发光灯效和类 HDR 效果:```typescript-const blur = PostProcess.createBlur();-PostProcess.addPass('blur', blur);-PostProcess.setUniform('blur', 'u_intensity', 3.0);+const fx = PostProcess.createStack();+fx.addPass('bloom', PostProcess.createBloom());+fx.setUniform('bloom', 'u_threshold', 0.8); // 亮度截断+fx.setUniform('bloom', 'u_intensity', 1.5); // 辉光强度+fx.setUniform('bloom', 'u_radius', 4.0); // 模糊扩散+PostProcess.bind(cameraEntity, fx);```-### 暗角+### 模糊 (Blur)-使屏幕边缘变暗。`u_intensity` 控制半径,`u_softness` 控制衰减:+9 次采样高斯模糊。`u_intensity` 越大模糊越强:```typescript-const vignette = PostProcess.createVignette();-PostProcess.addPass('vignette', vignette);-PostProcess.setUniform('vignette', 'u_intensity', 0.8);-PostProcess.setUniform('vignette', 'u_softness', 0.4);+const fx = PostProcess.createStack();+fx.addPass('blur', PostProcess.createBlur());+fx.setUniform('blur', 'u_intensity', 3.0);+PostProcess.bind(cameraEntity, fx);```-### 灰度+### 暗角 (Vignette)-在原色和灰度之间混合。`u_intensity` 为 `1.0` 时完全灰度:+使屏幕边缘变暗:```typescript-const gray = PostProcess.createGrayscale();-PostProcess.addPass('grayscale', gray);-PostProcess.setUniform('grayscale', 'u_intensity', 1.0);+const fx = PostProcess.createStack();+fx.addPass('vignette', PostProcess.createVignette());+fx.setUniform('vignette', 'u_intensity', 0.8);+fx.setUniform('vignette', 'u_softness', 0.4);+PostProcess.bind(cameraEntity, fx);```-### 色差+### 灰度 (Grayscale)-偏移 R 和 B 通道以产生镜头畸变效果:+在原色和灰度之间混合:```typescript-const ca = PostProcess.createChromaticAberration();-PostProcess.addPass('chromatic', ca);-PostProcess.setUniform('chromatic', 'u_intensity', 2.0);+const fx = PostProcess.createStack();+fx.addPass('grayscale', PostProcess.createGrayscale());+fx.setUniform('grayscale', 'u_intensity', 1.0); // 完全灰度+PostProcess.bind(cameraEntity, fx);```-## Pass 管理--```typescript-PostProcess.setEnabled('blur', false); // 禁用 pass-PostProcess.setEnabled('blur', true); // 重新启用-PostProcess.removePass('blur'); // 完全移除-const count = PostProcess.getPassCount(); // pass 数量-```+### 色差 (Chromatic Aberration)-## 设置 Uniform+偏移 R 和 B 通道以产生镜头畸变效果:```typescript-PostProcess.setUniform('blur', 'u_intensity', 5.0);-PostProcess.setUniformVec4('custom', 'u_tint', { x: 1, y: 0.8, z: 0.6, w: 1 });+const fx = PostProcess.createStack();+fx.addPass('chromatic', PostProcess.createChromaticAberration());+fx.setUniform('chromatic', 'u_intensity', 2.0);+PostProcess.bind(cameraEntity, fx);```-## 旁路模式--没有活跃 pass 时,启用旁路模式跳过 FBO 开销:--```typescript-PostProcess.setBypass(true); // 直接渲染到屏幕-PostProcess.setBypass(false); // 使用管线--const bypassed = PostProcess.isBypassed();-```+## 编辑器工作流-## 窗口缩放+在编辑器中为 Camera 实体添加 **PostProcessVolume** 组件即可可视化配置效果:-画布尺寸变化时更新帧缓冲尺寸:+1. 在 Hierarchy 中选中 Camera 实体+2. **添加组件** → **PostProcessVolume**+3. 点击 **添加效果** 并从内置效果列表中选择+4. 使用滑块调整参数-```typescript-window.addEventListener('resize', () => {- PostProcess.resize(canvas.width, canvas.height);-});-```+效果在场景视图和游戏视图中都可见。组件数据随场景文件保存。## 自定义 Pass-编写自定义片段着色器并添加为 pass。顶点着色器是固定的全屏四边形,你只需编写片段着色器:+编写自定义片段着色器。顶点着色器使用固定的全屏四边形 — 你只需编写片段着色器:```typescriptimport { Material, PostProcess } from 'esengine';@@ -154,8 +190,10 @@ const invertShader = Material.createShader(}`);-PostProcess.addPass('invert', invertShader);-PostProcess.setUniform('invert', 'u_intensity', 1.0);+const fx = PostProcess.createStack();+fx.addPass('invert', invertShader);+fx.setUniform('invert', 'u_intensity', 1.0);+PostProcess.bind(cameraEntity, fx);```参见[材质与着色器](/microes/zh/guides/materials/)了解更多着色器编写方法。@@ -167,38 +205,50 @@ PostProcess.setUniform('invert', 'u_intensity', 1.0);```typescriptimport { PostProcess } from 'esengine';-const blurShader = PostProcess.createBlur();-const grayShader = PostProcess.createGrayscale();-PostProcess.addPass('pause-blur', blurShader);-PostProcess.addPass('pause-gray', grayShader);-PostProcess.setEnabled('pause-blur', false);-PostProcess.setEnabled('pause-gray', false);+const pauseFx = PostProcess.createStack();+pauseFx.addPass('blur', PostProcess.createBlur());+pauseFx.addPass('gray', PostProcess.createGrayscale());+pauseFx.setAllPassesEnabled(false);++PostProcess.bind(cameraEntity, pauseFx);function setPaused(paused: boolean) {- PostProcess.setEnabled('pause-blur', paused);- PostProcess.setEnabled('pause-gray', paused);- PostProcess.setUniform('pause-blur', 'u_intensity', 4.0);- PostProcess.setUniform('pause-gray', 'u_intensity', 0.6);+ pauseFx.setAllPassesEnabled(paused);+ pauseFx.setUniform('blur', 'u_intensity', 4.0);+ pauseFx.setUniform('gray', 'u_intensity', 0.6);}```-## 完整 API 参考+## 示例:不同相机使用不同效果++```typescript+// 主相机 — 辉光 + 暗角+const mainFx = PostProcess.createStack();+mainFx.addPass('bloom', PostProcess.createBloom());+mainFx.addPass('vignette', PostProcess.createVignette());+mainFx.setUniform('bloom', 'u_threshold', 0.7);+mainFx.setUniform('vignette', 'u_intensity', 0.6);+PostProcess.bind(mainCamera, mainFx);++// 小地图相机 — 灰度+const minimapFx = PostProcess.createStack();+minimapFx.addPass('gray', PostProcess.createGrayscale());+minimapFx.setUniform('gray', 'u_intensity', 0.5);+PostProcess.bind(minimapCamera, minimapFx);+```++## 生命周期| 方法 | 说明 ||------|------|-| `PostProcess.init(width, height)` | 初始化管线 |+| `PostProcess.createStack()` | 创建新的效果栈 |+| `PostProcess.bind(camera, stack)` | 将 Stack 绑定到相机 |+| `PostProcess.unbind(camera)` | 解绑相机的 Stack |+| `PostProcess.getStack(camera)` | 获取已绑定的 Stack(无则返回 null) |+| `PostProcess.init(width, height)` | 初始化管线(自动调用) || `PostProcess.shutdown()` | 关闭管线 |-| `PostProcess.resize(width, height)` | 更新帧缓冲尺寸 |-| `PostProcess.addPass(name, shader)` | 添加命名 pass |-| `PostProcess.removePass(name)` | 移除 pass |-| `PostProcess.setEnabled(name, enabled)` | 启用或禁用 pass |-| `PostProcess.isEnabled(name)` | 检查 pass 是否启用 |-| `PostProcess.setUniform(pass, name, value)` | 设置 float uniform |-| `PostProcess.setUniformVec4(pass, name, value)` | 设置 vec4 uniform |-| `PostProcess.getPassCount()` | 获取 pass 数量 |-| `PostProcess.isInitialized()` | 检查管线是否活跃 |-| `PostProcess.setBypass(bypass)` | 启用或禁用旁路模式 |-| `PostProcess.isBypassed()` | 检查旁路状态 |+| `PostProcess.resize(width, height)` | 更新帧缓冲尺寸(自动调用) |+| `PostProcess.createBloom()` | 创建辉光效果着色器 || `PostProcess.createBlur()` | 创建模糊效果着色器 || `PostProcess.createVignette()` | 创建暗角效果着色器 || `PostProcess.createGrayscale()` | 创建灰度效果着色器 |diff --git a/docs/astro/src/content/docs/zh/guides/scenes.mdx b/docs/astro/src/content/docs/zh/guides/scenes.mdxindex a9ae3bea6..ad0f16435 100644--- a/docs/astro/src/content/docs/zh/guides/scenes.mdx+++ b/docs/astro/src/content/docs/zh/guides/scenes.mdx@@ -40,6 +40,10 @@ import { Aside } from '@astrojs/starlight/components';构建项目后,引擎会自动加载场景、解析所有引用的资源(纹理、材质、Spine),并在没有相机时创建默认相机。你不需要手动处理场景加载。+<Aside type="tip">+ 编辑器中创建的场景文件(`.esscene`)在构建时会**直接嵌入构建产物**。你不需要指定文件路径或关心部署 URL — 构建系统会自动处理。`SceneConfig` 中的 `path` 字段仅用于高级场景,例如运行时从远程服务器加载场景。+</Aside>+## 查找实体### 按名字查找@@ -149,7 +153,23 @@ addSystem(defineSystem(## 注册场景-场景在编辑器中管理 — 创建 `.scene` 文件并在项目设置中配置。如需高级用例,可在 `setup` 函数中以编程方式注册场景:+### 编辑器工作流(推荐)++大多数项目完全通过编辑器管理场景:++1. 在 **Content Browser** 中右键 → **创建** → **场景**,创建 `.esscene` 文件(默认位置:`assets/scenes/main.esscene`)+2. 打开**构建设置**,添加需要包含在构建中的场景+3. 构建项目 — 构建系统读取每个 `.esscene` 文件,提取场景名称,并将**场景数据直接嵌入**构建产物++运行时引擎会自动注册和加载这些嵌入的场景。**你不需要编写任何场景加载代码,也不需要指定任何文件路径。**++<Aside type="note">+ 构建时,`assets/scenes/main.esscene` 文件会变成名为 `"main"` 的场景。文件路径仅在构建时使用,不是运行时 URL。+</Aside>++### 编程注册++对于需要场景切换、自定义系统、或 setup/cleanup 回调的多场景项目,在 `setup` 函数中注册场景。同样不需要 `path` — 构建系统会自动处理数据嵌入:```typescriptimport { SceneManager, Schedule, type App } from 'esengine';@@ -159,7 +179,6 @@ export function setup(app: App) {mgr.register({name: 'menu',- path: '/scenes/menu.json',systems: [{ schedule: Schedule.Update, system: menuUpdateSystem },],@@ -171,15 +190,25 @@ export function setup(app: App) {},});- mgr.register({ name: 'game', path: '/scenes/game.json' });+ mgr.register({ name: 'game' });mgr.setInitial('menu');}```-除了通过 `path` 指定场景文件路径外,也可以通过 `data` 直接传入场景数据对象,适用于动态生成或内存中的场景:+<Aside type="tip">+ `name` 必须与场景文件名(不含扩展名)一致。例如 `assets/scenes/menu.esscene` → `name: 'menu'`。+</Aside>++<Aside type="tip">+ `systems` 中注册的系统会自动包装为场景作用域系统,仅在该场景状态为 `running` 时执行。+</Aside>++### 内联场景数据++也可以通过 `data` 直接传入场景数据对象,适用于动态生成或内存中的场景:```typescript-app.registerScene({+mgr.register({name: 'procedural',data: {version: '1.0',@@ -192,8 +221,27 @@ app.registerScene({});```-<Aside type="tip">- `systems` 中注册的系统会自动包装为场景作用域系统,仅在该场景状态为 `running` 时执行。+### 从 URL 加载(高级)++如需从 CDN 加载或开发时热加载等高级场景,可使用 `path` 字段指定 URL:++```typescript+mgr.register({+ name: 'menu',+ path: '/scenes/menu.json',+});+```++路径解析规则:++| 路径格式 | 解析方式 | 示例 |+|----------|----------|------|+| 以 `/` 开头 | 从站点根目录的绝对路径,原样使用 | `/scenes/menu.json` → `/scenes/menu.json` |+| 以 `http://` 或 `https://` 开头 | 完整 URL,原样使用 | `https://cdn.example.com/scenes/menu.json` |+| 相对路径 | 拼接 `AssetServer.baseUrl` 前缀 | `scenes/menu.json` → `{baseUrl}/scenes/menu.json` |++<Aside type="caution">+ `path` 是**运行时 URL**,不是项目文件路径。不要把 `.esscene` 文件路径填在这里(例如 `assets/scenes/main.esscene`)。通过编辑器构建的项目,场景数据已经嵌入,完全不需要 `path`。</Aside>## 切换场景