Skip to content

Commit

Permalink
PBR NdotV tweak
Browse files Browse the repository at this point in the history
PBR NdotV tweak
  • Loading branch information
robtfm authored Jan 17, 2023
2 parents 3774f08 + fa88d76 commit 16bc287
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
15 changes: 8 additions & 7 deletions crates/bevy_pbr/src/render/pbr_ambient.wgsl
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#define_import_path bevy_pbr::pbr_ambient

// A precomputed `NdotV` is provided because it is computed regardless,
// but `world_normal` and the view vector `V` are provided separately for more advanced uses.
fn ambient_light(
world_position: vec4<f32>,
world_normal: vec3<f32>,
V: vec3<f32>,
diffuse_color: vec3<f32>,
specular_color: vec3<f32>,
world_position: vec4<f32>,
world_normal: vec3<f32>,
V: vec3<f32>,
NdotV: f32,
diffuse_color: vec3<f32>,
specular_color: vec3<f32>,
perceptual_roughness: f32,
occlusion: f32,
) -> vec3<f32> {
let NdotV = max(dot(world_normal, V), 0.0001);

let diffuse_ambient = EnvBRDFApprox(diffuse_color, 1.0, NdotV);
let specular_ambient = EnvBRDFApprox(specular_color, perceptual_roughness, NdotV);

Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_pbr/src/render/pbr_functions.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ fn pbr(
light_accum = light_accum + light_contrib * shadow;
}

let ambient_contrib = ambient_light(in.world_position, in.N, in.V, diffuse_color, F0, perceptual_roughness, occlusion);
let ambient_contrib = ambient_light(in.world_position, in.N, in.V, NdotV, diffuse_color, F0, perceptual_roughness, occlusion);

output_color = vec4<f32>(
light_accum + ambient_contrib + emissive.rgb * output_color.a,
Expand Down Expand Up @@ -264,4 +264,3 @@ fn dither(color: vec4<f32>, pos: vec2<f32>) -> vec4<f32> {
return vec4<f32>(color.rgb + screen_space_dither(pos.xy), color.a);
}
#endif

0 comments on commit 16bc287

Please sign in to comment.