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(material): wet ground: a map says where it is damp and where water stands

yhh119f386a3371
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1cb29eaad..f733e0425 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@ published separately; it ships inside the editor.
- **The sky lights the scene.** Sky Atmosphere's **Light the Scene** makes the sky the scene's environment: every Ambient light that names no environment of its own lights with it, its diffuse light from the dome and the clouds and its reflection on metal and wet ground, scaled by the light's colour and intensity as an imported one is. The sky is worked out again as it changes (the sun moving, a weather coming in, clouds drifting), at most once a second; with clouds that takes about 20 ms on a desktop. The sun's disc is left out, since the directional light the sky follows is its direct light. Below the horizon it is the ground, lit by the sky's sun and dome and giving back **Ground Albedo** of it (0.2 by default, between asphalt and grass; Unreal's atmosphere uses 0.4), so a wall in shadow takes the sunlit ground's bounce as well as the sky's: under a high clear sun that doubles its fill, under a low hazy one it adds little. Off by default, so a scene already lit by hand looks as it did.
- **The sky's lower half is the sunlit ground.** When Sky Atmosphere lights the scene, the panorama below the horizon is the ground lit by the sky's own sun and by the dome above, giving back **Ground Albedo** of it (0.2) and fading into the horizon colour; it was the horizon's haze at a quarter, a ground that took no sun. A wall in shadow takes the sunlit ground's bounce. Lighting only: the sky drawn below the horizon is unchanged.
- **Rooms stay dark under a sky that changes (sky occlusion).** With **Sky occlusion** on in the Lighting settings (`BakedLighting.skyOcclusion`), a probe bake keeps how much of the sky each probe sees instead of the sky itself: the probes hold the lights and their bounces, and the sky the frame has now (a live Sky Atmosphere, a weather, an environment) is added through what each probe sees of it, to the diffuse light and to the sky's reflection. A ball inside a roofed room measured 119 where the baked sky gave it 150, and a ball outside kept its light. A `.esprobes` baked this way carries `skyVisibility`; one without it lights as before. Probes are read per object, as Unity's light probes are: one large mesh spanning indoors and out takes one value.
+- **Wet ground: a map says where it is damp and where water stands.** The Model material takes a wet map over the world's X and Z (`u_wetMask`, with `u_wetOrigin` and `u_wetSize`) and a master `u_wetness`: red is standing water, green dampness; damp ground darkens (`u_wetDarken`) and grows smoother (`u_wetRoughness`), a puddle goes flat and near-mirror, and a Planar Reflection on the same mesh then shows the scene in the pools alone. Wetness 0 (the default) costs one comparison. wet-ground checks a puddle, a damp patch and dry ground under one sun on both backends.
- **Color Grade has split toning, an S-curve and lift.** **Shadow Tint** and **Highlight Tint** multiply the dark and the bright tones (blended by luma between **Tone Low** and **Tone High**), **S-Curve** blends in a smoothstep about the picture's range and **Lift** adds a tinted black level, all on the picture as the display shows it (put the grade after Tonemap). Defaults are white, white, 0 and black, so no existing grade changes. A reference game's neutral-grey shed turned out to be a scene as orange as ours, graded teal in the shadows and lifted toward teal in the blacks; color-grade-split checks the three tones on both backends.
- **A captured probe volume drives reflections too.** What a shiny surface inside a capturing `LightProbeVolume` reflects is the capture, box-projected, rather than the outdoor sky: the SDK prefilters each capture into a column of one reflection atlas beside the sky and the frame uses it wherever no baked `ReflectionProbe` is. A mesh now picks its reflection box by its world bounds (its centre, else the smallest box it overlaps), as probes do, so an imported level's walls whose origin sits outside the room still reflect it. A capture face now counts as done only once it is drawn. probe-capture-reflection checks a chrome ball shows the green wall on its right and the magenta one on its left, on both backends.
- **A probe volume can be filled at run time.** `LightProbeVolume.capture` draws the scene from the box's centre all round (one small face a frame, no post-processing), reads it back and lights everything inside with it in place of a bake — the walls as the lamps light them now and the sky through the openings, which a bake cannot see on meshes without lightmap UVs. `captureInterval` recaptures (each pass a bounce). Unreal's real-time Sky Light / Reflection Capture; probe-capture checks a white ball between a red wall, a blue wall and a green ceiling takes each colour on the side that faces it, on both backends.
diff --git a/docs/astro/src/content/docs/graphics/materials.mdx b/docs/astro/src/content/docs/graphics/materials.mdx
index 5f8718911..cec81c261 100644
--- a/docs/astro/src/content/docs/graphics/materials.mdx
+++ b/docs/astro/src/content/docs/graphics/materials.mdx
@@ -58,6 +58,21 @@ The **Water** shader (`builtin:water`) draws a body of water: refraction by meas
ocean, a lake or a river is, and a `WaterZone` bakes them into one surface drawn with it, lifts the geometry with waves and answers for the surface from code.
All of it is in [Water](/docs/graphics/water/).
+## Wet ground
+
+A Model material can lay a **wet map** over the ground, so a yard is damp in places and has standing water in others rather than one roughness
+all over. Give it `u_wetMask`, a small texture read in the world's X and Z (red is standing water, 0 dry to 1 a puddle; green is dampness),
+the world corner it starts at (`u_wetOrigin`) and how big it is (`u_wetSize`, 0 leaves wetness off), and raise `u_wetness` above 0:
+
+| Where the map says | The surface |
+|---|---|
+| damp (green, or red) | darkens by `u_wetDarken` (water in the pores takes the light a dry surface scatters) and grows smoother, toward `u_wetRoughness` |
+| a puddle (red) | goes flat (the normal map is let go of) and nearly a mirror, roughness 0.05 |
+| outside the map | stays dry |
+
+Put a **Planar Reflection** on the same mesh (see Lighting) and the puddles show the scene. The map is data, not a picture: import it without sRGB (the
+shader's `texel(data)` says so). With `u_wetness` at 0, which is the default, a surface pays one comparison.
+
## Skin and hair
Two shaders for the parts of a character a metal/rough pair does not describe. Both take the base colour from the mesh's own texture, as
diff --git a/docs/astro/src/content/docs/zh-cn/graphics/materials.mdx b/docs/astro/src/content/docs/zh-cn/graphics/materials.mdx
index ba50dccde..42e258b84 100644
--- a/docs/astro/src/content/docs/zh-cn/graphics/materials.mdx
+++ b/docs/astro/src/content/docs/zh-cn/graphics/materials.mdx
@@ -50,6 +50,20 @@ Terrain、Foliage、Water、Hair、Skin、Eye 这几个模板属于各自的模
**Water** 着色器(`builtin:water`)画一片水体:按实测水深折射,以及反射和泡沫。`WaterBody` 组件说明海洋、湖泊或河流在哪里,`WaterZone` 把它们烘成一个用它画出的水面,用波浪抬起几何体,并让代码能查询水面。全部内容在[水](/docs/zh-cn/graphics/water/)一章。
+## 潮湿的地面
+
+Model 材质可以在地面上铺一张**潮湿贴图**,让一个堆场有的地方潮、有的地方积水,而不是整片一个粗糙度。给它 `u_wetMask`(一张按世界 X、Z 读取的小贴图,
+红色是积水,0 为干、1 为水坑;绿色是潮湿度)、它起始的世界角点(`u_wetOrigin`)和大小(`u_wetSize`,为 0 则不启用),再把 `u_wetness` 调到 0 以上:
+
+| 贴图所说 | 表面 |
+|---|---|
+| 潮湿(绿色或红色) | 按 `u_wetDarken` 变暗(孔隙里的水吃掉了干表面散射的光),并向 `u_wetRoughness` 变光滑 |
+| 水坑(红色) | 变平(不再读法线贴图),近乎镜面,粗糙度 0.05 |
+| 贴图之外 | 保持干燥 |
+
+在同一个网格上放一个**平面反射**(见光照一章),水坑就会映出场景。这张图是数据而不是画面:导入时不要按 sRGB(着色器的 `texel(data)` 已经声明)。
+`u_wetness` 为 0(默认)时,表面只多付一次比较的代价。
+
## 皮肤与头发
两个着色器,给金属/粗糙度这一对参数描述不了的角色部位用。它们都和 Model 着色器一样,从网格自己的纹理取基础颜色,并把 `u_normalMap` 和 `u_ormMap`(红色是遮蔽,绿色是粗糙度)当作**数据**纹理:导入时要把 sRGB **关掉**,否则法线贴图会被颜色曲线扭曲,表面会出现斑块。
diff --git a/fixtures/scenes/wet-ground-mask.png b/fixtures/scenes/wet-ground-mask.png
new file mode 100644
index 000000000..cdb82e46e
Binary files /dev/null and b/fixtures/scenes/wet-ground-mask.png differ
diff --git a/fixtures/scenes/wet-ground-mask.png.meta b/fixtures/scenes/wet-ground-mask.png.meta
new file mode 100644
index 000000000..743a960c1
--- /dev/null
+++ b/fixtures/scenes/wet-ground-mask.png.meta
@@ -0,0 +1,20 @@
+{
+ "uuid": "6f0d2b1c-4b5e-4c1a-9d3e-7a1f2c3b4d5e",
+ "version": "2.0",
+ "type": "texture",
+ "importer": {
+ "maxSize": 2048,
+ "compress": false,
+ "compressFormat": "uastc",
+ "filterMode": "linear",
+ "wrapMode": "clamp",
+ "premultiplyAlpha": false,
+ "sRGB": false,
+ "sliceBorder": {
+ "left": 0,
+ "right": 0,
+ "top": 0,
+ "bottom": 0
+ }
+ }
+}
\ No newline at end of file
diff --git a/fixtures/scenes/wet-ground.esmaterial b/fixtures/scenes/wet-ground.esmaterial
new file mode 100644
index 000000000..88ef1c0fc
--- /dev/null
+++ b/fixtures/scenes/wet-ground.esmaterial
@@ -0,0 +1,23 @@
+{
+ "version": "1.0",
+ "type": "material",
+ "shader": "builtin:model",
+ "blendMode": 9,
+ "depthTest": true,
+ "depthWrite": true,
+ "cull": 1,
+ "properties": {
+ "u_metallic": 0,
+ "u_roughness": 0.8,
+ "u_wetness": 1,
+ "u_wetMask": "wet-ground-mask.png",
+ "u_wetOrigin": {
+ "x": -300,
+ "y": -100
+ },
+ "u_wetSize": {
+ "x": 600,
+ "y": 200
+ }
+ }
+}
\ No newline at end of file
diff --git a/fixtures/scenes/wet-ground.esscene b/fixtures/scenes/wet-ground.esscene
new file mode 100644
index 000000000..7fcfb8f8f
--- /dev/null
+++ b/fixtures/scenes/wet-ground.esscene
@@ -0,0 +1,155 @@
+{
+ "version": 4,
+ "name": "Wet Ground",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 400,
+ "z": 0
+ },
+ "rotation": {
+ "x": -0.70710678,
+ "y": 0,
+ "z": 0,
+ "w": 0.70710678
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 1,
+ "orthoSize": 300,
+ "nearPlane": 1,
+ "farPlane": 2000,
+ "isActive": true,
+ "priority": 0
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Ground",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "scale": {
+ "x": 6,
+ "y": 0.1,
+ "z": 2
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "material": "/scenes/wet-ground.esmaterial",
+ "color": {
+ "r": 0.8,
+ "g": 0.8,
+ "b": 0.8,
+ "a": 1
+ },
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "Ambient",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Light",
+ "data": {
+ "type": 2,
+ "color": {
+ "r": 1,
+ "g": 1,
+ "b": 1,
+ "a": 1
+ },
+ "intensity": 0.2,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 3,
+ "name": "Sun",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "rotation": {
+ "x": -0.70710678,
+ "y": 0,
+ "z": 0,
+ "w": 0.70710678
+ }
+ }
+ },
+ {
+ "type": "Light",
+ "data": {
+ "type": 1,
+ "color": {
+ "r": 1,
+ "g": 1,
+ "b": 1,
+ "a": 1
+ },
+ "intensity": 0.3,
+ "enabled": true
+ }
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/fixtures/scenes/wet-ground.textures.json b/fixtures/scenes/wet-ground.textures.json
new file mode 100644
index 000000000..0967ef424
--- /dev/null
+++ b/fixtures/scenes/wet-ground.textures.json
@@ -0,0 +1 @@
+{}
diff --git a/sdk/src/render/builtinShaders.ts b/sdk/src/render/builtinShaders.ts
index a49954884..85bdb3c4e 100644
--- a/sdk/src/render/builtinShaders.ts
+++ b/sdk/src/render/builtinShaders.ts
@@ -510,6 +510,16 @@ export const MODEL = `#pragma shader "Model"
#pragma param u_iridescence float default(0) range(0,1) ui(slider)
#pragma param u_iridescenceIor float default(1.3) range(1,2.5) ui(slider)
#pragma param u_iridescenceThickness float default(400) range(0,1200) ui(slider)
+// Wet ground: a map laid over the world's ground (X and Z) that says where it is damp and where water stands. Red is standing water
+// (0 dry to 1 a puddle), green dampness; where it reads above zero the surface darkens, grows smoother and, in a puddle, goes flat and
+// mirror-like, which a Planar Reflection on the same mesh then shows. Wetness is the master amount: 0 leaves the surface alone and
+// pays one comparison. The map starts at Origin, in world X and Z, and is Size wide and deep; outside it the ground is dry.
+#pragma param u_wetness float default(0) range(0,1) ui(slider)
+#pragma param u_wetMask texture default(black) texel(data)
+#pragma param u_wetOrigin vec2 default(0,0)
+#pragma param u_wetSize vec2 default(0,0)
+#pragma param u_wetDarken float default(0.4) range(0,1) ui(slider)
+#pragma param u_wetRoughness float default(0.3) range(0,1) ui(slider)
#pragma fragment
precision mediump float;
@@ -613,6 +623,20 @@ void main() {
float roughness = u_roughness * mr.g;
#endif
#ifdef MESH_NORMALS
+ // Wet ground: where the map says damp the surface is darker (water in the pores takes the light a dry one scatters) and smoother;
+ // where it says water stands it is flat and nearly a mirror. Before the specular anti-aliasing, which works on the roughness left.
+ if (u_wetness > 0.0 && u_wetSize.x > 0.0 && u_wetSize.y > 0.0) {
+ vec2 wuv = (P.xz + u_renderOrigin.xz - u_wetOrigin) / u_wetSize;
+ if (wuv.x >= 0.0 && wuv.x <= 1.0 && wuv.y >= 0.0 && wuv.y <= 1.0) {
+ vec2 wm = textureLod(u_wetMask, wuv, 0.0).rg;
+ float puddle = u_wetness * wm.r;
+ float damp = u_wetness * max(wm.g, wm.r);
+ base.rgb *= 1.0 - u_wetDarken * damp;
+ roughness = mix(roughness, min(roughness, u_wetRoughness), damp);
+ roughness = mix(roughness, 0.05, puddle);
+ N = normalize(mix(N, Ng, puddle));
+ }
+ }
roughness = specularAA(dndx, dndy, roughness);
#endif
SurfaceExt ext = surfaceExtNone(N);
@@ -782,6 +806,19 @@ fn packNormal(n : vec3f) -> vec2f {
var roughness = mc.u_roughness * mr.g;
#endif
#ifdef MESH_NORMALS
+ // See the GLSL twin: wet ground, before the specular anti-aliasing.
+ if (mc.u_wetness > 0.0 && mc.u_wetSize.x > 0.0 && mc.u_wetSize.y > 0.0) {
+ let wuv = (P.xz + frame.renderOrigin.xz - mc.u_wetOrigin) / mc.u_wetSize;
+ if (wuv.x >= 0.0 && wuv.x <= 1.0 && wuv.y >= 0.0 && wuv.y <= 1.0) {
+ let wm = textureSampleLevel(u_wetMask, u_wetMask_s, wuv, 0.0).rg;
+ let puddle = mc.u_wetness * wm.r;
+ let damp = mc.u_wetness * max(wm.g, wm.r);
+ base = vec4f(base.rgb * (1.0 - mc.u_wetDarken * damp), base.a);
+ roughness = mix(roughness, min(roughness, mc.u_wetRoughness), damp);
+ roughness = mix(roughness, 0.05, puddle);
+ N = normalize(mix(N, Ng, vec3f(puddle)));
+ }
+ }
roughness = specularAA(dndx, dndy, roughness);
#endif
var ext = surfaceExtNone(N);
diff --git a/sdk/tests/shader-reflect.test.ts b/sdk/tests/shader-reflect.test.ts
index b8196d879..6ebbc3299 100644
--- a/sdk/tests/shader-reflect.test.ts
+++ b/sdk/tests/shader-reflect.test.ts
@@ -140,6 +140,8 @@ describe('which texture params a shader reads as numbers', () => {
u_normalMap: 'data', u_emissiveMap: 'colour', u_occlusionMap: 'data', u_metallicRoughnessMap: 'data',
// The picture of the scene the frame binds for refraction: never a project texture, so nothing to flag.
u_sceneColor: 'colour',
+ // Wet ground's map holds amounts, not a picture.
+ u_wetMask: 'data',
});
});
});
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index 834a7ec98..0db30b895 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -615,6 +615,10 @@ export const SCENES = [
// highlight tint and a blue lift. The dark grey takes the shadow tint and the lift, the bright one the highlight tint, the middle one
// half and half: (0.05,0.05,0.05) -> (6,10,26), (0.35) -> (67,71,80), (0.8) -> (204,163,115).
{ id: "color-grade-split", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_SCENE: "/scenes/color-grade-split.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/color-grade-split.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "6", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.25,\"y\":0.5,\"rgb\":[6,10,26],\"tol\":6},{\"x\":0.5,\"y\":0.5,\"rgb\":[67,71,80],\"tol\":8},{\"x\":0.75,\"y\":0.5,\"rgb\":[204,163,115],\"tol\":8}]" } },
+ // Wet ground: a 3-texel mask over a lit grey slab (puddle | damp | dry), seen from above under a sun straight overhead. Dry is the
+ // diffuse alone (102); damp darkens by Wet Darken but is smoother, so it takes more of the sun's highlight (152); a puddle is flat and
+ // near-mirror, and the sun is in it (236).
+ { id: "wet-ground", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_SCENE: "/scenes/wet-ground.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/wet-ground.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "6", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.1667,\"y\":0.5,\"rgb\":[236,236,236],\"tol\":14},{\"x\":0.5,\"y\":0.5,\"rgb\":[152,152,152],\"tol\":12},{\"x\":0.8333,\"y\":0.5,\"rgb\":[102,102,102],\"tol\":8}]" } },
{ id: "bloom-ldr", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_SCENE: "/scenes/bloom-ldr.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/bloom-ldr.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "10", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.61,\"y\":0.5,\"rgb\":[0,58,0],\"tol\":25},{\"x\":0.7,\"y\":0.5,\"rgb\":[0,12,0],\"tol\":10},{\"x\":0.85,\"y\":0.5,\"rgb\":[0,0,0],\"tol\":12}]" } },
{ id: "hdr-bloom", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/hdr-bloom.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/hdr-bloom.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "10", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":25},{\"x\":0.64,\"y\":0.5,\"rgb\":[0,208,0],\"tol\":35},{\"x\":0.85,\"y\":0.5,\"rgb\":[0,76,0],\"tol\":25}]" } },
// A small hot spot, and the glow it throws: as far out along a diagonal as along an axis, so the halo is round. A blur