Fix alpha blending for wgpu msaa

This commit is contained in:
Cory Forsstrom 2022-06-16 12:26:03 -07:00
parent 449bbb112e
commit aae880ca5d
3 changed files with 8 additions and 28 deletions

View file

@ -48,6 +48,10 @@ impl Application for SolarSystem {
String::from("Solar system - Iced") String::from("Solar system - Iced")
} }
fn background_color(&self) -> Color {
Color::BLACK
}
fn update(&mut self, message: Message) -> Command<Message> { fn update(&mut self, message: Message) -> Command<Message> {
match message { match message {
Message::Tick(instant) => { Message::Tick(instant) => {
@ -137,16 +141,12 @@ impl<Message> canvas::Program<Message> for State {
use std::f32::consts::PI; use std::f32::consts::PI;
let background = self.space_cache.draw(bounds.size(), |frame| { 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| { let stars = Path::new(|path| {
for (p, size) in &self.stars { for (p, size) in &self.stars {
path.rectangle(*p, Size::new(*size, *size)); path.rectangle(*p, Size::new(*size, *size));
} }
}); });
frame.fill(&space, Color::BLACK);
frame.translate(frame.center() - Point::ORIGIN); frame.translate(frame.center() - Point::ORIGIN);
frame.fill(&stars, Color::WHITE); frame.fill(&stars, Color::WHITE);
}); });

View file

@ -162,18 +162,7 @@ impl Pipeline {
entry_point: "fs_main", entry_point: "fs_main",
targets: &[wgpu::ColorTargetState { targets: &[wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState { blend: Some(wgpu::BlendState::ALPHA_BLENDING),
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,
},
}),
write_mask: wgpu::ColorWrites::ALL, write_mask: wgpu::ColorWrites::ALL,
}], }],
}), }),

View file

@ -95,18 +95,9 @@ impl Blit {
entry_point: "fs_main", entry_point: "fs_main",
targets: &[wgpu::ColorTargetState { targets: &[wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState { blend: Some(
color: wgpu::BlendComponent { wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING,
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,
},
}),
write_mask: wgpu::ColorWrites::ALL, write_mask: wgpu::ColorWrites::ALL,
}], }],
}), }),