bevy
bevy copied to clipboard
Add 2d opaque phase with depth buffer
This PR is based on top of #12982
Objective
- Mesh2d currently only has an alpha blended phase. Most sprites don't need transparency though.
- For some 2d games it can be useful to have a 2d depth buffer
Solution
- Add an opaque phase for to render Mesh2d that don't need transparency
- This phase currently uses the
SortedRenderPhaseto make it easier to implement based on the already existing transparent phase. A follow up PR will switch this toBinnedRenderPhase.
- This phase currently uses the
- Add a 2d depth buffer
Changelog
- Added
AlphaMode2d - Added
Opaque2drender phase - Camera2d now have a
ViewDepthTexturecomponent
Migration Guide
ColorMaterialnow containsAlphaMode2d. To keep previous behaviour, useAlphaMode::BLEND. If you know your sprite is opaque, use AlphaMode::OPAQUE
Notes
- Should this new depth buffer be optional?
Follow up PRs
- Add AlphaMask support
- Switch to BinnedRenderPhase
Alright, CI didn't catch it, but I broke sprite rendering because it's not aware of the depth buffer. This will need a bit more work
Sprite rendering issue is now fixed
Most sprites don't need transparency though.
Is this true? Even with tight fitting meshes, almost every sprite will have some areas that are covered by the geometry that don't actually want anything drawn to.
That can be handled by alpha mask, which I already have the code for. I just didn't want to bloat this PR.
The alpha mask PR needs this PR though. And this PR needs the clean up PR I linked at the top.
I'm waiting on #12982 to be merged before updating this PR more
The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.
I updated this PR to main and fixed the conflicts
I'm using this pr in a project alongside bevy_ecs_tilemap and it seems to be working (although I have a little more to do before my own experiment is successful).
One thing I ran into was that the depth needs to be added to the gizmos as well: https://github.com/IceSentry/bevy/pull/5
The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.