Skip to content

Commit

Permalink
Fix black spots appearing due to NANs when SSAO is enabled (#8926)
Browse files Browse the repository at this point in the history
# Objective

Fixes #8925

## Solution

~~Clamp the bad values.~~

Normalize the prepass normals when we get them in the `prepass_normal()`
function.

## More Info

The issue is that NdotV is sometimes very slightly greater than 1 (maybe
FP rounding issues?), which caused `F_Schlick()` to return NANs in
`pow(1.0 - NdotV, 5.0)` (call stack looked like`pbr()` ->
`directional_light()` -> `Fd_Burley()` -> `F_Schlick()`)
  • Loading branch information
Elabajaba authored Jul 1, 2023
1 parent 982e337 commit 94291cf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/prepass/prepass_utils.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn prepass_normal(frag_coord: vec4<f32>, sample_index: u32) -> vec3<f32> {
#else
let normal_sample = textureLoad(view_bindings::normal_prepass_texture, vec2<i32>(frag_coord.xy), 0);
#endif // MULTISAMPLED
return normal_sample.xyz * 2.0 - vec3(1.0);
return normalize(normal_sample.xyz * 2.0 - vec3(1.0));
}
#endif // NORMAL_PREPASS

Expand Down

0 comments on commit 94291cf

Please sign in to comment.