A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(post): the tonemap has the fitted ACES curve too - Tonemap's Fitted ACES (u_curve 1) runs Hill's fit of the RRT and ODT, the one three.js calls ACES Filmic, in place of the engine's curve: a picture made for it was a third brighter in its shadows and kept colours it sends to white
yhh5097e3b68c66
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6fdb38e39..b6db1c7c8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,7 @@ published separately; it ships inside the editor.### Added+- **The tonemap has the fitted ACES curve too.** The `tonemap` effect ran one curve, the engine's (Narkowicz's fit). A picture made for the other ACES fit in wide use (Hill's RRT and ODT, what three.js calls ACES Filmic) came out with shadows about a third brighter at the same mid tones, and with the hue kept in bright colours that curve sends to white. **Fitted ACES** (`u_curve` 1) runs that fit; off, which is the default, nothing changes.- **An anchor on a waterfall.** A `Waterfall` lands wherever the ground or the water under it is, and nothing said where that was, so the mist at its foot had to be placed by hand and stayed behind when the fall moved. A child of the fall's with a `WaterfallAnchor` is kept on the middle of its path: at the foot (`at` 1), at the lip (0) or a share of the time down, `lift` above it. A `ParticleEmitter` on that child is the mist.- **A waterfall.** A river's surface lies over the ground and stopped at the edge of a cliff with nothing after it. A `Waterfall` on an entity at the lip, facing the way the water leaves, throws sheets of water level at `speed` and lets gravity take them: each ends where it meets the ground, or water that is not the water it left, or `maxDrop` under the lip, and is made again when what is under it changes. It is the entity's own `MeshRenderer`; with no material it takes the stock Waterfall shader, glass at the lip that tears into strands and then veils, its pattern riding down with the water at the water's own speed.- **A sky of your own shades the ground under its clouds.** Sky Atmosphere's clouds cast their shadow on the scene; a sky written with `defineSkyEffect` could not, so a stylised sky lit a world with no cloud shadow on it. With `groundShadow: true` the sky's source holds a second function, `skyShadow(world, sun)`, what is left of the light at a world position, and every surface the sky pass finds is multiplied by it.diff --git a/docs/astro/src/content/docs/graphics/post-processing.mdx b/docs/astro/src/content/docs/graphics/post-processing.mdxindex eca2214c1..348ee73a8 100644--- a/docs/astro/src/content/docs/graphics/post-processing.mdx+++ b/docs/astro/src/content/docs/graphics/post-processing.mdx@@ -15,7 +15,7 @@ several can stack in one frame at no extra target cost beyond the passes.| Effect | What it does | Key uniforms ||---|---|---|| `bloom` | Glow on bright areas | `threshold`, `intensity`, `radius` |-| `tonemap` | ACES filmic tonemapping | `exposure` |+| `tonemap` | ACES filmic tonemapping | `exposure`, `curve` || `colorGrade` | Exposure / contrast / saturation / white balance, split toning, S-curve and a tinted black level | `exposure`, `contrast`, `saturation`, `temperature`, `tint`, `shadowTint`, `highlightTint`, `toneLow`, `toneHigh`, `curve`, `lift` || `lutGrade` | Color grading through a lookup-table texture, on scene values in the chain | `u_lut` (texture), `intensity` || `displayLut` | A look read off a lookup table by the picture as the display shows it, in the last pass after the output transform | `u_lut` (texture), `intensity` |@@ -436,7 +436,10 @@ clamping at the 8-bit store:widens all of it. Keep a bright sky under `threshold`, or every dark edge against ittakes the sky's glow.- **`tonemap`** receives true HDR input, so the ACES curve rolls off highlights- instead of shaping already-clamped values.+ instead of shaping already-clamped values. **Fitted ACES** (`u_curve` 1) swaps the engine's curve for the other ACES fit in wide+ use, the one three.js calls ACES Filmic: it mixes the channels before the curve, so a bright colour goes to white where the+ engine's keeps its hue, and its shadows are deeper. A picture made for that curve wants it; three.js also multiplies the+ exposure by 1/0.6 first, which is `u_exposure` 0.74 here.- Without a tonemap pass, over-range values simply clip at the finallinear→sRGB encode — fine for subtle glow, harsh for large over-exposure.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.mdxindex 378a4226e..dc51c707e 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@@ -14,7 +14,7 @@ Estella 通过 ping-pong 帧缓冲运行全屏后处理。加一个 `PostProcess| 效果 | 作用 | 关键 uniform ||---|---|---|| `bloom` | 亮部辉光 | `threshold`、`intensity`、`radius` |-| `tonemap` | ACES filmic 色调映射 | `exposure` |+| `tonemap` | ACES filmic 色调映射 | `exposure`、`curve` || `colorGrade` | 曝光 / 对比度 / 饱和度 / 白平衡,分离色调、S 曲线和带色相的黑位 | `exposure`、`contrast`、`saturation`、`temperature`、`tint`、`shadowTint`、`highlightTint`、`toneLow`、`toneHigh`、`curve`、`lift` || `lutGrade` | 通过查找表纹理(LUT)调色,作用在效果链里的场景值上 | `u_lut`(纹理)、`intensity` || `displayLut` | 在最后一个通道里、输出变换之后,按画面在显示器上的样子从查找表取出的调色 | `u_lut`(纹理)、`intensity` |@@ -325,7 +325,9 @@ registerEffect({这就是经典的"自发光辉光"配方:拉高灯的 `intensity`,把 `threshold` 设在约 1.2–1.5。辉光建在从 1/2 到 1/64 尺寸的图像金字塔上(和 Unreal、使命召唤的做法一样):衰减圆润柔和,带一条很淡的长尾,`radius` 让整体变宽。亮天空要压在 `threshold` 以下,否则每条贴着天空的暗边都会被天空的辉光冲淡。-- **`tonemap`** 收到真正的 HDR 输入,ACES 曲线得以收卷高光,而不是对已压平的值做整形。+- **`tonemap`** 收到真正的 HDR 输入,ACES 曲线得以收卷高光,而不是对已压平的值做整形。**Fitted ACES**(`u_curve` 为 1)把引擎的曲线换成另一条+ 常用的 ACES 拟合,也就是 three.js 所说的 ACES Filmic:它在过曲线之前先混合通道,所以亮的颜色会走向白色(引擎的曲线保持色相),暗部也压得更深。+ 按那条曲线做出来的画面要用它;three.js 还会先把曝光乘以 1/0.6,在这里就是 `u_exposure` 0.74。- 不加 tonemap 时,超范围值在最终的线性→sRGB 编码处直接截断——轻微辉光没问题,大面积过曝会显得生硬。伽马模式(或无浮点目标能力)下效果链仍是 LDR,行为与从前一致;此时 `threshold` 超过约 0.75diff --git a/sdk/src/postprocess/effects.ts b/sdk/src/postprocess/effects.tsindex b5c918703..f3563104e 100644--- a/sdk/src/postprocess/effects.ts+++ b/sdk/src/postprocess/effects.ts@@ -277,6 +277,7 @@ registerEffect({factory: () => postProcessEffects.createTonemap(),uniforms: [{ name: 'u_exposure', label: 'Exposure', min: -3, max: 3, step: 0.05, defaultValue: 0 },+ { name: 'u_curve', label: 'Fitted ACES', min: 0, max: 1, step: 1, defaultValue: 0, neutralValue: 0 },],});diff --git a/sdk/src/postprocess/sources/basic.ts b/sdk/src/postprocess/sources/basic.tsindex eb3f53861..9832901fc 100644--- a/sdk/src/postprocess/sources/basic.ts+++ b/sdk/src/postprocess/sources/basic.ts@@ -596,13 +596,13 @@ void main() {return Material.compileShader(source);},createTonemap(): ShaderHandle {- // The manual tonemap: the same acesFilmic() every fragment stage is given,- // at a point of the stack's choosing and with an exposure. Carry this OR- // PostProcess.setOutputTransform — the curve is not idempotent.+ // The manual tonemap: acesFilmic(), as every fragment stage has it, with an exposure. Carry this OR setOutputTransform: the+ // curve is not idempotent. u_curve 1 is Hill's fit of the RRT and ODT (three.js's ACES Filmic): channels mixed first, a deeper toe.const source = `#pragma shader "PP Tonemap"#pragma version 300 es#pragma domain PostProcess#pragma param u_exposure float default(0) range(-3,3)+#pragma param u_curve float default(0) range(0,1)#pragma fragmentprecision highp float;@@ -611,17 +611,34 @@ in vec2 v_texCoord;uniform sampler2D u_texture;out vec4 fragColor;+vec3 acesFitted(vec3 x) {+ const mat3 toCurve = mat3(0.59719, 0.07600, 0.02840, 0.35458, 0.90834, 0.13383, 0.04823, 0.01566, 0.83777);+ const mat3 fromCurve = mat3(1.60475, -0.10208, -0.00327, -0.53108, 1.10813, -0.07276, -0.07367, -0.00605, 1.07602);+ vec3 v = toCurve * x;+ v = (v * (v + 0.0245786) - 0.000090537) / (v * (0.983729 * v + 0.4329510) + 0.238081);+ return clamp(fromCurve * v, 0.0, 1.0);+}+void main() {vec4 src = texture(u_texture, v_texCoord);vec3 c = src.rgb * exp2(u_exposure);- fragColor = vec4(acesFilmic(c), src.a);+ fragColor = vec4(u_curve > 0.5 ? acesFitted(c) : acesFilmic(c), src.a);}#pragma end#pragma fragment wgsl+fn acesFitted(x : vec3f) -> vec3f {+ let toCurve = mat3x3f(0.59719, 0.07600, 0.02840, 0.35458, 0.90834, 0.13383, 0.04823, 0.01566, 0.83777);+ let fromCurve = mat3x3f(1.60475, -0.10208, -0.00327, -0.53108, 1.10813, -0.07276, -0.07367, -0.00605, 1.07602);+ var v = toCurve * x;+ v = (v * (v + 0.0245786) - 0.000090537) / (v * (0.983729 * v + 0.4329510) + 0.238081);+ return clamp(fromCurve * v, vec3f(0.0), vec3f(1.0));+}+@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {let src = textureSampleLevel(t0, s0, v.v_texCoord, 0.0);let c = src.rgb * exp2(mc.u_exposure);+ if (mc.u_curve > 0.5) { return vec4f(acesFitted(c), src.a); }return vec4f(acesFilmic(c), src.a);}#pragma enddiff --git a/sdk/tests/postprocess.test.ts b/sdk/tests/postprocess.test.tsindex 149ed8b0b..909bb75da 100644--- a/sdk/tests/postprocess.test.ts+++ b/sdk/tests/postprocess.test.ts@@ -497,8 +497,12 @@ describe('PostProcess API', () => {expect(src).toContain('#pragma param u_exposure float');// The curve is pinned where it is defined (test_shader_variant.cpp);// what this layer owns is that the effect REACHES it, in both dialects.- expect(src).toContain('vec4(acesFilmic(c), src.a)');+ expect(src).toContain('acesFilmic(c), src.a)');expect(src).toContain('vec4f(acesFilmic(c), src.a)');+ // The other fit is the effect's own, behind u_curve, in both dialects; off, the engine's curve is what runs.+ expect(src).toContain('#pragma param u_curve float default(0)');+ expect(src).toContain('u_curve > 0.5 ? acesFitted(c) : acesFilmic(c)');+ expect(src).toContain('if (mc.u_curve > 0.5) { return vec4f(acesFitted(c), src.a); }');expect(handle).toBe(42);});@@ -547,7 +551,7 @@ describe('PostProcess API', () => {const def = (t: string) =>Object.fromEntries((getEffectDef(t)?.uniforms ?? []).map(u => [u.name, u.defaultValue]));// Tonemap: 2^0 = 1 exposure (the ACES curve itself always applies).- expect(def('tonemap')).toEqual({ u_exposure: 0 });+ expect(def('tonemap')).toEqual({ u_exposure: 0, u_curve: 0 });// Lens distortion: strength 0 + zoom 1 == sample uv unchanged (no-op).expect(def('lensDistortion')).toEqual({ u_strength: 0, u_zoom: 1 });// FXAA full strength by default; pixelate visibly chunky so it reads as on.diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 4484e0782..cef41ac49 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -4576,6 +4576,8 @@ export const NOTED = {{"note": "A waterfall."},"feat(water): an anchor on a waterfall - a child of a Waterfall with a WaterfallAnchor is kept on the middle of the fall, at its foot wherever the water lands or a share of the time down, so the mist a ParticleEmitter makes there follows the fall when what is under it changes":{"note": "An anchor on a waterfall."},+ "feat(post): the tonemap has the fitted ACES curve too - Tonemap's Fitted ACES (u_curve 1) runs Hill's fit of the RRT and ODT, the one three.js calls ACES Filmic, in place of the engine's curve: a picture made for it was a third brighter in its shadows and kept colours it sends to white":+ {"note": "The tonemap has the fitted ACES curve too."},"fix(terrain): a detail the pages cannot hold no longer cracks the ground - a tree that wanted more nodes than the atlas has pages was drawn in part by coarser pages standing in, which do not meet their finer neighbours' edges, and the pages were fought over every frame; the ground is now drawn at the share of its detail's range that fits, and says so once":{"note": "A detail the pages cannot hold no longer cracks the ground."},"fix(foliage): a far plant grows across the ground, not taller - a mesh plant kept in a far version was grown the same every way to cover the ground of those left out, so a flower that stood for ten stood ten times as high and a far meadow was a field of poles; it now grows across the ground only, and Foliage.farGrowUp gives its height a share of the growth back":