bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Add 2d opaque phase with depth buffer

Open IceSentry opened this issue 1 year ago • 6 comments

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 SortedRenderPhase to make it easier to implement based on the already existing transparent phase. A follow up PR will switch this to BinnedRenderPhase.
  • Add a 2d depth buffer

Changelog

  • Added AlphaMode2d
  • Added Opaque2d render phase
  • Camera2d now have a ViewDepthTexture component

Migration Guide

  • ColorMaterial now contains AlphaMode2d. To keep previous behaviour, use AlphaMode::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

IceSentry avatar Apr 22 '24 22:04 IceSentry

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

IceSentry avatar Apr 23 '24 00:04 IceSentry

Sprite rendering issue is now fixed

IceSentry avatar Apr 23 '24 01:04 IceSentry

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.

james7132 avatar Apr 24 '24 17:04 james7132

That can be handled by alpha mask, which I already have the code for. I just didn't want to bloat this PR.

IceSentry avatar Apr 24 '24 21:04 IceSentry

The alpha mask PR needs this PR though. And this PR needs the clean up PR I linked at the top.

IceSentry avatar Apr 24 '24 21:04 IceSentry

I'm waiting on #12982 to be merged before updating this PR more

IceSentry avatar May 06 '24 18:05 IceSentry

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.

github-actions[bot] avatar May 12 '24 18:05 github-actions[bot]

I updated this PR to main and fixed the conflicts

IceSentry avatar Jun 10 '24 18:06 IceSentry

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

ChristopherBiscardi avatar Jun 24 '24 20:06 ChristopherBiscardi

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.

github-actions[bot] avatar Aug 06 '24 23:08 github-actions[bot]