Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up 2d render phases #12982

Merged
merged 3 commits into from
May 8, 2024
Merged

Conversation

IceSentry
Copy link
Contributor

@IceSentry IceSentry commented Apr 15, 2024

Objective

Currently, the 2d pipeline only has a transparent pass that is used for everything. I want to have separate passes for opaque/alpha mask/transparent meshes just like in 3d.

This PR does the basic work to start adding new phases to the 2d pipeline and get the current setup a bit closer to 3d.

Solution

  • Use ViewNode for MainTransparentPass2dNode
  • Added Node2d::StartMainPass, Node2d::EndMainPass
  • Rename everything to clarify that the main pass is currently the transparent pass

Changelog

  • Added Node2d::StartMainPass, Node2d::EndMainPass

Migration Guide

If you were using Node2d::MainPass to order your own custom render node. You now need to order it relative to Node2d::StartMainPass or Node2d::EndMainPass.

@IceSentry IceSentry added A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Apr 15, 2024
@IceSentry IceSentry force-pushed the 2d-phases-cleanup branch 3 times, most recently from ace2d1e to df23a13 Compare April 22, 2024 21:52
Copy link
Contributor

@kristoff3r kristoff3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, simple changes and I ran a bunch of the 2D examples on Linux and everything still worked.

Copy link
Contributor

@jgayfer jgayfer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New to Bevy, but this seems relatively straight forward 👍

@IceSentry IceSentry added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label May 6, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 8, 2024
Merged via the queue into bevyengine:main with commit 64e1a78 May 8, 2024
28 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Aug 7, 2024
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 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
- Use that depth buffer in the transparent phase to make sure that
sprites and transparent mesh2d are displayed correctly

## Testing

I added the mesh2d_transforms example that layers many opaque and
transparent mesh2d to make sure they all get displayed correctly. I also
confirmed it works with sprites by modifying that example locally.

---

## 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`

## Follow up PRs

- See tracking issue: #13265

---------

Co-authored-by: Alice Cecile <[email protected]>
Co-authored-by: Christopher Biscardi <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Aug 12, 2024
Based on top of #12982  and #13069 

# Objective

- Opaque2d was implemented with SortedRenderPhase but BinnedRenderPhase
should be much faster

## Solution

- Implement BinnedRenderPhase for Opaque2d

## Notes

While testing this PR, before the change I had ~14 fps in bevymark with
100k entities. After this change I get ~71 fps, compared to using
sprites where I only get ~63 fps. This means that after this PR mesh2d
with opaque meshes will be faster than the sprite path. This is not a 1
to 1 comparison since sprites do alpha blending.
@IceSentry IceSentry deleted the 2d-phases-cleanup branch October 9, 2024 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants