Implement the following plan: Plan: Y-Sort Depth Bias for Parent/Child Rendering Order…
- User
Implement the following plan:
Plan: Y-Sort Depth Bias for Parent/Child Rendering Order
Context
Rotation wobble is already implemented.
elephant-kidandelephant-kid-shilhouetteshare the same world Y position (child inherits parent's transform), soYSortSystemcomputes the same interpolated depth for both. The only tiebreaker is entity creation index inMasterRenderSystem(.ThenBy(x => x.index)), which depends on Blender export order — fragile and implicit.We can't use
GetDepth(Characters, subOffset)becauseTryGetYSortRangedoes an exact float match onSpriteInfo.LayerDepth— any offset breaks Y-sort membership.Approach:
YSortDepthBiasfield onSpriteInfoA small float (default 0f) applied after Y-sort interpolation. The base
LayerDepthstays at the exact Characters depth (so Y-sort lookup works), then the bias shifts the final value. This is a generally useful core feature for any entities at the same Y that need deterministic front/back ordering.Changes
1.
MonoDreams/Component/Draw/SpriteInfo.cs— add fieldcsharppublic float YSortDepthBias = 0f;2.
MonoDreams/System/Draw/YSortSystem.cs(line 48) — apply bias after interpolationcsharpdrawComponent.LayerDepth = minDepth + t * (maxDepth - minDepth) + spriteInfo.YSortDepthBias;3.
MonoDreams.Examples/Screens/LoadLevelExampleGameScreen.cs— set bias for shilhouette in NPC handlerAfter the existing shilhouette amplitude check, set bias on SpriteInfo:
csharpif (blenderObj.Name.EndsWith("shilhouette")) { ref var sprite = ref entity.Get<SpriteInfo>(); sprite.YSortDepthBias = -0.0005f; }Rendering math
Entity YSortDepthBias Result elephant-kid 0 (default) Base Y-sort depth elephant-kid-shilhouette Assistant
I'll start by reading the three files that need changes, plus building to confirm the baseline compiles.
Assistant
Baseline builds cleanly. Now I'll make all three changes.
Assistant
All three edits applied. Let me verify the build.
Assistant
Build succeeds with 0 errors. Here's a summary of what was changed:
-
MonoDreams/Component/Draw/SpriteInfo.cs— AddedYSortDepthBiasfield (default0f) that gets applied after Y-sort depth interpolation, giving any entity a deterministic front/back offset relative to same-Y entities. -
MonoDreams/System/Draw/YSortSystem.cs— Appended+ spriteInfo.YSortDepthBiasto the interpolated depth calculation on line 48. -
MonoDreams.Examples/Screens/LoadLevelExampleGameScreen.cs— In the NPC collection handler, setYSortDepthBias = -0.0005fon shilhouette entities so they render behind their parent (negative bias = lower depth = further back).
You can verify by running the game and loading the Blender level —
elephant-kidshould always render on top ofelephant-kid-shilhouette, and both should still Y-sort correctly against other characters.-
- User
Checkout to a new branch, commit, push and open a pull request
Assistant
The diff includes both the rotation wobble feature (untracked files + game screen changes) and the Y-sort depth bias. Let me create the branch, commit, push, and open the PR.
Assistant
PR created: https://github.com/roo-oliv/monodreams/pull/21