#graphics #antialiasing #smaa

smaa

A library for post process antialiasing using SMAA

6 releases (breaking)

Uses new Rust 2021

0.5.0 Nov 7, 2021
0.4.0 Jul 13, 2021
0.3.0 Apr 30, 2021
0.2.2 Apr 3, 2021
0.1.0 Feb 6, 2021

#21 in Rendering

48 downloads per month
Used in 2 crates (via pilka_wgpu)

MIT license

1.5MB
16K SLoC

smaa-rs crates.io docs.rs

Post-process antialiasing for wgpu-rs, relying on the SMAA reference implementation.

Example

// Create SMAA target
let mut smaa_target = SmaaTarget::new(
    &device,
    &queue,
    window.inner_size().width,
    window.inner_size().height,
    swapchain_format,
    SmaaMode::Smaa1X,
);

// Main loop
event_loop.run(move |event, _, control_flow| {
    match event {
        Event::RedrawRequested(_) => {
            let output_frame = swap_chain.get_current_frame().unwrap().output;
            let frame = smaa_target.start_frame(&device, &queue, &output_frame.view);

            // Render the scene into `*frame`.
            // [...]
        }
        _ => {}
    }
});


lib.rs:

Post-process antialiasing for wgpu-rs, using the SMAA reference implementation.

Example

# use smaa::{SmaaMode, SmaaTarget};
# use winit::event::Event;
# use winit::event_loop::EventLoop;
# use winit::window::Window;
# fn main() { futures::executor::block_on(run()); }
# async fn run() -> Result<(), Box<dyn std::error::Error>> {
// Initialize wgpu
let event_loop = EventLoop::new();
let window = winit::window::Window::new(&event_loop).unwrap();
let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY);
let surface = unsafe { instance.create_surface(&window) };
let adapter = instance.request_adapter(&Default::default()).await.unwrap();
let (device, queue) = adapter.request_device(&Default::default(), None).await?;
let swapchain_format = surface.get_preferred_format(&adapter)
    .unwrap_or(wgpu::TextureFormat::Bgra8UnormSrgb);
let mut config = wgpu::SurfaceConfiguration {
    usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
    format: swapchain_format,
    width: window.inner_size().width,
    height: window.inner_size().height,
    present_mode: wgpu::PresentMode::Mailbox,
};
surface.configure(&device, &config);

// Create SMAA target
let mut smaa_target = SmaaTarget::new(
    &device,
    &queue,
    window.inner_size().width,
    window.inner_size().height,
    swapchain_format,
    SmaaMode::Smaa1X,
);

// Main loop
event_loop.run(move |event, _, control_flow| {
#    *control_flow = winit::event_loop::ControlFlow::Exit;
    match event {
        Event::RedrawRequested(_) => {
            let output_frame = surface.get_current_texture().unwrap();
            let output_view = output_frame.texture.create_view(&Default::default());
            {
                let frame = smaa_target.start_frame(&device, &queue, &output_view);

                // Render the scene into `*frame`.
                // [...]

            }
            output_frame.present();
        }
        _ => {}
    }
});
# }

Dependencies

~34MB
~756K SLoC