A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(render): a camera that does not start at the window's corner draws through the post chain
yhhd5ad271089d9
diff --git a/fixtures/scenes/camera-split-3d.esscene b/fixtures/scenes/camera-split-3d.esscenenew file mode 100644index 000000000..73564907c--- /dev/null+++ b/fixtures/scenes/camera-split-3d.esscene@@ -0,0 +1,170 @@+{+ "version": 4,+ "name": "camera-split-3d",+ "entities": [+ {+ "id": 0,+ "name": "Left",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -5000,+ "y": 400,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0,+ "viewport": {+ "x": 0,+ "y": 0,+ "z": 0.5,+ "w": 1+ }+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Left Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -5000,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 4,+ "y": 0.1,+ "z": 4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 1,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Right",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 5000,+ "y": 400,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 1,+ "viewport": {+ "x": 0.5,+ "y": 0,+ "z": 0.5,+ "w": 1+ }+ }+ }+ ]+ },+ {+ "id": 3,+ "name": "Right Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 5000,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 4,+ "y": 0.1,+ "z": 4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0,+ "g": 1,+ "b": 0,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ }+ ]+}\ No newline at end of filediff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cppindex a9011d0b8..8b5642596 100644--- a/src/esengine/renderer/frame/RenderFrame.cpp+++ b/src/esengine/renderer/frame/RenderFrame.cpp@@ -440,7 +440,18 @@ void RenderFrame::begin(const glm::mat4& view_projection, RenderTargetManager::H}void RenderFrame::begin(const glm::mat4& view_projection, RenderTargetManager::Handle target,- const PassClear& clear) {+ const PassClear& camera_clear) {+ // A chain that is engaged draws the scene into a capture exactly as big as the camera's rect, and only its present lands at+ // the rect's offset (setOutputViewport). So the camera's rect starts at the capture's origin: left at the camera's own x/y+ // it names pixels outside the capture, and a camera that does not start at the window's corner (the right half of a split,+ // a minimap) drew nothing at all whenever the frame was linear, tone mapped or post-processed.+ PassClear clear = camera_clear;+#ifdef ES_ENABLE_POSTPROCESS+ if (post_process_ && post_process_->isEngaged()) {+ clear.x = 0;+ clear.y = 0;+ }+#endif// Emptied before the device is asked, so a refused frame starts empty too: the host still submits text and skinned batches into// it, and while a lost device waits for its content no end() ever ran to empty them, so the staging grew every frame until an// allocation of gigabytes failed.diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjsindex 053493dd0..dc755e552 100644--- a/tools/renderScenes.mjs+++ b/tools/renderScenes.mjs@@ -188,6 +188,12 @@ export const SCENES = [{ id: "frame-debugger-2d", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/sprite-rendering.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/sprite-rendering.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_FRAME_DEBUG: "1" } },{ id: "frame-debugger-3d", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/ssao.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_FRAME_DEBUG: "1" } },{ id: "frame-debugger-split", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/camera-split.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/camera-split.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_FRAME_DEBUG: "1" } },+ // The 3D counterpart: two meshes' worth of world, one camera for each half of the frame. A camera+ // that starts away from the window's corner drew nothing at all once the frame went through the+ // post chain (linear light, an output transform, any effect), because the scene was drawn at the+ // camera's offset inside an intermediate target only as big as the camera. The second entry is that path.+ { id: "camera-split-3d", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/camera-split-3d.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-renderer.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.25,\"y\":0.5,\"rgb\":[255,0,0],\"tol\":30},{\"x\":0.75,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":30}]" } },+ { id: "camera-split-3d-linear", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/camera-split-3d.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-renderer.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.25,\"y\":0.5,\"rgb\":[255,0,0],\"tol\":30},{\"x\":0.75,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":30}]" } },{ id: "mesh-renderer", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mesh-renderer.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-renderer.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.30,\"y\":0.556,\"rgb\":[255,0,0],\"tol\":40},{\"x\":0.70,\"y\":0.556,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.30,\"y\":0.40,\"rgb\":[255,0,0],\"tol\":40}]" } },// One mask, both its sides, and a sprite that never asked. A mask that does nothing// paints the frame red; a side that inverted swaps green and red. The blue bar states