Skip to content

Commit

Permalink
Dither fix (#7977)
Browse files Browse the repository at this point in the history
- 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 <mcanders1@gmail.com>
  • Loading branch information
Ababwa and cart authored Mar 27, 2023
1 parent 9784186 commit 846b748
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
6 changes: 3 additions & 3 deletions crates/bevy_pbr/src/render/pbr.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ fn fragment(in: FragmentInput) -> @location(0) vec4<f32> {
}

#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);
Expand All @@ -116,8 +115,9 @@ fn fragment(in: FragmentInput) -> @location(0) vec4<f32> {
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;
}
6 changes: 0 additions & 6 deletions crates/bevy_pbr/src/render/pbr_functions.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,6 @@ fn pbr(
}
#endif // NORMAL_PREPASS

#ifdef DEBAND_DITHER
fn dither(color: vec4<f32>, pos: vec2<f32>) -> vec4<f32> {
return vec4<f32>(color.rgb + screen_space_dither(pos.xy), color.a);
}
#endif // DEBAND_DITHER

#ifndef NORMAL_PREPASS
fn apply_fog(input_color: vec4<f32>, fragment_world_position: vec3<f32>, view_world_position: vec3<f32>) -> vec4<f32> {
let view_to_world = fragment_world_position.xyz - view_world_position.xyz;
Expand Down

0 comments on commit 846b748

Please sign in to comment.