Skip to content

Commit 0df3b19

Browse files
aevyriecart
authored andcommitted
Fix missing sRGB conversion for dithering non-HDR pipelines (#6707)
# Objective - Fixes #6706 Zoom in on the shadow in the following images: ## Current bevy/main ### HDR On - correct ![current-hdron](https://user-images.githubusercontent.com/2632925/202943151-ecad3cbe-a76e-46df-bac9-9e590a31a9f3.png) ### HDR Off - incorrect ![current-hdroff](https://user-images.githubusercontent.com/2632925/202943154-34e3f527-a00e-4546-931d-0691204cc6a4.png) ## This PR ### HDR On - correct ![new-hdron](https://user-images.githubusercontent.com/2632925/202943383-081990de-9a14-45bd-ac52-febcc4289079.png) ### HDR Off - corrected ![new-hdroff](https://user-images.githubusercontent.com/2632925/202943388-a3b05d79-a0f3-4b1e-b114-0a9f03efe351.png) ## Close-up comparison ### New ![Screenshot from 2022-11-20 17-46-46](https://user-images.githubusercontent.com/2632925/202943552-d45c3a48-841e-47a6-981f-776c5a9563f6.png) ### Old ![Screenshot from 2022-11-20 17-46-41](https://user-images.githubusercontent.com/2632925/202943562-555cb5a2-2b20-45f9-b250-89f2bc87af5f.png) ## Solution - It turns out there was an outright missing sRGB conversion for dithering non-HDR cameras. - I also tried using a precise sRGB conversion, but it had no apparent effect on the final image. --- ## Changelog - Fix deband dithering intensity for non-HDR pipelines.
1 parent 3643074 commit 0df3b19

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

crates/bevy_core_pipeline/src/tonemapping/tonemapping_shared.wgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ fn screen_space_dither(frag_coord: vec2<f32>) -> vec3<f32> {
3434
var dither = vec3<f32>(dot(vec2<f32>(171.0, 231.0), frag_coord)).xxx;
3535
dither = fract(dither.rgb / vec3<f32>(103.0, 71.0, 97.0));
3636
return (dither - 0.5) / 255.0;
37-
}
37+
}

crates/bevy_pbr/src/render/pbr.wgsl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ fn fragment(in: FragmentInput) -> @location(0) vec4<f32> {
9999
output_color = tone_mapping(output_color);
100100
#endif
101101
#ifdef DEBAND_DITHER
102-
output_color = dither(output_color, in.frag_coord.xy);
102+
var output_rgb = output_color.rgb;
103+
output_rgb = pow(output_rgb, vec3<f32>(1.0 / 2.2));
104+
output_rgb = output_rgb + screen_space_dither(in.frag_coord.xy);
105+
// This conversion back to linear space is required because our output texture format is
106+
// SRGB; the GPU will assume our output is linear and will apply an SRGB conversion.
107+
output_rgb = pow(output_rgb, vec3<f32>(2.2));
108+
output_color = vec4(output_rgb, output_color.a);
103109
#endif
104110
return output_color;
105111
}

0 commit comments

Comments
 (0)