Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix black spots appearing due to NANs when SSAO is enabled #8926

Merged
merged 4 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/render/pbr_functions.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn pbr(
output_color = alpha_discard(in.material, output_color);

// Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886"
let NdotV = max(dot(in.N, in.V), 0.0001);
let NdotV = clamp(dot(in.N, in.V), 0.0001, 1.0);
Elabajaba marked this conversation as resolved.
Show resolved Hide resolved

// Remapping [0,1] reflectance to F0
// See https://google.github.io/filament/Filament.html#materialsystem/parameterization/remapping
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_pbr/src/render/pbr_lighting.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ fn point_light(
// Comes after specular since its NoL is used in the lighting equation.
L = normalize(light_to_frag);
H = normalize(L + V);
NoL = saturate(dot(N, L));
NoH = saturate(dot(N, H));
LoH = saturate(dot(L, H));
NoL = clamp(saturate(dot(N, L)), 0.0, 1.0);
NoH = clamp(saturate(dot(N, H)), 0.0, 1.0);
Elabajaba marked this conversation as resolved.
Show resolved Hide resolved
LoH = clamp(saturate(dot(L, H)), 0.0, 1.0);
Elabajaba marked this conversation as resolved.
Show resolved Hide resolved

let diffuse = diffuseColor * Fd_Burley(roughness, NdotV, NoL, LoH);

Expand Down Expand Up @@ -270,9 +270,9 @@ fn directional_light(light_id: u32, roughness: f32, NdotV: f32, normal: vec3<f32
let incident_light = (*light).direction_to_light.xyz;

let half_vector = normalize(incident_light + view);
let NoL = saturate(dot(normal, incident_light));
let NoH = saturate(dot(normal, half_vector));
let LoH = saturate(dot(incident_light, half_vector));
let NoL = clamp(saturate(dot(normal, incident_light)), 0.0, 1.0);
let NoH = clamp(saturate(dot(normal, half_vector)), 0.0, 1.0);
let LoH = clamp(saturate(dot(incident_light, half_vector)), 0.0, 1.0);

let diffuse = diffuseColor * Fd_Burley(roughness, NdotV, NoL, LoH);
let specularIntensity = 1.0;
Expand Down