mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 23:13:13 -04:00
Introduce dithering to reduce banding (#4497)
This PR introduces dithering in the egui_glow and egui_wgpu backends to reduce banding artifacts. It's based on the approach mentioned in #4493 with the small difference that the amount of noise is scaled down slightly to avoid dithering colors that can be represented exactly. This keeps flat surfaces clean. Exaggerated dithering to show what is happening:  Subtle dithering as commited.  Closes #4493
This commit is contained in:
@@ -26,7 +26,7 @@ impl WebPainterGlow {
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
let gl = std::sync::Arc::new(gl);
|
||||
|
||||
let painter = egui_glow::Painter::new(gl, shader_prefix, None)
|
||||
let painter = egui_glow::Painter::new(gl, shader_prefix, None, options.dithering)
|
||||
.map_err(|err| format!("Error starting glow painter: {err}"))?;
|
||||
|
||||
Ok(Self { canvas, painter })
|
||||
|
||||
@@ -169,10 +169,16 @@ impl WebPainterWgpu {
|
||||
|
||||
let depth_format = egui_wgpu::depth_format_from_bits(options.depth_buffer, 0);
|
||||
|
||||
let render_state =
|
||||
RenderState::create(&options.wgpu_options, &instance, &surface, depth_format, 1)
|
||||
.await
|
||||
.map_err(|err| err.to_string())?;
|
||||
let render_state = RenderState::create(
|
||||
&options.wgpu_options,
|
||||
&instance,
|
||||
&surface,
|
||||
depth_format,
|
||||
1,
|
||||
options.dithering,
|
||||
)
|
||||
.await
|
||||
.map_err(|err| err.to_string())?;
|
||||
|
||||
let surface_configuration = wgpu::SurfaceConfiguration {
|
||||
format: render_state.target_format,
|
||||
|
||||
Reference in New Issue
Block a user