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.

fix(postprocess): an effect before bloom or SSAO takes effect

esengine66a7f9311781
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 251d382f3..66020ccbc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,7 @@ published separately; it ships inside the editor.
### Fixed
+- A post-process effect placed before bloom or SSAO takes effect. Their last pass laid its result over the untouched scene instead of over what the chain had made so far, so a volume's colour grade, exposure or grayscale — and SSAO, under bloom — vanished whenever bloom or SSAO came after it. They now composite over their own input.
- A double-sided mesh is lit on the side the camera sees. Its back faces took the front's normal, so a leaf, a flag or an awning turned away from the light went black on the side the light actually reached; the normal now flips for a back face, as glTF specifies, in the engine's mesh shader and in the material shaders an imported model uses.
- Normal maps stored in two channels light correctly. The shader rebuilds Z from X and Y instead of reading blue, so a BC5 map, or one a converter wrote with blue at 0 — every normal map of Bistro's glTF conversion — no longer points its surface's normals inward, which left normal-mapped surfaces unlit by their sun.
- Compressed (KTX2) textures on web and mini-games are sampled with their mip chain. The cook has always written one into every texture it compresses, and only level 0 reached the GPU: a compressed texture shimmered as it shrank into the distance, and the rest of its bytes shipped for nothing. A texture decoded to RGBA on a device with no compressed format gets its chain generated.
diff --git a/fixtures/scenes/post-chain-order.esscene b/fixtures/scenes/post-chain-order.esscene
new file mode 100644
index 000000000..2b018f08d
--- /dev/null
+++ b/fixtures/scenes/post-chain-order.esscene
@@ -0,0 +1,153 @@
+{
+ "version": 4,
+ "name": "PostChainOrder",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 300
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 1,
+ "orthoSize": 300,
+ "isActive": true,
+ "priority": 0
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Flat",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "color": {
+ "r": 1,
+ "g": 0,
+ "b": 0,
+ "a": 1
+ },
+ "layer": 0,
+ "enabled": true,
+ "opaque": true,
+ "mesh": "/scenes/textured-quad.esmesh"
+ }
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "Turned",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "rotation": {
+ "w": 0.8660254,
+ "x": 0,
+ "y": 0.5,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "color": {
+ "r": 0,
+ "g": 1,
+ "b": 0,
+ "a": 1
+ },
+ "layer": 0,
+ "enabled": true,
+ "opaque": true,
+ "mesh": "/scenes/textured-quad.esmesh"
+ }
+ }
+ ]
+ },
+ {
+ "id": 3,
+ "name": "Volume",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "PostProcessVolume",
+ "data": {
+ "isGlobal": true,
+ "priority": 0,
+ "weight": 1,
+ "effects": [
+ {
+ "type": "grayscale",
+ "enabled": true,
+ "uniforms": {
+ "u_intensity": 1
+ }
+ },
+ {
+ "type": "bloom",
+ "enabled": true,
+ "uniforms": {
+ "u_threshold": 2,
+ "u_intensity": 0.1,
+ "u_radius": 1
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 70460c7d6..441999307 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -6148,7 +6148,7 @@ static prototype: PostProcessPlugin
## PostProcessStack — class @experimental
```
-addPass: (name: string, shader: ShaderHandle, scale?: number) => PostProcessStack
+addPass: (name: string, shader: ShaderHandle, scale?: number, continuesEffect?: boolean) => PostProcessStack
clearDirty: () => void
clearPasses: () => PostProcessStack
destroy: () => void
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index ef2b2fb4d..914adeb1d 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -6339,7 +6339,7 @@ static prototype: PostProcessPlugin
## PostProcessStack — class @experimental
```
-addPass: (name: string, shader: ShaderHandle, scale?: number) => PostProcessStack
+addPass: (name: string, shader: ShaderHandle, scale?: number, continuesEffect?: boolean) => PostProcessStack
clearDirty: () => void
clearPasses: () => PostProcessStack
destroy: () => void
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index fa78ad5b0..5fd9cec29 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -6143,7 +6143,7 @@ static prototype: PostProcessPlugin
## PostProcessStack — class @experimental
```
-addPass: (name: string, shader: ShaderHandle, scale?: number) => PostProcessStack
+addPass: (name: string, shader: ShaderHandle, scale?: number, continuesEffect?: boolean) => PostProcessStack
clearDirty: () => void
clearPasses: () => PostProcessStack
destroy: () => void
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index b882a97b8..bb27f6f44 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -6413,7 +6413,7 @@ static prototype: PostProcessPlugin
## PostProcessStack — class @experimental
```
-addPass: (name: string, shader: ShaderHandle, scale?: number) => PostProcessStack
+addPass: (name: string, shader: ShaderHandle, scale?: number, continuesEffect?: boolean) => PostProcessStack
clearDirty: () => void
clearPasses: () => PostProcessStack
destroy: () => void
diff --git a/sdk/etc/wasm.api.md b/sdk/etc/wasm.api.md
index 9d5e9b80f..45341c628 100644
--- a/sdk/etc/wasm.api.md
+++ b/sdk/etc/wasm.api.md
@@ -375,6 +375,7 @@ postprocess_setBypass: (bypass: boolean) => void
postprocess_setMsaaSamples: (samples: number) => void
postprocess_setOutputTransform: ((transform: number) => void) | undefined
postprocess_setOutputViewport: (x: number, y: number, w: number, h: number) => void
+postprocess_setPassContinuesEffect: (name: string) => void
postprocess_setPassScale: (name: string, scale: number) => void
postprocess_setPassTexture: (passName: string, uniform: string, textureHandle: number) => void
postprocess_setPresentRequired: ((required: boolean) => void) | undefined
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index 88966b157..fc034d6e1 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -6150,7 +6150,7 @@ static prototype: PostProcessPlugin
## PostProcessStack — class @experimental
```
-addPass: (name: string, shader: ShaderHandle, scale?: number) => PostProcessStack
+addPass: (name: string, shader: ShaderHandle, scale?: number, continuesEffect?: boolean) => 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 9383ed597..7cd86bebd 100644
--- a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts
+++ b/sdk/src/ecs/bridge/nativeEngineApi.generated.ts
@@ -107,6 +107,7 @@ export interface NativeEngineApi {
postprocess_setMsaaSamples?(samples: number): void;
postprocess_setOutputTransform?(transform: number): void;
postprocess_setOutputViewport?(x: number, y: number, w: number, h: number): void;
+ postprocess_setPassContinuesEffect?(passName: string): void;
postprocess_setPassScale?(passName: string, scale: number): void;
postprocess_setPassTexture?(passName: string, uniform: string, textureHandle: number): void;
postprocess_setPresentRequired?(required: boolean): void;
@@ -383,6 +384,7 @@ export function createNativeEngineApi(
bind('postprocess_setMsaaSamples', 'es_postprocess_setMsaaSamples', false);
bind('postprocess_setOutputTransform', 'es_postprocess_setOutputTransform', false);
bind('postprocess_setOutputViewport', 'es_postprocess_setOutputViewport', false);
+ bind('postprocess_setPassContinuesEffect', 'es_postprocess_setPassContinuesEffect', false);
bind('postprocess_setPassScale', 'es_postprocess_setPassScale', false);
bind('postprocess_setPassTexture', 'es_postprocess_setPassTexture', false);
bind('postprocess_setPresentRequired', 'es_postprocess_setPresentRequired', false);
diff --git a/sdk/src/postprocess/PostProcessAPI.ts b/sdk/src/postprocess/PostProcessAPI.ts
index 68dfb1246..a2a83101e 100644
--- a/sdk/src/postprocess/PostProcessAPI.ts
+++ b/sdk/src/postprocess/PostProcessAPI.ts
@@ -17,6 +17,7 @@ type PostProcessCore = Required<Pick<NonNullable<EngineApi>,
'postprocess_init' | 'postprocess_shutdown' | 'postprocess_resize'
| 'postprocess_isInitialized' | 'postprocess_begin' | 'postprocess_end'
| 'postprocess_clearPasses' | 'postprocess_addPass' | 'postprocess_setPassScale'
+ | 'postprocess_setPassContinuesEffect'
| 'postprocess_setPassTexture'
| 'postprocess_setUniformFloat' | 'postprocess_setUniformVec4'
| 'postprocess_setBypass' | 'postprocess_setOutputTransform' | 'postprocess_setMsaaSamples'
@@ -118,6 +119,7 @@ export function syncStackToWasm(stack: PostProcessStack, force = false): void {
// 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);
+ if (pass.continuesEffect) m.postprocess_setPassContinuesEffect(pass.name);
} 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 43a582273..108bcfe50 100644
--- a/sdk/src/postprocess/PostProcessStack.ts
+++ b/sdk/src/postprocess/PostProcessStack.ts
@@ -17,6 +17,9 @@ export interface PassConfig {
* enough to compute small and read back big (SSAO's occlusion term).
*/
scale: number;
+ /** A later pass of a multi-pass effect: its composite reads the input the
+ * effect started from rather than the pass before it. */
+ continuesEffect: boolean;
}
/**
@@ -59,7 +62,7 @@ export class PostProcessStack {
state.stacks.set(this.id, this);
}
- addPass(name: string, shader: ShaderHandle, scale = 1): this {
+ addPass(name: string, shader: ShaderHandle, scale = 1, continuesEffect = false): this {
this.passes_.push({
name,
shader,
@@ -68,6 +71,7 @@ export class PostProcessStack {
vec4Uniforms: new Map(),
textureUniforms: new Map(),
scale,
+ continuesEffect,
});
this.dirty_ = true;
return this;
diff --git a/sdk/src/postprocess/volumeSystem.ts b/sdk/src/postprocess/volumeSystem.ts
index c5fd5bc00..5d163a736 100644
--- a/sdk/src/postprocess/volumeSystem.ts
+++ b/sdk/src/postprocess/volumeSystem.ts
@@ -107,9 +107,9 @@ function applyBlendedEffects(
if (!def) continue;
if (def.multiPass) {
- for (const subPass of def.multiPass) {
+ for (const [index, subPass] of def.multiPass.entries()) {
const shader = getOrCreateShader(api, subPass.name, subPass.factory);
- stack.addPass(subPass.name, shader, subPass.scale ?? 1);
+ stack.addPass(subPass.name, shader, subPass.scale ?? 1, index > 0);
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 e19683867..929cb9637 100644
--- a/sdk/src/wasm.ts
+++ b/sdk/src/wasm.ts
@@ -500,6 +500,7 @@ export interface ESEngineModule {
postprocess_resize(width: number, height: number): void;
postprocess_addPass(name: string, shaderHandle: number): number;
postprocess_setPassScale(name: string, scale: number): void;
+ postprocess_setPassContinuesEffect(name: string): void;
postprocess_setMsaaSamples(samples: number): void;
postprocess_effectiveMsaaSamples?(): number;
postprocess_maxMsaaSamples?(): number;
diff --git a/src/esengine/bindings/PostProcessBindings.cpp b/src/esengine/bindings/PostProcessBindings.cpp
index dd3ad6a4d..c0be6e594 100644
--- a/src/esengine/bindings/PostProcessBindings.cpp
+++ b/src/esengine/bindings/PostProcessBindings.cpp
@@ -104,6 +104,12 @@ void postprocess_setPassScale(const std::string& passName, f32 scale) {
}
}
+void postprocess_setPassContinuesEffect(const std::string& passName) {
+ if (g_postProcessPipeline) {
+ g_postProcessPipeline->setPassContinuesEffect(passName);
+ }
+}
+
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 f354e9b83..da2b2db76 100644
--- a/src/esengine/bindings/PostProcessBindings.hpp
+++ b/src/esengine/bindings/PostProcessBindings.hpp
@@ -37,6 +37,8 @@ i32 postprocess_hdrFormat(uintptr_t outPtr);
std::string postprocess_hdrFormatNames();
/** Draw a pass at a fraction of the chain size; the next pass upsamples it. */
void postprocess_setPassScale(const std::string& passName, f32 scale);
+/** A later pass of a multi-pass effect: it composites over that effect's input. */
+void postprocess_setPassContinuesEffect(const std::string& passName);
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 edd93d397..0822b4af9 100644
--- a/src/esengine/bindings/WebSDKEntry.cpp
+++ b/src/esengine/bindings/WebSDKEntry.cpp
@@ -580,6 +580,7 @@ EMSCRIPTEN_BINDINGS(esengine_renderer) {
emscripten::function("postprocess_resize", &esengine::postprocess_resize);
emscripten::function("postprocess_addPass", &esengine::postprocess_addPass);
emscripten::function("postprocess_setPassScale", &esengine::postprocess_setPassScale);
+ emscripten::function("postprocess_setPassContinuesEffect", &esengine::postprocess_setPassContinuesEffect);
emscripten::function("postprocess_setMsaaSamples", &esengine::postprocess_setMsaaSamples);
emscripten::function("postprocess_effectiveMsaaSamples", &esengine::postprocess_effectiveMsaaSamples);
emscripten::function("postprocess_maxMsaaSamples", &esengine::postprocess_maxMsaaSamples);
diff --git a/src/esengine/renderer/frame/PostProcessPipeline.cpp b/src/esengine/renderer/frame/PostProcessPipeline.cpp
index c7ab1fe94..22ddb7a5e 100644
--- a/src/esengine/renderer/frame/PostProcessPipeline.cpp
+++ b/src/esengine/renderer/frame/PostProcessPipeline.cpp
@@ -251,6 +251,10 @@ void PostProcessPipeline::setPassScale(const std::string& passName, f32 scale) {
}
}
+void PostProcessPipeline::setPassContinuesEffect(const std::string& passName) {
+ if (auto* pass = findPass(passName)) pass->continuesEffect = true;
+}
+
void PostProcessPipeline::releasePassResources(PostProcessPass& pass) {
if (pass.paramUbo != BufferHandle::Invalid) {
device_.deleteBuffer(pass.paramUbo);
@@ -583,15 +587,17 @@ void PostProcessPipeline::runChain(std::vector<PostProcessPass>& passes, rg::Res
}
rg::ResourceId input = scene;
+ rg::ResourceId effectInput = scene;
for (usize i = 0; i < passes.size(); ++i) {
auto& pass = passes[i];
if (!pass.enabled) continue;
+ if (!pass.continuesEffect) effectInput = input;
rg::PassDesc node;
node.name = pass.name;
- // The scene rides along as a second read for every pass because a
- // 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};
+ // Unit 1 is the image the pass's effect started from, which a composite
+ // (bloom's and SSAO's last link) lays its result over — not the untouched
+ // scene, which would discard every effect earlier in the chain.
+ node.reads = {input, effectInput};
// 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;
diff --git a/src/esengine/renderer/frame/PostProcessPipeline.hpp b/src/esengine/renderer/frame/PostProcessPipeline.hpp
index c4d5d2f0d..3ddae63af 100644
--- a/src/esengine/renderer/frame/PostProcessPipeline.hpp
+++ b/src/esengine/renderer/frame/PostProcessPipeline.hpp
@@ -67,6 +67,11 @@ struct PostProcessPass {
/// the CANVAS, so a fractional pass must read its extent off its texture.
f32 scale = 1.0f;
+ /// Set on every pass of a multi-pass effect after its first: unit 1 then
+ /// reads the input that effect started from, not this pass's own input. False
+ /// starts an effect, so a single-pass effect sees the chain as it reached it.
+ bool continuesEffect = false;
+
/// #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.
@@ -140,6 +145,8 @@ public:
u32 requestedSamples() const { return requested_samples_; }
/// Draw @p passName at @p scale of the chain size (clamped to (0, 1]).
void setPassScale(const std::string& passName, f32 scale);
+ /// Mark @p passName as a later pass of the effect the pass before it began.
+ void setPassContinuesEffect(const std::string& passName);
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 24d39864f..043feefd4 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -1238,6 +1238,8 @@ export const NOTED = {
{ note: 'Exporting compresses textures on every core' },
'fix(render): a double-sided mesh is lit on the side the camera sees':
{ note: 'A double-sided mesh is lit on the side the camera sees' },
+ 'fix(postprocess): an effect before bloom or SSAO takes effect':
+ { note: 'A post-process effect placed before bloom or SSAO takes effect' },
'fix(eht): the generator writes LF on every platform':
{ internal: 'The engine header tool is a repository generator; on Windows it rewrote every generated file with CRLF, which only a contributor there ever saw.' },
};
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index 3930dab2f..08b48dfb9 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -697,6 +697,10 @@ export const SCENES = [
// through a material (the path an imported model takes) and once without one.
{ id: "mesh-backface-material", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PREFAB: "/scenes/backface-quad.esprefab", ESTELLA_VERIFY_SCENE: "/scenes/mesh-backface.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-backface.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[255,255,255],\"tol\":40}]" } },
{ id: "mesh-backface-plain", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PREFAB: "/scenes/backface-quad-plain.esprefab", ESTELLA_VERIFY_SCENE: "/scenes/mesh-backface.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-backface.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[255,255,255],\"tol\":40}]" } },
+ // Grayscale, then bloom: the red and green quads must come out grey. A multi-pass
+ // effect composites over its own input, and one handed the untouched scene
+ // instead drops every effect before it — the quads kept their colour.
+ { id: "post-chain-order", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/post-chain-order.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\":[150,150,150],\"tol\":20},{\"x\":0.58,\"y\":0.5,\"rgb\":[76,76,76],\"tol\":20}]" } },
// The channels only a material can carry, one quad each, through the products a
// real import wrote. Ambient light only: the black quad's lit half can only be
// emission, the white quad's right half is occluded away, the cutout discards.