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
fix(render): contact shadows no longer speckle a surface the sun does not reach, and a temporal pass placed before a noisy effect is flagged
yhh0fa993350c94
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3b02e744f..d98505073 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -17,6 +17,7 @@ published separately; it ships inside the editor.### Added- **Contact shadows and screen-space bounce light.** Contact Shadows and Screen Space GI effects add small sharp shadows at contacts and one bounce of colour between surfaces, and the weather softens the sun's shadows. `contactShadows` marches a short ray toward the scene's sun in the depth buffer; `ssgi` gathers eight rays a pixel over the G-buffer's normals at half size into a float target and averages the neighbours on the same surface before laying the light, times the receiver's colour, over the picture. The Weather component raises the sun's `sourceAngle` and lowers its `shadowStrength` as the sky clouds over.+- **Cleaner contact shadows.** Contact shadows are soft and keep off surfaces facing away from the sun, so a wall no longer carries a speckle a temporal pass could not average, and the effect stack flags a Temporal Anti-Aliasing that sits before a noisy effect. The march now fades along its length (a hit at the far end is half a shadow), starts at a different offset every frame as well as every pixel so a temporal pass averages the whole march, and skips a surface facing away from the sun. On the Bistro hero the grain on a flat wall fell from 3.95 to 2.82 (the same wall with the effect off: 2.72); the example now runs `taa` after the fog, where it can average the noise before it.- **Details panels for the world.** Time Of Day shows the day as a curve with a hand for the hour, Weather as preset buttons with a live readout, a volume's effects are grouped and tagged, and a Model material's surface layers are sections with switches. The sun's curve is the real one for the component's latitude and declination; the effect stack lists colour parameters it used to leave out, folds, and marks the effects that need WebGPU; a layer's switch writes its strength parameter as an ordinary undoable edit.- **Subsurface scattering.** A Subsurface Scattering effect blurs the lit colour of the surfaces a material marks as scattering, red furthest, without bleeding across a depth edge. The Model material's `u_subsurface` marks its pixels (alpha 0.996, which nothing shows and the effect restores to 1); the effect is an x and a y pass whose width is a world length, each colour reaching a different share of it. Only marked neighbours on the same surface are gathered. It blurs the whole lit colour, specular included, and the width is the effect's, shared by every marked material; the low quality level leaves it out.- **Refraction.** Glass and water refract: a material with transmission bends and tints the opaque scene behind it, softened by its roughness. The frame draws the scene in two halves with a copy of the picture taken between them: the materials that read it (a shader that declares `u_sceneColor`, the Model shader while its transmission is above zero) are drawn second, ray-bent through their thickness. The surface's own highlights are no longer dimmed by blending, as they were when transmission was only coverage. Only the opaque scene is refracted, and it needs a post-process chain to copy from; without one transmission falls back to the earlier coverage.diff --git a/desktop b/desktopindex cdac1fb16..f24cdc077 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit cdac1fb167ebca5e49a511195d42708d1a9b1749+Subproject commit f24cdc077a185b3d5beb23a62639b5da1d752461diff --git a/docs/astro/src/content/docs/graphics/post-processing.mdx b/docs/astro/src/content/docs/graphics/post-processing.mdxindex ee46d93c1..b029aaa70 100644--- a/docs/astro/src/content/docs/graphics/post-processing.mdx+++ b/docs/astro/src/content/docs/graphics/post-processing.mdx@@ -301,6 +301,11 @@ start offset that hides the banding is what `taa` averages away — use them tog### Temporal anti-aliasing+**Put `taa` after every effect whose noise it should average** — ambient occlusion, contact shadows, global illumination,+reflections, fog. A temporal pass resolves what runs before it; a speckle added after it reaches the screen as it is. In the+Bistro example moving `taa` from second place to after the fog lowered the grain on a flat wall by a quarter. The editor marks a+`taa` that has such an effect after it with a warning tag.+`taa` smooths what MSAA cannot reach — shader aliasing and thin geometry — byaccumulating frames. While the effect is in the chain the engine shifts the picture bya different sub-pixel amount each frame (eight positions, repeating), keeps the effect'sdiff --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 3e22e44a4..f83c3cb43 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@@ -226,6 +226,8 @@ registerEffect({### 时间性抗锯齿+**把 `taa` 放在所有它该平均掉噪点的效果之后**——环境光遮蔽、接触阴影、全局光照、反射、雾。时间性 pass 只能处理排在它前面的东西;排在它后面的效果带来的噪点会原样到达屏幕。在 Bistro 示例里,把 `taa` 从第二位挪到雾之后,平坦墙面上的颗粒少了四分之一。如果 `taa` 后面还有这类效果,编辑器会给它一个警告标记。+`taa` 抹平 MSAA 够不到的东西——着色锯齿和细几何——办法是跨帧累积。效果在链路里时,引擎每帧把画面偏移一个不同的亚像素量(八个位置循环),保留这个效果上一帧的输出,再把两者混合。像素上一帧在哪,由深度缓冲得出:把像素反投影到世界,再用上一帧的相机投影回去,所以相机移动时历史还在。`blend`diff --git a/examples/bistro/assets/scenes/main.esscene b/examples/bistro/assets/scenes/main.essceneindex 6d1646f2e..127d84b75 100644--- a/examples/bistro/assets/scenes/main.esscene+++ b/examples/bistro/assets/scenes/main.esscene@@ -51,13 +51,6 @@"u_sunBrightness": 40}},- {- "type": "taa",- "enabled": true,- "uniforms": {- "u_blend": 0.1- }- },{"type": "ssao","enabled": true,@@ -126,6 +119,13 @@"u_volumeRange": 6000}},+ {+ "type": "taa",+ "enabled": true,+ "uniforms": {+ "u_blend": 0.1+ }+ },{"type": "autoExposure","enabled": true,diff --git a/examples/bistro/tools/build-scene.mjs b/examples/bistro/tools/build-scene.mjsindex 4c7431159..208abc8bc 100644--- a/examples/bistro/tools/build-scene.mjs+++ b/examples/bistro/tools/build-scene.mjs@@ -49,12 +49,14 @@ add('Camera', [{ type: 'Camera', data: { projectionType: 0, fov: 33, nearPlane: 10, farPlane: 40000, isActive: true, priority: 0 } },{ type: 'PostProcessVolume', data: { isGlobal: true, priority: 0, weight: 1, effects: [{ type: 'skyAtmosphere', enabled: true, uniforms: { u_intensity: 1.1, u_sunBrightness: 40 } },- { type: 'taa', enabled: true, uniforms: { u_blend: 0.1 } },{ type: 'ssao', enabled: true, uniforms: { u_radius: 70, u_intensity: 1, u_bias: 0.12, u_power: 1.5 } },{ type: 'contactShadows', enabled: true, uniforms: { u_intensity: 0.55, u_length: 28, u_thickness: 10 } },{ type: 'ssgi', enabled: true, uniforms: { u_intensity: 0.9, u_radius: 240, u_thickness: 40, u_maxBounce: 2.5 } },{ type: 'ssr', enabled: true, uniforms: { u_intensity: 0.6, u_maxDistance: 500, u_thickness: 14, u_floorBias: 1 } },{ type: 'heightFog', enabled: true, colors: { u_fogColor: { r: 0.72, g: 0.78, b: 0.86, a: 1 }, u_sunColor: { r: 1, g: 0.9, b: 0.7, a: 1 } }, uniforms: { u_density: 4e-05, u_heightFalloff: 0.0008, u_baseHeight: 0, u_inscatter: 0.5, u_sunAzimuth: 40, u_sunElevation: 35, u_skyFog: 0.6, u_volumetric: 0.5, u_volumeRange: 6000 } },+ // After every effect whose noise it is there to average (ambient occlusion, contact shadows, GI, reflections, fog): a temporal+ // pass only resolves what runs BEFORE it, and a speckle added after it reaches the screen as it is.+ { type: 'taa', enabled: true, uniforms: { u_blend: 0.1 } },{ type: 'autoExposure', enabled: true, uniforms: { u_bias: 0.15, u_minEV: -2, u_maxEV: 2 } },{ type: 'colorGrade', enabled: true, uniforms: { u_exposure: 0, u_contrast: 1.08, u_saturation: 1.1, u_temperature: 0, u_tint: 0 } },{ type: 'bloom', enabled: true, uniforms: { u_threshold: 0.9, u_intensity: 0.5, u_radius: 1.2 } },diff --git a/sdk/src/postprocess/postProcessEffects.ts b/sdk/src/postprocess/postProcessEffects.tsindex 0a914b303..082772eba 100644--- a/sdk/src/postprocess/postProcessEffects.ts+++ b/sdk/src/postprocess/postProcessEffects.ts@@ -2508,7 +2508,22 @@ void main() {: vec3(cos(el) * sin(az), sin(el), cos(el) * cos(az));vec3 P = worldFromDepth(uvOfTexel(c, size), d);- float jitter = ign(gl_FragCoord.xy);+ // A surface that faces away from the sun is already dark, and a shadow on it is a second one: the term fades out before+ // the terminator instead of speckling the dark side. The normal is the depth buffer's own, from the nearer neighbour on+ // each axis (the same pick the occlusion passes make, so a silhouette does not average into a normal facing neither).+ 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));+ if (dot(N, viewDirection(P)) < 0.0) N = -N;+ float facing = smoothstep(0.02, 0.25, dot(N, L));+ if (facing <= 0.0) { fragColor = src; return; }+ // A different start offset every frame as well as every pixel, so what a temporal pass averages is the whole march and not one+ // fixed pattern of it.+ float jitter = ign(gl_FragCoord.xy + 5.588238 * float(int(u_time.x * 60.0) & 63));float occluded = 0.0;for (int i = 0; i < STEPS; ++i) {float t = (float(i) + jitter + 0.5) / float(STEPS) * u_length;@@ -2522,10 +2537,14 @@ void main() {float surface = (u_projection * vec4(worldAt(tx, size), 1.0)).w;// Behind what the buffer shows by more than the surface's own noise, and by less than a wall's thickness.float behind = q.w - surface;- if (behind > u_thickness * 0.08 + t * 0.01 && behind < u_thickness) { occluded = 1.0; break; }+ if (behind > u_thickness * 0.08 + t * 0.01 && behind < u_thickness) {+ // The nearer the blocker, the harder the contact: a hit at the far end of the march is half a shadow, not a whole one.+ float reach = t / u_length;+ occluded = 1.0 - reach * reach;+ break;+ }}- // The nearer the blocker, the harder the contact: fades along the ray's length.- fragColor = vec4(src.rgb * (1.0 - u_intensity * occluded), src.a);+ fragColor = vec4(src.rgb * (1.0 - u_intensity * occluded * facing), src.a);}#pragma end@@ -2552,7 +2571,19 @@ fn ign(p : vec2f) -> f32 {if (mc.u_followSun > 0.5 && found.dir.w > 0.5) { L = found.dir.xyz; }let P = worldFromDepth(uvOfTexel(c, size), d);- let jitter = ign(v.pos.xy);+ 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 facing = smoothstep(0.02, 0.25, dot(N, L));+ if (facing <= 0.0) { return src; }+ let jitter = ign(v.pos.xy + vec2f(5.588238 * f32(i32(tc.u_time.x * 60.0) & 63)));var occluded = 0.0;for (var i : i32 = 0; i < STEPS; i = i + 1) {let t = (f32(i) + jitter + 0.5) / f32(STEPS) * mc.u_length;@@ -2566,9 +2597,13 @@ fn ign(p : vec2f) -> f32 {if (depthAt(tx, size) >= 1.0) { continue; }let surface = (frame.projection * vec4f(worldAt(tx, size), 1.0)).w;let behind = q.w - surface;- if (behind > mc.u_thickness * 0.08 + t * 0.01 && behind < mc.u_thickness) { occluded = 1.0; break; }+ if (behind > mc.u_thickness * 0.08 + t * 0.01 && behind < mc.u_thickness) {+ let reach = t / mc.u_length;+ occluded = 1.0 - reach * reach;+ break;+ }}- return vec4f(src.rgb * (1.0 - mc.u_intensity * occluded), src.a);+ return vec4f(src.rgb * (1.0 - mc.u_intensity * occluded * facing), src.a);}#pragma end`;diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex f7f5ab3b7..3efaf5f36 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -2495,6 +2495,8 @@ export const NOTED = {{"note":"Height Fog and Light Shafts follow the scene's own sun, and Height Fog can carry the sun's shadows as volumetric light."},"feat(editor): Time Of Day and Weather panels, a grouped effect stack and material layer switches":{"internal":"the desktop half of the Details panels entry just below, which carries the note"},+ "fix(render): contact shadows no longer speckle a surface the sun does not reach, and a temporal pass placed before a noisy effect is flagged":+ {"note":"Contact shadows are soft and keep off surfaces facing away from the sun, so a wall no longer carries a speckle a temporal pass could not average, and the effect stack flags a Temporal Anti-Aliasing that sits before a noisy effect."},"feat(editor): Time Of Day and Weather have Details panels of their own, the effect stack is grouped, and a material's surface layers are switches":{"note":"Time Of Day shows the day as a curve with a hand for the hour, Weather as preset buttons with a live readout, a volume's effects are grouped and tagged, and a Model material's surface layers are sections with switches."},"feat(render): screen-space subsurface scattering blurs the lit colour of surfaces a material marks":