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.

fix(render): a glass roof keeps rain off

yhh5bbbd0c7c21c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fddc006d8..584ade93a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,7 @@ published separately; it ships inside the editor.
### Fixed
+- **Rain does not fall through a glass roof.** The rain's map of what stands overhead took only what casts a shadow, so a see-through roof set to cast none — glass, as it usually is — left the floor under it wet. A see-through surface keeps rain off whether or not light passes it; what is opaque and casts no shadow (a held gun) still stays out. Gate: ssr-shelter-glass.
- **A character controller or a 3D collider added with its defaults is a real size.** Their defaults were metres (a 0.3 radius, a 0.5 box) under a world that reads centimetres unless told otherwise: a 3 mm character, a 5 mm crate. They are a 1.6 m person and a 1 m box now, in whatever units the project uses. Every example and template stated its sizes, so none changes.
- **A model's import no longer calls it tiny in a metre project.** The note read every model as if a world unit were a design pixel; it now measures the model in metres by the project's units per metre and suggests that as the Scale.
- **Navigation bakes an imported level.** The bake took only bodies with a static RigidBody3D, so a level of mesh colliders (static by themselves) baked to no ground; and it placed every collider at its LOCAL pose and unscaled, so one under a parent landed elsewhere. It now takes what the solver builds, where the solver builds it.
diff --git a/fixtures/scenes/glass-roof_m0.esmaterial b/fixtures/scenes/glass-roof_m0.esmaterial
new file mode 100644
index 000000000..5ef7ad6b5
--- /dev/null
+++ b/fixtures/scenes/glass-roof_m0.esmaterial
@@ -0,0 +1,13 @@
+{
+ "version": "1.0",
+ "type": "material",
+ "shader": "builtin:model",
+ "blendMode": 0,
+ "depthTest": true,
+ "depthWrite": false,
+ "cull": 0,
+ "properties": {
+ "u_metallic": 0,
+ "u_roughness": 0.1
+ }
+}
diff --git a/fixtures/scenes/ssr-shelter-glass.esscene b/fixtures/scenes/ssr-shelter-glass.esscene
new file mode 100644
index 000000000..49920c7b9
--- /dev/null
+++ b/fixtures/scenes/ssr-shelter-glass.esscene
@@ -0,0 +1,250 @@
+{
+ "version": 4,
+ "name": "SSR shelter under a glass roof",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 300,
+ "z": 500
+ },
+ "rotation": {
+ "w": 0.9732489894677302,
+ "x": -0.22975292054736118,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 0,
+ "fov": 60,
+ "nearPlane": 1,
+ "farPlane": 5000,
+ "isActive": true,
+ "priority": 0
+ }
+ },
+ {
+ "type": "PostProcessVolume",
+ "data": {
+ "isGlobal": true,
+ "priority": 0,
+ "weight": 1,
+ "effects": [
+ {
+ "type": "rain",
+ "enabled": true,
+ "uniforms": {
+ "u_intensity": 0,
+ "u_wetness": 0,
+ "u_puddles": 0
+ }
+ },
+ {
+ "type": "ssr",
+ "enabled": true,
+ "uniforms": {
+ "u_intensity": 1,
+ "u_wetness": 1,
+ "u_puddles": 0,
+ "u_skyReflection": 0
+ }
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Sun",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "rotation": {
+ "w": 0.8646239550683974,
+ "x": -0.476200656600911,
+ "y": -0.14030915235402952,
+ "z": -0.07727672832384176
+ }
+ }
+ },
+ {
+ "type": "Light",
+ "data": {
+ "type": 1,
+ "color": {
+ "r": 1,
+ "g": 1,
+ "b": 1,
+ "a": 1
+ },
+ "intensity": 1
+ }
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "Floor",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "rotation": {
+ "w": 0.7071067811865476,
+ "x": -0.7071067811865475,
+ "y": 0,
+ "z": 0
+ },
+ "scale": {
+ "x": 4,
+ "y": 4,
+ "z": 1
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "/scenes/normalmap-quad.esmesh",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": false,
+ "enabled": true,
+ "material": "/scenes/ssr-shelter-floor_m0.esmaterial",
+ "color": {
+ "r": 0.5,
+ "g": 0.5,
+ "b": 0.5,
+ "a": 1
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 3,
+ "name": "Wall",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 150,
+ "z": -300
+ },
+ "rotation": {
+ "w": 1,
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "scale": {
+ "x": 4,
+ "y": 1.5,
+ "z": 1
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "/scenes/normalmap-quad.esmesh",
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": false,
+ "enabled": true,
+ "color": {
+ "r": 1,
+ "g": 0.1,
+ "b": 0.1,
+ "a": 1
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 4,
+ "name": "Roof",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -300,
+ "y": 700,
+ "z": 100
+ },
+ "rotation": {
+ "w": 0.7071067811865476,
+ "x": -0.7071067811865475,
+ "y": 0,
+ "z": 0
+ },
+ "scale": {
+ "x": 2,
+ "y": 3,
+ "z": 1
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "/scenes/normalmap-quad.esmesh",
+ "lit": true,
+ "opaque": false,
+ "cullBackfaces": false,
+ "enabled": true,
+ "color": {
+ "r": 0.6,
+ "g": 0.8,
+ "b": 0.9,
+ "a": 0.3
+ },
+ "material": "/scenes/glass-roof_m0.esmaterial",
+ "castShadows": false
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/src/esengine/renderer/RenderTypePlugin.hpp b/src/esengine/renderer/RenderTypePlugin.hpp
index fc664c30c..4b588d8f1 100644
--- a/src/esengine/renderer/RenderTypePlugin.hpp
+++ b/src/esengine/renderer/RenderTypePlugin.hpp
@@ -92,6 +92,10 @@ struct RenderFrameContext {
glm::vec3 view_eye{0.0f};
bool has_view_eye = false;
bool lighting_direct = false;
+ /// This shadow-depth collect is the RAIN's map of what stands overhead, not a light's: what keeps rain off is solid
+ /// whether or not light passes it, so a see-through surface that casts no shadow (a glass roof) is in it all the same.
+ /// Last, so the positional initialisers before it keep their places.
+ bool rainCover = false;
};
/** @brief What every plugin needs to know about the camera, derived once per collect
diff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cpp
index ea47f3466..75853eead 100644
--- a/src/esengine/renderer/frame/RenderFrame.cpp
+++ b/src/esengine/renderer/frame/RenderFrame.cpp
@@ -2792,6 +2792,7 @@ void RenderFrame::collectCover(ecs::Registry& registry) {
auto ctx = makeContext();
ctx.view_projection = cover_view_projection_;
ctx.purpose = RenderPurpose::ShadowDepth;
+ ctx.rainCover = true;
RenderCollectContext collectCtx{registry, frustum, clip_state_, cover_pool_, cover_list_, ctx,
computeCameraView(cover_view_projection_)};
collectCtx.screen_ui = screen_domain_;
diff --git a/src/esengine/renderer/plugins/MeshPlugin.cpp b/src/esengine/renderer/plugins/MeshPlugin.cpp
index 10a4340fc..8ea1a9718 100644
--- a/src/esengine/renderer/plugins/MeshPlugin.cpp
+++ b/src/esengine/renderer/plugins/MeshPlugin.cpp
@@ -753,8 +753,10 @@ void MeshPlugin::collect(RenderCollectContext& collect_ctx) {
// Many placements of one mesh, drawn as instances of it. What is placed does not move on its own, so the motion pass has nothing to say.
const ecs::MeshInstances* placements = resident ? registry.tryGet<ecs::MeshInstances>(entity) : nullptr;
if (placements && (placements->transforms.empty() || motion)) continue;
- // What light passes through (water) stands in no light's way.
- if (shadowDepth && !mesh.castShadows) continue;
+ // What light passes through (water) stands in no light's way. Rain's way is another matter: a see-through surface
+ // set to cast no shadow (glass) still keeps rain off what is under it, so the rain's cover map takes it. What is
+ // opaque and casts no shadow (a held gun, an effect's mesh) stays out of both.
+ if (shadowDepth && !mesh.castShadows && !(ctx.rainCover && !mesh.opaque)) continue;
// Only a surface that draws opaque and unblended has a motion worth writing: what is blended over
// something has two, and the picture can follow one.
if (motion && !mesh.opaque) continue;
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index dcebf9bb1..d3ad34a0e 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -891,6 +891,9 @@ export const SCENES = [
// Wet ground under a roof stays dry: reflections read the rain's map of what stands over each place, as the rain does. A floor too rough
// to reflect dry, wet by the reflections' own Wetness, under a roof over its left half: only the open right half mirrors the red wall. Reading no map, the left half reads 148,40,40 too.
{ id: "ssr-shelter", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/ssr-shelter.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-backface.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "6", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.25,\"y\":0.5,\"rgb\":[53,53,53],\"tol\":12},{\"x\":0.75,\"y\":0.5,\"rgb\":[147,39,39],\"tol\":15}]" } },
+ // The same floor under a GLASS roof: rain does not fall through glass, however much light does. A blended, see-through roof
+ // keeps the floor under it as dry as an opaque one; the cover map is the rain's, not the sun's, and alpha is not what stops rain.
+ { id: "ssr-shelter-glass", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/ssr-shelter-glass.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-backface.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "6", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.25,\"y\":0.5,\"rgb\":[53,53,53],\"tol\":12},{\"x\":0.75,\"y\":0.5,\"rgb\":[147,39,39],\"tol\":15}]" } },
// Sky Atmosphere's Light the Scene: a white diffuse quad lit by nothing but an Ambient light that names no environment, under a clear
// sky with the sun up behind it. The sky lights it as an environment, the blue of the dome it faces; off, it is the flat white 255.
{ id: "sky-lights-scene", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/sky-lights-scene.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-backface.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "6", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[96,113,115],\"tol\":12}]" } },