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
examples(postprocess-effects): rebuild as an interactive effect gallery
yhh7e94025759e6
diff --git a/examples/postprocess-effects/README.md b/examples/postprocess-effects/README.mdnew file mode 100644index 000000000..33a9496b2--- /dev/null+++ b/examples/postprocess-effects/README.md@@ -0,0 +1,60 @@+# Post-Processing++A gallery of the engine's `PostProcessVolume` effects. Page through the ten+built-in effects with on-screen buttons; the last page shows a **local volume**+sweeping across the camera.++## Controls++| Input | Action |+| ----------------------- | ----------------------------------- |+| **Prev / Next** buttons | Page to the previous / next effect |+| `←` / `→` / `Space` | Same, from the keyboard |++## The effects++`Bloom` · `Blur` · `Pixelate` · `Chromatic Aberration` · `Lens Distortion` ·+`Vignette` · `Grayscale` · `Color Grade` · `Tonemap (ACES)` · `FXAA` — each is a+full-screen pass with its own uniforms (see `src/config.ts`). The final+`Local Volume` page is a spatial demo rather than a single effect.++## How it works++Post-processing here is **data-driven**: the scene owns one global+`PostProcessVolume` (tagged `SceneVolume`) and the engine's `postProcessVolumeSystem`+reads it every frame and rebuilds the camera's pass stack. Nothing calls the+pipeline imperatively.++- **Switching** (`src/systems/switch.ts`) just rewrites the volume's `effects`+ array via `Mut(PostProcessVolume)`; the volume system applies it next frame.+ A click surfaces as a `'click'` UI event that the system reads with+ `events.query('click').some(e => e.target === entity)`. The title and hint+ `Text` are updated on each switch.+- **The buttons** are plain UI entities in the scene (`UINode` + `UIVisual` ++ `Interactable`, with a `Text` label child).+- **The local volume** (`src/config.ts` `spawnLocalVolume`) is a non-global+ sphere volume with a warm grade + bloom, carrying a `Sweep` component that+ ping-pongs it along x. The camera is fixed, so as the volume drifts past,+ `computeVolumeFactor` fades its effect in near the centre and out at the edges+ — the camera-relative blend that `blendVolumeEffects` resolves each frame.+ It's tagged `ShowcaseOwned` and despawned when you page away.++The backdrop — a bright core ringed by orbiting colored sprites — gives the+effects something with highlights and edges to act on.++## Files++```+assets/+ scenes/main.esscene # camera, backdrop, SceneVolume, UI (title/hint + Prev/Next)+src/+ main.ts # registers the systems+ config.ts # the ten effects + spawnLocalVolume()+ components.ts # tags (buttons, SceneVolume, ShowcaseOwned) + Orbit + Sweep+ state.ts # the current effect index+ systems/+ setup.ts # apply the first effect, set the labels+ switch.ts # buttons / keys page through the effects+ animate.ts # orbit the backdrop sprites+ sweep.ts # ping-pong the local volume across the camera+```diff --git a/examples/postprocess-effects/assets/scenes/main.esscene b/examples/postprocess-effects/assets/scenes/main.essceneindex cacce4528..8489412f0 100644--- a/examples/postprocess-effects/assets/scenes/main.esscene+++ b/examples/postprocess-effects/assets/scenes/main.esscene@@ -7,152 +7,259 @@"name": "Camera","parent": null,"children": [],+ "visible": true,"components": [{ "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 10 } } },- { "type": "Camera", "data": { "projectionType": 1, "orthoSize": 300, "isActive": true, "priority": 0 } }- ],- "visible": true+ { "type": "Camera", "data": { "projectionType": 1, "orthoSize": 360, "isActive": true, "priority": 0 } }+ ]},{"id": 1,+ "name": "Background",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 0 } } },+ { "type": "Sprite", "data": { "size": { "x": 1400, "y": 820 }, "color": { "r": 0.04, "g": 0.04, "b": 0.06, "a": 1 }, "layer": 0 } }+ ]+ },+ {+ "id": 2,+ "name": "GlowCore",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 0 } } },+ { "type": "Sprite", "data": { "size": { "x": 84, "y": 84 }, "color": { "r": 1, "g": 0.96, "b": 0.78, "a": 1 }, "layer": 2 } }+ ]+ },+ {+ "id": 3,"name": "OrbitSprite0","parent": null,"children": [],+ "visible": true,"components": [{ "type": "Transform", "data": { "position": { "x": 100, "y": 0, "z": 0 } } },- { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.96, "g": 0.24, "b": 0.24, "a": 1 } } },+ { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.96, "g": 0.24, "b": 0.24, "a": 1 }, "layer": 1 } },{ "type": "Orbit", "data": { "speed": 0.5, "radius": 80 } }- ],- "visible": true+ ]},{- "id": 2,+ "id": 4,"name": "OrbitSprite1","parent": null,"children": [],+ "visible": true,"components": [{ "type": "Transform", "data": { "position": { "x": 70.71, "y": 70.71, "z": 0 } } },- { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.96, "g": 0.78, "b": 0.24, "a": 1 } } },+ { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.96, "g": 0.78, "b": 0.24, "a": 1 }, "layer": 1 } },{ "type": "Orbit", "data": { "speed": 0.6, "radius": 110, "angle": 0.79 } }- ],- "visible": true+ ]},{- "id": 3,+ "id": 5,"name": "OrbitSprite2","parent": null,"children": [],+ "visible": true,"components": [{ "type": "Transform", "data": { "position": { "x": 0, "y": 100, "z": 0 } } },- { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.6, "g": 0.96, "b": 0.24, "a": 1 } } },+ { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.6, "g": 0.96, "b": 0.24, "a": 1 }, "layer": 1 } },{ "type": "Orbit", "data": { "speed": 0.7, "radius": 140, "angle": 1.57 } }- ],- "visible": true+ ]},{- "id": 4,+ "id": 6,"name": "OrbitSprite3","parent": null,"children": [],+ "visible": true,"components": [{ "type": "Transform", "data": { "position": { "x": -70.71, "y": 70.71, "z": 0 } } },- { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.24, "g": 0.96, "b": 0.42, "a": 1 } } },+ { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.24, "g": 0.96, "b": 0.42, "a": 1 }, "layer": 1 } },{ "type": "Orbit", "data": { "speed": 0.8, "radius": 80, "angle": 2.36 } }- ],- "visible": true+ ]},{- "id": 5,+ "id": 7,"name": "OrbitSprite4","parent": null,"children": [],+ "visible": true,"components": [{ "type": "Transform", "data": { "position": { "x": -100, "y": 0, "z": 0 } } },- { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.24, "g": 0.96, "b": 0.96, "a": 1 } } },+ { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.24, "g": 0.96, "b": 0.96, "a": 1 }, "layer": 1 } },{ "type": "Orbit", "data": { "speed": 0.9, "radius": 110, "angle": 3.14 } }- ],- "visible": true+ ]},{- "id": 6,+ "id": 8,"name": "OrbitSprite5","parent": null,"children": [],+ "visible": true,"components": [{ "type": "Transform", "data": { "position": { "x": -70.71, "y": -70.71, "z": 0 } } },- { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.24, "g": 0.42, "b": 0.96, "a": 1 } } },+ { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.24, "g": 0.42, "b": 0.96, "a": 1 }, "layer": 1 } },{ "type": "Orbit", "data": { "speed": 1.0, "radius": 140, "angle": 3.93 } }- ],- "visible": true+ ]},{- "id": 7,+ "id": 9,"name": "OrbitSprite6","parent": null,"children": [],+ "visible": true,"components": [{ "type": "Transform", "data": { "position": { "x": 0, "y": -100, "z": 0 } } },- { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.6, "g": 0.24, "b": 0.96, "a": 1 } } },+ { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.6, "g": 0.24, "b": 0.96, "a": 1 }, "layer": 1 } },{ "type": "Orbit", "data": { "speed": 1.1, "radius": 80, "angle": 4.71 } }- ],- "visible": true+ ]},{- "id": 8,+ "id": 10,"name": "OrbitSprite7","parent": null,"children": [],+ "visible": true,"components": [{ "type": "Transform", "data": { "position": { "x": 70.71, "y": -70.71, "z": 0 } } },- { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.96, "g": 0.24, "b": 0.78, "a": 1 } } },+ { "type": "Sprite", "data": { "size": { "x": 50, "y": 50 }, "color": { "r": 0.96, "g": 0.24, "b": 0.78, "a": 1 }, "layer": 1 } },{ "type": "Orbit", "data": { "speed": 1.2, "radius": 110, "angle": 5.50 } }- ],- "visible": true+ ]},{- "id": 9,- "name": "CenterSprite",+ "id": 11,+ "name": "SceneVolume","parent": null,"children": [],+ "visible": true,"components": [{ "type": "Transform", "data": {} },- { "type": "Sprite", "data": { "size": { "x": 60, "y": 60 } } }- ],- "visible": true+ { "type": "PostProcessVolume", "data": { "isGlobal": true, "priority": 0, "weight": 1, "effects": [] } },+ { "type": "SceneVolume", "data": {} }+ ]},{- "id": 10,- "name": "PostProcess",+ "id": 12,+ "name": "Canvas","parent": null,+ "children": [13, 14, 15, 17],+ "visible": true,+ "components": [+ { "type": "Transform", "data": {} },+ { "type": "Canvas", "data": { "designResolution": { "x": 1280, "y": 720 }, "scaleMode": 2, "backgroundColor": { "r": 0, "g": 0, "b": 0, "a": 0 } } },+ { "type": "UINode", "data": {} }+ ]+ },+ {+ "id": 13,+ "name": "Title",+ "parent": 12,+ "children": [],+ "visible": true,+ "components": [+ { "type": "Transform", "data": {} },+ { "type": "UINode", "data": {+ "position": 1,+ "width": { "value": 600, "unit": 0 }, "height": { "value": 52, "unit": 0 },+ "insetLeft": { "value": 0, "unit": 1 }, "marginLeft": { "value": 340, "unit": 0 },+ "insetTop": { "value": 0, "unit": 1 }, "marginTop": { "value": 26, "unit": 0 }+ } },+ { "type": "Text", "data": { "content": "Bloom", "fontSize": 34, "color": { "r": 0.95, "g": 0.95, "b": 1, "a": 1 }, "align": 1, "verticalAlign": 1 } },+ { "type": "TitleLabel", "data": {} }+ ]+ },+ {+ "id": 14,+ "name": "Hint",+ "parent": 12,+ "children": [],+ "visible": true,+ "components": [+ { "type": "Transform", "data": {} },+ { "type": "UINode", "data": {+ "position": 1,+ "width": { "value": 900, "unit": 0 }, "height": { "value": 24, "unit": 0 },+ "insetLeft": { "value": 0, "unit": 1 }, "marginLeft": { "value": 190, "unit": 0 },+ "insetTop": { "value": 0, "unit": 1 }, "marginTop": { "value": 84, "unit": 0 }+ } },+ { "type": "Text", "data": { "content": "", "fontSize": 17, "color": { "r": 0.72, "g": 0.76, "b": 0.86, "a": 0.9 }, "align": 1, "verticalAlign": 1 } },+ { "type": "HintLabel", "data": {} }+ ]+ },+ {+ "id": 15,+ "name": "PrevButton",+ "parent": 12,+ "children": [16],+ "visible": true,+ "components": [+ { "type": "Transform", "data": {} },+ { "type": "UINode", "data": {+ "position": 1,+ "width": { "value": 140, "unit": 0 }, "height": { "value": 54, "unit": 0 },+ "insetLeft": { "value": 0, "unit": 1 }, "marginLeft": { "value": 480, "unit": 0 },+ "insetTop": { "value": 0, "unit": 1 }, "marginTop": { "value": 626, "unit": 0 }+ } },+ { "type": "UIVisual", "data": { "visualType": 1, "color": { "r": 0.18, "g": 0.2, "b": 0.28, "a": 0.92 } } },+ { "type": "Interactable", "data": {} },+ { "type": "PrevButton", "data": {} }+ ]+ },+ {+ "id": 16,+ "name": "PrevLabel",+ "parent": 15,+ "children": [],+ "visible": true,+ "components": [+ { "type": "Transform", "data": {} },+ { "type": "UINode", "data": {+ "position": 1,+ "insetLeft": { "value": 0, "unit": 1 }, "insetRight": { "value": 0, "unit": 1 },+ "insetTop": { "value": 0, "unit": 1 }, "insetBottom": { "value": 0, "unit": 1 }+ } },+ { "type": "Text", "data": { "content": "Prev", "fontSize": 22, "color": { "r": 1, "g": 1, "b": 1, "a": 1 }, "align": 1, "verticalAlign": 1 } }+ ]+ },+ {+ "id": 17,+ "name": "NextButton",+ "parent": 12,+ "children": [18],+ "visible": true,+ "components": [+ { "type": "Transform", "data": {} },+ { "type": "UINode", "data": {+ "position": 1,+ "width": { "value": 140, "unit": 0 }, "height": { "value": 54, "unit": 0 },+ "insetLeft": { "value": 0, "unit": 1 }, "marginLeft": { "value": 660, "unit": 0 },+ "insetTop": { "value": 0, "unit": 1 }, "marginTop": { "value": 626, "unit": 0 }+ } },+ { "type": "UIVisual", "data": { "visualType": 1, "color": { "r": 0.18, "g": 0.2, "b": 0.28, "a": 0.92 } } },+ { "type": "Interactable", "data": {} },+ { "type": "NextButton", "data": {} }+ ]+ },+ {+ "id": 18,+ "name": "NextLabel",+ "parent": 17,"children": [],+ "visible": true,"components": [{ "type": "Transform", "data": {} },- { "type": "PostProcessVolume", "data": {- "isGlobal": true,- "priority": 0,- "weight": 1,- "effects": [- {- "type": "bloom",- "enabled": true,- "uniforms": {- "u_threshold": 0.3,- "u_intensity": 1.5,- "u_radius": 6- }- },- {- "type": "vignette",- "enabled": true,- "uniforms": {- "u_intensity": 0.8,- "u_softness": 0.5- }- }- ]- }}- ],- "visible": true+ { "type": "UINode", "data": {+ "position": 1,+ "insetLeft": { "value": 0, "unit": 1 }, "insetRight": { "value": 0, "unit": 1 },+ "insetTop": { "value": 0, "unit": 1 }, "insetBottom": { "value": 0, "unit": 1 }+ } },+ { "type": "Text", "data": { "content": "Next", "fontSize": 22, "color": { "r": 1, "g": 1, "b": 1, "a": 1 }, "align": 1, "verticalAlign": 1 } }+ ]}]}diff --git a/examples/postprocess-effects/project.esproject b/examples/postprocess-effects/project.esprojectindex 0572ec32e..f7104edf1 100644--- a/examples/postprocess-effects/project.esproject+++ b/examples/postprocess-effects/project.esproject@@ -1,13 +1,13 @@{"formatVersion": "1","name": "Post-Processing",- "description": "Full-screen post-processing: bloom, vignette and color grading.",+ "description": "An interactive gallery of the engine's post-process effects, plus a camera-relative local volume.","tag": "Effects","version": "0.1.0","defaultScene": "assets/scenes/main.esscene","designResolution": {- "width": 800,- "height": 600+ "width": 1280,+ "height": 720},"spineVersion": "none"}diff --git a/examples/postprocess-effects/src/components.ts b/examples/postprocess-effects/src/components.tsindex 9d3b7820a..76b0ad94b 100644--- a/examples/postprocess-effects/src/components.ts+++ b/examples/postprocess-effects/src/components.ts@@ -1,7 +1,22 @@-import { defineComponent } from 'esengine';+import { defineComponent, defineTag } from 'esengine';-export const Orbit = defineComponent('Orbit', {- speed: 1,- radius: 100,- angle: 0,-});+// Heading + one-line hint that name the current effect.+export const TitleLabel = defineTag('TitleLabel');+export const HintLabel = defineTag('HintLabel');++// The two on-screen buttons that page through the effects.+export const PrevButton = defineTag('PrevButton');+export const NextButton = defineTag('NextButton');++// The scene-wide (global) post-process volume the gallery drives.+export const SceneVolume = defineTag('SceneVolume');++// Anything spawned for the current showcase — despawned as a group on switch.+export const ShowcaseOwned = defineTag('ShowcaseOwned');++// Circular motion for the backdrop sprites.+export const Orbit = defineComponent('Orbit', { speed: 1, radius: 100, angle: 0 });++// Horizontal ping-pong, used by the local-volume demo to sweep a volume across+// the fixed camera so its effect fades in and out by proximity.+export const Sweep = defineComponent('Sweep', { range: 300, speed: 1, t: 0 });diff --git a/examples/postprocess-effects/src/config.ts b/examples/postprocess-effects/src/config.tsnew file mode 100644index 000000000..bf07d0b91--- /dev/null+++ b/examples/postprocess-effects/src/config.ts@@ -0,0 +1,67 @@+import { PostProcessVolume, Transform } from 'esengine';+import type { PostProcessVolumeData, CommandsInstance } from 'esengine';+import { Sweep, ShowcaseOwned } from './components';++type EffectList = PostProcessVolumeData['effects'];++// One entry per screen. `global` is the effect list applied to the scene-wide+// volume; the final `local` entry instead spawns an orbiting local volume (see+// spawnLocalVolume) to show off camera-relative volume blending.+export interface Showcase {+ name: string;+ hint: string;+ global: EffectList;+ local?: boolean;+}++const fx = (type: string, uniforms: Record<string, number>): EffectList[number] =>+ ({ type, enabled: true, uniforms });++export const SHOWCASES: Showcase[] = [+ { name: 'Bloom', hint: 'bright pixels bleed a soft glow', global: [+ fx('bloom', { u_threshold: 0.3, u_intensity: 1.6, u_radius: 5 })] },+ { name: 'Blur', hint: 'a 9-tap gaussian softens the frame', global: [+ fx('blur', { u_intensity: 3 })] },+ { name: 'Pixelate', hint: 'snaps sampling to a coarse grid', global: [+ fx('pixelate', { u_pixelSize: 8 })] },+ { name: 'Chromatic Aberration', hint: 'splits the colour channels radially', global: [+ fx('chromaticAberration', { u_intensity: 6 })] },+ { name: 'Lens Distortion', hint: 'barrels the image like a wide lens', global: [+ fx('lensDistortion', { u_strength: 0.35, u_zoom: 1.1 })] },+ { name: 'Vignette', hint: 'darkens toward the corners', global: [+ fx('vignette', { u_intensity: 0.7, u_softness: 0.45 })] },+ { name: 'Grayscale', hint: 'luma-weighted desaturation', global: [+ fx('grayscale', { u_intensity: 1 })] },+ { name: 'Color Grade', hint: 'exposure, contrast, saturation, white balance', global: [+ fx('colorGrade', { u_exposure: 0.2, u_contrast: 1.15, u_saturation: 1.35, u_temperature: 0.4, u_tint: 0.05 })] },+ { name: 'Tonemap (ACES)', hint: 'filmic curve maps HDR into display range', global: [+ fx('tonemap', { u_exposure: 0.6 })] },+ { name: 'FXAA', hint: 'edge-directed antialiasing', global: [+ fx('fxaa', { u_intensity: 1 })] },+ { name: 'Local Volume', hint: 'a warm bloom pocket sweeps across the camera', global: [], local: true },+];++export const SHOWCASE_COUNT = SHOWCASES.length;++// Deep-copy an effect list so a live volume never shares the SHOWCASES constant.+export function cloneEffects(list: EffectList): EffectList {+ return list.map((e) => ({ ...e, uniforms: { ...e.uniforms } }));+}++// The local-volume demo: a sphere volume with a warm grade + bloom, ping-ponging+// across the fixed camera so its effect fades in near the centre and out at the+// edges — the camera-relative blend that volumeSystem resolves each frame.+export function spawnLocalVolume(cmds: CommandsInstance): void {+ cmds.spawn()+ .insert(Transform, { position: { x: 0, y: 0, z: 0 } })+ .insert(PostProcessVolume, {+ isGlobal: false, shape: 'sphere', size: { x: 220, y: 220 },+ priority: 1, weight: 1, blendDistance: 150,+ effects: [+ fx('colorGrade', { u_exposure: 0.3, u_contrast: 1.1, u_saturation: 1.5, u_temperature: 0.55, u_tint: 0.1 }),+ fx('bloom', { u_threshold: 0.25, u_intensity: 1.5, u_radius: 5 }),+ ],+ })+ .insert(Sweep, { range: 360, speed: 0.6, t: 0 })+ .insert(ShowcaseOwned, {});+}diff --git a/examples/postprocess-effects/src/main.ts b/examples/postprocess-effects/src/main.tsindex c67100fc2..7b78bfab8 100644--- a/examples/postprocess-effects/src/main.ts+++ b/examples/postprocess-effects/src/main.ts@@ -1,6 +1,19 @@-import { addSystemToSchedule, Schedule } from 'esengine';+// Post-processing — a gallery of the engine's PostProcessVolume effects, paged+// with on-screen buttons.+//+// • Prev / Next (or ← / → / Space) cycle the built-in effects, each applied+// to the scene-wide volume.+// • The final "Local Volume" page spawns a local volume that sweeps across the+// camera, showing camera-relative volume blending.+import { addStartupSystem, addSystemToSchedule, Schedule } from 'esengine';import './components';+import { setupSystem } from './systems/setup';+import { switchSystem } from './systems/switch';import { animateSystem } from './systems/animate';+import { sweepSystem } from './systems/sweep';+addStartupSystem(setupSystem);+addSystemToSchedule(Schedule.Update, switchSystem);addSystemToSchedule(Schedule.Update, animateSystem);+addSystemToSchedule(Schedule.Update, sweepSystem);diff --git a/examples/postprocess-effects/src/state.ts b/examples/postprocess-effects/src/state.tsnew file mode 100644index 000000000..6f87048e3--- /dev/null+++ b/examples/postprocess-effects/src/state.ts@@ -0,0 +1,3 @@+// Which effect is on screen. Shared between the setup system (applies the first)+// and the switch system (pages through them).+export const state = { current: 0 };diff --git a/examples/postprocess-effects/src/systems/setup.ts b/examples/postprocess-effects/src/systems/setup.tsnew file mode 100644index 000000000..445086d32--- /dev/null+++ b/examples/postprocess-effects/src/systems/setup.ts@@ -0,0 +1,16 @@+import { defineSystem, Query, Mut, PostProcessVolume, Text } from 'esengine';+import { SceneVolume, TitleLabel, HintLabel } from '../components';+import { SHOWCASES, cloneEffects } from '../config';+import { state } from '../state';++// Apply the first showcase to the scene-wide volume and set the labels.+export const setupSystem = defineSystem(+ [Query(Mut(PostProcessVolume), SceneVolume), Query(Mut(Text), TitleLabel), Query(Mut(Text), HintLabel)],+ (volumes, titles, hints) => {+ const sc = SHOWCASES[state.current];+ for (const [, vol] of volumes) vol.effects = cloneEffects(sc.global);+ for (const [, text] of titles) text.content = sc.name;+ for (const [, text] of hints) text.content = sc.hint;+ },+ { name: 'SetupSystem' },+);diff --git a/examples/postprocess-effects/src/systems/sweep.ts b/examples/postprocess-effects/src/systems/sweep.tsnew file mode 100644index 000000000..035ca3d85--- /dev/null+++ b/examples/postprocess-effects/src/systems/sweep.ts@@ -0,0 +1,15 @@+import { defineSystem, Query, Mut, Res, Time, Transform } from 'esengine';+import { Sweep } from '../components';++// Ping-pong a sweeping entity along x, so a local volume drifts through the+// fixed camera and its effect blends in and out by distance.+export const sweepSystem = defineSystem(+ [Query(Mut(Transform), Mut(Sweep)), Res(Time)],+ (query, time) => {+ for (const [, transform, sweep] of query) {+ sweep.t += time.delta;+ transform.position.x = Math.sin(sweep.t * sweep.speed) * sweep.range;+ }+ },+ { name: 'SweepSystem' },+);diff --git a/examples/postprocess-effects/src/systems/switch.ts b/examples/postprocess-effects/src/systems/switch.tsnew file mode 100644index 000000000..db091a08b--- /dev/null+++ b/examples/postprocess-effects/src/systems/switch.ts@@ -0,0 +1,42 @@+import {+ defineSystem, Query, Mut, Res, Commands,+ Input, UIEvents, PostProcessVolume, Text,+} from 'esengine';+import type { UIEventQueue } from 'esengine';+import { SceneVolume, ShowcaseOwned, TitleLabel, HintLabel, PrevButton, NextButton } from '../components';+import { SHOWCASES, SHOWCASE_COUNT, cloneEffects, spawnLocalVolume } from '../config';+import { state } from '../state';++// Page through the effects with the Prev/Next buttons or the arrow keys / Space.+// On a change, despawn the previous page's entities, rewrite the scene-wide+// volume's effect list, spawn anything the new page needs, then retitle.+export const switchSystem = defineSystem(+ [+ Res(Input), Res(UIEvents),+ Query(PrevButton), Query(NextButton),+ Query(Mut(PostProcessVolume), SceneVolume), Query(ShowcaseOwned),+ Query(Mut(Text), TitleLabel), Query(Mut(Text), HintLabel),+ Commands(),+ ],+ (input, events: UIEventQueue, prevs, nexts, volumes, owned, titles, hints, cmds) => {+ let dir = 0;+ if (input.isKeyPressed('ArrowRight') || input.isKeyPressed('Space')) dir = 1;+ else if (input.isKeyPressed('ArrowLeft')) dir = -1;++ const clicks = events.query('click');+ for (const [entity] of nexts) if (clicks.some((c) => c.target === entity)) dir = 1;+ for (const [entity] of prevs) if (clicks.some((c) => c.target === entity)) dir = -1;+ if (dir === 0) return;++ state.current = (state.current + dir + SHOWCASE_COUNT) % SHOWCASE_COUNT;+ const sc = SHOWCASES[state.current];++ for (const [entity] of owned) cmds.despawn(entity);+ for (const [, vol] of volumes) vol.effects = cloneEffects(sc.global);+ if (sc.local) spawnLocalVolume(cmds);++ for (const [, text] of titles) text.content = sc.name;+ for (const [, text] of hints) text.content = sc.hint;+ },+ { name: 'SwitchSystem' },+);