主题
GameGraph Rendering Color Pipeline
Read 渲染颜色管线:Gamma 校正、Bloom 与色调映射 before implementing a main viewport or diagnosing its colors. In a generated project, the guide is at docs/sdk/guides/RenderColorPipeline.md; this skill's XML assets stay under assets/RenderPaths/.
The guide applies to 3D scenes, 2D sprites and mixed views. Choose by output target and authoring intent, not by whether the view is called "2D" or "3D".
Existing Project Migration
SDK sync copies skills by directory. An existing project may still contain .codex/skills/gamegraph-2d-rendering or .cursor/skills/gamegraph-2d-rendering after resyncing the SDK. Inspect that old directory: if it is only the generated copy, archive the old entry; if it contains project-specific files, preserve those files and archive only the generated entry. Do not rely on automatic cleanup. New projects should have only render-color-pipeline.
Choose The Output Contract
- Keep the official SCE scene main path for ordinary 3D and mixed scenes. It uses full-strength Bloom +
ACES_APPROXand keeps geometry, lighting, SSAO and tone mapping together. Do not replace the whole path with the flat sprite path: opaque meshes, lighting and other passes would disappear. ACES_APPROXandPBR_NEUTRALare variants of the officialTonemapshader; do not add a project shader, technique XML or a second tone-mapping pass. The SCE default is full Bloom + ACES; direct SceneGraph 3D,AnimatedSprite2DandTilemapviews usually want a project path with weak Bloom + PBR Neutral. Do not generalize the SCE default to Canvas/GameUI, transparent overlays or arbitrary RTT targets.- To opt into weak Bloom + PBR Neutral, copy the official main path into project
res/RenderPaths/, replace itsGamePostProcess.xmlreference with a project post-process file, and useGameBloomHDR.xml(weak) +PbrNeutralTonemap.xml. Use the suppliedGamePostProcessPbrNeutral.xmlandTonemapPbrNeutral.xmlas the starting point. Load that complete path withSetRenderPathduring client initialization; do not set a bare Tonemap fragment as the render path and do not stack it on an existingGammaCorrectionpath. - Preserve the official Tonemap command's
tag="BloomHDR Tonemap". The tag drives post-process gating and render-target routing; renaming it is not a harmless display change. - Use
Renderer.GetMainViewport().SetRenderPath("RenderPaths/...xml")for a complete main path. A single Tonemap fragment is not a complete path. Check the return value and prefer one init-time assignment. - A dedicated unlit 2D sprite view that must preserve authored pixels exactly can use the supplied
Flat2DLinear.xmlandFlat2DBackbuffer.xml. This is an opt-in pixel-fidelity path, not a rule for all 2D games. - Canvas/GameUI, transparent overlays and custom RenderToTexture targets have separate output contracts. For an RTT, determine its texture format/sRGB flag and downstream consumer before choosing Gamma encoding. The main editor-canvas property alone does not classify an arbitrary RTT.
Implementation Invariants
SceneGraphMainViewportController.Bind/Renderer.SetupMainViewportretain the host RenderPath. An independent SceneGraph and an orthographic camera do not isolate fullscreen effects. Set the dedicated view's path explicitly during initialization.- Bloom and tone mapping are separate steps. The SCE default uses
GameBloomHDR_FullStrength.xml;GameBloomHDR.xmlis the weak tier used by templates and explicit SceneGraph/2D paths. Either Bloom file only builds glow;AcesApproxTonemap.xmlorPbrNeutralTonemap.xmlapplies the curve afterwards. Zero glow strength does not remove tone mapping. - RenderPath file names are not proof. Inspect the actual
command,ps,psdefinesandtag. Older paths may bake tone mapping into the Bloom combine. - For ordinary PNG color art, configure the matching texture XML with
srgb=trueand preserve intentional existing resource settings. Composite in linear space and perform final Gamma encoding once. Treat data/mask/normal textures separately. - The official path does not need an extra
GammaCorrectioncommand. The engine addsGAMMA_IN_SHADERINGwhen a fullscreen command writes the backbuffer, so the official Tonemap/Bloom/GaussianBlur shader encodes once. In PIE the game canvas is an intermediate target, so the editor UI encodes once. Do not add the macro manually or append a second Gamma pass. - The flat 2D backbuffer path is the exception: default Urho2D sprite shaders do not encode output, so
Flat2DBackbuffer.xmlcontains exactly oneGammaCorrectionquad.Flat2DLinear.xmlleaves encoding to the editor UI in PIE. Renderer.IsEditorDebugViewportActivedistinguishes the main PIE canvas from a standalone backbuffer. Do not select byGame.IsClientOnlyor apply Gamma twice.- Keep the existing normal-game postprocessing setting enabled for these paths. Disabling the global postprocessing switch can skip Bloom/Tonemap and change sprite shader defines; do not use it as a shortcut to remove Bloom or tone mapping.
- Save the retained
Viewport.GetRenderPath()reference and every viewport option you change. Restore them before disposing the viewport controller and graph, then dispose the retained path wrapper. Own cleanup on initialization failure, level changes and game end. - A dedicated default-unlit sprite scene needs no LightGroup just to restore its original colors. Inspect LightGroup/Zone when the selected path uses their postprocessing parameters; do not reset global lighting as an unexplained workaround.
- If a required Tonemap variant is missing at runtime, update the official shader/resource package. Do not replace it with a project shader or compensate by changing PNG sRGB flags.
Supplied XML
Copy the files you need into project res/RenderPaths/; code uses RenderPaths/... without res/.
| Asset | Purpose |
|---|---|
TonemapAcesApprox.xml | ACES-approximate Tonemap command; matches the SCE default curve |
TonemapPbrNeutral.xml | PBR Neutral Tonemap command; weak-tier route |
GamePostProcessAces.xml | GameBloomHDR_FullStrength.xml + ACES + GaussianBlur |
GamePostProcessPbrNeutral.xml | GameBloomHDR.xml (weak) + PBR Neutral + GaussianBlur |
Flat2DLinear.xml | Pixel-fidelity 2D view: linear PIE output |
Flat2DBackbuffer.xml | Pixel-fidelity 2D view: standalone Gamma output |
Flat2DMainView.cs | Main-view owner: path selection, state save/restore and cleanup |
Verify The Result
Use the existing project's normal editor debug workflow for iteration. Include an independent-client comparison when diagnosing that route; follow the project's debug tools and process ownership rules.
- Record the chosen RenderPath, actual editor-canvas state and current resources. Check
SetRenderPath's return value and the command'spsdefines/tag. - Compare cold PIE, PIE after another scene run, and standalone output against the same source PNG or intended look. Window aspect ratio changes framing, not the intended palette.
- Inspect runtime screenshots and game rendering logs.
GammaCorrection()andGammaCorrection(GAMMA_IN_SHADERING)are distinct requested variants; published shaders must cover the actual platform and define string. A successful XML load or C# build does not prove shader availability. - A black map with a visible HUD warrants checking shader failures as well as scene/camera visibility. Do not compensate for missing shaders by changing texture sRGB flags.
- Check color on the target platform and rendering path. Texture format and GPU behavior can affect the result, and the supplied flat path does not establish the behavior of a custom material or a path with postprocessing disabled.
Related
- Client SceneGraph game for graph/camera/game lifecycle and input.
- TMX maps for loading and coordinate contracts.
- Transparent picture-in-picture for alpha-preserving compositing.
- Custom shaders for genuinely custom materials; tone-mapping curves are not a custom-shader task.