Skip to content

Additive blend without drawcall #5551

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Tom94
Copy link
Collaborator

@Tom94 Tom94 commented Nov 28, 2022

Moves the distinction between "Additive" and "Mixture" blend modes into the shader. This is controlled by the sign bit of each vertex's alpha channel, which feels slightly hacky, but is the least-intrusive solution I could think of. (And it's basically free, perf-wise.)

A necessary component of this change is the use of premultiplied alpha in the shader outputs, which means that buffered containers need special treatment: their framebuffers become textures with premultiplied alpha, which needs to be unmultiplied further down the line (for backwards compatibility). In this PR, this is handled by an additional shader uniform that denotes whether the input texture has premultiplied alpha or not.

Another thing of note: in the interest of API compatibility, additive blending on the Drawable side is controlled by an extra boolean within BlendingParameters, which feels hacky. I'd prefer removing the distinction between additive and mixture blend modes as far as the graphics API is concerned... but that'd require changing every single place where additive blending is currently set.

Lastly: some osu-resources-side shaders also need to have their output multiplied by alpha. I can make another PR for those -- it's a minor change. Until then, isolated places like osu!'s intro shader look broken.

@peppy peppy self-requested a review November 30, 2022 07:43
@peppy
Copy link
Member

peppy commented Nov 30, 2022

I think this looks like a pretty good direction to take things, but will note that TestSceneComplexBlending no longer work at my end:

osu.Framework.Tests.2022-11-30.at.07.48.25.mp4

This bug existed before this PR already and probably did not have visible effects in the past. However, overlapping objects with an alpha channel, blended in mixture mode, should now have more correct transparency.
1. Alpha unmultiplication didn't work for fully additive textures (due to their alpha being zero), which is fixed by a minimum, non-zero, alpha value.
2. Alpha unmultiplication didn't occur in sRGB space (which, physically, it shouldn't, but osu! wants blending to happen in sRGB space)
@Tom94
Copy link
Collaborator Author

Tom94 commented Nov 30, 2022

Fixed!

This problem shed light on a few problems osu! has with its blending in general. A few of those, I could fix and should make the game look slightly more correct looking forward. A few others of those are too late to be adjusted (or shouldn't be adjusted for aesthetic reasons, such as the design decision to do most, but not all, blending in sRGB space), so I added workarounds for these, along with verbose comments.

@frenzibyte frenzibyte self-assigned this Apr 8, 2023
@frenzibyte frenzibyte removed their assignment Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: On hold
Development

Successfully merging this pull request may close these issues.

3 participants