Skip to content

Commit 83305af

Browse files
authored
Fix SSAO specular occlusion roughness bug (#20067)
Noticed that we're converting perceptual_roughness to roughness for SSAO specular occlusion up here, _but_ that happens _before_ we sample the metallic_roughness texture map. So we're using the wrong roughness. I assume this is a bug and was not intentional. Suggest reviewing while hiding the whitespace diff.
1 parent f868013 commit 83305af

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

crates/bevy_pbr/src/render/pbr_fragment.wgsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ fn pbr_input_from_standard_material(
377377
var perceptual_roughness: f32 = pbr_bindings::material.perceptual_roughness;
378378
#endif // BINDLESS
379379

380-
let roughness = lighting::perceptualRoughnessToRoughness(perceptual_roughness);
381380
#ifdef VERTEX_UVS
382381
if ((flags & pbr_types::STANDARD_MATERIAL_FLAGS_METALLIC_ROUGHNESS_TEXTURE_BIT) != 0u) {
383382
let metallic_roughness =
@@ -627,7 +626,7 @@ fn pbr_input_from_standard_material(
627626
var specular_occlusion: f32 = 1.0;
628627
#ifdef VERTEX_UVS
629628
if ((flags & pbr_types::STANDARD_MATERIAL_FLAGS_OCCLUSION_TEXTURE_BIT) != 0u) {
630-
diffuse_occlusion *=
629+
diffuse_occlusion *=
631630
#ifdef MESHLET_MESH_MATERIAL_PASS
632631
textureSampleGrad(
633632
#else // MESHLET_MESH_MATERIAL_PASS
@@ -660,7 +659,8 @@ fn pbr_input_from_standard_material(
660659
diffuse_occlusion = min(diffuse_occlusion, ssao_multibounce);
661660
// Use SSAO to estimate the specular occlusion.
662661
// Lagarde and Rousiers 2014, "Moving Frostbite to Physically Based Rendering"
663-
specular_occlusion = saturate(pow(NdotV + ssao, exp2(-16.0 * roughness - 1.0)) - 1.0 + ssao);
662+
let roughness = lighting::perceptualRoughnessToRoughness(pbr_input.material.perceptual_roughness);
663+
specular_occlusion = saturate(pow(NdotV + ssao, exp2(-16.0 * roughness - 1.0)) - 1.0 + ssao);
664664
#endif
665665
pbr_input.diffuse_occlusion = diffuse_occlusion;
666666
pbr_input.specular_occlusion = specular_occlusion;

0 commit comments

Comments
 (0)