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): a wire narrower than a pixel is no longer painted over by the sky in dashes
yhhb5e54e72f1f2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d98505073..342c8f6d2 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.+- **Thin lines against the sky.** A wire or railing thinner than a pixel stays one line against the sky instead of breaking into dashes. The Sky Atmosphere effect paints every pixel whose depth is the far plane, and depth is resolved from a single sample of a multisampled target, so a wire covered at some samples and not at that one was painted over wherever the sample missed. With the sky in the chain the scene is now cleared to nothing, its alpha is how much of each pixel geometry covers, and the sky is laid under it by that coverage: on a half-pixel wire across the sky the columns that show it went from 49% to 100%, on WebGL2 and WebGPU. An effect asks for this by declaring `u_sceneCoverage`; with Keep Background above zero the scene is cleared to the camera's colour as before.- **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.diff --git a/desktop b/desktopindex f24cdc077..a2e05a02f 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit f24cdc077a185b3d5beb23a62639b5da1d752461+Subproject commit a2e05a02fa3fb679a24a4316d07173876db3b98ediff --git a/docs/astro/src/content/docs/graphics/post-processing.mdx b/docs/astro/src/content/docs/graphics/post-processing.mdxindex b029aaa70..9cfe909f3 100644--- a/docs/astro/src/content/docs/graphics/post-processing.mdx+++ b/docs/astro/src/content/docs/graphics/post-processing.mdx@@ -67,6 +67,13 @@ temporal effect does, so it can be used without `taa`.`filmGrain` and `lensFlare` are plain post effects. The flare reads the picture itself, so it only has something tothrow where the picture holds values above `threshold`: a bright sun disc, a lamp, an emissive surface (in HDR).+### The sky and thin geometry++`skyAtmosphere` draws the sky after the scene, under it. For that to leave a wire or a railing thinner than a pixel whole, the+scene is cleared to nothing while the effect is in the chain and its alpha says how much of each pixel geometry covers, so the+sky is laid under an edge by that share instead of replacing the pixel. Nothing downstream sees it: the effect hands back alpha 1.+Turn **Keep Background** up and the scene is cleared to the camera's colour again, which is what keeping the background means.+### Rain, wet ground and puddles`rain` is a storm in two parts. **Falling rain** is three layers of thin slanted streaks scrolling down thediff --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 f83c3cb43..3f7352fef 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@@ -58,6 +58,10 @@ Estella 通过 ping-pong 帧缓冲运行全屏后处理。加一个 `PostProcess`filmGrain` 和 `lensFlare` 是普通的后处理效果。镜头光斑读取的是画面本身,所以只有画面里存在高于 `threshold` 的值(明亮的太阳圆盘、灯、HDR 下的自发光表面)时它才有东西可投。+### 天空与细小几何体++`skyAtmosphere` 在场景之后、在场景下面绘制天空。为了让比一个像素还细的电线或栏杆保持完整,只要这个效果在链里,场景就被清为全透明,它的 alpha 表示几何体覆盖了每个像素的多少,于是天空按这个比例垫在边缘下面,而不是整个替换这个像素。下游看不到这一点:效果交回的 alpha 是 1。把**保留背景**调高,场景就恢复成清为相机颜色,这正是保留背景的含义。+### 雨、潮湿的地面与水坑`rain` 是由两部分组成的暴雨。**落下的雨**是三层在屏幕上向下滚动的细斜线,每层站在自己的距离上:比该层更近的表面会挡住diff --git a/sdk/src/postprocess/postProcessEffects.ts b/sdk/src/postprocess/postProcessEffects.tsindex 082772eba..2135e8ba7 100644--- a/sdk/src/postprocess/postProcessEffects.ts+++ b/sdk/src/postprocess/postProcessEffects.ts@@ -1529,6 +1529,9 @@ fn depthAt(texel : vec2i, size : vec2i) -> f32 {#pragma domain PostProcess#pragma param u_intensity float default(1) range(0,8)#pragma param u_panorama float default(0) range(0,1)+// A marker the engine reads, not a setting: with it declared (and the background not kept) the scene is cleared to nothing, so its alpha+// is how much of each pixel geometry covers and the sky is laid under it. See PostProcessPipeline::sceneCoverageWanted.+#pragma param u_sceneCoverage float default(1) range(0,1)#pragma param u_overcast float default(0) range(0,1)#pragma param u_haze float default(1) range(0,8)#pragma param u_altitude float default(0.1) range(0,20)@@ -1656,7 +1659,10 @@ void main() {vec4 src = texture(u_texture, v_texCoord);ivec2 size = textureSize(u_sceneDepth, 0);float depth = texelFetch(u_sceneDepth, clamp(ivec2(v_texCoord * vec2(size)), ivec2(0), size - ivec2(1)), 0).r;- if (depth < 1.0) { fragColor = src; return; }+ // The scene was cleared to nothing when the background is not kept (the engine's rule, same threshold): what is left of a pixel's+ // alpha is how much the sky shows through it, and that includes a pixel whose depth says surface because one sample of it is.+ bool covered = u_panorama <= 0.001;+ if (covered ? (depth < 1.0 && src.a > 0.999) : depth < 1.0) { fragColor = src; return; }vec3 entry = worldFromDepth(v_texCoord, 0.0);vec3 dir = normalize(worldFromDepth(v_texCoord, 1.0) - entry);@@ -1764,6 +1770,11 @@ void main() {float luma = dot(col, vec3(0.2126, 0.7152, 0.0722));col = mix(col, vec3(luma), overcast * 0.5);+ if (covered) {+ // Under the geometry by its coverage; a mark in the alpha (a scattering surface's 0.996) is kept, a partial edge becomes whole.+ fragColor = vec4(src.rgb + (1.0 - src.a) * col, src.a > 0.99 ? src.a : 1.0);+ return;+ }fragColor = vec4(mix(col, src.rgb, clamp(u_panorama, 0.0, 1.0)), src.a);}#pragma end@@ -1872,7 +1883,8 @@ fn cloudDensity(p : vec3f, coverage : f32, base : f32, thick : f32, octaves : i3let src = textureSampleLevel(t0, s0, v.v_texCoord, 0.0);let size = vec2i(textureDimensions(t7, 0));let depth = textureLoad(t7, clamp(vec2i(v.v_texCoord * vec2f(size)), vec2i(0), size - vec2i(1)), 0);- if (depth < 1.0) { return src; }+ let covered = mc.u_panorama <= 0.001;+ if ((covered && depth < 1.0 && src.a > 0.999) || (!covered && depth < 1.0)) { return src; }let entry = worldFromDepth(v.v_texCoord, 0.0);let dir = normalize(worldFromDepth(v.v_texCoord, 1.0) - entry);@@ -1973,7 +1985,10 @@ fn cloudDensity(p : vec3f, coverage : f32, base : f32, thick : f32, octaves : i3let luma = dot(col, vec3f(0.2126, 0.7152, 0.0722));col = mix(col, vec3f(luma), overcast * 0.5);- return vec4f(mix(col, src.rgb, clamp(mc.u_panorama, 0.0, 1.0)), src.a);+ if (covered) {+ return vec4f(src.rgb + (1.0 - src.a) * col, select(1.0, src.a, src.a > 0.99));+ }+ return vec4f(mix(col, src.rgb, vec3f(clamp(mc.u_panorama, 0.0, 1.0))), src.a);}#pragma end`;diff --git a/src/esengine/renderer/frame/PostProcessPipeline.cpp b/src/esengine/renderer/frame/PostProcessPipeline.cppindex 809f734d8..1545157d1 100644--- a/src/esengine/renderer/frame/PostProcessPipeline.cpp+++ b/src/esengine/renderer/frame/PostProcessPipeline.cpp@@ -414,6 +414,18 @@ void PostProcessPipeline::trackView(const glm::mat4& viewProjection, u64 key) {++state.frame;}+bool PostProcessPipeline::sceneCoverageWanted() {+ if (!initialized_ || bypass_) return false;+ for (const auto& pass : passes_) {+ if (!pass.enabled || !pass.nativeKind.empty()) continue;+ const MaterialUniformLayout* layout = context_.materials().layoutFor(pass.shader);+ if (!layout || !layout->find("u_sceneCoverage")) continue;+ if (const auto it = pass.floatUniforms.find("u_panorama"); it != pass.floatUniforms.end() && it->second > 0.001f) continue;+ return true;+ }+ return false;+}+bool PostProcessPipeline::velocityWanted() {if (!initialized_ || bypass_ || !device_.supportsFloatTargets()) return false;for (const auto& pass : passes_) {diff --git a/src/esengine/renderer/frame/PostProcessPipeline.hpp b/src/esengine/renderer/frame/PostProcessPipeline.hppindex aa6ecf936..fe6e9fa0d 100644--- a/src/esengine/renderer/frame/PostProcessPipeline.hpp+++ b/src/esengine/renderer/frame/PostProcessPipeline.hpp@@ -268,6 +268,18 @@ public:/// encode: a copy, with the alpha set to a marker (0.5) a shader can tell from the white a texture param falls back to.void grabScene();+ /**+ * @brief Whether the scene is to be cleared to nothing (all four channels zero) so that its alpha says how much of each pixel geometry covers.+ *+ * @details A sky drawn after the scene (the Sky Atmosphere effect) replaces every pixel whose depth is the far plane. Depth is resolved from+ * one sample of a multisampled target, so a wire narrower than a pixel — covered at some samples, not at the one depth keeps — is+ * painted over wherever that sample missed, and a line becomes dashes. With a clear of (0,0,0,0) the resolved colour is the+ * geometry's share premultiplied and the alpha is its coverage, which is exactly what the sky has to be laid UNDER.+ * An enabled pass asks for it by declaring `u_sceneCoverage`, unless it keeps the scene's own background (`u_panorama` above zero):+ * there the cleared pixels are what the picture shows, and they must stay the camera's colour.+ */+ bool sceneCoverageWanted();+/// Records this frame's camera as the view @p key's current one, and last frame's as its previous. No shift.void trackView(const glm::mat4& viewProjection, u64 key);diff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cppindex bd2bf47b6..245e2fc9f 100644--- a/src/esengine/renderer/frame/RenderFrame.cpp+++ b/src/esengine/renderer/frame/RenderFrame.cpp@@ -427,6 +427,12 @@ void RenderFrame::openPass(const PassClear& clear, RenderTargetManager::Handle tpass.clearColorValue[2] = clearRgb.b;pass.clearColorValue[3] = clear.colorValue.a;scene_clear_ = glm::make_vec4(pass.clearColorValue);+#ifdef ES_ENABLE_POSTPROCESS+ // An effect that lays a sky UNDER the scene needs the scene's alpha to be its coverage, which a clear to nothing makes it.+ if (usePostProcess && post_process_->sceneCoverageWanted()) {+ for (f32& channel : pass.clearColorValue) channel = 0.0f;+ }+#endifpass.clearX = clear.x;pass.clearY = clear.y;pass.clearW = clear.w;diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 3efaf5f36..1b5cf68e0 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): a wire narrower than a pixel is no longer painted over by the sky in dashes":+ {"note":"A wire or railing thinner than a pixel stays one line against the sky instead of breaking into dashes."},"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":