-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix alpha blending for wgpu msaa #1367
Conversation
blend: Some(wgpu::BlendState { | ||
color: wgpu::BlendComponent { | ||
src_factor: wgpu::BlendFactor::SrcAlpha, | ||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, | ||
operation: wgpu::BlendOperation::Add, | ||
}, | ||
alpha: wgpu::BlendComponent { | ||
src_factor: wgpu::BlendFactor::One, | ||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, | ||
operation: wgpu::BlendOperation::Add, | ||
}, | ||
}), | ||
blend: Some(wgpu::BlendState::ALPHA_BLENDING), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ALPHA_BLENDING
is equal to this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. I see they added new useful variants 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you and good catch!
I'm not sure if this is something they changed in wgpu
, I remember changing these to match the glow
backend.
It's great to see the fix consists in removing a bunch of code! 🥳
blend: Some(wgpu::BlendState { | ||
color: wgpu::BlendComponent { | ||
src_factor: wgpu::BlendFactor::SrcAlpha, | ||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, | ||
operation: wgpu::BlendOperation::Add, | ||
}, | ||
alpha: wgpu::BlendComponent { | ||
src_factor: wgpu::BlendFactor::One, | ||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, | ||
operation: wgpu::BlendOperation::Add, | ||
}, | ||
}), | ||
blend: Some(wgpu::BlendState::ALPHA_BLENDING), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. I see they added new useful variants 👌
Alpha is not blended correctly when using MSAA on wgpu. When the fragments are stored to the multisampled color attachment, the color components are multiplied by alpha. When they are sampled and then stored to the non-multisampled resolve attachment, they are getting multiplied by alpha again. Using
PREMULTIPLIED_ALPHA_BLENDING
for the resolve attachment fixes this since it uses asrc_factor
ofOne
for color components.This is evident when adding a background color to the
solar_system
example and removing theframe.fill
call to cover the canvas in a background color. The orbit, which has a small alpha value to begin with, becomes nearly fully transparent due to the double alpha blending. This fixes it so the orbit looks identical in alpha to the example without anti-aliasing enabled.