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(render): Height Fog and Light Shafts effects give a hazy horizon, the sun's glow and rays through what stands in front of it
yhh6452c0c46b94
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f1de2bfa9..539e67ec1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,7 @@ published separately; it ships inside the editor.### Added+- **Height Fog and Light Shafts.** Height Fog and Light Shafts post-process effects add atmosphere. `heightFog` is exponential height fog with a closed-form integral — no marching — so a valley fills and a hilltop clears, the horizon turns hazy while the zenith stays clear, and looking toward the sun the haze takes the sun's colour; sky pixels run through the same formula with a very long ray, and `skyFog` sets how much haze the sky keeps. `lightShafts` marches each pixel toward the sun's place on screen and counts how much of the way is open sky, leaving rays through whatever stands in front of the sun. The sun's direction is set on the effects (azimuth and elevation), not read from a light. Neither is a shadowed volume: fog is lit evenly. Both run on WebGL2 and WebGPU; with an output transform of None, a floor fully taken by the fog reads exactly the authored colour on both.- **Screen Space Reflections.** A Screen Space Reflections post-process effect mirrors props in floors. Add `ssr` to a `PostProcessVolume`: with no G-buffer, the surface normal is rebuilt from the depth buffer, the reflected ray is marched through the world and projected back to the screen at every step, and a step landing just behind the visible surface is a hit, refined by bisection. The reflection is blended over the pixel by a Schlick Fresnel term — faint face-on, strong at a grazing angle — and blurred by how far the ray travelled, which stands in for roughness. `intensity`, `maxDistance`, `thickness` and `floorBias` are the settings; `floorBias` at 1 lets only up-facing surfaces reflect, since the chain does not know a material's roughness. What is off screen or in the sky is not reflected; the pixel is left as it was. It reads the same depth buffer as ambient occlusion, runs on WebGL2 and WebGPU alike, and its per-pixel start offset is meant to be averaged away by `taa`. Verified in the editor on a lit scene with both backends: the props appear in the floor they stand on and nothing else on screen changes.- **Temporal Anti-Aliasing.** A Temporal Anti-Aliasing post-process effect smooths edges across frames. Add `taa` to a `PostProcessVolume` and the engine shifts the scene's picture by a different sub-pixel amount each frame (eight positions, repeating), keeps the effect's last output as its history, and blends the two — reaching what multisampling cannot: shader aliasing and thin geometry. Where a pixel was last frame comes from the depth buffer and the previous camera, so a moving camera keeps its history; the history is clipped to the colours around it, so what no longer matches is dropped rather than smeared, and each camera keeps a history of its own. One `blend` setting says how much of each frame is new. Measured in the editor on a lit scene with multisampling off, in-between edge pixels went from 2% of edge pixels to 43% on WebGL2 and 44% on WebGPU, still frames held still, and a picture taken mid-slide of the camera matched the plain one to within a fraction of a level. Objects that move by themselves are not tracked — they are handled by the clip, so fast movers can look slightly soft.- **Smaller meshes on disk.** Newly imported meshes are about 9% smaller on disk. A mesh whose indices all fit in 16 bits is now written with 16-bit indices (`.esmesh` version 4), half the index bytes, and read back as 32-bit so nothing downstream changes: the renderer, the lightmap and decal bakers and static batching see the same indices as before. A mesh that needs 32 bits is written exactly as before, on the version every earlier reader knows, and files written before this change still load. Measured on the Bistro meshes (1143 files, 116 MB), re-encoding saves 10.4 MB; existing `.esmesh` files are not rewritten until the model is re-imported.@@ -31,6 +32,7 @@ published separately; it ships inside the editor.### Fixed+- **Distance Fog's colour was drawn too bright in a linear project.** The fog colour is authored as sRGB, like a clear colour or a light colour, but the effect took it as linear light, so a fully fogged surface showed a much lighter colour than the one picked (a 0.4, 0.5, 0.6 fog read as about 0.66, 0.73, 0.80). It is now converted for a linear project, so the colour picked is the colour a fully fogged surface shows. A linear project that tuned its fog colour by eye against the old result will look darker and may want it re-picked.- Opening a timeline opens the Sequencer. Double-clicking a timeline used to leave the Sequencer closed unless its tab was already open.## [0.93.0] - 2026-10-19diff --git a/desktop b/desktopindex f2d16e7cf..01f419305 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit f2d16e7cf27d79bc97020fd7dbc006efe41a733a+Subproject commit 01f41930550a72eea767fd7ba2a9b5ced69b88b5diff --git a/docs/astro/src/content/docs/graphics/post-processing.mdx b/docs/astro/src/content/docs/graphics/post-processing.mdxindex 6ca62cfac..6374aba11 100644--- a/docs/astro/src/content/docs/graphics/post-processing.mdx+++ b/docs/astro/src/content/docs/graphics/post-processing.mdx@@ -22,6 +22,9 @@ several can stack in one frame at no extra target cost beyond the passes.| `chromaticAberration` | RGB fringing | `intensity` || `blur` | Gaussian blur | `intensity` || `fxaa` | Fast anti-aliasing | `intensity` |+| `distanceFog` | Linear fog by distance from the camera | `near`, `far`, `intensity`, colour |+| `heightFog` | Exponential height fog with the sun's glow and a hazy horizon | `density`, `heightFalloff`, `baseHeight`, `sunAzimuth`, `sunElevation`, `skyFog`, colours |+| `lightShafts` | Sun rays through whatever stands in front of it | `intensity`, `sunAzimuth`, `sunElevation`, `decay`, `reach` || `ssr` | Screen-space reflections: props mirrored in the floor they stand on | `intensity`, `maxDistance`, `thickness`, `floorBias` || `taa` | Temporal anti-aliasing: edges smoothed over several frames | `blend` || `lensDistortion` | Barrel / pincushion warp | `strength`, `zoom` |@@ -38,6 +41,26 @@ Android, desktop, Steam) runs on. `createWebApp({ msaaSamples })` sizes it, and`fxaa` is the cheaper, blurrier alternative for devices where even one sampleextra is too much.+### Fog and atmosphere++`heightFog` is fog that thins with height: a valley fills, a hilltop clears. Its density falls+off exponentially, so how much of it a ray crosses has a closed form — no marching — and the same+formula makes the **horizon hazy and the zenith clear**, because a ray skimming the ground stays in+the thick part and one aimed up leaves it at once. Sky pixels have no surface to measure to, so they+take the formula with a very long ray; `skyFog` says how much of that haze the sky keeps. Looking toward+the sun the haze takes `sunColor`: give it the sun's direction as `sunAzimuth` (degrees from +Z toward++X) and `sunElevation` (degrees above the horizon) — these are settings of the effect, not read from+a `Light`, so keep them in step with the sun you placed.++`lightShafts` finds the sun's light through whatever stands in front of it, in screen space: each pixel+marches toward the sun's place on screen and counts how much of the way is open sky. It needs the+sun on screen or just off it, and only what the depth buffer holds can cast a shaft. Together the two+give the haze-and-rays look of a low sun; neither is a shadowed volume — fog does not know where a+shadow map says the light is blocked, so the fog itself is lit evenly.++Fog colours are authored as **sRGB** and converted for a linear project, the way a clear colour+and a light colour are, so the colour you pick is the colour a fully fogged surface shows.+### Screen-space reflections`ssr` reflects what is on screen in the surfaces that face up: a wet street, a polisheddiff --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 738b65b5b..5a6cecd97 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@@ -21,6 +21,9 @@ Estella 通过 ping-pong 帧缓冲运行全屏后处理。加一个 `PostProcess| `chromaticAberration` | RGB 色散 | `intensity` || `blur` | 高斯模糊 | `intensity` || `fxaa` | 快速抗锯齿 | `intensity` |+| `distanceFog` | 按到相机的距离做线性雾 | `near`、`far`、`intensity`、颜色 |+| `heightFog` | 指数高度雾,带太阳辉光和朦胧的地平线 | `density`、`heightFalloff`、`baseHeight`、`sunAzimuth`、`sunElevation`、`skyFog`、颜色 |+| `lightShafts` | 太阳光穿过前方遮挡物形成的光束 | `intensity`、`sunAzimuth`、`sunElevation`、`decay`、`reach` || `ssr` | 屏幕空间反射:道具映在它们所站的地面上 | `intensity`、`maxDistance`、`thickness`、`floorBias` || `taa` | 时间性抗锯齿:边缘跨多帧平滑 | `blend` || `lensDistortion` | 桶形 / 枕形畸变 | `strength`、`zoom` |@@ -35,6 +38,21 @@ Estella 通过 ping-pong 帧缓冲运行全屏后处理。加一个 `PostProcess`createWebApp({ msaaSamples })` 调它的大小,`msaaSamples: 1` 在填充率比边缘更要紧的设备上关掉它。`fxaa` 是更便宜也更糊的替代品,留给连多一个采样都吃不下的设备。+### 雾与大气++`heightFog` 是随高度变薄的雾:山谷被填满,山顶是清朗的。它的密度按指数下降,所以射线穿过多少雾有+闭式解——不用步进——而同一个公式让**地平线朦胧、天顶清澈**:贴着地面的射线一直待在浓处,朝上的射线+立刻离开。天空像素没有可测量的表面,所以它们用一条很长的射线代入公式;`skyFog` 决定天空保留多少这样的+雾。朝向太阳看时雾带上 `sunColor`:用 `sunAzimuth`(从 +Z 向 +X 的角度)和 `sunElevation`(地平线以上的+角度)给出太阳方向——它们是这个效果自己的设置,不是从 `Light` 读的,所以要和你放的太阳保持一致。++`lightShafts` 在屏幕空间里找出太阳光穿过前方遮挡物的样子:每个像素朝太阳在屏幕上的位置步进,数这一路有+多少是开阔天空。太阳需要在屏幕上或刚好在屏幕外,而且只有深度缓冲里有的东西才能投出光束。两者配合出+低角度太阳的"雾加光束"的样子;都不是带阴影的体积——雾不知道阴影贴图说光在哪里被挡住,所以雾本身是均匀被照亮的。++雾的颜色按 **sRGB** 书写,线性项目里会被转换,和清屏色、灯光色一样,所以你选的颜色就是完全被雾吞没的表面+显示的颜色。+### 屏幕空间反射`ssr` 把屏幕上已有的东西反射到朝上的表面里:湿街道、抛光地板、湖岸。没有 G-buffer,所以只用链路diff --git a/sdk/src/postprocess/effects.ts b/sdk/src/postprocess/effects.tsindex a9f81922a..11e351e23 100644--- a/sdk/src/postprocess/effects.ts+++ b/sdk/src/postprocess/effects.ts@@ -220,6 +220,50 @@ registerEffect({],});+registerEffect({+ type: 'heightFog',+ label: 'Height Fog',+ factory: () => postProcessEffects.createHeightFog(),+ uniforms: [+ // Per WORLD unit at the base height: the share of light a unit of fog takes out.+ { name: 'u_density', label: 'Density', min: 0, max: 0.05, step: 0.0001, defaultValue: 0.0015, neutralValue: 0 },+ // How fast the fog thins with height; 0 is a fog of one density at every height.+ { name: 'u_heightFalloff', label: 'Height Falloff', min: 0, max: 0.1, step: 0.0005, defaultValue: 0.003 },+ { name: 'u_baseHeight', label: 'Base Height', min: -1000, max: 5000, step: 10, defaultValue: 0 },+ { name: 'u_startDistance', label: 'Start Distance', min: 0, max: 3000, step: 10, defaultValue: 0 },+ { name: 'u_maxOpacity', label: 'Max Opacity', min: 0, max: 1, step: 0.01, defaultValue: 1 },+ // Where the sun is, to colour the haze toward it: degrees from +Z toward +X, and above the horizon.+ { name: 'u_sunAzimuth', label: 'Sun Azimuth', min: 0, max: 360, step: 1, defaultValue: 40 },+ { name: 'u_sunElevation', label: 'Sun Elevation', min: -10, max: 90, step: 1, defaultValue: 25 },+ { name: 'u_inscatter', label: 'Sun Glow', min: 0, max: 2, step: 0.01, defaultValue: 0.6, neutralValue: 0 },+ { name: 'u_sunExponent', label: 'Glow Sharpness', min: 1, max: 64, step: 1, defaultValue: 8 },+ // How much of the sky takes the horizon haze; 0 leaves the sky untouched.+ { name: 'u_skyFog', label: 'Sky Haze', min: 0, max: 1, step: 0.01, defaultValue: 0.8, neutralValue: 0 },+ ],+ colors: [+ { name: 'u_fogColor', label: 'Colour', defaultValue: { r: 0.62, g: 0.7, b: 0.8, a: 1 } },+ { name: 'u_sunColor', label: 'Sun Colour', defaultValue: { r: 1, g: 0.82, b: 0.55, a: 1 } },+ ],+});++registerEffect({+ type: 'lightShafts',+ label: 'Light Shafts',+ factory: () => postProcessEffects.createLightShafts(),+ uniforms: [+ { name: 'u_intensity', label: 'Intensity', min: 0, max: 3, step: 0.01, defaultValue: 0.6, neutralValue: 0 },+ { name: 'u_sunAzimuth', label: 'Sun Azimuth', min: 0, max: 360, step: 1, defaultValue: 40 },+ { name: 'u_sunElevation', label: 'Sun Elevation', min: -10, max: 90, step: 1, defaultValue: 25 },+ // Per step of the march: lower fades the shafts sooner along their length.+ { name: 'u_decay', label: 'Decay', min: 0.8, max: 1, step: 0.005, defaultValue: 0.96 },+ // How much of the way to the sun each pixel looks: shorter shafts at lower values.+ { name: 'u_reach', label: 'Reach', min: 0.1, max: 1, step: 0.01, defaultValue: 0.6 },+ ],+ colors: [+ { name: 'u_sunColor', label: 'Sun Colour', defaultValue: { r: 1, g: 0.85, b: 0.6, a: 1 } },+ ],+});+registerEffect({type: 'ssao',label: 'Ambient Occlusion',diff --git a/sdk/src/postprocess/postProcessEffects.ts b/sdk/src/postprocess/postProcessEffects.tsindex 39a3d5dc9..cf28308fc 100644--- a/sdk/src/postprocess/postProcessEffects.ts+++ b/sdk/src/postprocess/postProcessEffects.ts@@ -1185,6 +1185,263 @@ fn depthAt(texel : vec2i, size : vec2i) -> f32 {return Material.compileShader(source);},+ /**+ * Exponential height fog with the atmosphere's two tells: the sun's glow in the haze and a+ * sky that thickens toward the horizon.+ *+ * The fog's density falls off exponentially with height, so how much of it a ray crosses has a+ * closed form: the density at the eye, times the length, times a term that says how fast the+ * ray climbs out of it. That is also what makes the horizon hazy and the zenith clear — a ray+ * that skims the ground stays in the thick part for ever, and one aimed up leaves it at once —+ * so the sky pixels, which have no surface to measure to, are run through the same formula+ * with a very long ray. Looking toward the sun the haze takes the sun's colour.+ *+ * The fog colours are authored as sRGB and brought into linear light here when the project is+ * linear, as a clear colour and a light colour are: a colour is a colour, and the pipeline+ * under it is not the author's business.+ */+ createHeightFog(): ShaderHandle {+ const source = `#pragma shader "PP Height Fog"+#pragma version 300 es+#pragma domain PostProcess+#pragma param u_fogColor color default(0.62,0.7,0.8,1)+#pragma param u_sunColor color default(1,0.82,0.55,1)+#pragma param u_density float default(0.0015) range(0,0.05)+#pragma param u_heightFalloff float default(0.003) range(0,0.1)+#pragma param u_baseHeight float default(0) range(-1000,5000)+#pragma param u_startDistance float default(0) range(0,3000)+#pragma param u_maxOpacity float default(1) range(0,1)+#pragma param u_sunAzimuth float default(40) range(0,360)+#pragma param u_sunElevation float default(25) range(-10,90)+#pragma param u_inscatter float default(0.6) range(0,2)+#pragma param u_sunExponent float default(8) range(1,64)+#pragma param u_skyFog float default(0.8) range(0,1)++#pragma fragment+precision highp float;++in vec2 v_texCoord;+uniform sampler2D u_texture;+uniform highp sampler2D u_sceneDepth;+out vec4 fragColor;++const float FAR_RAY = 100000.0;++/// What the exponential density integrates to along a ray: the eye's density, the length,+/// and the term for how fast the ray leaves the fog. Written so a level ray (no climb)+/// needs no division, and so a long ray downward cannot overflow.+float opticalDepth(float eyeY, float dirY, float len) {+ float k = u_heightFalloff;+ float dens = u_density * exp(clamp(-k * (eyeY - u_baseHeight), -60.0, 60.0));+ float kd = k * dirY * len;+ float span = abs(kd) < 1e-4 ? 1.0 : (1.0 - exp(clamp(-kd, -60.0, 60.0))) / kd;+ return dens * len * span;+}++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;+ bool sky = depth >= 1.0;++ // The ray starts on the near plane, which is the one place that is a point under a+ // perspective camera and under an orthographic one alike.+ vec3 entry = worldFromDepth(v_texCoord, 0.0);+ vec3 target = worldFromDepth(v_texCoord, sky ? 1.0 : depth);+ vec3 dir = normalize(target - entry);+ float len = sky ? FAR_RAY : length(target - entry);+ float effective = max(len - u_startDistance, 0.0);+ if (effective <= 0.0) { fragColor = src; return; }++ float tau = opticalDepth(entry.y + dir.y * u_startDistance, dir.y, effective);+ float amount = (1.0 - exp(-tau)) * u_maxOpacity * (sky ? u_skyFog : 1.0);++ float az = radians(u_sunAzimuth);+ float el = radians(u_sunElevation);+ vec3 sun = vec3(cos(el) * sin(az), sin(el), cos(el) * cos(az));+ float glow = pow(max(dot(dir, sun), 0.0), u_sunExponent);+ vec3 fog = u_fogColor.rgb;+ vec3 sunTint = u_sunColor.rgb;+#ifdef ES_LINEAR+ fog = srgbToLinear(fog);+ sunTint = srgbToLinear(sunTint);+#endif+ vec3 colour = mix(fog, sunTint, clamp(glow * u_inscatter, 0.0, 1.0));+ fragColor = vec4(mix(src.rgb, colour, clamp(amount, 0.0, 1.0)), src.a);+}+#pragma end++#pragma fragment wgsl+const FAR_RAY : f32 = 100000.0;++fn opticalDepth(eyeY : f32, dirY : f32, len : f32) -> f32 {+ let k = mc.u_heightFalloff;+ let dens = mc.u_density * exp(clamp(-k * (eyeY - mc.u_baseHeight), -60.0, 60.0));+ let kd = k * dirY * len;+ var span = 1.0;+ if (abs(kd) >= 1e-4) { span = (1.0 - exp(clamp(-kd, -60.0, 60.0))) / kd; }+ return dens * len * span;+}++@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {+ let 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);+ let sky = depth >= 1.0;++ let entry = worldFromDepth(v.v_texCoord, 0.0);+ var d = depth;+ if (sky) { d = 1.0; }+ let tgt = worldFromDepth(v.v_texCoord, d);+ let dir = normalize(tgt - entry);+ var len = length(tgt - entry);+ if (sky) { len = FAR_RAY; }+ let effective = max(len - mc.u_startDistance, 0.0);+ if (effective <= 0.0) { return src; }++ let tau = opticalDepth(entry.y + dir.y * mc.u_startDistance, dir.y, effective);+ var amount = (1.0 - exp(-tau)) * mc.u_maxOpacity;+ if (sky) { amount = amount * mc.u_skyFog; }++ let az = radians(mc.u_sunAzimuth);+ let el = radians(mc.u_sunElevation);+ let sun = vec3f(cos(el) * sin(az), sin(el), cos(el) * cos(az));+ let glow = pow(max(dot(dir, sun), 0.0), mc.u_sunExponent);+ var fog = mc.u_fogColor.rgb;+ var sunTint = mc.u_sunColor.rgb;+#ifdef ES_LINEAR+ fog = srgbToLinear(fog);+ sunTint = srgbToLinear(sunTint);+#endif+ let colour = mix(fog, sunTint, clamp(glow * mc.u_inscatter, 0.0, 1.0));+ return vec4f(mix(src.rgb, colour, clamp(amount, 0.0, 1.0)), src.a);+}+#pragma end+`;+ return Material.compileShader(source);+ },++ /**+ * Light shafts: the sun's light through whatever stands between it and the camera, found in+ * screen space. From each pixel a short march toward the sun's position on screen collects+ * how much of the way is open sky; a pixel behind a branch or a building sees little of it+ * and one in the open sees all of it, so what stands in front of the sun leaves rays in the+ * glow around it. The sun's place comes from projecting its direction with the camera's own+ * matrix, so nothing but the direction is asked of the author.+ *+ * Only what the depth buffer holds can cast a shaft, and the sun has to be on screen or+ * just off it: the march has nowhere to go toward a sun behind the camera.+ */+ createLightShafts(): ShaderHandle {+ const source = `#pragma shader "PP Light Shafts"+#pragma version 300 es+#pragma domain PostProcess+#pragma param u_sunColor color default(1,0.85,0.6,1)+#pragma param u_intensity float default(0.6) range(0,3)+#pragma param u_sunAzimuth float default(40) range(0,360)+#pragma param u_sunElevation float default(25) range(-10,90)+#pragma param u_decay float default(0.96) range(0.8,1)+#pragma param u_reach float default(0.6) range(0.1,1)++#pragma fragment+precision highp float;++in vec2 v_texCoord;+uniform sampler2D u_texture;+uniform highp sampler2D u_sceneDepth;+out vec4 fragColor;++const int SAMPLES = 40;++float ign(vec2 p) {+ return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715))));+}++void main() {+ vec4 src = texture(u_texture, v_texCoord);+ float az = radians(u_sunAzimuth);+ float el = radians(u_sunElevation);+ vec3 sun = vec3(cos(el) * sin(az), sin(el), cos(el) * cos(az));+ vec3 eye = worldFromDepth(v_texCoord, 0.0);+ vec4 clip = u_projection * vec4(eye + sun * 10000.0, 1.0);+ // Behind the camera there is no screen position to march toward.+ if (clip.w <= 1e-4) { fragColor = src; return; }+ vec2 sunUv = clip.xy / clip.w * 0.5 + 0.5;++ ivec2 size = textureSize(u_sceneDepth, 0);+ vec2 toSun = (sunUv - v_texCoord) * u_reach;+ float aspect = float(size.x) / float(size.y);+ float dist = length(vec2((sunUv.x - v_texCoord.x) * aspect, sunUv.y - v_texCoord.y));+ vec2 stepUv = toSun / float(SAMPLES);+ vec2 uv = v_texCoord + stepUv * ign(gl_FragCoord.xy);+ float light = 0.0;+ float weight = 1.0;+ for (int i = 0; i < SAMPLES; ++i) {+ uv += stepUv;+ ivec2 t = clamp(ivec2(uv * vec2(size)), ivec2(0), size - ivec2(1));+ // Open sky is where the sun reaches; anything with a surface blocks it.+ float open = texelFetch(u_sceneDepth, t, 0).r >= 1.0 ? 1.0 : 0.0;+ light += open * weight;+ weight *= u_decay;+ }+ light /= float(SAMPLES);+ // Strongest next to the sun, gone a screen away from it.+ float falloff = 1.0 - smoothstep(0.0, 1.2, dist);+ vec3 tint = u_sunColor.rgb;+#ifdef ES_LINEAR+ tint = srgbToLinear(tint);+#endif+ fragColor = vec4(src.rgb + tint * light * falloff * u_intensity, src.a);+}+#pragma end++#pragma fragment wgsl+const SAMPLES : i32 = 40;++fn ign(p : vec2f) -> f32 {+ return fract(52.9829189 * fract(dot(p, vec2f(0.06711056, 0.00583715))));+}++@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {+ let src = textureSampleLevel(t0, s0, v.v_texCoord, 0.0);+ let az = radians(mc.u_sunAzimuth);+ let el = radians(mc.u_sunElevation);+ let sun = vec3f(cos(el) * sin(az), sin(el), cos(el) * cos(az));+ let eye = worldFromDepth(v.v_texCoord, 0.0);+ let clip = frame.projection * vec4f(eye + sun * 10000.0, 1.0);+ if (clip.w <= 1e-4) { return src; }+ // This device's uv runs down the rows, so clip y is flipped on the way back.+ let sunUv = vec2f(clip.x / clip.w * 0.5 + 0.5, 0.5 - clip.y / clip.w * 0.5);++ let size = vec2i(textureDimensions(t7, 0));+ let toSun = (sunUv - v.v_texCoord) * mc.u_reach;+ let aspect = f32(size.x) / f32(size.y);+ let dist = length(vec2f((sunUv.x - v.v_texCoord.x) * aspect, sunUv.y - v.v_texCoord.y));+ let stepUv = toSun / f32(SAMPLES);+ var uv = v.v_texCoord + stepUv * ign(v.pos.xy);+ var light = 0.0;+ var weight = 1.0;+ for (var i : i32 = 0; i < SAMPLES; i = i + 1) {+ uv = uv + stepUv;+ let t = clamp(vec2i(uv * vec2f(size)), vec2i(0), size - vec2i(1));+ var lit = 0.0;+ if (textureLoad(t7, t, 0) >= 1.0) { lit = 1.0; }+ light = light + lit * weight;+ weight = weight * mc.u_decay;+ }+ light = light / f32(SAMPLES);+ let falloff = 1.0 - smoothstep(0.0, 1.2, dist);+ var tint = mc.u_sunColor.rgb;+#ifdef ES_LINEAR+ tint = srgbToLinear(tint);+#endif+ return vec4f(src.rgb + tint * light * falloff * mc.u_intensity, src.a);+}+#pragma end+`;+ return Material.compileShader(source);+ },+createDistanceFog(): ShaderHandle {// Fog is a DISTANCE and a depth sample is not one: the same 0.9 is a// metre away up close and a hundred out. `worldFromDepth` (injected with@@ -1220,7 +1477,12 @@ void main() {vec3 entry = worldFromDepth(v_texCoord, 0.0);float dist = length(world - entry);float t = clamp((dist - u_fogNear) / max(u_fogFar - u_fogNear, 1e-4), 0.0, 1.0);- fragColor = vec4(mix(src.rgb, u_fogColor.rgb, t * u_intensity), src.a);+ // Authored as sRGB, like every colour: a linear frame takes it as light, not as a code.+ vec3 fog = u_fogColor.rgb;+#ifdef ES_LINEAR+ fog = srgbToLinear(fog);+#endif+ fragColor = vec4(mix(src.rgb, fog, t * u_intensity), src.a);}#pragma end@@ -1234,7 +1496,11 @@ void main() {let entry = worldFromDepth(v.v_texCoord, 0.0);let dist = length(world - entry);let t = clamp((dist - mc.u_fogNear) / max(mc.u_fogFar - mc.u_fogNear, 1e-4), 0.0, 1.0);- return vec4f(mix(src.rgb, mc.u_fogColor.rgb, vec3f(t * mc.u_intensity)), src.a);+ var fog = mc.u_fogColor.rgb;+#ifdef ES_LINEAR+ fog = srgbToLinear(fog);+#endif+ return vec4f(mix(src.rgb, fog, vec3f(t * mc.u_intensity)), src.a);}#pragma end`;diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex b768fcf65..dff1c818c 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -2475,4 +2475,6 @@ export const NOTED = {{"note":"A Temporal Anti-Aliasing post-process effect smooths edges across frames."},"feat(render): a Screen Space Reflections effect mirrors the scene in the surfaces that face up":{"note":"A Screen Space Reflections post-process effect mirrors props in floors."},+ "feat(render): Height Fog and Light Shafts effects give a hazy horizon, the sun's glow and rays through what stands in front of it":+ {"note":"Height Fog and Light Shafts post-process effects add atmosphere."},};