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

Add Order Independent Transparency #14876

Merged
merged 38 commits into from
Oct 8, 2024

Conversation

IceSentry
Copy link
Contributor

@IceSentry IceSentry commented Aug 22, 2024

Objective

  • Alpha blending can easily fail in many situations and requires sorting on the cpu

Solution

  • Implement order independent transparency (OIT) as an alternative to alpha blending
  • The implementation uses 2 passes
    • The first pass records all the fragments colors and position to a buffer that is the size of N layers * the render target resolution.
    • The second pass sorts the fragments, blends them and draws them to the screen. It also currently does manual depth testing because early-z fails in too many cases in the first pass.

Testing

  • We've been using this implementation at foresight in production for many months now and we haven't had any issues related to OIT.

Showcase

image
image

Future work

  • Add an example showing how to use OIT for a custom material
  • Next step would be to implement a per-pixel linked list to reduce memory use
  • I'd also like to investigate using a BinnedRenderPhase instead of a SortedRenderPhase. If it works, it would make the transparent pass significantly faster.

@IceSentry IceSentry added A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible S-Needs-Review Needs reviewer attention (from anyone!) to move forward D-Domain-Expert Requires deep knowledge in a given domain D-Shaders This code uses GPU shader languages labels Aug 22, 2024
Copy link
Contributor

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.

@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Aug 22, 2024
@alice-i-cecile alice-i-cecile added the M-Needs-Release-Note Work that should be called out in the blog due to impact label Aug 22, 2024
Copy link
Contributor

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

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

Very cool, is a surprisingly straightforward technique to follow along. Just a few minor comments. I tested with multiple cameras/viewports/hdr and everything worked fine, except the crash noted with MSAA enabled.

crates/bevy_core_pipeline/src/oit/mod.rs Outdated Show resolved Hide resolved
crates/bevy_core_pipeline/src/oit/resolve/mod.rs Outdated Show resolved Hide resolved
crates/bevy_core_pipeline/src/oit/mod.rs Outdated Show resolved Hide resolved
crates/bevy_core_pipeline/src/oit/resolve/mod.rs Outdated Show resolved Hide resolved
@IceSentry IceSentry marked this pull request as ready for review September 29, 2024 17:32
Copy link
Contributor

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

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

LGTM sans one comment about panic.

crates/bevy_core_pipeline/src/oit/mod.rs Outdated Show resolved Hide resolved
crates/bevy_core_pipeline/src/oit/mod.rs Show resolved Hide resolved
crates/bevy_core_pipeline/src/oit/resolve/mod.rs Outdated Show resolved Hide resolved
crates/bevy_core_pipeline/src/oit/resolve/mod.rs Outdated Show resolved Hide resolved
crates/bevy_pbr/src/render/mesh.rs Outdated Show resolved Hide resolved
examples/3d/order_independent_transparency.rs Outdated Show resolved Hide resolved
crates/bevy_core_pipeline/src/oit/mod.rs Outdated Show resolved Hide resolved
@IceSentry
Copy link
Contributor Author

IceSentry commented Oct 3, 2024

This PR should fix the CI failure #15629

The big remaining issue is that you can't toggle the OIT in the example because removing the component doesn't propagate to the RenderWorld.

@kristoff3r
Copy link
Contributor

This PR should fix the CI failure #15629

The big remaining issue is that you can't toggle the OIT in the example because removing the component doesn't propagate to the RenderWorld.

This will get fixed in #15582, it's a general problem that shouldn't block this PR

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 6, 2024
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 6, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 6, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 6, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 6, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 7, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 7, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 7, 2024
Merged via the queue into bevyengine:main with commit 4bf647f Oct 8, 2024
30 checks passed
@IceSentry IceSentry deleted the oit-upstreaming branch October 9, 2024 05:33
@alice-i-cecile
Copy link
Member

Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1720 if you'd like to help out.

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 D-Domain-Expert Requires deep knowledge in a given domain D-Shaders This code uses GPU shader languages M-Needs-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants