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

Fix alpha blending for wgpu msaa #1367

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/solar_system/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ impl Application for SolarSystem {
String::from("Solar system - Iced")
}

fn background_color(&self) -> Color {
Color::BLACK
}

fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Tick(instant) => {
Expand Down Expand Up @@ -137,16 +141,12 @@ impl<Message> canvas::Program<Message> for State {
use std::f32::consts::PI;

let background = self.space_cache.draw(bounds.size(), |frame| {
let space = Path::rectangle(Point::new(0.0, 0.0), frame.size());

let stars = Path::new(|path| {
for (p, size) in &self.stars {
path.rectangle(*p, Size::new(*size, *size));
}
});

frame.fill(&space, Color::BLACK);

frame.translate(frame.center() - Point::ORIGIN);
frame.fill(&stars, Color::WHITE);
});
Expand Down
13 changes: 1 addition & 12 deletions wgpu/src/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,7 @@ impl Pipeline {
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
format,
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),
Copy link
Member Author

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

Copy link
Member

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 👌

write_mask: wgpu::ColorWrites::ALL,
}],
}),
Expand Down
15 changes: 3 additions & 12 deletions wgpu/src/triangle/msaa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,9 @@ impl Blit {
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
format,
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::PREMULTIPLIED_ALPHA_BLENDING,
),
write_mask: wgpu::ColorWrites::ALL,
}],
}),
Expand Down