Implement Premultiplied Alpha for OIT#22821
Implement Premultiplied Alpha for OIT#22821Schmarni-Dev wants to merge 1 commit intobevyengine:mainfrom
Conversation
|
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
|
Thank you for making this PR! We are about to merge a big OIT refactor though so you will likely have some conflict with your PR #21831 |
|
I can rebase these changes once that PR is merged |
|
It seems multiply is the only unsupported mode as it requires a different blend function, which is not free. |
| fn oit_draw(position: vec4f, color: vec4f) { | ||
| // Don't add fully transparent fragments to the list | ||
| // because we don't want to have to sort them in the resolve pass | ||
| if color.a < oit_settings.alpha_threshold { |
There was a problem hiding this comment.
Can we do this somewhere before premultiply_alpha?
For Add and Premultiplied modes we should not cull alpha in here
There was a problem hiding this comment.
Or we could consider removing this setting. After all users can do it themselves in custom materials.
There was a problem hiding this comment.
this should be fixed now, i adjusted the check to work correctly for premultiplied alpha, should have the same results as before this change
There was a problem hiding this comment.
It is not correct to compare individual components. An alternative is to compare luminance.
I think there should be a luminance threshold setting for premultiplied or add mode.
There was a problem hiding this comment.
why would it not be correct to compare the individual components? it should be the same check as the one that was here before, just now it acts on premultiplied color
There was a problem hiding this comment.
Considering the color contribution of premultiplied alpha, it seems more reasonable to compare the emitted luminance rather than comparing each component individually
851cf14 to
1aa907a
Compare
1aa907a to
98b3b6b
Compare
Signed-off-by: Schmarni <marnistromer@gmail.com>
98b3b6b to
af27226
Compare
Objective
AlphaMode::PremultipliedandAlphaMode::Addwhile using Order Independent Transparency.Solution
AlphaMode::Blend, this shouldn't have any downsides since blending was done with premultiplied alpha anyway.oit_drawsignature by adding apremultiplybool to ensure that shader authors are aware of the changed meaning of thecolorargument.Testing
order_independent_transparencyexample, an older version of these changes has been in use in a project i work on.Showcase
Here the Red Sphere uses
AlphaMode::Blend, the Blue SphereAlphaMode::Addand the Green SphereAlphaMode::Premultiplied.