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(postprocess): pyramid bloom; a pass reads earlier passes of its effect

yhhc278f79059b4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 78e2046e4..44bf13a00 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,7 @@ published separately; it ships inside the editor.
- **The sky lights the scene.** Sky Atmosphere's **Light the Scene** makes the sky the scene's environment: every Ambient light that names no environment of its own lights with it, its diffuse light from the dome and the clouds and its reflection on metal and wet ground, scaled by the light's colour and intensity as an imported one is. The sky is worked out again as it changes (the sun moving, a weather coming in, clouds drifting), at most once a second; with clouds that takes about 20 ms on a desktop. The sun's disc is left out, since the directional light the sky follows is its direct light. Off by default, so a scene already lit by hand looks as it did.
- **Rooms stay dark under a sky that changes (sky occlusion).** With **Sky occlusion** on in the Lighting settings (`BakedLighting.skyOcclusion`), a probe bake keeps how much of the sky each probe sees instead of the sky itself: the probes hold the lights and their bounces, and the sky the frame has now (a live Sky Atmosphere, a weather, an environment) is added through what each probe sees of it, to the diffuse light and to the sky's reflection. A ball inside a roofed room measured 119 where the baked sky gave it 150, and a ball outside kept its light. A `.esprobes` baked this way carries `skyVisibility`; one without it lights as before. Probes are read per object, as Unity's light probes are: one large mesh spanning indoors and out takes one value.
+- **A post-process pass can read an earlier pass of its own effect.** A texture param named `u_pass_<name>` is bound to the output of the sub-pass called `<name>`, which the chain keeps alive until it has been read, so an effect can be a pyramid (down, then up, adding each level back) and not only a line of passes.
- **A probe volume lights each pixel, not each object.** A lit mesh inside a `LightProbeVolume` reads the baked grid where each of its pixels stands, so one large mesh that spans a dark room and the open yard outside it (a merged building, an imported level) is dark inside and lit outside, as in Unity's Adaptive Probe Volumes; before, it took the one value at its origin and was lit the same end to end. The grids ride one half-float atlas the frame builds when a bake changes. A mesh with lightmap UVs that has no bake still reads its volume per object, as before.
- **Defaults follow the project's units.** Every default that is a length, a speed or an acceleration — a character's capsule, a first-person walk and jump, a view model's near plane, a nav volume's cells, a perceiver's range, a particle's size and speed — is written at 100 units a metre and scaled by the project's units per metre (Project Settings → Physics → 3D). A centimetre project gets exactly the defaults it had; a metre project (an imported glTF scene) now gets metres instead of values 100 times too big. A value a scene states is never scaled. A component declares its own with `worldUnitFields`. Post-process effects follow too: a length a volume leaves unset (rain and snow shelter range and puddle size, SSR distance and thickness, GTAO / SSAO / SSGI radius, contact-shadow length, depth-of-field focus, voxel GI cell, height-fog start and range) takes its default in the project's units, and fog density and height falloff — rates per length — by the inverse; the inspector offers ranges in those units and writes an added effect's defaults in them. A metre project's rain used to shelter within 3 km.
- **`Particle.emitAt(emitter, count, position, { normal, velocity })` spawns a burst where something happened, now** — an impact's sparks, a muzzle's flash — from the emitter's own settings, its shape turned onto the normal, without moving the emitter or replaying it (Unity's `ParticleSystem.Emit`). CPU-simulated emitters.
@@ -35,6 +36,10 @@ published separately; it ships inside the editor.
- **A 3D collider with no RigidBody3D is a static body, as in Unity.** An imported level now collides with a `MeshCollider3D` on each mesh and nothing else; before, a collider without a body built nothing and a character fell through the floor. A collider under an entity with a RigidBody3D is still left to that body, and the collider wireframe marks the same shapes the world builds. Removing an entity's RigidBody3D while its collider stays now leaves a static body rather than none.
- **The 3D physics world is set in Project Settings, not in code.** **Physics → 3D Physics** sets what a scene unit is to the solver (**Units per metre**: 100, a centimetre, as before; 1 for a metre scene such as imported glTF), gravity in m/s², collision steps, velocity and position iterations, the bounce threshold, sleep and the body budget. Iterations and the bounce threshold left at 0 keep each solver's own (Jolt's, or Unity's for PhysX). The 3D world also takes the project's fixed step and collision-layer matrix, which only 2D did. A metre scene used to get gravity 100 times too strong, since everything was read as centimetres. Settings left at their defaults write nothing, so an existing project and its builds are unchanged. In `project.esproject` they are `features.physics.world3d`.
+### Changed
+
+- **Bloom glows round and soft, and costs less.** It is built on a pyramid (a half-size prefilter that tames single blazing pixels, five steps down to 1/64 and five back up, each adding its own size back), as Unreal's and Call of Duty's are, in place of five full-size Kawase passes that threw a diamond-shaped band: a dark edge against a bright sky no longer carries a hard glowing rim. Threshold, Intensity and Radius mean what they did; Radius now widens the whole glow. Scenes with strong bloom will look softer and wider. Measured at 1080p on WebGPU: 0.26 ms against the old 0.45 ms.
+
### Fixed
- **Rain does not fall through a glass roof.** The rain's map of what stands overhead took only what casts a shadow, so a see-through roof set to cast none — glass, as it usually is — left the floor under it wet. A see-through surface keeps rain off whether or not light passes it; what is opaque and casts no shadow (a held gun) still stays out. Gate: ssr-shelter-glass.
diff --git a/docs/astro/src/content/docs/graphics/post-processing.mdx b/docs/astro/src/content/docs/graphics/post-processing.mdx
index 9a27cc552..6303ece93 100644
--- a/docs/astro/src/content/docs/graphics/post-processing.mdx
+++ b/docs/astro/src/content/docs/graphics/post-processing.mdx
@@ -417,6 +417,10 @@ clamping at the 8-bit store:
- **`bloom` with `threshold` above 1** blooms only over-range energy — bright
lights glow while ordinary LDR art stays crisp. This is the classic "emissive
glow" setup: crank a light's `intensity`, set `threshold` ≈ 1.2–1.5.
+ The glow is built on a pyramid of half-size to 1/64-size images, as Unreal's and
+ Call of Duty's are: it falls off round and soft with a long faint tail, and `radius`
+ widens all of it. Keep a bright sky under `threshold`, or every dark edge against it
+ takes the sky's glow.
- **`tonemap`** receives true HDR input, so the ACES curve rolls off highlights
instead of shaping already-clamped values.
- Without a tonemap pass, over-range values simply clip at the final
@@ -499,6 +503,12 @@ A **multi-pass** effect like `bloom` exposes `def.multiPass`; add each sub-pass
anything beyond a fixed pipeline, a `PostProcessVolume` is simpler — it resolves
multi-pass and texture params for you.
+A sub-pass can read an EARLIER pass of its own effect, not only the one before it: declare
+a texture param named `u_pass_<name>` (`#pragma param u_pass_bloom_down_2 texture default(black)`)
+and the chain binds the output of the pass called `<name>`, keeping it alive until this pass
+has run. That is how bloom's upsample adds back the downsample of its own size; a sub-pass
+with `scale` below 1 draws at that fraction of the chain.
+
| Method | Description |
|---|---|
| `PostProcess.createStack()` | Create an empty effect stack. |
diff --git a/docs/astro/src/content/docs/zh-cn/graphics/post-processing.mdx b/docs/astro/src/content/docs/zh-cn/graphics/post-processing.mdx
index 4f9225021..d54045873 100644
--- a/docs/astro/src/content/docs/zh-cn/graphics/post-processing.mdx
+++ b/docs/astro/src/content/docs/zh-cn/graphics/post-processing.mdx
@@ -312,6 +312,8 @@ registerEffect({
- **`threshold` 大于 1 的 `bloom`** 只让超范围能量泛光——亮光发辉光,普通 LDR 美术保持锐利。
这就是经典的"自发光辉光"配方:拉高灯的 `intensity`,把 `threshold` 设在约 1.2–1.5。
+ 辉光建在从 1/2 到 1/64 尺寸的图像金字塔上(和 Unreal、使命召唤的做法一样):衰减圆润柔和,
+ 带一条很淡的长尾,`radius` 让整体变宽。亮天空要压在 `threshold` 以下,否则每条贴着天空的暗边都会被天空的辉光冲淡。
- **`tonemap`** 收到真正的 HDR 输入,ACES 曲线得以收卷高光,而不是对已压平的值做整形。
- 不加 tonemap 时,超范围值在最终的线性→sRGB 编码处直接截断——轻微辉光没问题,大面积过曝会显得生硬。
@@ -383,6 +385,11 @@ const setup = defineSystem([Query(Camera), Res(PostProcess)], (q, pp) => {
(`for (const p of grade.multiPass!) stack.addPass(p.name, p.factory())`)。固定管线之外,
`PostProcessVolume` 更省事——它会替你解析多 pass 与纹理参数。
+sub-pass 不只能读上一个 pass,还能读同一效果里更早的 pass:声明一个名为 `u_pass_<名字>` 的纹理参数
+(`#pragma param u_pass_bloom_down_2 texture default(black)`),链就会绑定名为 `<名字>` 的 pass 的输出,
+并让它一直保留到这个 pass 跑完。bloom 的上采样就是这样把同尺寸的下采样加回来的;`scale` 小于 1 的 sub-pass
+以链尺寸的这个比例绘制。
+
| 方法 | 说明 |
|---|---|
| `PostProcess.createStack()` | 创建一个空效果栈。 |
diff --git a/fixtures/scenes/bloom-round.esscene b/fixtures/scenes/bloom-round.esscene
new file mode 100644
index 000000000..b56bd24c0
--- /dev/null
+++ b/fixtures/scenes/bloom-round.esscene
@@ -0,0 +1,146 @@
+{
+ "version": 4,
+ "name": "BloomRound",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 10
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 1,
+ "orthoSize": 300,
+ "isActive": true,
+ "priority": 0
+ }
+ }
+ ],
+ "visible": true
+ },
+ {
+ "id": 1,
+ "name": "LitQuad",
+ "parent": null,
+ "children": [],
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "size": {
+ "x": 20,
+ "y": 20
+ },
+ "color": {
+ "r": 1,
+ "g": 1,
+ "b": 1,
+ "a": 1
+ },
+ "lit": true
+ }
+ }
+ ],
+ "visible": true
+ },
+ {
+ "id": 2,
+ "name": "HotGreenLight",
+ "parent": null,
+ "children": [],
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Light",
+ "data": {
+ "type": 0,
+ "color": {
+ "r": 0,
+ "g": 1,
+ "b": 0,
+ "a": 1
+ },
+ "intensity": 6,
+ "radius": 400
+ }
+ }
+ ],
+ "visible": true
+ },
+ {
+ "id": 3,
+ "name": "PostProcess",
+ "parent": null,
+ "children": [],
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "PostProcessVolume",
+ "data": {
+ "isGlobal": true,
+ "priority": 0,
+ "weight": 1,
+ "blendDistance": 0,
+ "shape": "box",
+ "size": {
+ "x": 5,
+ "y": 5
+ },
+ "effects": [
+ {
+ "type": "bloom",
+ "enabled": true,
+ "uniforms": {
+ "u_threshold": 1.0,
+ "u_intensity": 2,
+ "u_radius": 1
+ }
+ }
+ ]
+ }
+ }
+ ],
+ "visible": true
+ }
+ ]
+}
diff --git a/fixtures/scenes/bloom-round.textures.json b/fixtures/scenes/bloom-round.textures.json
new file mode 100644
index 000000000..0967ef424
--- /dev/null
+++ b/fixtures/scenes/bloom-round.textures.json
@@ -0,0 +1 @@
+{}
diff --git a/sdk/src/postprocess/effects.ts b/sdk/src/postprocess/effects.ts
index c9a01b45e..763fde536 100644
--- a/sdk/src/postprocess/effects.ts
+++ b/sdk/src/postprocess/effects.ts
@@ -190,13 +190,21 @@ registerEffect({
{ name: 'u_intensity', label: 'Intensity', min: 0, max: 5, step: 0.1, defaultValue: 1.5 },
{ name: 'u_radius', label: 'Radius', min: 0.5, max: 5, step: 0.1, defaultValue: 1 },
],
+ // A pyramid, not a blur at full size: the over-range light at half size, five steps down to 1/64, five back up, each
+ // adding the step of its own size back. The glow reaches far and falls off softly, near light stays tight, and almost
+ // all of the work is done on small targets (about a third of the five full-size blurs it replaces).
multiPass: [
- { name: 'bloom_extract', factory: () => postProcessEffects.createBloomExtract() },
- { name: 'bloom_kawase_0', factory: () => postProcessEffects.createBloomKawase(0) },
- { name: 'bloom_kawase_1', factory: () => postProcessEffects.createBloomKawase(1) },
- { name: 'bloom_kawase_2', factory: () => postProcessEffects.createBloomKawase(2) },
- { name: 'bloom_kawase_3', factory: () => postProcessEffects.createBloomKawase(3) },
- { name: 'bloom_kawase_4', factory: () => postProcessEffects.createBloomKawase(4) },
+ { name: 'bloom_prefilter', factory: () => postProcessEffects.createBloomPrefilter(), scale: 0.5 },
+ { name: 'bloom_down_1', factory: () => postProcessEffects.createBloomDown(1), scale: 0.25 },
+ { name: 'bloom_down_2', factory: () => postProcessEffects.createBloomDown(2), scale: 0.125 },
+ { name: 'bloom_down_3', factory: () => postProcessEffects.createBloomDown(3), scale: 0.0625 },
+ { name: 'bloom_down_4', factory: () => postProcessEffects.createBloomDown(4), scale: 0.03125 },
+ { name: 'bloom_down_5', factory: () => postProcessEffects.createBloomDown(5), scale: 0.015625 },
+ { name: 'bloom_up_4', factory: () => postProcessEffects.createBloomUp(4, 'bloom_down_4'), scale: 0.03125 },
+ { name: 'bloom_up_3', factory: () => postProcessEffects.createBloomUp(3, 'bloom_down_3'), scale: 0.0625 },
+ { name: 'bloom_up_2', factory: () => postProcessEffects.createBloomUp(2, 'bloom_down_2'), scale: 0.125 },
+ { name: 'bloom_up_1', factory: () => postProcessEffects.createBloomUp(1, 'bloom_down_1'), scale: 0.25 },
+ { name: 'bloom_up_0', factory: () => postProcessEffects.createBloomUp(0, 'bloom_prefilter'), scale: 0.5 },
{ name: 'bloom_composite', factory: () => postProcessEffects.createBloomComposite() },
],
});
diff --git a/sdk/src/postprocess/sources/basic.ts b/sdk/src/postprocess/sources/basic.ts
index d7fe581d7..02e27c3e6 100644
--- a/sdk/src/postprocess/sources/basic.ts
+++ b/sdk/src/postprocess/sources/basic.ts
@@ -39,6 +39,138 @@ function agxStrip(): { width: number; height: number; pixels: Uint8Array } {
return { width, height: n, pixels };
}
+/**
+ * A downsample of bloom's pyramid, in both languages. Thirteen taps around the destination texel, in source texels: the
+ * centre box (j k l m) and four corner boxes sharing the centre. Weighted 0.5 / 0.125 x 4 as a filter; the prefilter also
+ * weights each box by 1 / (1 + its luma) and renormalises, then keeps only what clears the soft threshold.
+ */
+function bloomDownSource(name: string, prefilter: boolean): string {
+ const glslBox = (v: string) => prefilter ? `(1.0 / (1.0 + dot(${v}, vec3(0.2126, 0.7152, 0.0722))))` : '1.0';
+ const wgslBox = (v: string) => prefilter ? `(1.0 / (1.0 + dot(${v}, vec3f(0.2126, 0.7152, 0.0722))))` : '1.0';
+ const glslThreshold = prefilter ? `
+ float brightness = max(c.r, max(c.g, c.b));
+ float knee = max(u_threshold * 0.5, 1e-4);
+ float soft = clamp(brightness - u_threshold + knee, 0.0, 2.0 * knee);
+ soft = soft * soft / (4.0 * knee);
+ c *= max(soft, brightness - u_threshold) / max(brightness, 1e-5);` : '';
+ const wgslThreshold = prefilter ? `
+ let brightness = max(c.r, max(c.g, c.b));
+ let knee = max(mc.u_threshold * 0.5, 1e-4);
+ var soft = clamp(brightness - mc.u_threshold + knee, 0.0, 2.0 * knee);
+ soft = soft * soft / (4.0 * knee);
+ c *= max(soft, brightness - mc.u_threshold) / max(brightness, 1e-5);` : '';
+ return `#pragma shader "${name}"
+#pragma version 300 es
+#pragma domain PostProcess
+#pragma highprecision
+${prefilter ? '#pragma param u_threshold float default(0.4) range(0,2)\n' : ''}
+#pragma fragment
+precision highp float;
+
+in vec2 v_texCoord;
+uniform sampler2D u_texture;
+out vec4 fragColor;
+
+vec3 tap(vec2 uv) { return min(texture(u_texture, uv).rgb, vec3(65000.0)); }
+
+void main() {
+ vec2 ts = 1.0 / vec2(textureSize(u_texture, 0));
+ vec2 uv = v_texCoord;
+ vec3 a = tap(uv + ts * vec2(-2.0, 2.0)), b = tap(uv + ts * vec2(0.0, 2.0)), cc = tap(uv + ts * vec2(2.0, 2.0));
+ vec3 d = tap(uv + ts * vec2(-2.0, 0.0)), e = tap(uv), f = tap(uv + ts * vec2(2.0, 0.0));
+ vec3 g = tap(uv + ts * vec2(-2.0, -2.0)), h = tap(uv + ts * vec2(0.0, -2.0)), i = tap(uv + ts * vec2(2.0, -2.0));
+ vec3 j = tap(uv + ts * vec2(-1.0, 1.0)), k = tap(uv + ts * vec2(1.0, 1.0));
+ vec3 l = tap(uv + ts * vec2(-1.0, -1.0)), m = tap(uv + ts * vec2(1.0, -1.0));
+ vec3 inner = (j + k + l + m) * 0.25;
+ vec3 tl = (a + b + d + e) * 0.25, tr = (b + cc + e + f) * 0.25;
+ vec3 bl = (d + e + g + h) * 0.25, br = (e + f + h + i) * 0.25;
+ float wi = 0.5 * ${glslBox('inner')};
+ float w0 = 0.125 * ${glslBox('tl')}, w1 = 0.125 * ${glslBox('tr')};
+ float w2 = 0.125 * ${glslBox('bl')}, w3 = 0.125 * ${glslBox('br')};
+ vec3 c = (inner * wi + tl * w0 + tr * w1 + bl * w2 + br * w3) / (wi + w0 + w1 + w2 + w3);${glslThreshold}
+ fragColor = vec4(c, 1.0);
+}
+#pragma end
+
+#pragma fragment wgsl
+fn tap(uv : vec2f) -> vec3f { return min(textureSampleLevel(t0, s0, uv, 0.0).rgb, vec3f(65000.0)); }
+
+@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
+ let ts = 1.0 / vec2f(textureDimensions(t0, 0));
+ let uv = v.v_texCoord;
+ let a = tap(uv + ts * vec2f(-2.0, 2.0)); let b = tap(uv + ts * vec2f(0.0, 2.0)); let cc = tap(uv + ts * vec2f(2.0, 2.0));
+ let d = tap(uv + ts * vec2f(-2.0, 0.0)); let e = tap(uv); let f = tap(uv + ts * vec2f(2.0, 0.0));
+ let g = tap(uv + ts * vec2f(-2.0, -2.0)); let h = tap(uv + ts * vec2f(0.0, -2.0)); let i = tap(uv + ts * vec2f(2.0, -2.0));
+ let j = tap(uv + ts * vec2f(-1.0, 1.0)); let k = tap(uv + ts * vec2f(1.0, 1.0));
+ let l = tap(uv + ts * vec2f(-1.0, -1.0)); let m = tap(uv + ts * vec2f(1.0, -1.0));
+ let inner = (j + k + l + m) * 0.25;
+ let tl = (a + b + d + e) * 0.25; let tr = (b + cc + e + f) * 0.25;
+ let bl = (d + e + g + h) * 0.25; let br = (e + f + h + i) * 0.25;
+ let wi = 0.5 * ${wgslBox('inner')};
+ let w0 = 0.125 * ${wgslBox('tl')}; let w1 = 0.125 * ${wgslBox('tr')};
+ let w2 = 0.125 * ${wgslBox('bl')}; let w3 = 0.125 * ${wgslBox('br')};
+ var c = (inner * wi + tl * w0 + tr * w1 + bl * w2 + br * w3) / (wi + w0 + w1 + w2 + w3);${wgslThreshold}
+ return vec4f(c, 1.0);
+}
+#pragma end
+`;
+}
+
+/**
+ * An upsample of bloom's pyramid: the smaller level (the chain's input) through a 3x3 tent of its own texels, mixed with
+ * `from`, the level of this size the way down wrote. Radius widens the tent (in the smaller level's texels) and tips the
+ * mix a little toward the wide light: at 1 each level keeps 0.6 of the one below it, about the weights Unreal's six
+ * bloom sizes default to, so a bigger radius makes the whole glow wider rather than piling it into the flattest level.
+ */
+function bloomUpSource(name: string, from: string): string {
+ const tex = `u_pass_${from}`;
+ return `#pragma shader "${name}"
+#pragma version 300 es
+#pragma domain PostProcess
+#pragma highprecision
+#pragma param u_radius float default(1) range(0.5,5)
+#pragma param ${tex} texture default(black)
+
+#pragma fragment
+precision highp float;
+
+in vec2 v_texCoord;
+uniform sampler2D u_texture;
+out vec4 fragColor;
+
+void main() {
+ vec2 ts = max(u_radius, 0.25) / vec2(textureSize(u_texture, 0));
+ vec2 uv = v_texCoord;
+ vec3 wide = texture(u_texture, uv).rgb * 4.0
+ + (texture(u_texture, uv + vec2(ts.x, 0.0)).rgb + texture(u_texture, uv - vec2(ts.x, 0.0)).rgb
+ + texture(u_texture, uv + vec2(0.0, ts.y)).rgb + texture(u_texture, uv - vec2(0.0, ts.y)).rgb) * 2.0
+ + texture(u_texture, uv + ts).rgb + texture(u_texture, uv - ts).rgb
+ + texture(u_texture, uv + vec2(ts.x, -ts.y)).rgb + texture(u_texture, uv + vec2(-ts.x, ts.y)).rgb;
+ wide *= 1.0 / 16.0;
+ vec3 near = texture(${tex}, uv).rgb;
+ float scatter = clamp(0.5 + 0.1 * u_radius, 0.5, 0.75);
+ fragColor = vec4(mix(near, wide, scatter), 1.0);
+}
+#pragma end
+
+#pragma fragment wgsl
+@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
+ let ts = max(mc.u_radius, 0.25) / vec2f(textureDimensions(t0, 0));
+ let uv = v.v_texCoord;
+ var wide = textureSampleLevel(t0, s0, uv, 0.0).rgb * 4.0
+ + (textureSampleLevel(t0, s0, uv + vec2f(ts.x, 0.0), 0.0).rgb + textureSampleLevel(t0, s0, uv - vec2f(ts.x, 0.0), 0.0).rgb
+ + textureSampleLevel(t0, s0, uv + vec2f(0.0, ts.y), 0.0).rgb + textureSampleLevel(t0, s0, uv - vec2f(0.0, ts.y), 0.0).rgb) * 2.0
+ + textureSampleLevel(t0, s0, uv + ts, 0.0).rgb + textureSampleLevel(t0, s0, uv - ts, 0.0).rgb
+ + textureSampleLevel(t0, s0, uv + vec2f(ts.x, -ts.y), 0.0).rgb + textureSampleLevel(t0, s0, uv + vec2f(-ts.x, ts.y), 0.0).rgb;
+ wide *= 1.0 / 16.0;
+ let near = textureSampleLevel(${tex}, ${tex}_s, uv, 0.0).rgb;
+ let scatter = clamp(0.5 + 0.1 * mc.u_radius, 0.5, 0.75);
+ return vec4f(mix(near, wide, scatter), 1.0);
+}
+#pragma end
+`;
+}
+
export const basicEffects = {
/** The AgX table, for the effect to upload once (see `builtinTextures` on its definition). */
agxLut: agxStrip,
@@ -373,6 +505,25 @@ void main() {
`;
return Material.compileShader(source);
},
+ /**
+ * Bloom's first link, at half size: thirteen taps of the picture (Jimenez, "Next Generation Post Processing in Call of
+ * Duty: Advanced Warfare"), the five overlapping boxes each weighted by 1 / (1 + luma) so one blazing texel cannot
+ * flicker into a blob as it crosses pixels (Karis), then the soft threshold. What is left is only the over-range light.
+ */
+ createBloomPrefilter(): ShaderHandle {
+ return Material.compileShader(bloomDownSource('PP Bloom Prefilter', true));
+ },
+ /** One step down the pyramid: the same thirteen taps, a quarter of the texels, no threshold. */
+ createBloomDown(level: number): ShaderHandle {
+ return Material.compileShader(bloomDownSource(`PP Bloom Down ${level}`, false));
+ },
+ /**
+ * One step up: the smaller level through a 3x3 tent, mixed with the level of this size that the way down left.
+ * The mix keeps the energy (its weights sum to one) and Radius tips it toward the wide levels.
+ */
+ createBloomUp(level: number, from: string): ShaderHandle {
+ return Material.compileShader(bloomUpSource(`PP Bloom Up ${level}`, from));
+ },
createBloomComposite(): ShaderHandle {
const source = `#pragma shader "PP Bloom Composite"
#pragma version 300 es
@@ -388,17 +539,28 @@ uniform sampler2D u_sceneTexture;
out vec4 fragColor;
void main() {
- vec4 blur = texture(u_texture, v_texCoord);
+ vec2 ts = 1.0 / vec2(textureSize(u_texture, 0));
+ vec3 blur = texture(u_texture, v_texCoord).rgb * 4.0
+ + (texture(u_texture, v_texCoord + vec2(ts.x, 0.0)).rgb + texture(u_texture, v_texCoord - vec2(ts.x, 0.0)).rgb
+ + texture(u_texture, v_texCoord + vec2(0.0, ts.y)).rgb + texture(u_texture, v_texCoord - vec2(0.0, ts.y)).rgb) * 2.0
+ + texture(u_texture, v_texCoord + ts).rgb + texture(u_texture, v_texCoord - ts).rgb
+ + texture(u_texture, v_texCoord + vec2(ts.x, -ts.y)).rgb + texture(u_texture, v_texCoord + vec2(-ts.x, ts.y)).rgb;
vec4 scene = texture(u_sceneTexture, v_texCoord);
- fragColor = vec4(scene.rgb + blur.rgb * u_intensity, scene.a);
+ fragColor = vec4(scene.rgb + blur * (u_intensity / 16.0), scene.a);
}
#pragma end
#pragma fragment wgsl
@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
- let blur = textureSampleLevel(t0, s0, v.v_texCoord, 0.0);
- let scene = textureSampleLevel(t1, s1, v.v_texCoord, 0.0);
- return vec4f(scene.rgb + blur.rgb * mc.u_intensity, scene.a);
+ let uv = v.v_texCoord;
+ let ts = 1.0 / vec2f(textureDimensions(t0, 0));
+ let blur = textureSampleLevel(t0, s0, uv, 0.0).rgb * 4.0
+ + (textureSampleLevel(t0, s0, uv + vec2f(ts.x, 0.0), 0.0).rgb + textureSampleLevel(t0, s0, uv - vec2f(ts.x, 0.0), 0.0).rgb
+ + textureSampleLevel(t0, s0, uv + vec2f(0.0, ts.y), 0.0).rgb + textureSampleLevel(t0, s0, uv - vec2f(0.0, ts.y), 0.0).rgb) * 2.0
+ + textureSampleLevel(t0, s0, uv + ts, 0.0).rgb + textureSampleLevel(t0, s0, uv - ts, 0.0).rgb
+ + textureSampleLevel(t0, s0, uv + vec2f(ts.x, -ts.y), 0.0).rgb + textureSampleLevel(t0, s0, uv + vec2f(-ts.x, ts.y), 0.0).rgb;
+ let scene = textureSampleLevel(t1, s1, uv, 0.0);
+ return vec4f(scene.rgb + blur * (mc.u_intensity / 16.0), scene.a);
}
#pragma end
`;
diff --git a/src/esengine/renderer/frame/PostProcessPipeline.cpp b/src/esengine/renderer/frame/PostProcessPipeline.cpp
index a9c2b2fdf..73f815191 100644
--- a/src/esengine/renderer/frame/PostProcessPipeline.cpp
+++ b/src/esengine/renderer/frame/PostProcessPipeline.cpp
@@ -968,6 +968,12 @@ void PostProcessPipeline::renderPass(PostProcessPass& pass, const rg::PassContex
for (const auto& [name, glId] : pass.textureUniforms) {
if (name == slot.name && glId != 0) { gpu = TextureHandle{glId}; break; }
}
+ for (const auto& [name, id] : pass.earlierInputs) {
+ if (name != slot.name || !graph_) continue;
+ const TextureHandle earlier = graph_->textureOf(id);
+ if (earlier != TextureHandle::Invalid) gpu = earlier;
+ break;
+ }
if (gpu != TextureHandle::Invalid) device->bindTexture(slot.unit, gpu);
}
} else if (glsl) {
@@ -1177,12 +1183,30 @@ void PostProcessPipeline::runChain(std::vector<PostProcessPass>& passes, rg::Res
rg::ResourceId input = scene;
rg::ResourceId effectInput = scene;
+ // The outputs of the current effect's passes so far, by pass name: what a `u_pass_<name>` texture reads.
+ std::vector<std::pair<std::string, rg::ResourceId>> effectOutputs;
for (usize i = 0; i < passes.size(); ++i) {
auto& pass = passes[i];
if (!runnable(pass)) continue;
- if (!pass.continuesEffect) effectInput = input;
+ if (!pass.continuesEffect) {
+ effectInput = input;
+ effectOutputs.clear();
+ }
rg::PassDesc node;
node.name = pass.name;
+ pass.earlierInputs.clear();
+ if (const MaterialUniformLayout* layout = context_.materials().layoutFor(pass.shader)) {
+ for (const auto& slot : layout->textures) {
+ if (slot.name.rfind("u_pass_", 0) != 0) continue;
+ const std::string wanted = slot.name.substr(7);
+ for (const auto& [name, id] : effectOutputs) {
+ if (name != wanted) continue;
+ pass.earlierInputs.emplace_back(slot.name, id);
+ node.dependencies.push_back(id);
+ break;
+ }
+ }
+ }
// 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.
@@ -1190,7 +1214,8 @@ void PostProcessPipeline::runChain(std::vector<PostProcessPass>& passes, rg::Res
// Every pass samples the scene's depth, so the scene target has to outlive
// the last pass that reads its colour: returned to the pool any earlier,
// an SSAO behind a colour grade found no depth and occluded nothing.
- if (scene_needs_depth_ || scene_gbuffer_) node.dependencies = {scene};
+ // Added to, not assigned: the `u_pass_` targets above are dependencies too, and must outlive this pass.
+ if (scene_needs_depth_ || scene_gbuffer_) node.dependencies.push_back(scene);
// The motion pass wrote a target this one reads by name, not by unit: the graph owes it ordering
// (and the pass its place in the culled set), and the pipeline binds it.
if (velocity_active_ && velocity_resource_ != rg::kNoResource && passHasTexture(pass, "u_velocity")) {
@@ -1256,6 +1281,7 @@ void PostProcessPipeline::runChain(std::vector<PostProcessPass>& passes, rg::Res
node.write = graph_->createTarget(writeDesc);
node.execute = [this, &pass](const rg::PassContext& ctx) { computePass(pass, ctx); };
input = node.write;
+ effectOutputs.emplace_back(pass.name, input);
graph_->addPass(std::move(node));
continue;
}
@@ -1305,6 +1331,7 @@ void PostProcessPipeline::runChain(std::vector<PostProcessPass>& passes, rg::Res
node.execute = [this, &pass](const rg::PassContext& ctx) { renderPass(pass, ctx); };
}
input = node.write;
+ effectOutputs.emplace_back(pass.name, input);
graph_->addPass(std::move(node));
}
diff --git a/src/esengine/renderer/frame/PostProcessPipeline.hpp b/src/esengine/renderer/frame/PostProcessPipeline.hpp
index ef3950de3..949e24be8 100644
--- a/src/esengine/renderer/frame/PostProcessPipeline.hpp
+++ b/src/esengine/renderer/frame/PostProcessPipeline.hpp
@@ -87,6 +87,11 @@ struct PostProcessPass {
/// starts an effect, so a single-pass effect sees the chain as it reached it.
bool continuesEffect = false;
+ /// What this pass reads from passes earlier in its own effect: a texture param named `u_pass_<name>` is the output
+ /// of the pass called <name> (a bloom's upsample adds the downsample of its own size back). Resolved by the chain
+ /// each frame, which also keeps those targets alive until this pass has run.
+ std::vector<std::pair<std::string, rg::ResourceId>> earlierInputs;
+
/// A compute pass (see PostProcessPipeline::addComputePass): the program, which floats its params block holds, in
/// order, and the workgroup the shader declares. Invalid for every pass that draws.
ComputeHandle compute = ComputeHandle::Invalid;
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index 415d37695..e16b28c62 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -603,8 +603,13 @@ export const SCENES = [
// picture whole — the grey in the middle read 0 and only the held red square was left. Composited by coverage, both stay.
{ id: "overlay-camera-linear", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/overlay-camera-linear.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/overlay-camera-linear.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[128,128,128],\"tol\":8},{\"x\":0.133,\"y\":0.5,\"rgb\":[128,0,0],\"tol\":12},{\"x\":0.85,\"y\":0.15,\"rgb\":[0,0,0],\"tol\":10}]" } },
// Post-process chain guards — bloom's first CI pixel coverage. The gamma scene pins the LDR multi-pass chain; the linear scene is the HDR discriminator: threshold 1.5 sits above anything an 8-bit chain can store, so glow OUTSIDE the sprite (x=0.64) proves over-range light survived the float intermediates — the same scene blooms NOTHING in gamma mode.
- { id: "bloom-ldr", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_SCENE: "/scenes/bloom-ldr.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/bloom-ldr.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "10", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.61,\"y\":0.5,\"rgb\":[0,130,0],\"tol\":35},{\"x\":0.70,\"y\":0.5,\"rgb\":[0,32,0],\"tol\":25},{\"x\":0.85,\"y\":0.5,\"rgb\":[0,0,0],\"tol\":12}]" } },
- { id: "hdr-bloom", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/hdr-bloom.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/hdr-bloom.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "10", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":25},{\"x\":0.64,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":35},{\"x\":0.85,\"y\":0.5,\"rgb\":[0,0,0],\"tol\":12}]" } },
+ // Since the pyramid bloom the glow has a long tail: the HDR scene (intensity 2, radius 3) lights the far corner too, and the gamma scene's falls to black within a third of the frame.
+ { id: "bloom-ldr", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_SCENE: "/scenes/bloom-ldr.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/bloom-ldr.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "10", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.61,\"y\":0.5,\"rgb\":[0,58,0],\"tol\":25},{\"x\":0.7,\"y\":0.5,\"rgb\":[0,12,0],\"tol\":10},{\"x\":0.85,\"y\":0.5,\"rgb\":[0,0,0],\"tol\":12}]" } },
+ { id: "hdr-bloom", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/hdr-bloom.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/hdr-bloom.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "10", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":25},{\"x\":0.64,\"y\":0.5,\"rgb\":[0,208,0],\"tol\":35},{\"x\":0.85,\"y\":0.5,\"rgb\":[0,76,0],\"tol\":25}]" } },
+ // A small hot spot, and the glow it throws: as far out along a diagonal as along an axis, so the halo is round. A blur
+ // that samples four diagonal taps per pass (the Kawase chain bloom was) throws a diamond, and a dark edge against a
+ // bright sky then carries a hard-cornered band; the pyramid's tents throw a round one with a long, faint tail.
+ { id: "bloom-round", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/bloom-round.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/bloom-round.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "10", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":25},{\"x\":0.5479,\"y\":0.5,\"rgb\":[0,96,0],\"tol\":22},{\"x\":0.5322,\"y\":0.5322,\"rgb\":[0,96,0],\"tol\":22},{\"x\":0.626,\"y\":0.5,\"rgb\":[0,21,0],\"tol\":10},{\"x\":0.5908,\"y\":0.5908,\"rgb\":[0,21,0],\"tol\":10}]" } },
// Lens flare, the first pixel coverage it has. A bright quad stands left of centre (the source at x=0.35), and the flare mirrors it through the centre: ghosts along the line to the other side, and a halo a fixed way out. Without the effect those places are black.
{ id: "hdr-lens-flare", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/hdr-lens-flare.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/hdr-lens-flare.textures.json", ESTELLA_VERIFY_W: "512", ESTELLA_VERIFY_H: "512", ESTELLA_VERIFY_STEPS: "10", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.75,\"y\":0.55,\"rgb\":[255,255,253],\"tol\":25},{\"x\":0.85,\"y\":0.8,\"rgb\":[255,255,182],\"tol\":35},{\"x\":0.5,\"y\":0.5,\"rgb\":[0,0,0],\"tol\":12},{\"x\":0.5,\"y\":0.1,\"rgb\":[0,0,0],\"tol\":12},{\"x\":0.9,\"y\":0.1,\"rgb\":[0,0,0],\"tol\":12}]" } },
// AgX: five patches of known scene-linear colour read against what Blender's own AgX displays for them (tools/render-align/agx_chart.py in the