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): motion blur, film grain and lens flare join the post-process effects
yhhfab9c61cb0fd
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2ecea6179..be99d4c55 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.+- **Motion blur, film grain and lens flare.** Motion blur, film grain and lens flare are post-process effects, and a moving mesh's motion now reaches effects on WebGPU too. Motion blur follows the camera by the depth buffer and a moving mesh by its own motion, with the shutter and a cap on the streak as its settings; it needs no temporal anti-aliasing and does not shift the picture. Film grain is mid-tone noise that crawls with the clock; lens flare throws ghosts and a halo from what is brighter than a threshold. The low quality level skips motion blur and lens flare. Also fixed: a 32-bit float texture an effect only reads texel by texel (the motion pass's) is no longer paired with a filtering sampler, which WebGPU refused — temporal anti-aliasing's object motion logged an error every frame there.- **Shading layers.** The Model material has shading layers — clear coat, sheen, anisotropy, translucency, thin film, index of refraction and transmission — and a glTF with the matching extensions arrives using them. Clear coat puts a second, sharper highlight over the base and darkens what is under it; sheen is the soft grazing-angle light of cloth; anisotropy stretches a highlight across brushed grooves; translucency lets light wrap past the terminator and show through from behind; thin film shifts the reflection's hue with the angle; the index of refraction sets how strongly a non-metal reflects; transmission lets a surface show what is behind it, drawn blended with no refraction. Custom Lit shaders reach the same lighting through `applyLightingSurface` and a `SurfaceExt`. A layer's textures are not read — its factors are — and the import says so; a material that sets none of them draws as before.- **Many lights.** A frame now carries up to 112 lights: sixteen are read for every pixel and the rest are tiled, so a street of lamps lights what each one reaches. The sun, the lights that cast a shadow and then the brightest go in the lighting loop as before; every other point and spot light without a shadow map is recorded per screen tile (16 x 12) and shaded only by the pixels it reaches, so the cost follows the lights near a pixel and not the lights in the scene. Tiled lights do not cast shadows, and the whole lighting block still fits the 16 KB a uniform block is guaranteed, so it runs on WebGL2 and WebGPU alike.- **Play on WebGPU.** Play runs the game on the graphics backend the project asks for, so a WebGPU project is played on WebGPU and its compute effects and Voxel GI are seen in the editor. Until now Play always ran on WebGL2 whatever the project asked for; it now follows `features.rendering.backend` the way a shipped build does, and falls back to WebGL2 on a machine with no WebGPU.diff --git a/desktop b/desktopindex 73b1187ca..6babe436b 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 73b1187cadf62599e6a27e3336a64bae3b163abb+Subproject commit 6babe436b43e78517bfd15ac92f00ee706de67c9diff --git a/docs/astro/src/content/docs/graphics/post-processing.mdx b/docs/astro/src/content/docs/graphics/post-processing.mdxindex 0b76f7147..87817d0bd 100644--- a/docs/astro/src/content/docs/graphics/post-processing.mdx+++ b/docs/astro/src/content/docs/graphics/post-processing.mdx@@ -36,6 +36,9 @@ several can stack in one frame at no extra target cost beyond the passes.| `ssr` | Screen-space reflections: props mirrored in the floor they stand on | `intensity`, `maxDistance`, `thickness`, `floorBias`, `skyReflection` || `taa` | Temporal anti-aliasing: edges smoothed over several frames, moving meshes followed by their own motion | `blend`, `objectMotion` || `lensDistortion` | Barrel / pincushion warp | `strength`, `zoom` |+| `motionBlur` | Smears what moved since the last frame: the camera's move from the depth buffer, a moving mesh's own from the motion pass | `intensity` (the shutter), `maxBlur`, `objectMotion` |+| `filmGrain` | Noise the size of a film crystal, strongest in the mid-tones, crawling with the clock | `intensity`, `size`, `response` |+| `lensFlare` | Ghosts and a halo thrown by whatever is brighter than a threshold, with a colour fringe | `intensity`, `threshold`, `ghosts`, `dispersal`, `haloWidth`, `chromatic`, `tint` || `pixelate` | Block quantization | `pixelSize` || `outline` | Ink-edge outlines (Sobel edge darkening) | `intensity`, `threshold`, `thickness` || `grayscale` | Desaturate | `intensity` |@@ -49,6 +52,18 @@ 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.+### Motion blur and the lens++`motionBlur` needs no setup: add it and it follows the camera by the depth buffer and any moving mesh by the same+motion pass temporal anti-aliasing uses, so a mesh that moves by itself is smeared along its own path and not the+camera's. `intensity` is the shutter — 0.5 is the half-frame exposure of a 180° shutter, 1 a whole frame — and+`maxBlur` caps the streak as a fraction of the picture so a cut or a teleport smears a little and not the frame.+It draws the picture still when the camera has not moved, and it does not shift the picture sub-pixel the way a+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 to+throw where the picture holds values above `threshold`: a bright sun disc, a lamp, an emissive surface (in HDR).+### 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 e8847d54a..d4eec3b4c 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@@ -19,6 +19,9 @@ Estella 通过 ping-pong 帧缓冲运行全屏后处理。加一个 `PostProcess| `lutGrade` | 通过查找表纹理(LUT)调色 | `u_lut`(纹理)、`intensity` || `vignette` | 屏幕边缘变暗 | `intensity`、`softness` || `chromaticAberration` | RGB 色散 | `intensity` |+| `motionBlur` | 沿上一帧以来的运动抹开:相机的移动来自深度缓冲,运动网格自身的移动来自运动 pass | `intensity`(快门)、`maxBlur`、`objectMotion` |+| `filmGrain` | 胶片晶粒大小的噪点,在中间调最强,随时钟闪动 | `intensity`、`size`、`response` |+| `lensFlare` | 亮于阈值的物体投出的鬼影和光晕,带色彩边缘 | `intensity`、`threshold`、`ghosts`、`dispersal`、`haloWidth`、`chromatic`、`tint` || `blur` | 高斯模糊 | `intensity` || `fxaa` | 快速抗锯齿 | `intensity` || `distanceFog` | 按到相机的距离做线性雾 | `near`、`far`、`intensity`、颜色 |@@ -46,6 +49,12 @@ Estella 通过 ping-pong 帧缓冲运行全屏后处理。加一个 `PostProcess`createWebApp({ msaaSamples })` 调它的大小,`msaaSamples: 1` 在填充率比边缘更要紧的设备上关掉它。`fxaa` 是更便宜也更糊的替代品,留给连多一个采样都吃不下的设备。+### 运动模糊与镜头++`motionBlur` 无需配置:加上它,相机的移动由深度缓冲得出,运动网格的移动由时间性抗锯齿用的同一个运动 pass 得出,所以自己在动的网格会沿着它自己的轨迹被抹开,而不是相机的轨迹。`intensity` 是快门——0.5 是 180° 快门的半帧曝光,1 是整帧——`maxBlur` 把拖影长度限制在画面的一个比例内,切镜头或瞬移只会抹开一点点,不会抹开整个画面。相机没动时它画出原图,并且不像时间性效果那样对画面做亚像素偏移,所以可以不带 `taa` 单独使用。++`filmGrain` 和 `lensFlare` 是普通的后处理效果。镜头光斑读取的是画面本身,所以只有画面里存在高于 `threshold` 的值(明亮的太阳圆盘、灯、HDR 下的自发光表面)时它才有东西可投。+### 雨、潮湿的地面与水坑`rain` 是由两部分组成的暴雨。**落下的雨**是三层在屏幕上向下滚动的细斜线,每层站在自己的距离上:比该层更近的表面会挡住diff --git a/sdk/src/postprocess/effects.ts b/sdk/src/postprocess/effects.tsindex bf9b90f75..b156f3df8 100644--- a/sdk/src/postprocess/effects.ts+++ b/sdk/src/postprocess/effects.ts@@ -2,6 +2,7 @@// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Teamimport type { ShaderHandle } from '../render/material';import { postProcessEffects } from './postProcessEffects';+import { lensEffects } from './lensEffects';import { SHARPEN_WGSL } from './computeEffects';export interface EffectUniformDef {@@ -588,6 +589,50 @@ registerEffect({],});+registerEffect({+ type: 'motionBlur',+ label: 'Motion Blur',+ factory: () => lensEffects.createMotionBlur(),+ // The camera's and the moving meshes' own motion, both from the frame; what is left to set is the exposure.+ uniforms: [+ // The shutter: how much of the distance a pixel moved in a frame the streak covers. 0.5 is a 180 degree shutter.+ { name: 'u_intensity', label: 'Shutter', min: 0, max: 2, step: 0.01, defaultValue: 0.5, neutralValue: 0 },+ // The longest streak as a fraction of the picture, so a cut or a teleport smears a little and not the frame.+ { name: 'u_maxBlur', label: 'Max Blur', min: 0.002, max: 0.25, step: 0.002, defaultValue: 0.05 },+ { name: 'u_objectMotion', label: 'Object Motion', min: 0, max: 1, step: 1, defaultValue: 1, neutralValue: 1 },+ ],+});++registerEffect({+ type: 'filmGrain',+ label: 'Film Grain',+ factory: () => lensEffects.createFilmGrain(),+ uniforms: [+ { name: 'u_intensity', label: 'Intensity', min: 0, max: 1, step: 0.01, defaultValue: 0.15, neutralValue: 0 },+ { name: 'u_size', label: 'Grain Size', min: 1, max: 6, step: 0.1, defaultValue: 1.6 },+ // 1 puts the grain in the mid-tones where film has it; 0 spreads it evenly, blacks and whites included.+ { name: 'u_response', label: 'Mid-tone Response', min: 0, max: 1, step: 0.01, defaultValue: 0.8 },+ ],+});++registerEffect({+ type: 'lensFlare',+ label: 'Lens Flare',+ factory: () => lensEffects.createLensFlare(),+ uniforms: [+ { name: 'u_intensity', label: 'Intensity', min: 0, max: 4, step: 0.01, defaultValue: 0.4, neutralValue: 0 },+ // Only what is brighter than this (in the picture's own units, HDR included) throws a flare.+ { name: 'u_threshold', label: 'Threshold', min: 0, max: 8, step: 0.05, defaultValue: 1.2 },+ { name: 'u_ghosts', label: 'Ghosts', min: 1, max: 8, step: 1, defaultValue: 5 },+ { name: 'u_dispersal', label: 'Dispersal', min: 0.05, max: 1, step: 0.01, defaultValue: 0.35 },+ { name: 'u_haloWidth', label: 'Halo Width', min: 0, max: 1, step: 0.01, defaultValue: 0.45 },+ { name: 'u_chromatic', label: 'Colour Fringe', min: 0, max: 0.05, step: 0.001, defaultValue: 0.012 },+ ],+ colors: [+ { name: 'u_tint', label: 'Tint', defaultValue: { r: 1, g: 0.85, b: 0.7, a: 1 } },+ ],+});+registerEffect({type: 'lutGrade',label: 'LUT Grade',diff --git a/sdk/src/postprocess/lensEffects.ts b/sdk/src/postprocess/lensEffects.tsnew file mode 100644index 000000000..be5d09fd3--- /dev/null+++ b/sdk/src/postprocess/lensEffects.ts@@ -0,0 +1,289 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file lensEffects.ts+ * @brief The effects that belong to a camera rather than a world: motion blur, film grain, lens flare.+ * @details Same seam as postProcessEffects.ts — fragment-only `.esshader` sources with a WGSL twin each — kept apart+ * because none of them reads a surface's material: they read the picture, and (for motion blur) where+ * each pixel was a frame ago.+ */+import type { ShaderHandle } from '../render/material';+import { Material } from '../render/material';+import { SSAO_GLSL, SSAO_WGSL } from './postProcessEffects';++export const lensEffects = {+ /**+ * Motion blur: each pixel is smeared along the way it moved since the last frame.+ *+ * Where a pixel was comes from two places, as it does for temporal anti-aliasing. The camera's own move is+ * exact for everything the camera moves past: un-project the pixel with the depth buffer and project it again+ * with last frame's camera. A surface that moved by itself is not explained by that, so the frame's motion+ * pass (`u_velocity`) is read where what it drew is the surface the scene shows. The streak is `u_intensity`+ * of that distance — the shutter: 1 is a whole frame's exposure, 0.5 the half most cameras use — and never+ * longer than `u_maxBlur` of the picture, so a cut or a teleport smears a little instead of the whole image.+ * Taps are spread over the streak and shifted by a per-pixel noise, which turns the stepping into grain a+ * temporal pass then averages away.+ */+ createMotionBlur(): ShaderHandle {+ const source = `#pragma shader "PP MotionBlur"+#pragma version 300 es+#pragma domain PostProcess+#pragma param u_intensity float default(0.5) range(0,2)+#pragma param u_maxBlur float default(0.05) range(0.002,0.25)+#pragma param u_objectMotion float default(1) range(0,1)+#pragma param u_prevViewProjection0 color default(1,0,0,0)+#pragma param u_prevViewProjection1 color default(0,1,0,0)+#pragma param u_prevViewProjection2 color default(0,0,1,0)+#pragma param u_prevViewProjection3 color default(0,0,0,1)+#pragma param u_velocity texture default(black)++#pragma fragment+precision highp float;++in vec2 v_texCoord;+uniform sampler2D u_texture;+uniform highp sampler2D u_sceneDepth;+out vec4 fragColor;++${SSAO_GLSL}++float ign(vec2 p) {+ return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715))));+}++void main() {+ vec4 cur = texture(u_texture, v_texCoord);+ ivec2 dsize = textureSize(u_sceneDepth, 0);+ float d = depthAt(screenTexel(v_texCoord, dsize), dsize);+ // How far this pixel is from where it was, in uv: the camera's move first...+ vec2 m = vec2(0.0);+ vec3 world = worldFromDepth(v_texCoord, d);+ vec4 prev = mat4(u_prevViewProjection0, u_prevViewProjection1,+ u_prevViewProjection2, u_prevViewProjection3) * vec4(world, 1.0);+ if (prev.w > 1e-6) m = prev.xy / prev.w * 0.5 + 0.5 - v_texCoord;+ // ...and, where a surface moved by itself, its own.+ ivec2 vsize = textureSize(u_velocity, 0);+ vec4 vel = texelFetch(u_velocity, screenTexel(v_texCoord, vsize), 0);+ if (u_objectMotion > 0.5 && vel.a > 0.5 && abs(vel.b - d) <= 2e-5 + (1.0 - d) * 0.02) m = vel.xy;+ m *= u_intensity;+ float reach = length(m);+ if (reach > u_maxBlur) m *= u_maxBlur / reach;+ vec2 pixels = m * u_viewport.xy;+ if (dot(pixels, pixels) < 1.0) { fragColor = cur; return; }++ const int TAPS = 16;+ float noise = ign(gl_FragCoord.xy) - 0.5;+ vec3 sum = cur.rgb;+ float weight = 1.0;+ for (int i = 0; i < TAPS; ++i) {+ float t = (float(i) + 0.5 + noise) / float(TAPS) - 0.5;+ vec2 uv = v_texCoord + m * t;+ if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) continue;+ sum += texture(u_texture, uv).rgb;+ weight += 1.0;+ }+ fragColor = vec4(sum / weight, cur.a);+}+#pragma end++#pragma fragment wgsl+${SSAO_WGSL}++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 cur = textureSampleLevel(t0, s0, v.v_texCoord, 0.0);+ let dsize = vec2i(textureDimensions(t7, 0));+ let d = depthAt(screenTexel(v.v_texCoord, dsize), dsize);+ var m = vec2f(0.0);+ let world = worldFromDepth(v.v_texCoord, d);+ let vp = mat4x4f(mc.u_prevViewProjection0, mc.u_prevViewProjection1,+ mc.u_prevViewProjection2, mc.u_prevViewProjection3);+ let prev = vp * vec4f(world, 1.0);+ // This device's uv runs down the rows, so clip y is flipped on the way back (as the temporal effect does).+ if (prev.w > 1e-6) { m = vec2f(prev.x / prev.w * 0.5 + 0.5, 0.5 - prev.y / prev.w * 0.5) - v.v_texCoord; }+ let vsize = vec2i(textureDimensions(u_velocity, 0));+ let vel = textureLoad(u_velocity, screenTexel(v.v_texCoord, vsize), 0);+ if (mc.u_objectMotion > 0.5 && vel.a > 0.5 && abs(vel.b - d) <= 2e-5 + (1.0 - d) * 0.02) {+ m = vec2f(vel.x, -vel.y);+ }+ m = m * mc.u_intensity;+ let reach = length(m);+ if (reach > mc.u_maxBlur) { m = m * (mc.u_maxBlur / reach); }+ let pixels = m * tc.u_viewport.xy;+ if (dot(pixels, pixels) < 1.0) { return cur; }++ let noise = ign(v.v_texCoord * tc.u_viewport.xy) - 0.5;+ var sum = cur.rgb;+ var weight = 1.0;+ for (var i : i32 = 0; i < 16; i = i + 1) {+ let t = (f32(i) + 0.5 + noise) / 16.0 - 0.5;+ let uv = v.v_texCoord + m * t;+ if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) { continue; }+ sum = sum + textureSampleLevel(t0, s0, uv, 0.0).rgb;+ weight = weight + 1.0;+ }+ return vec4f(sum / weight, cur.a);+}+#pragma end+`;+ return Material.compileShader(source);+ },++ /**+ * Film grain: noise the size of a film crystal, strongest in the mid-tones and absent from true black and from+ * clipped white, which is where film has none. The pattern is a hash of the grain cell and the frame clock, so it+ * crawls the way a projected film does instead of sitting on the screen as a texture.+ */+ createFilmGrain(): ShaderHandle {+ const source = `#pragma shader "PP FilmGrain"+#pragma version 300 es+#pragma domain PostProcess+#pragma param u_intensity float default(0.15) range(0,1)+#pragma param u_size float default(1.6) range(1,6)+#pragma param u_response float default(0.8) range(0,1)++#pragma fragment+precision highp float;++in vec2 v_texCoord;+uniform sampler2D u_texture;+out vec4 fragColor;++float hash(vec3 p) {+ p = fract(p * vec3(0.1031, 0.1030, 0.0973));+ p += dot(p, p.yxz + 33.33);+ return fract((p.x + p.y) * p.z);+}++void main() {+ vec4 color = texture(u_texture, v_texCoord);+ vec2 cell = floor(v_texCoord * u_viewport.xy / u_size);+ // Two hashes averaged: the sum of two uniforms is triangular, so grain is mostly small with the odd large speck.+ float n = hash(vec3(cell, floor(u_time.x * 24.0))) + hash(vec3(cell + 71.0, floor(u_time.x * 24.0))) - 1.0;+ float luma = dot(color.rgb, vec3(0.2126, 0.7152, 0.0722));+ float mid = 4.0 * clamp(luma, 0.0, 1.0) * (1.0 - clamp(luma, 0.0, 1.0));+ float weight = mix(1.0, mid, u_response);+ fragColor = vec4(max(color.rgb * (1.0 + n * u_intensity * weight * 2.0), vec3(0.0)), color.a);+}+#pragma end++#pragma fragment wgsl+fn hash(p0 : vec3f) -> f32 {+ var p = fract(p0 * vec3f(0.1031, 0.1030, 0.0973));+ p = p + dot(p, p.yxz + 33.33);+ return fract((p.x + p.y) * p.z);+}++@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {+ let color = textureSampleLevel(t0, s0, v.v_texCoord, 0.0);+ let cell = floor(v.v_texCoord * tc.u_viewport.xy / mc.u_size);+ let frameIndex = floor(tc.u_time.x * 24.0);+ let n = hash(vec3f(cell, frameIndex)) + hash(vec3f(cell + 71.0, frameIndex)) - 1.0;+ let luma = dot(color.rgb, vec3f(0.2126, 0.7152, 0.0722));+ let mid = 4.0 * clamp(luma, 0.0, 1.0) * (1.0 - clamp(luma, 0.0, 1.0));+ let weight = mix(1.0, mid, mc.u_response);+ return vec4f(max(color.rgb * (1.0 + n * mc.u_intensity * weight * 2.0), vec3f(0.0)), color.a);+}+#pragma end+`;+ return Material.compileShader(source);+ },++ /**+ * Lens flare: what bright things do inside a lens. Ghosts are reflections between the elements, mirrored through+ * the centre of the picture and walking along the line from the light to it; the halo is the ring a wide-angle+ * lens throws round the centre. Only what is brighter than `u_threshold` takes part, and each ghost is taken+ * with a little chromatic spread, since a lens does not bend every colour the same. Added over the picture.+ */+ createLensFlare(): ShaderHandle {+ const source = `#pragma shader "PP LensFlare"+#pragma version 300 es+#pragma domain PostProcess+#pragma param u_intensity float default(0.4) range(0,4)+#pragma param u_threshold float default(1.2) range(0,8)+#pragma param u_ghosts float default(5) range(1,8)+#pragma param u_dispersal float default(0.35) range(0.05,1)+#pragma param u_haloWidth float default(0.45) range(0,1)+#pragma param u_chromatic float default(0.012) range(0,0.05)+#pragma param u_tint color default(1,0.85,0.7,1)++#pragma fragment+precision highp float;++in vec2 v_texCoord;+uniform sampler2D u_texture;+out vec4 fragColor;++vec3 bright(vec2 uv, vec2 spread) {+ // A small cross of taps, since a single one of a point light is a speck.+ vec3 c = max(texture(u_texture, uv).rgb - u_threshold, 0.0) * 0.4;+ c += max(texture(u_texture, uv + vec2(spread.x, 0.0)).rgb - u_threshold, 0.0) * 0.15;+ c += max(texture(u_texture, uv - vec2(spread.x, 0.0)).rgb - u_threshold, 0.0) * 0.15;+ c += max(texture(u_texture, uv + vec2(0.0, spread.y)).rgb - u_threshold, 0.0) * 0.15;+ c += max(texture(u_texture, uv - vec2(0.0, spread.y)).rgb - u_threshold, 0.0) * 0.15;+ return c;+}+vec3 fringed(vec2 uv, vec2 dir, vec2 spread) {+ return vec3(bright(uv + dir * u_chromatic, spread).r, bright(uv, spread).g, bright(uv - dir * u_chromatic, spread).b);+}++void main() {+ vec4 color = texture(u_texture, v_texCoord);+ vec2 uv = vec2(1.0) - v_texCoord;+ vec2 toCentre = vec2(0.5) - uv;+ vec2 ghostStep = toCentre * u_dispersal;+ vec2 spread = 2.0 * u_viewport.zw;+ vec3 flare = vec3(0.0);+ for (int i = 0; i < 8; ++i) {+ if (float(i) >= u_ghosts) break;+ vec2 at = fract(uv + ghostStep * float(i));+ float edge = 1.0 - clamp(length(vec2(0.5) - at) / 0.7071, 0.0, 1.0);+ flare += fringed(at, normalize(toCentre + 1e-5), spread) * (edge * edge * edge);+ }+ vec2 haloDir = normalize(toCentre + 1e-5) * u_haloWidth;+ float haloEdge = 1.0 - clamp(length(vec2(0.5) - (uv + haloDir)) / 0.7071, 0.0, 1.0);+ flare += fringed(uv + haloDir, haloDir, spread) * pow(haloEdge, 4.0) * 2.0;+ fragColor = vec4(color.rgb + flare * u_tint.rgb * u_intensity, color.a);+}+#pragma end++#pragma fragment wgsl+fn bright(uv : vec2f, spread : vec2f) -> vec3f {+ var c = max(textureSampleLevel(t0, s0, uv, 0.0).rgb - vec3f(mc.u_threshold), vec3f(0.0)) * 0.4;+ c = c + max(textureSampleLevel(t0, s0, uv + vec2f(spread.x, 0.0), 0.0).rgb - vec3f(mc.u_threshold), vec3f(0.0)) * 0.15;+ c = c + max(textureSampleLevel(t0, s0, uv - vec2f(spread.x, 0.0), 0.0).rgb - vec3f(mc.u_threshold), vec3f(0.0)) * 0.15;+ c = c + max(textureSampleLevel(t0, s0, uv + vec2f(0.0, spread.y), 0.0).rgb - vec3f(mc.u_threshold), vec3f(0.0)) * 0.15;+ c = c + max(textureSampleLevel(t0, s0, uv - vec2f(0.0, spread.y), 0.0).rgb - vec3f(mc.u_threshold), vec3f(0.0)) * 0.15;+ return c;+}+fn fringed(uv : vec2f, dir : vec2f, spread : vec2f) -> vec3f {+ return vec3f(bright(uv + dir * mc.u_chromatic, spread).r, bright(uv, spread).g, bright(uv - dir * mc.u_chromatic, spread).b);+}++@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {+ let color = textureSampleLevel(t0, s0, v.v_texCoord, 0.0);+ let uv = vec2f(1.0) - v.v_texCoord;+ let toCentre = vec2f(0.5) - uv;+ let ghostStep = toCentre * mc.u_dispersal;+ let spread = 2.0 * tc.u_viewport.zw;+ let dir = normalize(toCentre + vec2f(1e-5));+ var flare = vec3f(0.0);+ for (var i : i32 = 0; i < 8; i = i + 1) {+ if (f32(i) >= mc.u_ghosts) { break; }+ let at = fract(uv + ghostStep * f32(i));+ let edge = 1.0 - clamp(length(vec2f(0.5) - at) / 0.7071, 0.0, 1.0);+ flare = flare + fringed(at, dir, spread) * (edge * edge * edge);+ }+ let haloDir = dir * mc.u_haloWidth;+ let haloEdge = 1.0 - clamp(length(vec2f(0.5) - (uv + haloDir)) / 0.7071, 0.0, 1.0);+ flare = flare + fringed(uv + haloDir, haloDir, spread) * pow(haloEdge, 4.0) * 2.0;+ return vec4f(color.rgb + flare * mc.u_tint.rgb * mc.u_intensity, color.a);+}+#pragma end+`;+ return Material.compileShader(source);+ },+};diff --git a/sdk/src/postprocess/postProcessEffects.ts b/sdk/src/postprocess/postProcessEffects.tsindex d684c7f84..0a914b303 100644--- a/sdk/src/postprocess/postProcessEffects.ts+++ b/sdk/src/postprocess/postProcessEffects.ts@@ -21,7 +21,7 @@ import { Material } from '../render/material';* definition each: a fix that reached only the first of three copies compiled* fine and drew a black screen.*/-const SSAO_GLSL = `/// A texel of the pass's uv, which runs in the device's own row order: up the+export const SSAO_GLSL = `/// A texel of the pass's uv, which runs in the device's own row order: up the/// screen here, down it on WebGPU. Its inverse round-trips through that uv.ivec2 screenTexel(vec2 uv, ivec2 size) {return clamp(ivec2(uv * vec2(size)), ivec2(0), size - ivec2(1));@@ -49,7 +49,7 @@ float worldPerDepth(vec2 uv, float d, vec3 P) {return length(worldFromDepth(uv, d + de) - P) / abs(de);}`;-const SSAO_WGSL = `fn screenTexel(uv : vec2f, size : vec2i) -> vec2i {+export const SSAO_WGSL = `fn screenTexel(uv : vec2f, size : vec2i) -> vec2i {return clamp(vec2i(uv * vec2f(size)), vec2i(0), size - vec2i(1));}fn uvOfTexel(t : vec2i, size : vec2i) -> vec2f {diff --git a/sdk/src/render/quality.ts b/sdk/src/render/quality.tsindex 30708dd13..45bdfddab 100644--- a/sdk/src/render/quality.ts+++ b/sdk/src/render/quality.ts@@ -60,7 +60,7 @@ const PROFILES: Record<QualityLevel, QualityProfile> = {shadowAtlasSize: 1024, shadowCellSize: 256, shadowCascades: 2,planarReflectionScale: 0.25, planarReflectionMaxSize: 512, planarReflectionUpdatesPerSecond: 0,shadowDistance: 0, particleLimit: 1000, postProcess: true, ssao: false,- skipEffects: ['ssr', 'taa', 'depthOfField', 'lightShafts'],+ skipEffects: ['ssr', 'taa', 'depthOfField', 'lightShafts', 'motionBlur', 'lensFlare'],},medium: {renderScale: 1, minRenderScale: 0.65, msaaSamples: 2,diff --git a/src/esengine/renderer/frame/PostProcessPipeline.cpp b/src/esengine/renderer/frame/PostProcessPipeline.cppindex a22b405e9..fd9e2d8aa 100644--- a/src/esengine/renderer/frame/PostProcessPipeline.cpp+++ b/src/esengine/renderer/frame/PostProcessPipeline.cpp@@ -376,6 +376,24 @@ bool PostProcessPipeline::temporalActive() {return false;}+bool PostProcessPipeline::cameraMotionWanted() {+ if (!initialized_ || bypass_) return false;+ for (const auto& pass : passes_) {+ if (!pass.enabled || !pass.nativeKind.empty() || passIsTemporal(pass)) continue;+ const MaterialUniformLayout* layout = context_.materials().layoutFor(pass.shader);+ if (layout && layout->find("u_prevViewProjection0")) return true;+ }+ return false;+}++void PostProcessPipeline::trackView(const glm::mat4& viewProjection, u64 key) {+ TemporalState& state = temporal_[key];+ temporalKey_ = key;+ state.previous = state.frame > 0 ? state.current : viewProjection;+ state.current = viewProjection;+ ++state.frame;+}+bool PostProcessPipeline::velocityWanted() {if (!initialized_ || bypass_ || !device_.supportsFloatTargets()) return false;for (const auto& pass : passes_) {@@ -788,6 +806,16 @@ void PostProcessPipeline::renderPass(PostProcessPass& pass, const rg::PassContexpass.floatUniforms["u_historyValid"] = temporal->valid ? 1.0f : 0.0f;pass.paramDirty = true;}+ // An effect that wants only where the camera WAS (motion blur): no history, so no `temporal` above, but the+ // same matrix. Nothing to send before the view has been followed once.+ if (!pass.temporal && layout && layout->find("u_prevViewProjection0")) {+ if (auto it = temporal_.find(temporalKey_); it != temporal_.end()) {+ for (int c = 0; c < 4; ++c) {+ pass.vec4Uniforms["u_prevViewProjection" + std::to_string(c)] = glm::vec4(it->second.previous[c]);+ }+ pass.paramDirty = true;+ }+ }if (layout) {if (layout->blockSize > 0) {if (pass.paramDirty || pass.paramBytes.size() < layout->blockSize) {diff --git a/src/esengine/renderer/frame/PostProcessPipeline.hpp b/src/esengine/renderer/frame/PostProcessPipeline.hppindex 84c5564ce..46849f574 100644--- a/src/esengine/renderer/frame/PostProcessPipeline.hpp+++ b/src/esengine/renderer/frame/PostProcessPipeline.hpp@@ -252,6 +252,18 @@ public:*/bool temporalActive();+ /**+ * @brief Whether an enabled pass that keeps no history reads the previous camera (`u_prevViewProjection0`).+ *+ * @details Motion blur is one: it needs to know where each pixel was a frame ago, and nothing else of the+ * temporal machinery — no history, and above all no sub-pixel shift, which would shake a picture+ * nothing resolves. The frame then follows the camera with @ref trackView.+ */+ bool cameraMotionWanted();++ /// 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);+/*** @brief Whether an enabled pass reads how far each moving surface travelled (`u_velocity`).*diff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cppindex ae87c32e4..3762bb8fb 100644--- a/src/esengine/renderer/frame/RenderFrame.cpp+++ b/src/esengine/renderer/frame/RenderFrame.cpp@@ -239,6 +239,8 @@ void RenderFrame::drawScene() {if (post_process_) post_process_->setEnvironmentTexture(environment_texture_id_);if (post_process_ && post_process_->isEngaged() && post_process_->temporalActive()) {jitter = post_process_->beginTemporalView(view_projection_, current_target_);+ } else if (post_process_ && post_process_->isEngaged() && post_process_->cameraMotionWanted()) {+ post_process_->trackView(view_projection_, current_target_);}#endifscene_jitter_ = jitter;@@ -2296,7 +2298,9 @@ void RenderFrame::collectMotion(ecs::Registry& registry) {ES_PROFILE_SCOPE("render.collect.motion");#ifdef ES_ENABLE_POSTPROCESSconst auto view = post_process_->peekTemporalView(view_projection_, static_cast<u64>(current_target_));- velocity_jitter_ = view.jitter;+ // The shift is only there when something resolves it; a chain that follows motion without a history draws still.+ const bool shifted = post_process_->temporalActive();+ velocity_jitter_ = shifted ? view.jitter : glm::vec2(0.0f);velocity_pool_.beginFrame();velocity_list_.clear();@@ -2306,7 +2310,7 @@ void RenderFrame::collectMotion(ecs::Registry& registry) {ctx.motion_key = static_cast<u64>(current_target_);ctx.motion_frame = planar_frame_;ctx.motion_prev_view_projection = view.previous;- ctx.motion_prev_jitter = view.previousJitter;+ ctx.motion_prev_jitter = shifted ? view.previousJitter : glm::vec2(0.0f);RenderCollectContext collectCtx{registry, frustum_, clip_state_, velocity_pool_, velocity_list_, ctx,computeCameraView(ctx.view_projection)};collectCtx.screen_ui = screen_domain_;diff --git a/src/esengine/resource/ShaderParser.cpp b/src/esengine/resource/ShaderParser.cppindex 4aeb843f5..ae2e9c24b 100644--- a/src/esengine/resource/ShaderParser.cpp+++ b/src/esengine/resource/ShaderParser.cpp@@ -1075,13 +1075,18 @@ std::string wgslReachedTextureDecls(const std::string& source, bool postProcess)// #pragma param texture uniforms: material units (>= 8) take the unit→binding// convention in rhi/WgslBindings.hpp, and the sampler rides the param's own name with// an _s suffix: textureSampleLevel(u_mask, u_mask_s, uv, 0.0).-std::string wgslMaterialTextureDecls(const ParsedShader& parsed) {+//+// The sampler is declared only for a texture the stage samples through it. A texture read with textureLoad alone has+// no sampler to bind, and that is what lets a 32-bit float one (the motion pass's) be its binding: a float32 texture+// cannot be filtered, and a layout that pairs it with a filtering sampler is refused by the device.+std::string wgslMaterialTextureDecls(const ParsedShader& parsed, const std::string& body) {std::string src;for (const auto& p : parsed.properties) {if (!p.fromParam || p.type != ShaderPropertyType::Texture || p.textureUnit < 0) continue;const u32 unit = static_cast<u32>(p.textureUnit);src += "@group(1) @binding(" + std::to_string(unit + 8) + ") var " + p.name +" : texture_2d<f32>;\n";+ if (body.find(p.name + "_s") == std::string::npos) continue;src += "@group(1) @binding(" + std::to_string(unit + 16) + ") var " + p.name +"_s : sampler;\n";}@@ -1991,7 +1996,7 @@ ShaderParser::AssembledStage assembleWGSLStage(const ParsedShader& parsed,inject(block);}if (stage == ShaderStage::Fragment) {- inject(wgslMaterialTextureDecls(parsed));+ inject(wgslMaterialTextureDecls(parsed, bodyIt->second));if (lit) inject(kLitHeaderWGSL);if (parsed.domain == "PostProcess" && parsed.usesLights) inject(kPostLightHeaderWGSL);inject(kColorHelpersWGSL);diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex f1a054075..6feabb869 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -2493,6 +2493,8 @@ export const NOTED = {{"note":"Skinned meshes are followed by their bones, from the palette they were last drawn with."},"feat(render): fog follows the scene's sun and can walk the air against its shadow map":{"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(render): motion blur, film grain and lens flare join the post-process effects":+ {"note":"Motion blur, film grain and lens flare are post-process effects, and a moving mesh's motion now reaches effects on WebGPU too."},"feat(render): materials carry a clear coat, sheen, anisotropy, translucency, thin film, index of refraction and transmission":{"note":"The Model material has shading layers — clear coat, sheen, anisotropy, translucency, thin film, index of refraction and transmission — and a glTF with the matching extensions arrives using them."},"feat(render): a frame carries 112 lights, the lights past the sixteenth lighting their pixels through screen tiles":