Skip to content

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.

feat(render): occlusion is a fraction of the neighbourhood, and one backend had it upside down

esengine1abf1f330c9a
diff --git a/examples/third-person-3d/assets/scenes/main.esscene b/examples/third-person-3d/assets/scenes/main.esscene
index 9d88210a9..14530e4f1 100644
--- a/examples/third-person-3d/assets/scenes/main.esscene
+++ b/examples/third-person-3d/assets/scenes/main.esscene
@@ -37,6 +37,26 @@
"distance": 420,
"pitch": 18
}
+ },
+ {
+ "type": "PostProcessVolume",
+ "data": {
+ "isGlobal": true,
+ "priority": 0,
+ "weight": 1,
+ "effects": [
+ {
+ "type": "ssao",
+ "enabled": true,
+ "uniforms": {
+ "u_radius": 70,
+ "u_intensity": 1,
+ "u_bias": 0.12,
+ "u_power": 1.6
+ }
+ }
+ ]
+ }
}
]
},
@@ -584,4 +604,4 @@
]
}
]
-}
\ No newline at end of file
+}
diff --git a/fixtures/scenes/ssao.esscene b/fixtures/scenes/ssao.esscene
new file mode 100644
index 000000000..56eb4ec47
--- /dev/null
+++ b/fixtures/scenes/ssao.esscene
@@ -0,0 +1,342 @@
+{
+ "version": 4,
+ "name": "Ssao",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 320,
+ "z": 480
+ },
+ "rotation": {
+ "x": -0.284,
+ "y": 0,
+ "z": 0,
+ "w": 0.9588
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 0,
+ "fov": 60,
+ "nearPlane": 10,
+ "farPlane": 3000,
+ "isActive": true,
+ "priority": 0
+ }
+ },
+ {
+ "type": "PostProcessVolume",
+ "data": {
+ "isGlobal": true,
+ "priority": 0,
+ "weight": 1,
+ "effects": [
+ {
+ "type": "ssao",
+ "enabled": true,
+ "uniforms": {
+ "u_radius": 100,
+ "u_intensity": 1,
+ "u_bias": 0.12,
+ "u_power": 1.6
+ }
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Floor",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": -200
+ },
+ "scale": {
+ "x": 14,
+ "y": 1,
+ "z": 14
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:plane",
+ "color": {
+ "r": 0.75,
+ "g": 0.75,
+ "b": 0.75,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "WallBack",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 125,
+ "z": -600
+ },
+ "scale": {
+ "x": 14,
+ "y": 2.5,
+ "z": 0.2
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.7,
+ "g": 0.72,
+ "b": 0.78,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 3,
+ "name": "WallLeft",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -600,
+ "y": 125,
+ "z": -200
+ },
+ "scale": {
+ "x": 0.2,
+ "y": 2.5,
+ "z": 8
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.7,
+ "g": 0.72,
+ "b": 0.78,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 4,
+ "name": "Step",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -330,
+ "y": 25,
+ "z": -80
+ },
+ "scale": {
+ "x": 2,
+ "y": 0.5,
+ "z": 2
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.65,
+ "g": 0.75,
+ "b": 0.6,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 5,
+ "name": "BoxContact",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -110,
+ "y": 50,
+ "z": -80
+ },
+ "scale": {
+ "x": 1,
+ "y": 1,
+ "z": 1
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.8,
+ "g": 0.55,
+ "b": 0.4,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 6,
+ "name": "BoxFloating",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 110,
+ "y": 100,
+ "z": -80
+ },
+ "scale": {
+ "x": 1,
+ "y": 1,
+ "z": 1
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "color": {
+ "r": 0.45,
+ "g": 0.65,
+ "b": 0.8,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 7,
+ "name": "Sphere",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 330,
+ "y": 50,
+ "z": -80
+ },
+ "scale": {
+ "x": 1,
+ "y": 1,
+ "z": 1
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:sphere",
+ "color": {
+ "r": 0.78,
+ "g": 0.7,
+ "b": 0.5,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 81355a4cc..8a7c5e9ff 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -6074,7 +6074,7 @@ static prototype: PostProcessPlugin
## PostProcessStack — class @experimental
```
-addPass: (name: string, shader: ShaderHandle) => PostProcessStack
+addPass: (name: string, shader: ShaderHandle, scale?: number) => PostProcessStack
clearDirty: () => void
clearPasses: () => PostProcessStack
destroy: () => void
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index 25c99020e..187a1cb5b 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -6257,7 +6257,7 @@ static prototype: PostProcessPlugin
## PostProcessStack — class @experimental
```
-addPass: (name: string, shader: ShaderHandle) => PostProcessStack
+addPass: (name: string, shader: ShaderHandle, scale?: number) => PostProcessStack
clearDirty: () => void
clearPasses: () => PostProcessStack
destroy: () => void
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 6c627351c..70122b2c8 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -6069,7 +6069,7 @@ static prototype: PostProcessPlugin
## PostProcessStack — class @experimental
```
-addPass: (name: string, shader: ShaderHandle) => PostProcessStack
+addPass: (name: string, shader: ShaderHandle, scale?: number) => PostProcessStack
clearDirty: () => void
clearPasses: () => PostProcessStack
destroy: () => void
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index 2f291b375..24c577262 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -6315,7 +6315,7 @@ static prototype: PostProcessPlugin
## PostProcessStack — class @experimental
```
-addPass: (name: string, shader: ShaderHandle) => PostProcessStack
+addPass: (name: string, shader: ShaderHandle, scale?: number) => PostProcessStack
clearDirty: () => void
clearPasses: () => PostProcessStack
destroy: () => void
diff --git a/sdk/etc/wasm.api.md b/sdk/etc/wasm.api.md
index c0c749d6a..cf3505de7 100644
--- a/sdk/etc/wasm.api.md
+++ b/sdk/etc/wasm.api.md
@@ -326,6 +326,7 @@ postprocess_resize: (width: number, height: number) => void
postprocess_setBypass: (bypass: boolean) => void
postprocess_setOutputTransform: ((transform: number) => void) | undefined
postprocess_setOutputViewport: (x: number, y: number, w: number, h: number) => void
+postprocess_setPassScale: (name: string, scale: number) => void
postprocess_setPassTexture: (passName: string, uniform: string, textureHandle: number) => void
postprocess_setPresentRequired: ((required: boolean) => void) | undefined
postprocess_setScreenUniformFloat: (passName: string, uniform: string, value: number) => void
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index c35b59112..1913ca19b 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -6076,7 +6076,7 @@ static prototype: PostProcessPlugin
## PostProcessStack — class @experimental
```
-addPass: (name: string, shader: ShaderHandle) => PostProcessStack
+addPass: (name: string, shader: ShaderHandle, scale?: number) => PostProcessStack
clearDirty: () => void
clearPasses: () => PostProcessStack
destroy: () => void
diff --git a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts b/sdk/src/ecs/bridge/nativeEngineApi.generated.ts
index 12e64b861..77168a796 100644
--- a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts
+++ b/sdk/src/ecs/bridge/nativeEngineApi.generated.ts
@@ -95,6 +95,7 @@ export interface NativeEngineApi {
postprocess_setBypass?(bypass: boolean): void;
postprocess_setOutputTransform?(transform: number): void;
postprocess_setOutputViewport?(x: number, y: number, w: number, h: number): void;
+ postprocess_setPassScale?(passName: string, scale: number): void;
postprocess_setPassTexture?(passName: string, uniform: string, textureHandle: number): void;
postprocess_setPresentRequired?(required: boolean): void;
postprocess_setScreenUniformFloat?(passName: string, uniform: string, value: number): void;
@@ -331,6 +332,7 @@ export function createNativeEngineApi(
bind('postprocess_setBypass', 'es_postprocess_setBypass', false);
bind('postprocess_setOutputTransform', 'es_postprocess_setOutputTransform', false);
bind('postprocess_setOutputViewport', 'es_postprocess_setOutputViewport', false);
+ bind('postprocess_setPassScale', 'es_postprocess_setPassScale', false);
bind('postprocess_setPassTexture', 'es_postprocess_setPassTexture', false);
bind('postprocess_setPresentRequired', 'es_postprocess_setPresentRequired', false);
bind('postprocess_setScreenUniformFloat', 'es_postprocess_setScreenUniformFloat', false);
diff --git a/sdk/src/postprocess/PostProcessAPI.ts b/sdk/src/postprocess/PostProcessAPI.ts
index 57be24c7b..bfa1e04eb 100644
--- a/sdk/src/postprocess/PostProcessAPI.ts
+++ b/sdk/src/postprocess/PostProcessAPI.ts
@@ -16,7 +16,8 @@ import { PostProcessStack, PostProcessState } from './PostProcessStack';
type PostProcessCore = Required<Pick<NonNullable<EngineApi>,
'postprocess_init' | 'postprocess_shutdown' | 'postprocess_resize'
| 'postprocess_isInitialized' | 'postprocess_begin' | 'postprocess_end'
- | 'postprocess_clearPasses' | 'postprocess_addPass' | 'postprocess_setPassTexture'
+ | 'postprocess_clearPasses' | 'postprocess_addPass' | 'postprocess_setPassScale'
+ | 'postprocess_setPassTexture'
| 'postprocess_setUniformFloat' | 'postprocess_setUniformVec4'
| 'postprocess_setBypass' | 'postprocess_setOutputTransform' | 'postprocess_setPresentRequired'
| 'postprocess_setOutputViewport'
@@ -88,6 +89,9 @@ export function syncStackToWasm(stack: PostProcessStack, force = false): void {
if (!pass.enabled) continue;
try {
m.postprocess_addPass(pass.name, pass.shader);
+ // Only when it is not 1: every pass that predates fractional sizing
+ // means full size, and saying so is the same answer.
+ if (pass.scale !== 1) m.postprocess_setPassScale(pass.name, pass.scale);
} catch (e) {
handleWasmError(e, `PostProcess._applyForCamera:addPass("${pass.name}")`);
continue;
diff --git a/sdk/src/postprocess/PostProcessStack.ts b/sdk/src/postprocess/PostProcessStack.ts
index 6e0d2a8e6..43a582273 100644
--- a/sdk/src/postprocess/PostProcessStack.ts
+++ b/sdk/src/postprocess/PostProcessStack.ts
@@ -11,6 +11,12 @@ export interface PassConfig {
vec4Uniforms: Map<string, Vec4>;
/** Effect-declared textures (LUTs, masks): sampler uniform -> SDK texture handle. */
textureUniforms: Map<string, number>;
+ /**
+ * Fraction of the chain size this pass draws at. 1 is every pass that has
+ * ever existed here; a fraction is for an effect whose result is smooth
+ * enough to compute small and read back big (SSAO's occlusion term).
+ */
+ scale: number;
}
/**
@@ -53,7 +59,7 @@ export class PostProcessStack {
state.stacks.set(this.id, this);
}
- addPass(name: string, shader: ShaderHandle): this {
+ addPass(name: string, shader: ShaderHandle, scale = 1): this {
this.passes_.push({
name,
shader,
@@ -61,6 +67,7 @@ export class PostProcessStack {
floatUniforms: new Map(),
vec4Uniforms: new Map(),
textureUniforms: new Map(),
+ scale,
});
this.dirty_ = true;
return this;
diff --git a/sdk/src/postprocess/effects.ts b/sdk/src/postprocess/effects.ts
index bc2434e62..6cda0a0c0 100644
--- a/sdk/src/postprocess/effects.ts
+++ b/sdk/src/postprocess/effects.ts
@@ -28,6 +28,12 @@ export interface EffectTextureDef {
export interface EffectSubPass {
name: string;
factory: () => ShaderHandle;
+ /**
+ * Fraction of the chain size this sub-pass draws at (default 1). The chain's
+ * LAST pass always draws full size — it feeds the blit — so a fractional
+ * effect ends on a pass that reads the small result and writes the big one.
+ */
+ scale?: number;
}
export interface EffectDef {
@@ -202,6 +208,36 @@ registerEffect({
// and a colour row is an editor surface of its own rather than part of this.
});
+registerEffect({
+ type: 'ssao',
+ label: 'Ambient Occlusion',
+ factory: () => postProcessEffects.createSsaoAo(),
+ // Four knobs, each a term in the estimator. Sample count, spiral turns and
+ // the blur's slope limit stay constants in the shader: a number nobody can
+ // set right is not a setting, it is a way to break the effect.
+ uniforms: [
+ // A WORLD length: positions come back in world space, so this is "how far
+ // around a point counts as its neighbourhood", not a pixel count.
+ { name: 'u_radius', label: 'Radius', min: 1, max: 400, step: 1, defaultValue: 60 },
+ { name: 'u_intensity', label: 'Intensity', min: 0, max: 2, step: 0.01, defaultValue: 1 },
+ // How far above the tangent plane a sample must sit to count. This is
+ // what keeps a flat floor from occluding itself into grey.
+ { name: 'u_bias', label: 'Bias', min: 0, max: 0.6, step: 0.005, defaultValue: 0.12 },
+ // Contrast on the finished term; neutral at 1, so a blend toward "no
+ // effect" has to fade toward 1 and not 0.
+ { name: 'u_power', label: 'Power', min: 0.5, max: 4, step: 0.05, defaultValue: 1.6, neutralValue: 1 },
+ ],
+ // Half resolution for the three passes that carry the term, full for the one
+ // that applies it — the chain's last pass feeds the blit and is full size
+ // regardless, so the composite is where the upsample has to happen.
+ multiPass: [
+ { name: 'ssao_ao', factory: () => postProcessEffects.createSsaoAo(), scale: 0.5 },
+ { name: 'ssao_blur_x', factory: () => postProcessEffects.createSsaoBlur(0), scale: 0.5 },
+ { name: 'ssao_blur_y', factory: () => postProcessEffects.createSsaoBlur(1), scale: 0.5 },
+ { name: 'ssao_composite', factory: () => postProcessEffects.createSsaoComposite() },
+ ],
+});
+
registerEffect({
type: 'lutGrade',
label: 'LUT Grade',
diff --git a/sdk/src/postprocess/postProcessEffects.ts b/sdk/src/postprocess/postProcessEffects.ts
index 7a6cb6c29..677062ded 100644
--- a/sdk/src/postprocess/postProcessEffects.ts
+++ b/sdk/src/postprocess/postProcessEffects.ts
@@ -16,6 +16,63 @@
import type { ShaderHandle } from '../render/material';
import { Material } from '../render/material';
+/**
+ * Depth-reading helpers the three SSAO passes share, in both languages. One
+ * definition each: a fix that reached only the first of three copies compiled
+ * fine and drew a black screen.
+ */
+const SSAO_GLSL = `/// A SCREEN texel: +y up, origin bottom-left, and the same number on both
+/// backends. Its inverse round-trips through a uv, which is backend-independent
+/// because one vertex stage serves both.
+ivec2 screenTexel(vec2 uv, ivec2 size) {
+ return clamp(ivec2(uv * vec2(size)), ivec2(0), size - ivec2(1));
+}
+vec2 uvOfTexel(ivec2 t, ivec2 size) {
+ return (vec2(t) + 0.5) / vec2(size);
+}
+/// The one place the row order matters: GL numbers rows from the BOTTOM, so a
+/// screen texel is already the row.
+float depthAt(ivec2 t, ivec2 size) {
+ ivec2 q = clamp(t, ivec2(0), size - ivec2(1));
+ return texelFetch(u_sceneDepth, q, 0).r;
+}
+vec3 worldAt(ivec2 t, ivec2 size) {
+ ivec2 q = clamp(t, ivec2(0), size - ivec2(1));
+ return worldFromDepth(uvOfTexel(q, size), depthAt(q, size));
+}
+/// World distance along the view ray per unit of window depth, at THIS pixel.
+/// One derivative here replaces an un-projection per tap. Measured rather than
+/// assumed, so it holds for both projections.
+float worldPerDepth(vec2 uv, float d, vec3 P) {
+ float e = max((1.0 - d) * 0.01, 1e-5);
+ // Signed so the probe stays inside the depth range at the far plane.
+ float de = d + e > 1.0 ? -e : e;
+ return length(worldFromDepth(uv, d + de) - P) / abs(de);
+}`;
+
+const SSAO_WGSL = `fn screenTexel(uv : vec2f, size : vec2i) -> vec2i {
+ return clamp(vec2i(uv * vec2f(size)), vec2i(0), size - vec2i(1));
+}
+fn uvOfTexel(t : vec2i, size : vec2i) -> vec2f {
+ return (vec2f(t) + 0.5) / vec2f(size);
+}
+// The one place the row order matters: row 0 is the TOP here and the BOTTOM on
+// GL, so a screen texel is the mirrored row.
+fn depthAt(t : vec2i, size : vec2i) -> f32 {
+ let q = clamp(t, vec2i(0), size - vec2i(1));
+ return textureLoad(t7, vec2i(q.x, size.y - 1 - q.y), 0);
+}
+fn worldAt(t : vec2i, size : vec2i) -> vec3f {
+ let q = clamp(t, vec2i(0), size - vec2i(1));
+ return worldFromDepth(uvOfTexel(q, size), depthAt(q, size));
+}
+fn worldPerDepth(uv : vec2f, d : f32, P : vec3f) -> f32 {
+ let e = max((1.0 - d) * 0.01, 1e-5);
+ var e2 = e;
+ if (d + e > 1.0) { e2 = -e; }
+ return length(worldFromDepth(uv, d + e2) - P) / abs(e2);
+}`;
+
export const postProcessEffects = {
createLutGrade(): ShaderHandle {
// True LUT color grading: a 2D-packed 32^3 LUT (1024x32 — 32 slices of
@@ -831,6 +888,396 @@ void main() {
return textureSampleLevel(t0, s0, uv, 0.0);
}
#pragma end
+`;
+ return Material.compileShader(source);
+ },
+
+ /**
+ * SSAO, pass 1 of 4: the occlusion term, at half resolution. No G-buffer —
+ * scene depth and the injected `worldFromDepth` are the whole input, and
+ * positions come back in WORLD space, so the radius is a world length.
+ * Coordinates are SCREEN texels (+y up); only `depthAt` knows the row order.
+ */
+ createSsaoAo(): ShaderHandle {
+ const source = `#pragma shader "PP SSAO"
+#pragma version 300 es
+#pragma domain PostProcess
+#pragma param u_radius float default(60) range(1,400)
+#pragma param u_intensity float default(1) range(0,2)
+#pragma param u_bias float default(0.12) range(0,0.6)
+#pragma param u_power float default(1.6) range(0.5,4)
+
+#pragma fragment
+precision highp float;
+
+in vec2 v_texCoord;
+uniform highp sampler2D u_sceneDepth;
+out vec4 fragColor;
+
+${SSAO_GLSL}
+
+const int K = 12;
+const float TAU = 6.28318530718;
+
+void main() {
+ // Depth is full resolution and this pass is not, so the texel comes from the
+ // uv — gl_FragCoord here counts THIS pass's smaller grid.
+ ivec2 size = textureSize(u_sceneDepth, 0);
+ ivec2 c = screenTexel(v_texCoord, size);
+ float d = depthAt(c, size);
+ // The cleared far plane is the absence of a surface: nothing there is
+ // occluded, and shading it would ring the sky in grey.
+ if (d >= 1.0) { fragColor = vec4(1.0); return; }
+
+ // The TEXEL CENTRE, not this pass's uv: at half resolution they differ by
+ // half a depth texel, and the tangents below are one texel long. Mixing the
+ // two conventions reconstructs noise instead of a normal.
+ vec2 cuv = uvOfTexel(c, size);
+ vec3 P = worldFromDepth(cuv, d);
+
+ // The NEARER neighbour on each axis. Across a silhouette the far side is a
+ // different surface, and a centred derivative would average the two into a
+ // normal facing neither — the smeared ring a naive reconstruction leaves.
+ float dl = depthAt(c + ivec2(-1, 0), size);
+ float dr = depthAt(c + ivec2( 1, 0), size);
+ float dd = depthAt(c + ivec2(0, -1), size);
+ float du = depthAt(c + ivec2(0, 1), size);
+ vec3 ax = abs(dr - d) < abs(dl - d) ? worldAt(c + ivec2(1, 0), size) - P
+ : P - worldAt(c + ivec2(-1, 0), size);
+ vec3 ay = abs(du - d) < abs(dd - d) ? worldAt(c + ivec2(0, 1), size) - P
+ : P - worldAt(c + ivec2(0, -1), size);
+ vec3 N = normalize(cross(ax, ay));
+ // Which side each pick came from decides the sign of the cross; the camera
+ // settles it, because a visible surface faces the eye.
+ if (dot(N, viewDirection(P)) < 0.0) N = -N;
+
+ // A world radius spans different pixel counts near and far. One texel step
+ // un-projected AT THIS DEPTH measures that scale without a projection matrix
+ // or a neighbour's geometry. The ceiling is the bandwidth budget.
+ float worldPerTexel = max(length(worldFromDepth(cuv + vec2(1.0 / float(size.x), 0.0), d) - P), 1e-6);
+ float radiusTexels = clamp(u_radius / worldPerTexel, 2.0, 96.0);
+
+ // A 4x4 rotation scrambled by a factor coprime to 16, so the blur averages a
+ // pattern and not a band. Keyed to THIS pass's pixel — c counts full-res
+ // texels, and raw it would give a half-res pass every other phase.
+ ivec2 rp = c / 2;
+ int idx = ((rp.x & 3) * 4 + (rp.y & 3)) * 7;
+ float rot = float(idx - (idx / 16) * 16) * (TAU / 16.0);
+
+ // Every sample votes equally: the result is the fraction of the
+ // neighbourhood closed off. Weighting near taps louder is the tempting
+ // mistake — they land back on this surface and would vote OPEN loudest.
+ float occl = 0.0;
+ for (int i = 0; i < K; ++i) {
+ float a = (float(i) + 0.5) / float(K);
+ float ang = a * 7.0 * TAU + rot;
+ vec2 off = vec2(cos(ang), sin(ang)) * (a * radiusTexels);
+ ivec2 st = c + ivec2(floor(off + 0.5));
+ float ds = depthAt(st, size);
+ // Sky: nothing in that direction, so it votes OPEN by contributing
+ // nothing. This is what lightens the top of a wall toward its edge.
+ if (ds >= 1.0) continue;
+
+ // Measured in radii, so the estimator keeps its shape when the radius
+ // changes and u_bias keeps one meaning.
+ vec3 u = (worldAt(st, size) - P) / max(u_radius, 1e-4);
+ float uu = dot(u, u);
+ // Elevation above the tangent plane, less the bias that stops a flat
+ // surface from occluding itself into grey.
+ float sinE = dot(u, N) / max(sqrt(uu), 1e-6);
+ // Beyond the radius a sample is a different surface, not an occluder:
+ // this is what stops a silhouette haloing what is behind it. Faded, not
+ // cut, or the term pops as geometry crosses the edge under camera motion.
+ float range = 1.0 - smoothstep(0.6, 1.0, uu);
+ occl += max(sinE - u_bias, 0.0) * range;
+ }
+
+ float ao = 1.0 - clamp(occl / float(K) * u_intensity, 0.0, 1.0);
+ fragColor = vec4(vec3(pow(ao, u_power)), 1.0);
+}
+#pragma end
+
+#pragma fragment wgsl
+${SSAO_WGSL}
+
+const K : i32 = 12;
+const TAU : f32 = 6.28318530718;
+
+@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
+ let size = vec2i(textureDimensions(t7, 0));
+ let c = screenTexel(v.v_texCoord, size);
+ let d = depthAt(c, size);
+ if (d >= 1.0) { return vec4f(1.0); }
+
+ let cuv = uvOfTexel(c, size);
+ let P = worldFromDepth(cuv, d);
+
+ let dl = depthAt(c + vec2i(-1, 0), size);
+ let dr = depthAt(c + vec2i( 1, 0), size);
+ let dd = depthAt(c + vec2i(0, -1), size);
+ let du = depthAt(c + vec2i(0, 1), size);
+ var ax = P - worldAt(c + vec2i(-1, 0), size);
+ if (abs(dr - d) < abs(dl - d)) { ax = worldAt(c + vec2i(1, 0), size) - P; }
+ var ay = P - worldAt(c + vec2i(0, -1), size);
+ if (abs(du - d) < abs(dd - d)) { ay = worldAt(c + vec2i(0, 1), size) - P; }
+ var N = normalize(cross(ax, ay));
+ if (dot(N, viewDirection(P)) < 0.0) { N = -N; }
+
+ let worldPerTexel = max(length(worldFromDepth(cuv + vec2f(1.0 / f32(size.x), 0.0), d) - P), 1e-6);
+ let radiusTexels = clamp(mc.u_radius / worldPerTexel, 2.0, 96.0);
+
+ let rp = c / 2;
+ let idx = ((rp.x & 3) * 4 + (rp.y & 3)) * 7;
+ let rot = f32(idx - (idx / 16) * 16) * (TAU / 16.0);
+
+ var occl = 0.0;
+ for (var i : i32 = 0; i < K; i = i + 1) {
+ let a = (f32(i) + 0.5) / f32(K);
+ let ang = a * 7.0 * TAU + rot;
+ let off = vec2f(cos(ang), sin(ang)) * (a * radiusTexels);
+ let st = c + vec2i(floor(off + 0.5));
+ let ds = depthAt(st, size);
+ if (ds >= 1.0) { continue; }
+
+ let u = (worldAt(st, size) - P) / max(mc.u_radius, 1e-4);
+ let uu = dot(u, u);
+ let sinE = dot(u, N) / max(sqrt(uu), 1e-6);
+ let range = 1.0 - smoothstep(0.6, 1.0, uu);
+ occl = occl + max(sinE - mc.u_bias, 0.0) * range;
+ }
+
+ let ao = 1.0 - clamp(occl / f32(K) * mc.u_intensity, 0.0, 1.0);
+ return vec4f(vec3f(pow(ao, mc.u_power)), 1.0);
+}
+#pragma end
+`;
+ return Material.compileShader(source);
+ },
+
+ /**
+ * SSAO, passes 2 and 3: a separable blur that will not cross a depth edge,
+ * or a contact shadow ends up on the wall behind. Each tap is weighted by
+ * its gap ALONG THE VIEW RAY in world units against the pixel's own scale,
+ * so one constant holds near and far where a raw depth compare would not.
+ */
+ createSsaoBlur(axis: 0 | 1): ShaderHandle {
+ const step = axis === 0 ? 'vec2(1.0, 0.0)' : 'vec2(0.0, 1.0)';
+ const stepW = axis === 0 ? 'vec2f(1.0, 0.0)' : 'vec2f(0.0, 1.0)';
+ const source = `#pragma shader "PP SSAO Blur ${axis.toFixed(0)}"
+#pragma version 300 es
+#pragma domain PostProcess
+
+#pragma fragment
+precision highp float;
+
+in vec2 v_texCoord;
+uniform sampler2D u_texture;
+uniform highp sampler2D u_sceneDepth;
+out vec4 fragColor;
+
+${SSAO_GLSL}
+
+const int R = 3;
+/// A tap whose view-ray gap exceeds this many texel-widths is another surface.
+const float SLOPE = 4.0;
+
+void main() {
+ ivec2 dsize = textureSize(u_sceneDepth, 0);
+ ivec2 hsize = textureSize(u_texture, 0);
+ ivec2 dc = screenTexel(v_texCoord, dsize);
+ float d = depthAt(dc, dsize);
+ if (d >= 1.0) { fragColor = texture(u_texture, v_texCoord); return; }
+
+ vec2 cuv = uvOfTexel(dc, dsize);
+ vec3 P = worldFromDepth(cuv, d);
+ // The pixel's own world scale, from one texel step at ITS depth — the same
+ // measure the AO pass sizes its radius with.
+ float worldPerTexel = max(length(worldFromDepth(cuv + vec2(1.0 / float(dsize.x), 0.0), d) - P), 1e-6);
+ float tol = worldPerTexel * SLOPE;
+ float perDepth = worldPerDepth(cuv, d, P);
+
+ vec2 stepUv = ${step} / vec2(hsize);
+ float sum = 0.0;
+ float wsum = 0.0;
+ for (int i = -R; i <= R; ++i) {
+ vec2 uv = v_texCoord + stepUv * float(i);
+ float g = exp(-float(i * i) / 8.0);
+
+ ivec2 dt = screenTexel(uv, dsize);
+ float dj = depthAt(dt, dsize);
+ // Off the far plane there is no surface to agree with; the Gaussian
+ // alone would let the sky pull the edge of a silhouette toward white.
+ float w = dj >= 1.0 ? 0.0
+ : g * (1.0 - clamp(abs(dj - d) * perDepth / tol, 0.0, 1.0));
+ sum += texture(u_texture, uv).r * w;
+ wsum += w;
+ }
+ // Every neighbour rejected (a one-pixel sliver): keep this pixel's own value
+ // rather than dividing by nothing.
+ float ao = wsum > 1e-5 ? sum / wsum : texture(u_texture, v_texCoord).r;
+ fragColor = vec4(vec3(ao), 1.0);
+}
+#pragma end
+
+#pragma fragment wgsl
+${SSAO_WGSL}
+
+const R : i32 = 3;
+const SLOPE : f32 = 4.0;
+
+@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
+ let dsize = vec2i(textureDimensions(t7, 0));
+ let hsize = vec2i(textureDimensions(t0, 0));
+ let dc = screenTexel(v.v_texCoord, dsize);
+ let d = depthAt(dc, dsize);
+ if (d >= 1.0) { return textureSampleLevel(t0, s0, v.v_texCoord, 0.0); }
+
+ let cuv = uvOfTexel(dc, dsize);
+ let P = worldFromDepth(cuv, d);
+ let worldPerTexel = max(length(worldFromDepth(cuv + vec2f(1.0 / f32(dsize.x), 0.0), d) - P), 1e-6);
+ let tol = worldPerTexel * SLOPE;
+ let perDepth = worldPerDepth(cuv, d, P);
+
+ let stepUv = ${stepW} / vec2f(hsize);
+ var sum = 0.0;
+ var wsum = 0.0;
+ for (var i : i32 = -R; i <= R; i = i + 1) {
+ let uv = v.v_texCoord + stepUv * f32(i);
+ let g = exp(-f32(i * i) / 8.0);
+
+ let dt = screenTexel(uv, dsize);
+ let dj = depthAt(dt, dsize);
+ var w = 0.0;
+ if (dj < 1.0) {
+ w = g * (1.0 - clamp(abs(dj - d) * perDepth / tol, 0.0, 1.0));
+ }
+ sum = sum + textureSampleLevel(t0, s0, uv, 0.0).r * w;
+ wsum = wsum + w;
+ }
+ var ao = textureSampleLevel(t0, s0, v.v_texCoord, 0.0).r;
+ if (wsum > 1e-5) { ao = sum / wsum; }
+ return vec4f(vec3f(ao), 1.0);
+}
+#pragma end
+`;
+ return Material.compileShader(source);
+ },
+
+ /**
+ * SSAO, pass 4 of 4: upsample the half-resolution term and apply it. Plain
+ * bilinear would undo the blur's care — a half-res texel straddling a
+ * silhouette bleeds back across it — so the four candidates carry the same
+ * view-ray gap weight. The scene arrives at unit 1, as bloom's composite.
+ */
+ createSsaoComposite(): ShaderHandle {
+ const source = `#pragma shader "PP SSAO Composite"
+#pragma version 300 es
+#pragma domain PostProcess
+
+#pragma fragment
+precision highp float;
+
+in vec2 v_texCoord;
+uniform sampler2D u_texture;
+uniform sampler2D u_sceneTexture;
+uniform highp sampler2D u_sceneDepth;
+out vec4 fragColor;
+
+${SSAO_GLSL}
+
+const float SLOPE = 4.0;
+
+void main() {
+ vec4 scene = texture(u_sceneTexture, v_texCoord);
+ ivec2 dsize = textureSize(u_sceneDepth, 0);
+ ivec2 dc = screenTexel(v_texCoord, dsize);
+ float d = depthAt(dc, dsize);
+ if (d >= 1.0) { fragColor = scene; return; }
+
+ vec2 cuv = uvOfTexel(dc, dsize);
+ vec3 P = worldFromDepth(cuv, d);
+ float worldPerTexel = max(length(worldFromDepth(cuv + vec2(1.0 / float(dsize.x), 0.0), d) - P), 1e-6);
+ float tol = worldPerTexel * SLOPE;
+ float perDepth = worldPerDepth(cuv, d, P);
+
+ // The four half-resolution texels this pixel falls between, in SCREEN texel
+ // space so the bilinear weights mean the same on both backends.
+ ivec2 hsize = textureSize(u_texture, 0);
+ vec2 hf = v_texCoord * vec2(hsize) - 0.5;
+ ivec2 base = ivec2(floor(hf));
+ vec2 frac = hf - vec2(base);
+
+ float sum = 0.0;
+ float wsum = 0.0;
+ for (int j = 0; j < 4; ++j) {
+ ivec2 o = ivec2(j & 1, j >> 1);
+ ivec2 t = clamp(base + o, ivec2(0), hsize - ivec2(1));
+ vec2 uv = uvOfTexel(t, hsize);
+ float bw = (o.x == 1 ? frac.x : 1.0 - frac.x) * (o.y == 1 ? frac.y : 1.0 - frac.y);
+
+ ivec2 dt = screenTexel(uv, dsize);
+ float dj = depthAt(dt, dsize);
+ float w = dj >= 1.0 ? 0.0
+ : bw * (1.0 - clamp(abs(dj - d) * perDepth / tol, 0.0, 1.0));
+ sum += texture(u_texture, uv).r * w;
+ wsum += w;
+ }
+ // No candidate agreed: this pixel is its own sliver, so take the term
+ // straight rather than leaving it unshaded.
+ float ao = wsum > 1e-5 ? sum / wsum : texture(u_texture, v_texCoord).r;
+ fragColor = vec4(scene.rgb * ao, scene.a);
+}
+#pragma end
+
+#pragma fragment wgsl
+${SSAO_WGSL}
+
+const SLOPE : f32 = 4.0;
+
+@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
+ let scene = textureSampleLevel(t1, s1, v.v_texCoord, 0.0);
+ let dsize = vec2i(textureDimensions(t7, 0));
+ let dc = screenTexel(v.v_texCoord, dsize);
+ let d = depthAt(dc, dsize);
+ if (d >= 1.0) { return scene; }
+
+ let cuv = uvOfTexel(dc, dsize);
+ let P = worldFromDepth(cuv, d);
+ let worldPerTexel = max(length(worldFromDepth(cuv + vec2f(1.0 / f32(dsize.x), 0.0), d) - P), 1e-6);
+ let tol = worldPerTexel * SLOPE;
+ let perDepth = worldPerDepth(cuv, d, P);
+
+ let hsize = vec2i(textureDimensions(t0, 0));
+ let hf = v.v_texCoord * vec2f(hsize) - 0.5;
+ let base = vec2i(floor(hf));
+ let frac = hf - vec2f(base);
+
+ var sum = 0.0;
+ var wsum = 0.0;
+ for (var j : i32 = 0; j < 4; j = j + 1) {
+ let o = vec2i(j & 1, j >> 1);
+ let t = clamp(base + o, vec2i(0), hsize - vec2i(1));
+ let uv = uvOfTexel(t, hsize);
+ var bwx = 1.0 - frac.x;
+ if (o.x == 1) { bwx = frac.x; }
+ var bwy = 1.0 - frac.y;
+ if (o.y == 1) { bwy = frac.y; }
+ let bw = bwx * bwy;
+
+ let dt = screenTexel(uv, dsize);
+ let dj = depthAt(dt, dsize);
+ var w = 0.0;
+ if (dj < 1.0) {
+ w = bw * (1.0 - clamp(abs(dj - d) * perDepth / tol, 0.0, 1.0));
+ }
+ sum = sum + textureSampleLevel(t0, s0, uv, 0.0).r * w;
+ wsum = wsum + w;
+ }
+ var ao = textureSampleLevel(t0, s0, v.v_texCoord, 0.0).r;
+ if (wsum > 1e-5) { ao = sum / wsum; }
+ return vec4f(scene.rgb * ao, scene.a);
+}
+#pragma end
`;
return Material.compileShader(source);
},
diff --git a/sdk/src/postprocess/volumeSystem.ts b/sdk/src/postprocess/volumeSystem.ts
index 8bcb586fc..c5fd5bc00 100644
--- a/sdk/src/postprocess/volumeSystem.ts
+++ b/sdk/src/postprocess/volumeSystem.ts
@@ -109,7 +109,7 @@ function applyBlendedEffects(
if (def.multiPass) {
for (const subPass of def.multiPass) {
const shader = getOrCreateShader(api, subPass.name, subPass.factory);
- stack.addPass(subPass.name, shader);
+ stack.addPass(subPass.name, shader, subPass.scale ?? 1);
for (const [uniformName, uniformValue] of effectData.uniforms) {
stack.setUniform(subPass.name, uniformName, uniformValue);
}
diff --git a/sdk/src/wasm.ts b/sdk/src/wasm.ts
index 232fed99e..3c0986794 100644
--- a/sdk/src/wasm.ts
+++ b/sdk/src/wasm.ts
@@ -396,6 +396,7 @@ export interface ESEngineModule {
postprocess_shutdown(): void;
postprocess_resize(width: number, height: number): void;
postprocess_addPass(name: string, shaderHandle: number): number;
+ postprocess_setPassScale(name: string, scale: number): void;
postprocess_setUniformFloat(passName: string, uniform: string, value: number): void;
postprocess_setPassTexture(passName: string, uniform: string, textureHandle: number): void;
postprocess_setUniformVec4(passName: string, uniform: string, x: number, y: number, z: number, w: number): void;
diff --git a/sdk/tests/shader-twins.test.ts b/sdk/tests/shader-twins.test.ts
index 8415840d5..8a0e83ca5 100644
--- a/sdk/tests/shader-twins.test.ts
+++ b/sdk/tests/shader-twins.test.ts
@@ -53,7 +53,7 @@ describe('embedded .esshader structure', () => {
it('found the filter, effect and grid sources', () => {
expect(CASES.filter((c) => c.name.startsWith('filters.ts')).length).toBe(1);
expect(CASES.filter((c) => c.name.startsWith('spriteFilter.ts')).length).toBe(2);
- expect(CASES.filter((c) => c.name.startsWith('postProcessEffects.ts')).length).toBe(16);
+ expect(CASES.filter((c) => c.name.startsWith('postProcessEffects.ts')).length).toBe(19);
expect(CASES.filter((c) => c.name.startsWith('editorGridRenderer.ts')).length).toBe(1);
});
diff --git a/src/esengine/bindings/PostProcessBindings.cpp b/src/esengine/bindings/PostProcessBindings.cpp
index f7028ad62..739870618 100644
--- a/src/esengine/bindings/PostProcessBindings.cpp
+++ b/src/esengine/bindings/PostProcessBindings.cpp
@@ -65,6 +65,12 @@ u32 postprocess_addPass(const std::string& name, u32 shaderHandle) {
return g_postProcessPipeline->addPass(name, resource::ShaderHandle(shaderHandle));
}
+void postprocess_setPassScale(const std::string& passName, f32 scale) {
+ if (g_postProcessPipeline) {
+ g_postProcessPipeline->setPassScale(passName, scale);
+ }
+}
+
void postprocess_setUniformFloat(const std::string& passName,
const std::string& uniform, f32 value) {
if (g_postProcessPipeline) {
diff --git a/src/esengine/bindings/PostProcessBindings.hpp b/src/esengine/bindings/PostProcessBindings.hpp
index 7cf087a7d..0db9f2514 100644
--- a/src/esengine/bindings/PostProcessBindings.hpp
+++ b/src/esengine/bindings/PostProcessBindings.hpp
@@ -12,6 +12,8 @@ bool postprocess_init(u32 width, u32 height);
void postprocess_shutdown();
void postprocess_resize(u32 width, u32 height);
u32 postprocess_addPass(const std::string& name, u32 shaderHandle);
+/** Draw a pass at a fraction of the chain size; the next pass upsamples it. */
+void postprocess_setPassScale(const std::string& passName, f32 scale);
void postprocess_setUniformFloat(const std::string& passName,
const std::string& uniform, f32 value);
void postprocess_setPassTexture(const std::string& passName,
diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cpp
index da3244680..5741155c9 100644
--- a/src/esengine/bindings/WebSDKEntry.cpp
+++ b/src/esengine/bindings/WebSDKEntry.cpp
@@ -571,6 +571,7 @@ EMSCRIPTEN_BINDINGS(esengine_renderer) {
emscripten::function("postprocess_shutdown", &esengine::postprocess_shutdown);
emscripten::function("postprocess_resize", &esengine::postprocess_resize);
emscripten::function("postprocess_addPass", &esengine::postprocess_addPass);
+ emscripten::function("postprocess_setPassScale", &esengine::postprocess_setPassScale);
emscripten::function("postprocess_setUniformFloat", &esengine::postprocess_setUniformFloat);
emscripten::function("postprocess_setUniformVec4", &esengine::postprocess_setUniformVec4);
emscripten::function("postprocess_setPassTexture", &esengine::postprocess_setPassTexture);
diff --git a/src/esengine/renderer/frame/PostProcessPipeline.cpp b/src/esengine/renderer/frame/PostProcessPipeline.cpp
index b0bf5cfb6..ac4bba7cc 100644
--- a/src/esengine/renderer/frame/PostProcessPipeline.cpp
+++ b/src/esengine/renderer/frame/PostProcessPipeline.cpp
@@ -238,6 +238,14 @@ u32 PostProcessPipeline::addPass(const std::string& name, resource::ShaderHandle
return static_cast<u32>(passes_.size() - 1);
}
+void PostProcessPipeline::setPassScale(const std::string& passName, f32 scale) {
+ if (auto* pass = findPass(passName)) {
+ // A pass that draws at zero has no pixels and one that draws above the
+ // chain size would resample upward for nothing: neither is a fraction.
+ pass->scale = std::clamp(scale, 0.01f, 1.0f);
+ }
+}
+
void PostProcessPipeline::releasePassResources(PostProcessPass& pass) {
if (pass.paramUbo != BufferHandle::Invalid) {
device_.deleteBuffer(pass.paramUbo);
@@ -568,7 +576,11 @@ void PostProcessPipeline::runChain(std::vector<PostProcessPass>& passes, rg::Res
// composite (bloom's last link) needs the un-blurred image, and the
// shaders address it as unit 1 — the declaration IS that wiring.
node.reads = {input, scene};
- node.write = graph_->createTarget(i == lastEnabled ? blitDesc : desc);
+ // The last pass feeds the blit, which copies into the output rect at the
+ // chain's size — so it draws full-size whatever fraction it asked for.
+ rg::TargetDesc writeDesc = (i == lastEnabled) ? blitDesc : desc;
+ if (i != lastEnabled) writeDesc.scale = pass.scale;
+ node.write = graph_->createTarget(writeDesc);
node.execute = [this, &pass](const rg::PassContext& ctx) { renderPass(pass, ctx); };
input = node.write;
graph_->addPass(std::move(node));
diff --git a/src/esengine/renderer/frame/PostProcessPipeline.hpp b/src/esengine/renderer/frame/PostProcessPipeline.hpp
index 3a9adcdac..8361d32ae 100644
--- a/src/esengine/renderer/frame/PostProcessPipeline.hpp
+++ b/src/esengine/renderer/frame/PostProcessPipeline.hpp
@@ -61,6 +61,11 @@ struct PostProcessPass {
/// (0 = input, 1 = scene).
std::vector<std::pair<std::string, u32>> textureUniforms;
+ /// Fraction of the chain's size this pass draws at; the pass consuming it
+ /// upsamples. The graph resolves the fraction, and u_viewport still reports
+ /// the CANVAS, so a fractional pass must read its extent off its texture.
+ f32 scale = 1.0f;
+
/// #pragma-param shaders: the pass's packed MaterialConstants payload +
/// its UBO (binding 1) — the same reflected block a material would use.
/// Rebuilt from float/vec4Uniforms over the layout defaults when dirty.
@@ -128,6 +133,8 @@ public:
* @return Index of the added pass
*/
u32 addPass(const std::string& name, resource::ShaderHandle shader);
+ /// Draw @p passName at @p scale of the chain size (clamped to (0, 1]).
+ void setPassScale(const std::string& passName, f32 scale);
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index b1a9b7a7e..a18149472 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -447,6 +447,10 @@ export const SCENES = [
// a 90-degree eye is 1.41x further from the frame's edge than from its centre:
// an effect reading depth paints them alike, and tol 10 does not reach between.
{ id: "distance-fog", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/distance-fog.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/depth-outline.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\": 0.5, \"y\": 0.5, \"rgb\": [107, 176, 143], \"tol\": 10}, {\"x\": 0.0625, \"y\": 0.5, \"rgb\": [134, 174, 176], \"tol\": 10}, {\"x\": 0.4375, \"y\": 0.5, \"rgb\": [190, 85, 92], \"tol\": 14}, {\"x\": 0.6875, \"y\": 0.5, \"rgb\": [200, 60, 62], \"tol\": 14}]" } },
+ // SSAO: one unlit grey floor read at seven places. Contact, corner and
+ // step come back darker than the open floor they are made of, the floating
+ // box does not, and the wall behind a silhouette keeps its colour.
+ { id: "ssao", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/ssao.esscene", ESTELLA_VERIFY_W: "320", ESTELLA_VERIFY_H: "240", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5016,\"y\":0.8996,\"rgb\":[191,191,191],\"tol\":6},{\"x\":0.3762,\"y\":0.4937,\"rgb\":[144,144,144],\"tol\":9},{\"x\":0.627,\"y\":0.4812,\"rgb\":[172,172,172],\"tol\":9},{\"x\":0.8527,\"y\":0.4686,\"rgb\":[147,147,147],\"tol\":9},{\"x\":0.1881,\"y\":0.5272,\"rgb\":[123,141,113],\"tol\":9},{\"x\":0.1285,\"y\":0.1967,\"rgb\":[133,136,148],\"tol\":9},{\"x\":0.627,\"y\":0.2008,\"rgb\":[179,184,199],\"tol\":5}]" } },
{ id: "depth-outline-flat", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/depth-outline-flat.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[230,102,26],\"tol\":20}]" } },
{ id: "mesh-opaque", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mesh-depth.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-depth.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.42,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.58,\"y\":0.5,\"rgb\":[255,0,0],\"tol\":40}]" } },
{ id: "mesh-opaque-off", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SET_FIELD: "{\"entity\":2,\"component\":\"MeshRenderer\",\"key\":\"opaque\",\"value\":false}", ESTELLA_VERIFY_SCENE: "/scenes/mesh-depth.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-depth.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.42,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.58,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":40}]" } },