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 mirror reads its reflection at level 0 on WebGL2 too

esengine0fcdc8d03c76
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a712e4190..fe9025681 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -350,6 +350,12 @@ published separately; it ships inside the editor.
### Fixed
+- **A mirror has no seam across it on WebGL2.** The prefiltered atlas stacks its
+ own mips, and the WebGL2 shader let the hardware pick one: wherever the
+ octahedral fold makes the derivatives jump, it read the neighbouring column,
+ and a thin grey arc and a vertical line crossed every shiny sphere. It now reads
+ level 0 by name, as the WebGPU shader always did.
+
- **A half-transparent texture looks the same on WebGPU as on WebGL2.** Without a
WebGL2 context a texture was read through a 2D canvas, whose pixels already come
back unpremultiplied, and then divided by alpha a second time. Every
diff --git a/fixtures/scenes/reflection-fold.esscene b/fixtures/scenes/reflection-fold.esscene
new file mode 100644
index 000000000..262249583
--- /dev/null
+++ b/fixtures/scenes/reflection-fold.esscene
@@ -0,0 +1,180 @@
+{
+ "version": 4,
+ "name": "Reflection Fold",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": -60,
+ "z": 400
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 0,
+ "fov": 20,
+ "nearPlane": 10,
+ "farPlane": 9000,
+ "isActive": true,
+ "priority": 0
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Sky",
+ "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": 1,
+ "environment": "/scenes/studio.esenv"
+ }
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "Probe",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "ReflectionProbe",
+ "data": {
+ "reflection": "/scenes/reflect-atlas.esenv",
+ "halfExtents": {
+ "x": 300,
+ "y": 300,
+ "z": 300
+ },
+ "slot": 1,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 3,
+ "name": "Ball",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "scale": {
+ "x": 3,
+ "y": 3,
+ "z": 3
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:sphere",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 1,
+ "g": 1,
+ "b": 1,
+ "a": 1
+ },
+ "material": "/scenes/mat-env/chrome.esmaterial"
+ }
+ }
+ ]
+ },
+ {
+ "id": 4,
+ "name": "Marker",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -14,
+ "y": -46,
+ "z": 300
+ },
+ "scale": {
+ "x": 0.06,
+ "y": 0.06,
+ "z": 0.06
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 0.8,
+ "g": 0,
+ "b": 0,
+ "a": 1
+ }
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/src/esengine/resource/ShaderParser.cpp b/src/esengine/resource/ShaderParser.cpp
index 76c49b68e..a7a05101b 100644
--- a/src/esengine/resource/ShaderParser.cpp
+++ b/src/esengine/resource/ShaderParser.cpp
@@ -2155,7 +2155,10 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p
" highp vec2 hi = vec2(column * col + size + 1.5, yOff + size + 1.5);\n"
" highp vec2 px = clamp(vec2(column * col + 1.0 + uv.x * size,\n"
" yOff + 1.0 + uv.y * size), lo, hi);\n"
- " highp vec4 t = texture(u_envMap, px / vec2(atlasW, atlasH));\n"
+ // Level 0 by name, like the WGSL twin: the atlas stacks its own mips, and
+ // one the hardware picks mixes neighbouring columns wherever the fold
+ // makes the derivatives jump.
+ " highp vec4 t = textureLod(u_envMap, px / vec2(atlasW, atlasH), 0.0);\n"
" return t.rgb * t.rgb * (t.a * t.a * u_envParams.y);\n"
"#endif\n"
"}\n"
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index ec3f13675..ae3f3bea0 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -309,6 +309,10 @@ export const SCENES = [
// A baked atlas has mixed channels at low alpha, which is what texture-alpha
// guards on WebGPU: dividing by alpha twice turns this ball grey.
{ id: "reflection-room", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/reflection-room.esscene", ESTELLA_VERIFY_W: "512", ESTELLA_VERIFY_H: "384", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\": 0.2, \"y\": 0.55, \"rgb\": [255, 62, 54], \"tol\": 45}, {\"x\": 0.42, \"y\": 0.62, \"rgb\": [42, 255, 71], \"tol\": 45}]" } },
+ // A mirror ball filling the frame inside a probe whose column is one red everywhere (the
+ // marker a darker red, so the frame is not flat): every pixel is that red. A tap letting the
+ // hardware pick a mip reads the next column across the octahedral fold — 65310 of 65536.
+ { id: "reflection-fold", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/reflection-fold.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_COUNT: "[{\"rgb\": [243, 0, 0], \"tol\": 45, \"atLeast\": 65536}]" } },
// The same ball with the probe off: both sides take the flat sky, and the room
// stops being visible in it.
{ id: "reflection-room-sky", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/reflection-room.esscene", ESTELLA_VERIFY_W: "512", ESTELLA_VERIFY_H: "384", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_SET_FIELD: "{\"entity\": 8, \"component\": \"ReflectionProbe\", \"key\": \"enabled\", \"value\": false, \"steps\": 2}", ESTELLA_VERIFY_EXPECT: "[{\"x\": 0.2, \"y\": 0.55, \"rgb\": [37, 37, 39], \"tol\": 25}, {\"x\": 0.42, \"y\": 0.62, \"rgb\": [37, 37, 39], \"tol\": 25}]" } },