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(renderer): a captured frame gets its target back after the shadow pass, clear or not

yhhaaceef7d90ef
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cba5d0af9..90e912fe0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,29 @@ published separately; it ships inside the editor.
## [Unreleased]
+### Fixed
+
+- **A packaged game in linear colour space rendered one flat black frame, and
+ always had.** Not a look problem and not new: the same package built at
+ `2c40bf011`, before any of this release's render work, produces a
+ byte-identical black PNG. Turning a 3D project to linear was the thing this
+ release was building toward, and it could not have shipped.
+
+ `RenderFrame::openPass` exists to hand the frame its target back after the
+ shadow pass has drawn through one of its own. Down the captured path it only
+ did so when the camera also had something to CLEAR; the other two branches
+ always bind. So a camera that clears nothing left the shadow atlas current, the
+ scene drew into that, and the final blit then painted an untouched capture over
+ the top. Gamma never showed it because with no capture the scene goes straight
+ to the surface, which the atlas hand-back restores anyway.
+
+ **Why no gate held it:** it needs a shadow pass INSIDE a capture, and the suite
+ had each axis alone — every linear gate was a flat scene that casts nothing,
+ every shadow gate was gamma. `mesh-shadow-linear` is that crossing, and it
+ reproduces the packaged symptom exactly: reverted, the frame comes back with
+ zero non-black pixels while `mesh-shadow`, `linear-lit` and `linear-midtone`
+ all still pass.
+
### Changed
- **The render graph owns the scene target now, not the post-process pipeline.**
diff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cpp
index 66a582dce..77acf561b 100644
--- a/src/esengine/renderer/frame/RenderFrame.cpp
+++ b/src/esengine/renderer/frame/RenderFrame.cpp
@@ -310,14 +310,13 @@ void RenderFrame::openPass(const PassClear& clear, RenderTargetManager::Handle t
}
}
// Fresh begin: colors the capture's own load-op clear. When TS already
- // began the capture (renderCamera drives pp.begin first) this no-ops...
+ // began the capture (renderCamera drives pp.begin first) this no-ops.
post_process_->begin(pass.clearColorValue);
- // ...so apply the camera's (possibly region-scoped) clear to the active
- // capture surface explicitly.
- if (pass.clearColor || pass.clearDepth) {
- pass.target = post_process_->currentSceneFBO();
- device_.beginRenderPass(pass);
- }
+ // Then BIND it, clear or no clear: this is where the frame gets its target
+ // back after the shadow pass drew through one of its own. Skipping that for
+ // a camera with nothing to clear left the atlas current — a black frame.
+ pass.target = post_process_->currentSceneFBO();
+ device_.beginRenderPass(pass);
#endif
} else if (target != RenderTargetManager::INVALID_HANDLE) {
auto* rt = target_manager_.get(target);
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index 4dafb7721..654678b3e 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -92,6 +92,10 @@ export const SCENES = [
// The same scene with a MATERIAL on the occluder, over three frames because a
// stale sampler unit needs a previous frame. Red at the centre says the material
// ran in the CAMERA's pass; black at 0.708 says the occluder still cast.
+ // A shadow pass INSIDE a capture, which nothing else here puts together: the other
+ // linear gates cast nothing and the other shadow gates are gamma. The atlas takes
+ // the target away mid-frame; whether the capture is handed back is what this pins.
+ { id: "mesh-shadow-linear", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/mesh-shadow.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.708,\"y\":0.5,\"rgb\":[0,0,0],\"tol\":20},{\"x\":0.167,\"y\":0.5,\"rgb\":[243,243,243],\"tol\":20},{\"x\":0.5,\"y\":0.5,\"rgb\":[243,243,243],\"tol\":20}]" } },
{ id: "mesh-shadow-material", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mesh-shadow-material.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "3", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[255,0,0],\"tol\":40},{\"x\":0.708,\"y\":0.5,\"rgb\":[0,0,0],\"tol\":20},{\"x\":0.167,\"y\":0.5,\"rgb\":[228,228,228],\"tol\":20}]" } },
// The same question through a PERSPECTIVE camera, which is what a 3D scene uses: