From 15d26da2534df42152e82f2f12dc47909d4951a4 Mon Sep 17 00:00:00 2001 From: Ababwa Date: Mon, 27 Mar 2023 16:27:04 -0500 Subject: [PATCH] Dither fix (#7977) - Fixes #7965 - Code quality improvements. - Removes the unreferenced function `dither` in pbr_functions.wgsl introduced in 72fbcc7, but made obsolete in c069c54. - Makes the reference to `screen_space_dither` in pbr.wgsl conditional on `#ifdef TONEMAP_IN_SHADER`, as the required import is conditional on the same, as deband dithering can only occur if tonemapping is also occurring. --------- Co-authored-by: Carter Anderson --- crates/bevy_pbr/src/render/pbr.wgsl | 6 +++--- crates/bevy_pbr/src/render/pbr_functions.wgsl | 6 ------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/bevy_pbr/src/render/pbr.wgsl b/crates/bevy_pbr/src/render/pbr.wgsl index b87208edca..d9f621977e 100644 --- a/crates/bevy_pbr/src/render/pbr.wgsl +++ b/crates/bevy_pbr/src/render/pbr.wgsl @@ -105,8 +105,7 @@ fn fragment(in: FragmentInput) -> @location(0) vec4 { } #ifdef TONEMAP_IN_SHADER - output_color = tone_mapping(output_color); -#endif + output_color = tone_mapping(output_color); #ifdef DEBAND_DITHER var output_rgb = output_color.rgb; output_rgb = powsafe(output_rgb, 1.0 / 2.2); @@ -116,8 +115,9 @@ fn fragment(in: FragmentInput) -> @location(0) vec4 { output_rgb = powsafe(output_rgb, 2.2); output_color = vec4(output_rgb, output_color.a); #endif +#endif #ifdef PREMULTIPLY_ALPHA - output_color = premultiply_alpha(material.flags, output_color); + output_color = premultiply_alpha(material.flags, output_color); #endif return output_color; } diff --git a/crates/bevy_pbr/src/render/pbr_functions.wgsl b/crates/bevy_pbr/src/render/pbr_functions.wgsl index 45f42268c0..8ded96cfae 100644 --- a/crates/bevy_pbr/src/render/pbr_functions.wgsl +++ b/crates/bevy_pbr/src/render/pbr_functions.wgsl @@ -270,12 +270,6 @@ fn pbr( } #endif // NORMAL_PREPASS -#ifdef DEBAND_DITHER -fn dither(color: vec4, pos: vec2) -> vec4 { - return vec4(color.rgb + screen_space_dither(pos.xy), color.a); -} -#endif // DEBAND_DITHER - #ifndef NORMAL_PREPASS fn apply_fog(input_color: vec4, fragment_world_position: vec3, view_world_position: vec3) -> vec4 { let view_to_world = fragment_world_position.xyz - view_world_position.xyz;