Skip to content

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.

feat(2d): rain that reads no depth, with rings and puddles on the ground and dry ground under a roof

yhh0524fc068bb0
diff --git a/desktop b/desktop
index 2f3864a33..4b4e9b303 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit 2f3864a33aa17affb40430c74f5e84f93705a935
+Subproject commit 4b4e9b30371aa6977153a2cf4bdb3e8d12ea88de
diff --git a/docs/astro/src/content/docs/graphics/post-processing.mdx b/docs/astro/src/content/docs/graphics/post-processing.mdx
index 840c5a128..1153cbf70 100644
--- a/docs/astro/src/content/docs/graphics/post-processing.mdx
+++ b/docs/astro/src/content/docs/graphics/post-processing.mdx
@@ -25,6 +25,7 @@ several can stack in one frame at no extra target cost beyond the passes.
| `blur` | Gaussian blur | `intensity` |
| `fxaa` | Fast anti-aliasing | `intensity` |
| `mist2d` | Drifting banks of mist laid over the ground in world units. Reads no depth, so a 2D scene can have it; what is lit glows through it | `density`, `coverage`, `scale`, `speed`, `direction`, `glow`, colour |
+| `rain2d` | Rain for a scene with no depth: streaks, rings and splashes and puddles on the ground in world units, dry under a `RainShelter` sprite | `intensity`, `wetness`, `puddles`, `puddleScale`, `rippleScale`, `wind`, `speed`, `streakLength`, colour |
| `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 |
| `skyAtmosphere` | An atmosphere that scatters the sun's light, with sun, moon, stars and volumetric clouds, drawn where there is no surface | `intensity`, `haze`, `altitude`, `clouds`, `cloudBase`, `cloudThickness`, `windSpeed`, `overcast`, `sunAzimuth`, `sunElevation` |
@@ -497,7 +498,7 @@ package carries only when its content uses one:
| Group | Subpath | Effects |
|---|---|---|
| Basic | `esengine/fx-basic` | blur, bloom, vignette, grayscale, colorGrade, lutGrade, agx, chromaticAberration, tonemap, fxaa, sharpen, lensDistortion, pixelate, outline, depthOutline, edgeOutline, filmGrain, motionBlur, lensFlare |
-| Atmosphere | `esengine/fx-atmosphere` | mist2d, skyAtmosphere, heightFog, distanceFog, rain |
+| Atmosphere | `esengine/fx-atmosphere` | mist2d, rain2d, skyAtmosphere, heightFog, distanceFog, rain |
| Lighting | `esengine/fx-lighting` | ssao, gtao, ssr, ssgi, voxelGI, contactShadows, lightShafts, autoExposure, depthOfField, subsurface, taa |
The export reads the effects a `PostProcessVolume` names (and a `Weather` or `TimeOfDay` component, which drive the atmosphere group) and imports
diff --git a/docs/astro/src/content/docs/graphics/sprites.mdx b/docs/astro/src/content/docs/graphics/sprites.mdx
index db598f760..23bf433dd 100644
--- a/docs/astro/src/content/docs/graphics/sprites.mdx
+++ b/docs/astro/src/content/docs/graphics/sprites.mdx
@@ -248,6 +248,22 @@ and eases back when the target leaves.
The covered ground is the sprite's size and pivot under the entity's scale; rotation is not read. It runs in play only.
+### Keeping the ground under a roof dry
+
+The 3D rain finds what stands over a place by drawing the scene from above; a 2D scene has no "above", so the covering sprite says so. Add a `rain2d` effect to the
+scene's post-process volume, and `RainShelter` to the roof or crown. The ground the sprite covers is dry: no streaks, no rings, no puddle.
+
+How dry follows how much of that ground can be seen. An opaque roof shows the roof, which the rain falls on; the same roof faded by a `CoverFade` to show the room
+has a room that is dry. So one roof carries both components, and the rain stops as the room appears.
+
+| Field | What it does |
+|---|---|
+| `round` | The covered ground is the ellipse inside the rectangle (a crown), not the whole rectangle (a roof). |
+| `margin` | Ground around the sprite's edge that stays dry too, in world units: eaves. |
+
+The eight shelters nearest the camera are the ones the rain reads. The rings and the darkening of a wet floor are drawn over everything, characters included, because a
+2D picture has no way to tell a character from the ground under it; they are small and low, which is why it reads as rain on the picture.
+
### Depth layers (2.5D)
Check a layer under **Settings → Project → Rendering → Advanced → Depth-sorted layers** and it
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.mdx
index fdf146ff7..253cc9543 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
@@ -27,6 +27,7 @@ Estella 通过 ping-pong 帧缓冲运行全屏后处理。加一个 `PostProcess
| `blur` | 高斯模糊 | `intensity` |
| `fxaa` | 快速抗锯齿 | `intensity` |
| `mist2d` | 按世界坐标铺在地面上的、会飘动的成团薄雾。不读深度,2D 场景也能用;被照亮的东西会在雾里发光 | `density`、`coverage`、`scale`、`speed`、`direction`、`glow`、颜色 |
+| `rain2d` | 给没有深度的场景用的雨:雨线、按世界坐标落在地面上的涟漪、溅花和积水,`RainShelter` 精灵下面是干的 | `intensity`、`wetness`、`puddles`、`puddleScale`、`rippleScale`、`wind`、`speed`、`streakLength`、颜色 |
| `distanceFog` | 按到相机的距离做线性雾 | `near`、`far`、`intensity`、颜色 |
| `heightFog` | 指数高度雾,带太阳辉光和朦胧的地平线 | `density`、`heightFalloff`、`baseHeight`、`sunAzimuth`、`sunElevation`、`skyFog`、颜色 |
| `skyAtmosphere` | 散射太阳光的大气,带太阳、月亮、星星和体积云,画在没有表面的地方 | `intensity`、`haze`、`altitude`、`clouds`、`cloudBase`、`cloudThickness`、`windSpeed`、`overcast`、`sunAzimuth`、`sunElevation` |
@@ -381,7 +382,7 @@ stack.addPass('lutGrade', getEffectDef('lutGrade')!.factory())
| 组 | 子路径 | 效果 |
|---|---|---|
| 基础 | `esengine/fx-basic` | blur、bloom、vignette、grayscale、colorGrade、lutGrade、chromaticAberration、tonemap、fxaa、sharpen、lensDistortion、pixelate、outline、depthOutline、edgeOutline、filmGrain、motionBlur、lensFlare |
-| 大气 | `esengine/fx-atmosphere` | mist2d、skyAtmosphere、heightFog、distanceFog、rain |
+| 大气 | `esengine/fx-atmosphere` | mist2d、rain2d、skyAtmosphere、heightFog、distanceFog、rain |
| 光照 | `esengine/fx-lighting` | ssao、gtao、ssr、ssgi、voxelGI、contactShadows、lightShafts、autoExposure、depthOfField、subsurface、taa |
导出会读 `PostProcessVolume` 里写了哪些效果(以及驱动大气组的 `Weather`、`TimeOfDay` 组件),并导入它们需要的组。**从脚本里**加的效果——
diff --git a/docs/astro/src/content/docs/zh-cn/graphics/sprites.mdx b/docs/astro/src/content/docs/zh-cn/graphics/sprites.mdx
index 080b69999..26e232e29 100644
--- a/docs/astro/src/content/docs/zh-cn/graphics/sprites.mdx
+++ b/docs/astro/src/content/docs/zh-cn/graphics/sprites.mdx
@@ -218,6 +218,19 @@ world.applyEntityOrder([other, another, card]);
覆盖范围取精灵尺寸与锚点、乘以实体缩放,不读旋转。只在运行时生效。
+### 让屋顶下的地面保持干燥
+
+3D 的雨靠"从上往下画一遍场景"找出头顶有什么;2D 场景没有"上面",所以由遮挡的精灵自己声明。在场景的后处理体积里加 `rain2d` 效果,在屋顶或树冠上加 `RainShelter`:精灵所覆盖的地面是干的,没有雨线、涟漪和积水。
+
+干到什么程度取决于那块地面能被看到多少。不透明的屋顶显示的是屋顶,雨就落在屋顶上;同一个屋顶被 `CoverFade` 淡出、露出房间时,房间里是干的。所以一个屋顶同时带两个组件,房间显出来的同时雨就停了。
+
+| 字段 | 作用 |
+|---|---|
+| `round` | 覆盖范围取矩形内接的椭圆(树冠),而不是整个矩形(屋顶)。 |
+| `margin` | 精灵边缘外多少世界单位也保持干燥(屋檐)。 |
+
+雨只读离相机最近的八个遮雨区。涟漪和湿地的变暗是画在所有东西上面的,包括角色,因为 2D 画面分不出角色和脚下的地面;它们小而低,看起来就是画面上的雨。
+
### 深度层(2.5D)
在 **设置 → 项目 → 渲染 → 高级 → 深度排序层** 勾选某个层后,该层完全不再依赖
diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.json
index f7782f2e8..21ef3ae68 100644
--- a/docs/astro/src/data/apiStability.generated.json
+++ b/docs/astro/src/data/apiStability.generated.json
@@ -3,10 +3,10 @@
"counts": {
"public": 115,
"beta": 171,
- "experimental": 2650,
+ "experimental": 2661,
"deprecated": 3
},
- "total": 2936,
+ "total": 2947,
"subsystems": [
{
"id": "mobile-controls",
diff --git a/docs/astro/src/data/componentDocs.ts b/docs/astro/src/data/componentDocs.ts
index b45c5e0f3..62f1288f7 100644
--- a/docs/astro/src/data/componentDocs.ts
+++ b/docs/astro/src/data/componentDocs.ts
@@ -82,6 +82,9 @@ export const COMPONENT_DOCS: Record<string, ComponentDoc> = {
BakedLighting: { category: 'graphics', summary: 'How this scene is baked — atlas size, density, bounces — and a record of what the last bake read.', doc: 'graphics/lighting', anchor: 'baked-light', anchorZh: '烘焙光照' },
DecalProjector: { category: 'graphics', summary: 'Prints this entity\'s material onto what its box covers — the surface is cut to the box and drawn again, so a decal is lit and shadowed as the surface under it.', doc: 'graphics/lighting', anchor: 'baked-light', anchorZh: '烘焙光照' },
BlobShadow: { category: 'graphics', summary: 'A soft dark disc on the ground under an entity — no shadow map, no light, no extra pass — that fades and shrinks as the entity leaves the ground.', doc: 'graphics/lighting', anchor: 'blob-shadows-a-disc-instead-of-a-shadow-map', anchorZh: '假阴影用一个圆片代替阴影图' },
+ CoverFade: { category: 'graphics', summary: 'A roof or a tree crown that thins out while a CoverFadeTarget stands under it, so the player is never hidden by what they walked into.', doc: 'graphics/sprites', anchor: 'fading-a-roof-or-a-crown-over-the-player', anchorZh: '屋顶与树冠遮挡淡出' },
+ CoverFadeTarget: { category: 'graphics', summary: 'Marks what a CoverFade keeps visible — the player, and anything else that must not be hidden by a roof or a crown.', doc: 'graphics/sprites', anchor: 'fading-a-roof-or-a-crown-over-the-player', anchorZh: '屋顶与树冠遮挡淡出' },
+ RainShelter: { category: 'graphics', summary: 'A roof, awning or crown that keeps the ground under it dry in the 2D rain, as far as the sprite lets that ground be seen.', doc: 'graphics/sprites', anchor: 'keeping-the-ground-under-a-roof-dry', anchorZh: '让屋顶下的地面保持干燥' },
StreamedWorld: { category: 'world', summary: 'Declares the scene a streamed world and how big the cook cuts its cells.', doc: 'world/streaming', anchor: 'declaring-a-streamed-world', anchorZh: '声明一个流送世界' },
WorldPersistent: { category: 'world', summary: 'Keeps an entity\'s whole subtree out of the partition — it belongs to the persistent world.', doc: 'world/streaming', anchor: 'declaring-a-streamed-world', anchorZh: '声明一个流送世界' },
WorldGen: { category: 'world', summary: 'A generated world: names the game\'s rules (biomes, recipes, layers), their version, the world and its seed; what the rules place is laid out round the streaming sources.', doc: 'world/generation', anchor: 'the-worldgen-component', anchorZh: 'worldgen-组件' },
diff --git a/docs/astro/src/data/components.generated.json b/docs/astro/src/data/components.generated.json
index 1789acd60..007a7e1d2 100644
--- a/docs/astro/src/data/components.generated.json
+++ b/docs/astro/src/data/components.generated.json
@@ -1106,6 +1106,55 @@
}
]
},
+ {
+ "name": "CoverFade",
+ "source": "ts",
+ "fields": [
+ {
+ "key": "opacity",
+ "type": "number",
+ "default": "0.25",
+ "doc": "The sprite's alpha, as a share of its own, while something stands under it.",
+ "range": "0–1, step 0.01"
+ },
+ {
+ "key": "fadeTime",
+ "type": "number",
+ "default": "0.25",
+ "doc": "Seconds the fade takes, either way.",
+ "range": "0–5, step 0.05"
+ },
+ {
+ "key": "margin",
+ "type": "number",
+ "default": "0",
+ "doc": "Ground around the sprite's edge that counts as under it, in world units.",
+ "range": "≥ 0, step 1"
+ },
+ {
+ "key": "round",
+ "type": "boolean",
+ "default": "false",
+ "doc": "The covered ground is the ellipse inside the sprite's rectangle (a tree crown) and not the whole of it (a roof)."
+ },
+ {
+ "key": "enabled",
+ "type": "boolean",
+ "default": "true"
+ }
+ ],
+ "animatable": [
+ "opacity",
+ "fadeTime",
+ "margin"
+ ]
+ },
+ {
+ "name": "CoverFadeTarget",
+ "source": "ts",
+ "fields": [],
+ "tag": true
+ },
{
"name": "DecalProjector",
"source": "ts",
@@ -4207,6 +4256,33 @@
"blendDistance"
]
},
+ {
+ "name": "RainShelter",
+ "source": "ts",
+ "fields": [
+ {
+ "key": "round",
+ "type": "boolean",
+ "default": "false",
+ "doc": "The covered ground is the ellipse inside the sprite's rectangle (a tree crown) and not the whole of it (a roof)."
+ },
+ {
+ "key": "margin",
+ "type": "number",
+ "default": "0",
+ "doc": "Ground around the sprite's edge that stays dry too, in world units.",
+ "range": "≥ 0, step 1"
+ },
+ {
+ "key": "enabled",
+ "type": "boolean",
+ "default": "true"
+ }
+ ],
+ "animatable": [
+ "margin"
+ ]
+ },
{
"name": "ReflectionProbe",
"source": "cpp",
diff --git a/pipeline/src/project/targetSupport.ts b/pipeline/src/project/targetSupport.ts
index 8c6df012b..e46cda724 100644
--- a/pipeline/src/project/targetSupport.ts
+++ b/pipeline/src/project/targetSupport.ts
@@ -86,7 +86,7 @@ export const POST_PROCESS_EFFECT_GROUP: Readonly<Record<string, Subsystem>> = {
chromaticAberration: 'fxBasic', tonemap: 'fxBasic', fxaa: 'fxBasic', lensDistortion: 'fxBasic', pixelate: 'fxBasic',
outline: 'fxBasic', depthOutline: 'fxBasic', edgeOutline: 'fxBasic', lutGrade: 'fxBasic', agx: 'fxBasic', sharpen: 'fxBasic', filmGrain: 'fxBasic',
motionBlur: 'fxBasic', lensFlare: 'fxBasic',
- mist2d: 'fxAtmosphere', distanceFog: 'fxAtmosphere', skyAtmosphere: 'fxAtmosphere', heightFog: 'fxAtmosphere', rain: 'fxAtmosphere',
+ mist2d: 'fxAtmosphere', rain2d: 'fxAtmosphere', distanceFog: 'fxAtmosphere', skyAtmosphere: 'fxAtmosphere', heightFog: 'fxAtmosphere', rain: 'fxAtmosphere',
voxelGI: 'fxLighting', ssgi: 'fxLighting', contactShadows: 'fxLighting', lightShafts: 'fxLighting',
autoExposure: 'fxLighting', depthOfField: 'fxLighting', ssao: 'fxLighting', subsurface: 'fxLighting',
gtao: 'fxLighting', ssr: 'fxLighting', taa: 'fxLighting',
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 753ce641e..f1c68830c 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 159 beta · 1911 experimental · 3 deprecated
+Symbols: 115 public · 159 beta · 1917 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -2871,7 +2871,7 @@ round: boolean
## CoverFadeTarget — const @experimental
```
-ComponentDef<Record<string, never>>
+ComponentDef<{}>
```
## CreateListViewOptions — interface @experimental
@@ -7903,6 +7903,18 @@ ReadonlySet<string>
Readonly<Required<RuntimeBuildConfig>>
```
+## RainShelter — const @experimental
+```
+ComponentDef<RainShelterData>
+```
+
+## RainShelterData — interface @experimental
+```
+enabled: boolean
+margin: number
+round: boolean
+```
+
## ReadableWorld — type @experimental
```
Pick<World, 'valid' | 'has' | 'get'>
@@ -9094,6 +9106,15 @@ pageWidth: number
spacing: number
```
+## Shelter — interface @experimental
+```
+dry: number
+hx: number
+hy: number
+x: number
+y: number
+```
+
## ShotState — interface @experimental
```
curve: number
@@ -13519,6 +13540,11 @@ MotionDriver<AnimatorBlend2DMotion>
Plugin
```
+## coveredGround — function @experimental
+```
+(sprite: SpriteData, transform: TransformData): { centre: { x: number; y: number; }; half: { x: number; y: number; }; }
+```
+
## coversPoint — function @experimental
```
(px: number, py: number, centre: { x: number; y: number; }, half: { x: number; y: number; }, margin: number, round: boolean): boolean
@@ -13889,6 +13915,11 @@ DragPlugin
(app: App, contacts?: readonly Contact3D[]): void
```
+## drynessOf — function @experimental
+```
+(alpha: number): number
+```
+
## editorViewAxes — function @experimental
```
(view: EditorViewData): { x: ScreenAxis; y: ScreenAxis; z: ScreenAxis; }
@@ -14879,6 +14910,11 @@ MeshRendererPlugin
(g: MaterialGraph, id: string, x: number, y: number): MaterialGraph
```
+## nearestShelters — function @experimental
+```
+(shelters: readonly Shelter[], x: number, y: number, count: number): Shelter[]
+```
+
## newMaterialGraph — function @beta
```
(): MaterialGraph
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index ed9b1d493..aebb3058d 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.native
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 164 beta · 1930 experimental · 3 deprecated
+Symbols: 115 public · 164 beta · 1936 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -2879,7 +2879,7 @@ round: boolean
## CoverFadeTarget — const @experimental
```
-ComponentDef<Record<string, never>>
+ComponentDef<{}>
```
## CreateListViewOptions — interface @experimental
@@ -8116,6 +8116,18 @@ ReadonlySet<string>
Readonly<Required<RuntimeBuildConfig>>
```
+## RainShelter — const @experimental
+```
+ComponentDef<RainShelterData>
+```
+
+## RainShelterData — interface @experimental
+```
+enabled: boolean
+margin: number
+round: boolean
+```
+
## ReadableWorld — type @experimental
```
Pick<World, 'valid' | 'has' | 'get'>
@@ -9307,6 +9319,15 @@ pageWidth: number
spacing: number
```
+## Shelter — interface @experimental
+```
+dry: number
+hx: number
+hy: number
+x: number
+y: number
+```
+
## ShotState — interface @experimental
```
curve: number
@@ -13747,6 +13768,11 @@ MotionDriver<AnimatorBlend2DMotion>
Plugin
```
+## coveredGround — function @experimental
+```
+(sprite: SpriteData, transform: TransformData): { centre: { x: number; y: number; }; half: { x: number; y: number; }; }
+```
+
## coversPoint — function @experimental
```
(px: number, py: number, centre: { x: number; y: number; }, half: { x: number; y: number; }, margin: number, round: boolean): boolean
@@ -14142,6 +14168,11 @@ DragPlugin
(app: App, contacts?: readonly Contact3D[]): void
```
+## drynessOf — function @experimental
+```
+(alpha: number): number
+```
+
## editorViewAxes — function @experimental
```
(view: EditorViewData): { x: ScreenAxis; y: ScreenAxis; z: ScreenAxis; }
@@ -15142,6 +15173,11 @@ MeshRendererPlugin
(g: MaterialGraph, id: string, x: number, y: number): MaterialGraph
```
+## nearestShelters — function @experimental
+```
+(shelters: readonly Shelter[], x: number, y: number, count: number): Shelter[]
+```
+
## newMaterialGraph — function @beta
```
(): MaterialGraph
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 930456aaa..2bafcaa7c 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.node
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 161 beta · 1910 experimental · 3 deprecated
+Symbols: 115 public · 161 beta · 1916 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -2866,7 +2866,7 @@ round: boolean
## CoverFadeTarget — const @experimental
```
-ComponentDef<Record<string, never>>
+ComponentDef<{}>
```
## CreateListViewOptions — interface @experimental
@@ -7898,6 +7898,18 @@ ReadonlySet<string>
Readonly<Required<RuntimeBuildConfig>>
```
+## RainShelter — const @experimental
+```
+ComponentDef<RainShelterData>
+```
+
+## RainShelterData — interface @experimental
+```
+enabled: boolean
+margin: number
+round: boolean
+```
+
## ReadableWorld — type @experimental
```
Pick<World, 'valid' | 'has' | 'get'>
@@ -9089,6 +9101,15 @@ pageWidth: number
spacing: number
```
+## Shelter — interface @experimental
+```
+dry: number
+hx: number
+hy: number
+x: number
+y: number
+```
+
## ShotState — interface @experimental
```
curve: number
@@ -13514,6 +13535,11 @@ MotionDriver<AnimatorBlend2DMotion>
Plugin
```
+## coveredGround — function @experimental
+```
+(sprite: SpriteData, transform: TransformData): { centre: { x: number; y: number; }; half: { x: number; y: number; }; }
+```
+
## coversPoint — function @experimental
```
(px: number, py: number, centre: { x: number; y: number; }, half: { x: number; y: number; }, margin: number, round: boolean): boolean
@@ -13884,6 +13910,11 @@ DragPlugin
(app: App, contacts?: readonly Contact3D[]): void
```
+## drynessOf — function @experimental
+```
+(alpha: number): number
+```
+
## editorViewAxes — function @experimental
```
(view: EditorViewData): { x: ScreenAxis; y: ScreenAxis; z: ScreenAxis; }
@@ -14879,6 +14910,11 @@ MeshRendererPlugin
(g: MaterialGraph, id: string, x: number, y: number): MaterialGraph
```
+## nearestShelters — function @experimental
+```
+(shelters: readonly Shelter[], x: number, y: number, count: number): Shelter[]
+```
+
## newMaterialGraph — function @beta
```
(): MaterialGraph
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index cfc995504..de6400247 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/minigame
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 159 beta · 1932 experimental · 3 deprecated
+Symbols: 115 public · 159 beta · 1938 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -2866,7 +2866,7 @@ round: boolean
## CoverFadeTarget — const @experimental
```
-ComponentDef<Record<string, never>>
+ComponentDef<{}>
```
## CreateListViewOptions — interface @experimental
@@ -8192,6 +8192,18 @@ ReadonlySet<string>
Readonly<Required<RuntimeBuildConfig>>
```
+## RainShelter — const @experimental
+```
+ComponentDef<RainShelterData>
+```
+
+## RainShelterData — interface @experimental
+```
+enabled: boolean
+margin: number
+round: boolean
+```
+
## ReadableWorld — type @experimental
```
Pick<World, 'valid' | 'has' | 'get'>
@@ -9383,6 +9395,15 @@ pageWidth: number
spacing: number
```
+## Shelter — interface @experimental
+```
+dry: number
+hx: number
+hy: number
+x: number
+y: number
+```
+
## ShotState — interface @experimental
```
curve: number
@@ -13814,6 +13835,11 @@ MotionDriver<AnimatorBlend2DMotion>
Plugin
```
+## coveredGround — function @experimental
+```
+(sprite: SpriteData, transform: TransformData): { centre: { x: number; y: number; }; half: { x: number; y: number; }; }
+```
+
## coversPoint — function @experimental
```
(px: number, py: number, centre: { x: number; y: number; }, half: { x: number; y: number; }, margin: number, round: boolean): boolean
@@ -14189,6 +14215,11 @@ DragPlugin
(app: App, contacts?: readonly Contact3D[]): void
```
+## drynessOf — function @experimental
+```
+(alpha: number): number
+```
+
## editorViewAxes — function @experimental
```
(view: EditorViewData): { x: ScreenAxis; y: ScreenAxis; z: ScreenAxis; }
@@ -15189,6 +15220,11 @@ MeshRendererPlugin
(g: MaterialGraph, id: string, x: number, y: number): MaterialGraph
```
+## nearestShelters — function @experimental
+```
+(shelters: readonly Shelter[], x: number, y: number, count: number): Shelter[]
+```
+
## newMaterialGraph — function @beta
```
(): MaterialGraph
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index ba7992597..ce383e62d 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/wechat
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 159 beta · 1923 experimental · 3 deprecated
+Symbols: 115 public · 159 beta · 1929 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -2866,7 +2866,7 @@ round: boolean
## CoverFadeTarget — const @experimental
```
-ComponentDef<Record<string, never>>
+ComponentDef<{}>
```
## CreateListViewOptions — interface @experimental
@@ -7905,6 +7905,18 @@ ReadonlySet<string>
Readonly<Required<RuntimeBuildConfig>>
```
+## RainShelter — const @experimental
+```
+ComponentDef<RainShelterData>
+```
+
+## RainShelterData — interface @experimental
+```
+enabled: boolean
+margin: number
+round: boolean
+```
+
## ReadableWorld — type @experimental
```
Pick<World, 'valid' | 'has' | 'get'>
@@ -9096,6 +9108,15 @@ pageWidth: number
spacing: number
```
+## Shelter — interface @experimental
+```
+dry: number
+hx: number
+hy: number
+x: number
+y: number
+```
+
## ShotState — interface @experimental
```
curve: number
@@ -13546,6 +13567,11 @@ MotionDriver<AnimatorBlend2DMotion>
Plugin
```
+## coveredGround — function @experimental
+```
+(sprite: SpriteData, transform: TransformData): { centre: { x: number; y: number; }; half: { x: number; y: number; }; }
+```
+
## coversPoint — function @experimental
```
(px: number, py: number, centre: { x: number; y: number; }, half: { x: number; y: number; }, margin: number, round: boolean): boolean
@@ -13916,6 +13942,11 @@ DragPlugin
(app: App, contacts?: readonly Contact3D[]): void
```
+## drynessOf — function @experimental
+```
+(alpha: number): number
+```
+
## editorViewAxes — function @experimental
```
(view: EditorViewData): { x: ScreenAxis; y: ScreenAxis; z: ScreenAxis; }
@@ -14916,6 +14947,11 @@ MeshRendererPlugin
(g: MaterialGraph, id: string, x: number, y: number): MaterialGraph
```
+## nearestShelters — function @experimental
+```
+(shelters: readonly Shelter[], x: number, y: number, count: number): Shelter[]
+```
+
## newMaterialGraph — function @beta
```
(): MaterialGraph
diff --git a/sdk/src/animation/AnimationPlugin.ts b/sdk/src/animation/AnimationPlugin.ts
index b06fadb4f..369ab5c5a 100644
--- a/sdk/src/animation/AnimationPlugin.ts
+++ b/sdk/src/animation/AnimationPlugin.ts
@@ -23,6 +23,7 @@ import type { AnimatorAvatar } from './animatorAvatar';
import { appRegistryAsset } from '../asset/registryLookup';
import { playModeOnly } from '../ecs/env';
import { installCoverFade } from '../render/coverFade';
+import { installRainShelter } from '../render/rainShelter';
import { SystemLabel } from '../ecs/systemLabels';
export class AnimationPlugin implements Plugin {
@@ -55,7 +56,8 @@ export class AnimationPlugin implements Plugin {
});
// A roof or a crown with a CoverFade thins out over what stands under it; with none in the scene the system finds nothing and returns.
const offCoverFade = installCoverFade(app);
- const release = (): void => { offDespawn(); offCoverFade(); };
+ const offRainShelter = installRainShelter(app);
+ const release = (): void => { offDespawn(); offCoverFade(); offRainShelter(); };
this.despawnCleanups_.set(app, release);
this.latestDespawnCleanup_ = release;
diff --git a/sdk/src/core-render.ts b/sdk/src/core-render.ts
index f7b3df7e1..d6c781e43 100644
--- a/sdk/src/core-render.ts
+++ b/sdk/src/core-render.ts
@@ -346,7 +346,8 @@ export { RenderDemand } from './render/renderDemand';
export { buildPathGeometry, mergeGeometry, cubicBezier, quadraticBezier, circlePoints } from './render/vectorPath';
export type { PathStyle, PathFill, PathStroke, PathColor, LineJoin, LineCap } from './render/vectorPath';
export { setPath, clearPath } from './render/pathRenderer';
-export { CoverFade, CoverFadeTarget, coversPoint, stepFade, type CoverFadeData } from './render/coverFade';
+export { RainShelter, drynessOf, nearestShelters, type RainShelterData, type Shelter } from './render/rainShelter';
+export { CoverFade, CoverFadeTarget, coveredGround, coversPoint, stepFade, type CoverFadeData } from './render/coverFade';
export { BlobShadow, setBlobShadowGround, buildBlobMesh, blobAlpha, type BlobShadowData, type BlobShadowGround } from './render/blobShadow';
export type { RenderOnDemandOptions } from './render/renderDemand';
export type { ShaderWarmup, ShaderWarmupOptions } from './render/shaderWarmup';
diff --git a/sdk/src/postprocess/effects.ts b/sdk/src/postprocess/effects.ts
index 8147e2ba0..bf54ca27d 100644
--- a/sdk/src/postprocess/effects.ts
+++ b/sdk/src/postprocess/effects.ts
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import type { ShaderHandle } from '../render/material';
+import { RAIN_SHELTER_UNIFORMS } from './rainShelterSlots';
import { effectSourcesOf, computeSourceOf } from './effectSources';
import type { basicEffects } from './sources/basic';
import type { atmosphereEffects } from './sources/atmosphere';
@@ -317,6 +318,31 @@ registerEffect({
],
});
+registerEffect({
+ type: 'rain2d',
+ label: 'Rain 2D',
+ factory: () => postProcessEffects.createRain2d(),
+ uniforms: [
+ // How much rain falls: how many of the streaks a layer could hold are there.
+ { name: 'u_intensity', label: 'Intensity', min: 0, max: 2, step: 0.01, defaultValue: 1, neutralValue: 0 },
+ // How wet the ground is: how far it darkens and how clearly the rings read.
+ { name: 'u_wetness', label: 'Wetness', min: 0, max: 1, step: 0.01, defaultValue: 1, neutralValue: 0 },
+ // How much of the ground is standing water, and how big the pools are (a WORLD length).
+ { name: 'u_puddles', label: 'Puddles', min: 0, max: 1, step: 0.01, defaultValue: 0.4, neutralValue: 0 },
+ { name: 'u_puddleScale', label: 'Puddle Size', min: 20, max: 4000, step: 10, defaultValue: 220 },
+ // A WORLD length: the size of the grid cell each ring lives in.
+ { name: 'u_rippleScale', label: 'Ripple Scale', min: 6, max: 400, step: 1, defaultValue: 36 },
+ { name: 'u_wind', label: 'Wind', min: -1, max: 1, step: 0.01, defaultValue: 0.15 },
+ { name: 'u_speed', label: 'Speed', min: 0.2, max: 6, step: 0.1, defaultValue: 1.6 },
+ { name: 'u_streakLength', label: 'Streak Length', min: 0.05, max: 0.9, step: 0.01, defaultValue: 0.3 },
+ // The shelters, written each frame by the rain-shelter system from the RainShelter sprites nearest the camera.
+ ...RAIN_SHELTER_UNIFORMS,
+ ],
+ colors: [
+ { name: 'u_streakColor', label: 'Streak Colour', defaultValue: { r: 0.78, g: 0.82, b: 0.9, a: 1 } },
+ ],
+});
+
registerEffect({
type: 'distanceFog',
label: 'Distance Fog',
@@ -861,7 +887,7 @@ const CATEGORIES: Record<EffectCategory, string[]> = {
lens: ['bloom', 'depthOfField', 'motionBlur', 'lensFlare', 'filmGrain', 'chromaticAberration', 'lensDistortion', 'vignette', 'sharpen'],
color: ['tonemap', 'agx', 'colorGrade', 'lutGrade', 'displayLut', 'autoExposure', 'grayscale'],
light: ['ssao', 'gtao', 'ssgi', 'ssr', 'voxelGI', 'contactShadows', 'lightShafts', 'subsurface'],
- atmosphere: ['mist2d', 'distanceFog', 'heightFog', 'skyAtmosphere', 'rain'],
+ atmosphere: ['mist2d', 'rain2d', 'distanceFog', 'heightFog', 'skyAtmosphere', 'rain'],
aa: ['fxaa', 'taa'],
stylize: ['blur', 'pixelate', 'outline', 'depthOutline', 'edgeOutline'],
};
diff --git a/sdk/src/postprocess/rainShelterSlots.ts b/sdk/src/postprocess/rainShelterSlots.ts
new file mode 100644
index 000000000..541fe6227
--- /dev/null
+++ b/sdk/src/postprocess/rainShelterSlots.ts
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file rainShelterSlots.ts
+ * @brief The uniforms the 2D rain reads its shelters from, named apart from its shader so every package can carry the names and only the ones that rain carry the source.
+ */
+import type { EffectUniformDef } from './effects';
+
+/** How many shelters the 2D rain reads. Each is five numbers: centre x and y, half width and height (negative for round), dryness. */
+export const RAIN_SHELTER_SLOTS = 8;
+export const SHELTER_FIELDS = ['x', 'y', 'hx', 'hy', 'dry'] as const;
+export type ShelterField = typeof SHELTER_FIELDS[number];
+
+/** The name of a shelter slot's uniform. */
+export function shelterUniform(slot: number, field: ShelterField): string {
+ return `u_sh${slot}${field}`;
+}
+
+/** The slots as effect uniforms: internal, because the shelter system writes them and nobody authors them. */
+export const RAIN_SHELTER_UNIFORMS: EffectUniformDef[] = Array.from({ length: RAIN_SHELTER_SLOTS }, (_, slot) =>
+ SHELTER_FIELDS.map((field): EffectUniformDef => ({
+ name: shelterUniform(slot, field), label: `Shelter ${slot} ${field}`, min: -100000, max: 100000, step: 1, defaultValue: 0, internal: true,
+ }))).flat();
diff --git a/sdk/src/postprocess/sources/atmosphere.ts b/sdk/src/postprocess/sources/atmosphere.ts
index 1721d78a2..4065c4714 100644
--- a/sdk/src/postprocess/sources/atmosphere.ts
+++ b/sdk/src/postprocess/sources/atmosphere.ts
@@ -7,9 +7,11 @@
import type { ShaderHandle } from '../../render/material';
import { Material } from '../../render/material';
import { registerEffectSources } from '../effectSources';
+import { rain2dEffects } from './rain2d';
import { SSAO_GLSL, SSAO_WGSL, PUDDLE_GLSL, PUDDLE_WGSL, BASIN_GLSL, BASIN_WGSL, GBUFFER_GLSL, GBUFFER_WGSL } from './shared';
export const atmosphereEffects = {
+ ...rain2dEffects,
/**
* A sky that has a time of day and weather in it: the scattering of the atmosphere, a sun that goes red as it sets, a
* moon, stars, and volumetric clouds that the sun lights.
diff --git a/sdk/src/postprocess/sources/rain2d.ts b/sdk/src/postprocess/sources/rain2d.ts
new file mode 100644
index 000000000..0ba8e7d66
--- /dev/null
+++ b/sdk/src/postprocess/sources/rain2d.ts
@@ -0,0 +1,240 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file rain2d.ts
+ * @brief Rain for a scene with no depth: rings and puddles on the ground plane, and ground that stays dry under a roof.
+ *
+ * @details The 3D rain finds the ground by its depth and its shelter by a map of the scene seen from above. A 2D scene has neither: its sprites
+ * are blended and write no depth, and there is no "above" to look from. This rain lays its rings and puddles on the ground plane in
+ * WORLD units (found from the screen as the 2D mist finds them) and asks the shelters it is told of where it is dry: up to eight boxes
+ * or ellipses, the ones nearest the camera, written each frame by the rain-shelter system. A shelter's dryness is how much of the ground
+ * under it can be seen, so an opaque roof (which shows the roof, and the rain falls on that) is not dry, and one faded to show the room is.
+ *
+ * It cannot tell a character from the ground it stands on, so rings and the darkening of a wet floor are drawn over everything. They are
+ * small and low, which is why that reads as rain on the picture and not as a fault.
+ */
+import type { ShaderHandle } from '../../render/material';
+import { Material } from '../../render/material';
+
+import { RAIN_SHELTER_SLOTS, SHELTER_FIELDS, shelterUniform } from '../rainShelterSlots';
+
+const slots = Array.from({ length: RAIN_SHELTER_SLOTS }, (_, i) => i);
+const PARAMS = slots.flatMap((i) => SHELTER_FIELDS.map((f) => `#pragma param ${shelterUniform(i, f)} float default(0) range(-100000,100000)`)).join('\n');
+const callGlsl = (i: number) => ` d = max(d, shelterOf(w, ${shelterUniform(i, 'x')}, ${shelterUniform(i, 'y')}, ${shelterUniform(i, 'hx')}, ${shelterUniform(i, 'hy')}, ${shelterUniform(i, 'dry')}));`;
+const callWgsl = (i: number) => ` d = max(d, shelterOf(w, mc.${shelterUniform(i, 'x')}, mc.${shelterUniform(i, 'y')}, mc.${shelterUniform(i, 'hx')}, mc.${shelterUniform(i, 'hy')}, mc.${shelterUniform(i, 'dry')}));`;
+
+const GLSL = `
+float hash11(float n) { return fract(sin(n * 127.1) * 43758.5453); }
+float hash21(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
+float vnoise(vec2 p) {
+ vec2 i = floor(p);
+ vec2 f = fract(p);
+ f = f * f * (3.0 - 2.0 * f);
+ return mix(mix(hash21(i), hash21(i + vec2(1.0, 0.0)), f.x), mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), f.x), f.y);
+}
+float puddleNoise(vec2 p) {
+ return vnoise(p) * 0.5 + vnoise(p * 2.07 + vec2(11.0, 5.0)) * 0.3 + vnoise(p * 4.3 + vec2(3.0, 17.0)) * 0.2;
+}
+/// How dry a point of the ground is under one shelter: 0 outside it, its dryness inside, soft at the edge. A negative half-height says round.
+float shelterOf(vec2 w, float cx, float cy, float hx, float hy, float dry) {
+ if (hx <= 0.0) return 0.0;
+ float h = abs(hy);
+ float m = hy < 0.0 ? (1.0 - length((w - vec2(cx, cy)) / vec2(hx, h))) * min(hx, h) : min(hx - abs(w.x - cx), h - abs(w.y - cy));
+ return smoothstep(0.0, 8.0, m) * dry;
+}
+float dryAt(vec2 w) {
+ float d = 0.0;
+${slots.map(callGlsl).join('\n')}
+ return d;
+}
+/// One layer of streaks: columns across the screen, one streak per cell at most, scrolling down.
+float streaks(vec2 uv, float aspect, float cols, float speed, float seed, float T) {
+ vec2 q = vec2(uv.x * aspect - uv.y * u_wind, uv.y);
+ float cx = floor(q.x * cols);
+ float fx = fract(q.x * cols);
+ float h1 = hash11(cx + seed);
+ float h2 = hash11(cx * 1.7 + seed * 3.1);
+ float y = q.y * 4.0 + T * speed * (0.8 + 0.4 * h1) + h2 * 17.0;
+ float cell = floor(y);
+ float fy = fract(y);
+ float here = hash11(cx * 31.0 + cell + seed);
+ if (here > u_intensity * 0.5) return 0.0;
+ float dx = abs(fx - 0.5 - (hash11(cell + cx) - 0.5) * 0.6);
+ float across = 1.0 - smoothstep(0.0, 0.06, dx);
+ float along = (1.0 - fy / u_streakLength) * step(fy, u_streakLength);
+ return across * along;
+}`;
+
+const WGSL = `
+fn hash11(n : f32) -> f32 { return fract(sin(n * 127.1) * 43758.5453); }
+fn hash21(p : vec2f) -> f32 { return fract(sin(dot(p, vec2f(127.1, 311.7))) * 43758.5453); }
+fn vnoise(p : vec2f) -> f32 {
+ let i = floor(p);
+ var f = fract(p);
+ f = f * f * (3.0 - 2.0 * f);
+ return mix(mix(hash21(i), hash21(i + vec2f(1.0, 0.0)), f.x), mix(hash21(i + vec2f(0.0, 1.0)), hash21(i + vec2f(1.0, 1.0)), f.x), f.y);
+}
+fn puddleNoise(p : vec2f) -> f32 {
+ return vnoise(p) * 0.5 + vnoise(p * 2.07 + vec2f(11.0, 5.0)) * 0.3 + vnoise(p * 4.3 + vec2f(3.0, 17.0)) * 0.2;
+}
+fn shelterOf(w : vec2f, cx : f32, cy : f32, hx : f32, hy : f32, dry : f32) -> f32 {
+ if (hx <= 0.0) { return 0.0; }
+ let h = abs(hy);
+ var m = min(hx - abs(w.x - cx), h - abs(w.y - cy));
+ if (hy < 0.0) { m = (1.0 - length((w - vec2f(cx, cy)) / vec2f(hx, h))) * min(hx, h); }
+ return smoothstep(0.0, 8.0, m) * dry;
+}
+fn dryAt(w : vec2f) -> f32 {
+ var d = 0.0;
+${slots.map(callWgsl).join('\n')}
+ return d;
+}
+fn streaks(uv : vec2f, aspect : f32, cols : f32, speed : f32, seed : f32, T : f32) -> f32 {
+ let q = vec2f(uv.x * aspect - (1.0 - uv.y) * mc.u_wind, 1.0 - uv.y);
+ let cx = floor(q.x * cols);
+ let fx = fract(q.x * cols);
+ let h1 = hash11(cx + seed);
+ let h2 = hash11(cx * 1.7 + seed * 3.1);
+ let y = q.y * 4.0 + T * speed * (0.8 + 0.4 * h1) + h2 * 17.0;
+ let cell = floor(y);
+ let fy = fract(y);
+ let here = hash11(cx * 31.0 + cell + seed);
+ if (here > mc.u_intensity * 0.5) { return 0.0; }
+ let dx = abs(fx - 0.5 - (hash11(cell + cx) - 0.5) * 0.6);
+ let across = 1.0 - smoothstep(0.0, 0.06, dx);
+ var along = 0.0;
+ if (fy <= mc.u_streakLength) { along = 1.0 - fy / mc.u_streakLength; }
+ return across * along;
+}`;
+
+const SOURCE = `#pragma shader "PP Rain 2D"
+#pragma version 300 es
+#pragma domain PostProcess
+#pragma param u_intensity float default(1) range(0,2)
+#pragma param u_wetness float default(1) range(0,1)
+#pragma param u_puddles float default(0.4) range(0,1)
+#pragma param u_puddleScale float default(220) range(20,4000)
+#pragma param u_rippleScale float default(36) range(6,400)
+#pragma param u_wind float default(0.15) range(-1,1)
+#pragma param u_speed float default(1.6) range(0.2,6)
+#pragma param u_streakLength float default(0.3) range(0.05,0.9)
+#pragma param u_streakColor color default(0.78,0.82,0.9,1)
+${PARAMS}
+
+#pragma fragment
+precision highp float;
+
+in vec2 v_texCoord;
+uniform sampler2D u_texture;
+out vec4 fragColor;
+${GLSL}
+
+void main() {
+ vec4 src = texture(u_texture, v_texCoord);
+ vec2 sz = vec2(textureSize(u_texture, 0));
+ float aspect = sz.x / sz.y;
+ float T = u_time.x;
+ vec2 w = worldFromDepth(v_texCoord, 0.0).xy + u_renderOrigin.xy;
+ vec3 tint = u_streakColor.rgb;
+#ifdef ES_LINEAR
+ tint = srgbToLinear(tint);
+#endif
+ // Where a roof or a crown shows the ground under it, that ground is dry and nothing falls on it.
+ float dry = min(dryAt(w) * 1.15, 1.0);
+ float wet = u_wetness * (1.0 - dry);
+ float falling = clamp(u_intensity, 0.0, 1.0) * (1.0 - dry);
+ vec3 col = src.rgb;
+
+ // Standing water where a slow noise of the ground passes a threshold; the rest of the ground is only darker.
+ float lo = 1.0 - u_puddles;
+ float puddle = u_puddles > 0.001 ? smoothstep(lo, lo + 0.1, puddleNoise(w / u_puddleScale)) * wet : 0.0;
+ col *= 1.0 - 0.3 * wet;
+ col *= 1.0 - 0.3 * puddle;
+ col += tint * 0.04 * puddle;
+
+ // Rings where drops land, on a grid in the world; denser and clearer on standing water.
+ vec2 g = w / u_rippleScale;
+ vec2 id = floor(g);
+ vec2 f = fract(g) - 0.5;
+ float h = hash21(id);
+ vec2 centre = (vec2(hash21(id + 7.0), hash21(id + 13.0)) - 0.5) * 0.5;
+ float phase = fract(T * 0.9 + h);
+ float ring = (1.0 - smoothstep(0.0, 0.05, abs(length(f - centre) - phase * 0.5)))
+ * (1.0 - phase) * (1.0 - phase) * step(hash21(id + 3.0), mix(0.4, 0.9, puddle));
+ col += tint * ring * mix(0.18, 0.6, puddle) * u_wetness * falling;
+ // Splashes: the small quick crown of a drop that lands on ground that is not water.
+ vec2 g2 = w / (u_rippleScale * 0.3);
+ vec2 id2 = floor(g2);
+ vec2 f2 = fract(g2) - 0.5;
+ float ph2 = fract(T * 2.4 + hash21(id2 + 29.0));
+ vec2 c2 = (vec2(hash21(id2 + 5.0), hash21(id2 + 11.0)) - 0.5) * 0.4;
+ float splash = (1.0 - smoothstep(0.0, 0.08, abs(length(f2 - c2) - ph2 * 0.3)))
+ * (1.0 - ph2) * (1.0 - ph2) * (1.0 - ph2) * step(hash21(id2 + 2.0), 0.4);
+ col += tint * splash * 0.35 * u_wetness * falling * (1.0 - puddle);
+
+ // Three layers of falling streaks; none where the ground under them is dry.
+ float rain = streaks(v_texCoord, aspect, 70.0, u_speed * 1.0, 1.0, T) * 0.35
+ + streaks(v_texCoord, aspect, 130.0, u_speed * 1.4, 2.0, T) * 0.28
+ + streaks(v_texCoord, aspect, 230.0, u_speed * 1.9, 3.0, T) * 0.22;
+ col += tint * rain * u_intensity * (1.0 - dry);
+ fragColor = vec4(col, src.a);
+}
+#pragma end
+
+#pragma fragment wgsl
+${WGSL}
+
+@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
+ let src = textureSampleLevel(t0, s0, v.v_texCoord, 0.0);
+ let sz = vec2f(vec2i(textureDimensions(t0, 0)));
+ let aspect = sz.x / sz.y;
+ let T = tc.u_time.x;
+ let w = worldFromDepth(v.v_texCoord, 0.0).xy + frame.renderOrigin.xy;
+ var tint = mc.u_streakColor.rgb;
+#ifdef ES_LINEAR
+ tint = srgbToLinear(tint);
+#endif
+ let dry = min(dryAt(w) * 1.15, 1.0);
+ let wet = mc.u_wetness * (1.0 - dry);
+ let falling = clamp(mc.u_intensity, 0.0, 1.0) * (1.0 - dry);
+ var col = src.rgb;
+
+ let lo = 1.0 - mc.u_puddles;
+ var puddle = 0.0;
+ if (mc.u_puddles > 0.001) { puddle = smoothstep(lo, lo + 0.1, puddleNoise(w / mc.u_puddleScale)) * wet; }
+ col = col * (1.0 - 0.3 * wet);
+ col = col * (1.0 - 0.3 * puddle);
+ col = col + tint * 0.04 * puddle;
+
+ let g = w / mc.u_rippleScale;
+ let id = floor(g);
+ let f = fract(g) - 0.5;
+ let h = hash21(id);
+ let centre = (vec2f(hash21(id + 7.0), hash21(id + 13.0)) - 0.5) * 0.5;
+ let phase = fract(T * 0.9 + h);
+ let ring = (1.0 - smoothstep(0.0, 0.05, abs(length(f - centre) - phase * 0.5)))
+ * (1.0 - phase) * (1.0 - phase) * step(hash21(id + 3.0), mix(0.4, 0.9, puddle));
+ col = col + tint * ring * mix(0.18, 0.6, puddle) * mc.u_wetness * falling;
+ let g2 = w / (mc.u_rippleScale * 0.3);
+ let id2 = floor(g2);
+ let f2 = fract(g2) - 0.5;
+ let ph2 = fract(T * 2.4 + hash21(id2 + 29.0));
+ let c2 = (vec2f(hash21(id2 + 5.0), hash21(id2 + 11.0)) - 0.5) * 0.4;
+ let splash = (1.0 - smoothstep(0.0, 0.08, abs(length(f2 - c2) - ph2 * 0.3)))
+ * (1.0 - ph2) * (1.0 - ph2) * (1.0 - ph2) * step(hash21(id2 + 2.0), 0.4);
+ col = col + tint * splash * 0.35 * mc.u_wetness * falling * (1.0 - puddle);
+
+ let rain = streaks(v.v_texCoord, aspect, 70.0, mc.u_speed * 1.0, 1.0, T) * 0.35
+ + streaks(v.v_texCoord, aspect, 130.0, mc.u_speed * 1.4, 2.0, T) * 0.28
+ + streaks(v.v_texCoord, aspect, 230.0, mc.u_speed * 1.9, 3.0, T) * 0.22;
+ col = col + tint * rain * mc.u_intensity * (1.0 - dry);
+ return vec4f(col, src.a);
+}
+#pragma end
+`;
+
+export const rain2dEffects = {
+ createRain2d(): ShaderHandle {
+ return Material.compileShader(SOURCE);
+ },
+};
diff --git a/sdk/src/postprocess/volumeSystem.ts b/sdk/src/postprocess/volumeSystem.ts
index 086a79b60..3c128a2ff 100644
--- a/sdk/src/postprocess/volumeSystem.ts
+++ b/sdk/src/postprocess/volumeSystem.ts
@@ -15,6 +15,7 @@ import type { ShaderHandle } from '../render/material';
import { Material } from '../render/material';
import { applyWeatherToEffects, currentWeather, currentWeatherDrive } from './weather';
import { applyCloudsToFog } from './cloudShafts';
+import { applyRainSheltersToRain } from '../render/rainShelter';
import { applyUnderwaterToEffects, currentUnderwater } from './underwater';
import { applyTimeToEffects, currentTimeOfDay, currentTimeDrive, timeLightsApplied } from './timeOfDay';
@@ -303,6 +304,8 @@ export function effectsAt(volumes: { data: PostProcessVolumeData; tx: VolumeTran
const clock = currentTimeOfDay();
if (clock) applyTimeToEffects(blended, clock, currentTimeDrive(), timeLightsApplied());
applyCloudsToFog(blended);
+ // A 2D rain is told where the ground under a roof is dry.
+ applyRainSheltersToRain(blended, x, y);
// A camera under water: the effect the water module says it needs.
applyUnderwaterToEffects(blended, currentUnderwater());
return blended;
diff --git a/sdk/src/postprocess/weather.ts b/sdk/src/postprocess/weather.ts
index a9ed39c75..d5ab626e4 100644
--- a/sdk/src/postprocess/weather.ts
+++ b/sdk/src/postprocess/weather.ts
@@ -246,13 +246,13 @@ export function applyWeatherToEffects(effects: Map<string, BlendedEffect>, state
}
}
if (drive & WeatherDrive.Fog) {
- // A 2D scene's mist is an opacity, not an exponent: the weather's multiplier is taken as a root so a rain thickens it
- // without clamping straight to opaque, and it spreads as it thickens (more of the ground under it, not only denser banks).
+ // A 2D scene's mist is an opacity, not an exponent: the weather's multiplier is taken as a logarithm so a rain
+ // thickens it without clamping straight to opaque, and it spreads a little as it thickens (more of the ground under it, not only denser banks).
const mist = effects.get('mist2d');
if (mist && mist.enabled) {
- mist.uniforms.set('u_density', Math.min(value(mist, 'mist2d', 'u_density') * Math.sqrt(state.fogDensity), 1));
- mist.uniforms.set('u_coverage', Math.min(value(mist, 'mist2d', 'u_coverage') * (1 + 0.1 * (state.fogDensity - 1)), 1));
- mist.uniforms.set('u_glow', value(mist, 'mist2d', 'u_glow') * state.fogGlow);
+ mist.uniforms.set('u_density', Math.min(value(mist, 'mist2d', 'u_density') * (1 + 0.25 * Math.log(Math.max(state.fogDensity, 1))), 1));
+ mist.uniforms.set('u_coverage', Math.min(value(mist, 'mist2d', 'u_coverage') * (1 + 0.04 * (state.fogDensity - 1)), 1));
+ mist.uniforms.set('u_glow', value(mist, 'mist2d', 'u_glow') * Math.min(state.fogGlow, 1.2));
const colour = mist.colors.get('u_fogColor')
?? getEffectDef('mist2d')?.colors?.find((c) => c.name === 'u_fogColor')?.defaultValue;
if (colour && state.fogTintAmount > 0) mist.colors.set('u_fogColor', towards(colour, state.fogTint, state.fogTintAmount));
@@ -265,9 +265,12 @@ export function applyWeatherToEffects(effects: Map<string, BlendedEffect>, state
if (drive & WeatherDrive.Rain) {
if (state.rain > 0.001 || state.wetness > 0.001) {
// A rain the scene authored is a floor the weather rises above; one the weather brings is exactly its own.
- const authored = effects.has('rain');
- const rain = entry(effects, 'rain');
- const pick = (name: string, level: number): number => authored ? Math.max(value(rain, 'rain', name), level) : level;
+ // A 2D scene's rain is the one that reads no depth; the weather raises it, and brings no second rain beside it.
+ const flat = effects.get('rain2d');
+ const type = flat && flat.enabled ? 'rain2d' : 'rain';
+ const authored = effects.has(type);
+ const rain = entry(effects, type);
+ const pick = (name: string, level: number): number => authored ? Math.max(value(rain, type, name), level) : level;
rain.uniforms.set('u_intensity', pick('u_intensity', state.rain));
rain.uniforms.set('u_wetness', pick('u_wetness', state.wetness));
rain.uniforms.set('u_puddles', pick('u_puddles', state.puddles));
diff --git a/sdk/src/render/coverFade.ts b/sdk/src/render/coverFade.ts
index 14fa12615..f93b65177 100644
--- a/sdk/src/render/coverFade.ts
+++ b/sdk/src/render/coverFade.ts
@@ -14,7 +14,7 @@
*/
import type { App } from '../app/app';
import type { Entity } from '../types';
-import { defineComponent, Sprite, Transform, type SpriteData, type TransformData } from '../ecs/component';
+import { defineComponent, defineTag, Sprite, Transform, type SpriteData, type TransformData } from '../ecs/component';
import { defineSystem, Schedule, GetWorld } from '../ecs/system';
import { Res, Time, type TimeData } from '../ecs/resource';
import { Query } from '../ecs/query';
@@ -53,7 +53,21 @@ export const CoverFade = defineComponent<CoverFadeData>('CoverFade',
);
/** Marks what a `CoverFade` keeps visible: the player, and anything else that must not be hidden. @experimental */
-export const CoverFadeTarget = defineComponent<Record<string, never>>('CoverFadeTarget', {});
+export const CoverFadeTarget = defineTag('CoverFadeTarget');
+
+/**
+ * The ground a sprite covers: its rectangle's centre and half extents, from its size and pivot under the entity's scale. The pivot is where the
+ * entity's position sits in the sprite (0.5 is the middle). Rotation is not read.
+ */
+export function coveredGround(sprite: SpriteData, transform: TransformData): { centre: { x: number; y: number }; half: { x: number; y: number } } {
+ const scale = transform.worldScale;
+ const half = { x: Math.abs(sprite.size.x * scale.x) / 2, y: Math.abs(sprite.size.y * scale.y) / 2 };
+ const origin = transform.worldPosition;
+ return {
+ half,
+ centre: { x: origin.x + (0.5 - sprite.pivot.x) * half.x * 2, y: origin.y + (0.5 - sprite.pivot.y) * half.y * 2 },
+ };
+}
/** Whether the point (px, py) is on the ground a sprite covers. */
export function coversPoint(
@@ -119,14 +133,7 @@ export function installCoverFade(app: App): () => void {
if (!cover.enabled) { if (state) restore(world, entity, state); continue; }
if (!state) { state = { authored: sprite.color.a, shown: 1 }; fading.set(entity, state); }
- const scale = transform.worldScale;
- const half = { x: Math.abs(sprite.size.x * scale.x) / 2, y: Math.abs(sprite.size.y * scale.y) / 2 };
- // The pivot is where the entity's position sits in the sprite: 0.5 is the middle.
- const origin = transform.worldPosition;
- const centre = {
- x: origin.x + (0.5 - sprite.pivot.x) * half.x * 2,
- y: origin.y + (0.5 - sprite.pivot.y) * half.y * 2,
- };
+ const { centre, half } = coveredGround(sprite, transform);
let under = false;
for (const p of points) {
if (coversPoint(p.x, p.y, centre, half, cover.margin, cover.round)) { under = true; break; }
diff --git a/sdk/src/render/rainShelter.ts b/sdk/src/render/rainShelter.ts
new file mode 100644
index 000000000..21504c78b
--- /dev/null
+++ b/sdk/src/render/rainShelter.ts
@@ -0,0 +1,125 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file rainShelter.ts
+ * @brief A roof, an awning or a tree crown that keeps the ground under it dry, for the 2D rain.
+ *
+ * @details The 3D rain finds what stands over a place by drawing the scene from straight above. A 2D scene has no "above" to draw it from, so the
+ * sprite that covers says so: `RainShelter` goes on it, and the ground it covers (its rectangle, or the ellipse inside it) is dry. How dry
+ * follows how much of that ground can be SEEN: an opaque roof shows the roof, which the rain falls on, and the same roof faded by a
+ * `CoverFade` to show the room has a room that is dry. So one roof carries both components and the rain stops as the room appears.
+ *
+ * The system lists the shelters each frame; the volume system hands the eight nearest the camera to a `rain2d` effect's uniforms.
+ */
+import type { App } from '../app/app';
+import type { Entity } from '../types';
+import { defineComponent, Sprite, Transform, type SpriteData, type TransformData } from '../ecs/component';
+import { defineSystem, Schedule } from '../ecs/system';
+import { Query } from '../ecs/query';
+import { coveredGround } from './coverFade';
+import { RAIN_SHELTER_SLOTS, SHELTER_FIELDS, shelterUniform } from '../postprocess/rainShelterSlots';
+import type { BlendedEffect } from '../postprocess/volumeBlending';
+
+/** The fields of the `RainShelter` component. @experimental */
+export interface RainShelterData {
+ /** The covered ground is the ellipse inside the sprite's rectangle (a crown), not the whole of it (a roof). */
+ round: boolean;
+ /** Ground around the sprite's edge that stays dry too, in world units: eaves. */
+ margin: number;
+ /** Off: the sprite shelters nothing. */
+ enabled: boolean;
+}
+
+/**
+ * Keeps the ground under this sprite dry in the 2D rain, as far as the sprite lets it be seen.
+ *
+ * @experimental
+ */
+export const RainShelter = defineComponent<RainShelterData>('RainShelter',
+ { round: false, margin: 0, enabled: true },
+ {
+ fields: {
+ round: { tooltip: "The covered ground is the ellipse inside the sprite's rectangle (a tree crown) and not the whole of it (a roof)." },
+ margin: { min: 0, step: 1, tooltip: 'Ground around the sprite\'s edge that stays dry too, in world units.' },
+ },
+ },
+);
+
+/** One shelter as the shader reads it: a negative half height says round. */
+export interface Shelter {
+ x: number;
+ y: number;
+ hx: number;
+ /** Negative for an ellipse. */
+ hy: number;
+ /** 0 where the ground under it cannot be seen, 1 where all of it can. */
+ dry: number;
+}
+
+let sheltersNow: Shelter[] = [];
+
+/** The shelters the last frame found. */
+export function currentRainShelters(): readonly Shelter[] {
+ return sheltersNow;
+}
+
+/** How dry the ground under a sprite is, from how much of it shows through: an opaque sprite hides it, a clear one hides nothing. */
+export function drynessOf(alpha: number): number {
+ return 1 - Math.min(Math.max(alpha, 0), 1);
+}
+
+/** The shelter a sprite is, or null where it has no ground to cover or no dryness to give. */
+export function shelterOf(sprite: SpriteData, transform: TransformData, data: RainShelterData): Shelter | null {
+ if (!data.enabled || !sprite.enabled) return null;
+ const dry = drynessOf(sprite.color.a);
+ if (dry <= 0) return null;
+ const { centre, half } = coveredGround(sprite, transform);
+ const hx = half.x + data.margin;
+ const hy = half.y + data.margin;
+ if (hx <= 0 || hy <= 0) return null;
+ return { x: centre.x, y: centre.y, hx, hy: data.round ? -hy : hy, dry };
+}
+
+/** The `count` shelters nearest (x, y), nearest first. The distance is to a shelter's edge, so a large roof is not passed over for a small shed. */
+export function nearestShelters(shelters: readonly Shelter[], x: number, y: number, count: number): Shelter[] {
+ const reach = (s: Shelter): number => Math.max(Math.hypot(s.x - x, s.y - y) - Math.max(s.hx, Math.abs(s.hy)), 0);
+ return [...shelters].sort((a, b) => reach(a) - reach(b)).slice(0, count);
+}
+
+/**
+ * Writes the shelters nearest the camera into a `rain2d` effect, and empties the slots it does not fill. With no such effect, nothing.
+ *
+ * @param x The camera's x.
+ * @param y The camera's y.
+ */
+export function applyRainSheltersToRain(effects: Map<string, BlendedEffect>, x: number, y: number): void {
+ const rain = effects.get('rain2d');
+ if (!rain || !rain.enabled) return;
+ const chosen = nearestShelters(sheltersNow, x, y, RAIN_SHELTER_SLOTS);
+ for (let slot = 0; slot < RAIN_SHELTER_SLOTS; slot++) {
+ const s = chosen[slot];
+ const values: Record<typeof SHELTER_FIELDS[number], number> = s
+ ? { x: s.x, y: s.y, hx: s.hx, hy: s.hy, dry: s.dry }
+ : { x: 0, y: 0, hx: 0, hy: 0, dry: 0 };
+ for (const field of SHELTER_FIELDS) rain.uniforms.set(shelterUniform(slot, field), values[field]);
+ }
+}
+
+/** Installs the system that lists the shelters each frame. Returns the function that forgets them. */
+export function installRainShelter(app: App): () => void {
+ const system = defineSystem(
+ [Query(RainShelter, Sprite, Transform)],
+ (shelters: Iterable<[Entity, RainShelterData, SpriteData, TransformData]>) => {
+ const found: Shelter[] = [];
+ for (const [, data, sprite, transform] of shelters) {
+ const shelter = shelterOf(sprite, transform, data);
+ if (shelter) found.push(shelter);
+ }
+ sheltersNow = found;
+ },
+ { name: 'RainShelterSystem' },
+ );
+ // After the cover fade has moved the sprites' alpha, so the rain stops the frame the roof thins and not the one after.
+ app.addSystemToSchedule(Schedule.PostUpdate, system);
+ return () => { sheltersNow = []; };
+}
diff --git a/sdk/tests/atmosphere-2d.test.ts b/sdk/tests/atmosphere-2d.test.ts
index 8c0617bcb..00b6bd239 100644
--- a/sdk/tests/atmosphere-2d.test.ts
+++ b/sdk/tests/atmosphere-2d.test.ts
@@ -2,6 +2,9 @@
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import { describe, expect, it } from 'vitest';
import { coversPoint, stepFade } from '../src/render/coverFade';
+import { applyRainSheltersToRain, drynessOf, nearestShelters, shelterOf, type Shelter } from '../src/render/rainShelter';
+import { RAIN_SHELTER_SLOTS, shelterUniform } from '../src/postprocess/rainShelterSlots';
+import type { SpriteData, TransformData } from '../src/ecs/component';
import { applyWeatherToEffects, blendWeather, WeatherDrive, WEATHER_CLEAR, WEATHER_NONE, WEATHER_RAIN } from '../src/postprocess/weather';
import { getEffectDef } from '../src/postprocess/effects';
import type { BlendedEffect } from '../src/postprocess/volumeBlending';
@@ -101,3 +104,81 @@ describe('the Sway sprite template', () => {
expect(template!.source).toContain('pow(clamp(v.v_texCoord.y, 0.0, 1.0), 1.5)');
});
});
+
+describe('the 2D rain', () => {
+ const sprite = (alpha: number, enabled = true): SpriteData =>
+ ({ size: { x: 100, y: 60 }, pivot: { x: 0.5, y: 0.5 }, color: { r: 1, g: 1, b: 1, a: alpha }, enabled }) as SpriteData;
+ const at = (x: number, y: number): TransformData =>
+ ({ worldPosition: { x, y, z: 0 }, worldScale: { x: 1, y: 1, z: 1 } }) as TransformData;
+ const data = { round: false, margin: 0, enabled: true };
+
+ it('is an effect that asks for no depth and for no shelter map, with every shelter slot internal', () => {
+ const def = getEffectDef('rain2d');
+ expect(def).toBeDefined();
+ expect(def!.category).toBe('atmosphere');
+ const slots = def!.uniforms.filter((u) => u.internal);
+ expect(slots).toHaveLength(RAIN_SHELTER_SLOTS * 5);
+ expect(def!.uniforms.map((u) => u.name)).toEqual(expect.arrayContaining(['u_intensity', 'u_wetness', 'u_puddles', 'u_puddleScale', 'u_rippleScale']));
+ });
+
+ it('keeps the ground dry as far as the sprite lets it be seen: an opaque roof hides it, a clear one hides nothing', () => {
+ expect(drynessOf(1)).toBe(0);
+ expect(drynessOf(0)).toBe(1);
+ expect(drynessOf(0.12)).toBeCloseTo(0.88, 6);
+ expect(drynessOf(7)).toBe(0);
+ expect(drynessOf(-1)).toBe(1);
+ });
+
+ it('lists a faded roof as a shelter, with its ground and the dryness the fade gives it', () => {
+ const s = shelterOf(sprite(0.25), at(10, 20), { ...data, margin: 5 })!;
+ expect(s).toMatchObject({ x: 10, y: 20, hx: 55, hy: 35 });
+ expect(s.dry).toBeCloseTo(0.75, 6);
+ });
+
+ it('says round by a negative half height', () => {
+ expect(shelterOf(sprite(0), at(0, 0), { ...data, round: true })!.hy).toBeLessThan(0);
+ });
+
+ it('lists nothing for an opaque sprite, a disabled one, or one with no ground', () => {
+ expect(shelterOf(sprite(1), at(0, 0), data)).toBeNull();
+ expect(shelterOf(sprite(0), at(0, 0), { ...data, enabled: false })).toBeNull();
+ expect(shelterOf(sprite(0, false), at(0, 0), data)).toBeNull();
+ expect(shelterOf({ ...sprite(0), size: { x: 0, y: 0 } }, at(0, 0), data)).toBeNull();
+ });
+
+ it('reads the sprite pivot: the ground is where the sprite is, not where the entity stands', () => {
+ const s = shelterOf({ ...sprite(0), pivot: { x: 0.5, y: 0 } }, at(0, 0), data)!;
+ expect(s.y).toBeCloseTo(30, 6);
+ });
+
+ it('hands the shader the shelters nearest the camera, by their edge, so a big roof is not passed over for a small shed', () => {
+ const roof: Shelter = { x: 300, y: 0, hx: 250, hy: 250, dry: 1 };
+ const shed: Shelter = { x: 120, y: 0, hx: 10, hy: 10, dry: 1 };
+ const far: Shelter = { x: 900, y: 0, hx: 10, hy: 10, dry: 1 };
+ expect(nearestShelters([far, shed, roof], 0, 0, 2)).toEqual([roof, shed]);
+ });
+
+ it('writes the slots of a rain2d effect and leaves other effects and a disabled rain alone', () => {
+ const effects = new Map([['rain2d', mist()]]);
+ applyRainSheltersToRain(effects, 0, 0);
+ const rain = effects.get('rain2d')!;
+ for (let slot = 0; slot < RAIN_SHELTER_SLOTS; slot++) expect(rain.uniforms.get(shelterUniform(slot, 'hx'))).toBe(0);
+ const none = new Map([['mist2d', mist()]]);
+ applyRainSheltersToRain(none, 0, 0);
+ expect(none.get('mist2d')!.uniforms.size).toBe(0);
+ const off = new Map([['rain2d', { ...mist(), enabled: false }]]);
+ applyRainSheltersToRain(off, 0, 0);
+ expect(off.get('rain2d')!.uniforms.size).toBe(0);
+ });
+
+ it('is the rain a weather raises, and brings no second rain beside it', () => {
+ const rain = blendWeather(WEATHER_RAIN, WEATHER_NONE, 0);
+ const effects = new Map([['rain2d', mist({ u_intensity: 0.1, u_wetness: 0.1 })]]);
+ applyWeatherToEffects(effects, rain, WeatherDrive.Rain);
+ expect(effects.has('rain')).toBe(false);
+ expect(effects.get('rain2d')!.uniforms.get('u_intensity')).toBeGreaterThan(0.1);
+ const plain = new Map<string, BlendedEffect>();
+ applyWeatherToEffects(plain, rain, WeatherDrive.Rain);
+ expect(plain.has('rain')).toBe(true);
+ });
+});
diff --git a/sdk/tests/shader-twins.test.ts b/sdk/tests/shader-twins.test.ts
index f1a8304d3..718d366d6 100644
--- a/sdk/tests/shader-twins.test.ts
+++ b/sdk/tests/shader-twins.test.ts
@@ -43,7 +43,7 @@ const CASES: Array<{ name: string; source: string }> = [
...BUILTIN_SHADER_TEMPLATES.map((t) => ({ name: `template:${t.id}`, source: t.source })),
...embeddedEsshaders('render/filters.ts').map((source, i) => ({ name: `filters.ts[${i}]`, source })),
...embeddedEsshaders('render/spriteFilter.ts').map((source, i) => ({ name: `spriteFilter.ts[${i}]`, source })),
- ...['basic', 'atmosphere', 'lighting'].flatMap((group) => embeddedEsshaders(`postprocess/sources/${group}.ts`).map(
+ ...['basic', 'atmosphere', 'lighting', 'rain2d'].flatMap((group) => embeddedEsshaders(`postprocess/sources/${group}.ts`).map(
(source, i) => ({ name: `postProcessEffects.ts[${group}:${i}]`, source }))),
...embeddedEsshaders('camera/editorGridRenderer.ts').map(
(source, i) => ({ name: `editorGridRenderer.ts[${i}]`, source })),
@@ -53,7 +53,7 @@ describe('embedded .esshader structure', () => {
it('found the filter, effect and grid sources', () => {
expect(CASES.filter((c) => c.name.startsWith('filters.ts')).length).toBe(1);
expect(CASES.filter((c) => c.name.startsWith('spriteFilter.ts')).length).toBe(2);
- expect(CASES.filter((c) => c.name.startsWith('postProcessEffects.ts')).length).toBe(40);
+ expect(CASES.filter((c) => c.name.startsWith('postProcessEffects.ts')).length).toBe(41);
expect(CASES.filter((c) => c.name.startsWith('editorGridRenderer.ts')).length).toBe(1);
});