diff --git a/crates/fj-viewer/src/graphics/mod.rs b/crates/fj-viewer/src/graphics/mod.rs index 6179b129a..06109fe5c 100644 --- a/crates/fj-viewer/src/graphics/mod.rs +++ b/crates/fj-viewer/src/graphics/mod.rs @@ -16,3 +16,4 @@ pub use self::{ }; const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float; +const SAMPLE_COUNT: u32 = 4; diff --git a/crates/fj-viewer/src/graphics/pipelines.rs b/crates/fj-viewer/src/graphics/pipelines.rs index 0eef9ef49..fb64e3cb8 100644 --- a/crates/fj-viewer/src/graphics/pipelines.rs +++ b/crates/fj-viewer/src/graphics/pipelines.rs @@ -3,7 +3,7 @@ use std::mem::size_of; use super::{ shaders::{Shader, Shaders}, vertices::Vertex, - DEPTH_FORMAT, + DEPTH_FORMAT, SAMPLE_COUNT, }; #[derive(Debug)] @@ -108,9 +108,9 @@ impl Pipeline { bias: wgpu::DepthBiasState::default(), }), multisample: wgpu::MultisampleState { - count: 1, + count: SAMPLE_COUNT, mask: !0, - alpha_to_coverage_enabled: false, + alpha_to_coverage_enabled: true, }, fragment: Some(wgpu::FragmentState { module: shader.module, diff --git a/crates/fj-viewer/src/graphics/renderer.rs b/crates/fj-viewer/src/graphics/renderer.rs index efdf76adc..cea4a85ce 100644 --- a/crates/fj-viewer/src/graphics/renderer.rs +++ b/crates/fj-viewer/src/graphics/renderer.rs @@ -14,7 +14,7 @@ use crate::{ use super::{ draw_config::DrawConfig, drawables::Drawables, geometries::Geometries, pipelines::Pipelines, transform::Transform, uniforms::Uniforms, - vertices::Vertices, DEPTH_FORMAT, + vertices::Vertices, DEPTH_FORMAT, SAMPLE_COUNT, }; /// Graphics rendering state and target abstraction @@ -26,6 +26,7 @@ pub struct Renderer { queue: wgpu::Queue, surface_config: wgpu::SurfaceConfiguration, + frame_buffer: wgpu::TextureView, depth_view: wgpu::TextureView, uniform_buffer: wgpu::Buffer, @@ -106,6 +107,7 @@ impl Renderer { }; surface.configure(&device, &surface_config); + let frame_buffer = Self::create_frame_buffer(&device, &surface_config); let depth_view = Self::create_depth_buffer(&device, &surface_config); let uniform_buffer = @@ -158,6 +160,7 @@ impl Renderer { queue, surface_config, + frame_buffer, depth_view, uniform_buffer, @@ -187,9 +190,10 @@ impl Renderer { self.surface.configure(&self.device, &self.surface_config); - let depth_view = + self.frame_buffer = + Self::create_frame_buffer(&self.device, &self.surface_config); + self.depth_view = Self::create_depth_buffer(&self.device, &self.surface_config); - self.depth_view = depth_view; } /// Draws the renderer, camera, and config state to the window. @@ -243,11 +247,12 @@ impl Renderer { label: None, color_attachments: &[Some( wgpu::RenderPassColorAttachment { - view: &color_view, - resolve_target: None, + view: &self.frame_buffer, + resolve_target: Some(&color_view), ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::WHITE), - store: true, + // Not necessary, due to MSAA being enabled. + store: false, }, }, )], @@ -304,6 +309,26 @@ impl Renderer { Ok(()) } + fn create_frame_buffer( + device: &wgpu::Device, + surface_config: &wgpu::SurfaceConfiguration, + ) -> wgpu::TextureView { + let texture = device.create_texture(&wgpu::TextureDescriptor { + label: None, + size: wgpu::Extent3d { + width: surface_config.width, + height: surface_config.height, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: SAMPLE_COUNT, + dimension: wgpu::TextureDimension::D2, + format: surface_config.format, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + }); + texture.create_view(&wgpu::TextureViewDescriptor::default()) + } + fn create_depth_buffer( device: &wgpu::Device, surface_config: &wgpu::SurfaceConfiguration, @@ -316,7 +341,7 @@ impl Renderer { depth_or_array_layers: 1, }, mip_level_count: 1, - sample_count: 1, + sample_count: SAMPLE_COUNT, dimension: wgpu::TextureDimension::D2, format: DEPTH_FORMAT, usage: wgpu::TextureUsages::RENDER_ATTACHMENT,