fix prepass normal_mapping (#8978)

# Objective

#5703 caused the normal prepass to fail as the prepass uses
`pbr_functions::apply_normal_mapping`, which uses
`mesh_view_bindings::view` to determine mip bias, which conflicts with
`prepass_bindings::view`.

## Solution

pass the mip bias to the `apply_normal_mapping` function explicitly.
This commit is contained in:
robtfm 2023-06-29 01:28:34 +01:00 committed by GitHub
parent ab3b429211
commit 15445c990e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 1 deletions

View file

@ -44,6 +44,7 @@ fn fragment(
#endif
#endif
mesh.uv,
view.mip_bias,
);
pbr_input.V = fns::calculate_view(mesh.world_position, pbr_input.is_orthographic);

View file

@ -131,6 +131,7 @@ fn fragment(
#ifdef VERTEX_UVS
uv,
#endif
view.mip_bias,
);
#endif

View file

@ -70,6 +70,7 @@ fn apply_normal_mapping(
#ifdef VERTEX_UVS
uv: vec2<f32>,
#endif
mip_bias: f32,
) -> vec3<f32> {
// NOTE: The mikktspace method of normal mapping explicitly requires that the world normal NOT
// be re-normalized in the fragment shader. This is primarily to match the way mikktspace
@ -94,7 +95,7 @@ fn apply_normal_mapping(
#ifdef VERTEX_UVS
#ifdef STANDARDMATERIAL_NORMAL_MAP
// Nt is the tangent-space normal.
var Nt = textureSampleBias(pbr_bindings::normal_map_texture, pbr_bindings::normal_map_sampler, uv, view_bindings::view.mip_bias).rgb;
var Nt = textureSampleBias(pbr_bindings::normal_map_texture, pbr_bindings::normal_map_sampler, uv, mip_bias).rgb;
if (standard_material_flags & pbr_types::STANDARD_MATERIAL_FLAGS_TWO_COMPONENT_NORMAL_MAP) != 0u {
// Only use the xy components and derive z for 2-component normal maps.
Nt = vec3<f32>(Nt.rg * 2.0 - 1.0, 0.0);

View file

@ -107,6 +107,7 @@ fn fragment(in: FragmentInput) -> FragmentOutput {
#ifdef VERTEX_UVS
in.uv,
#endif // VERTEX_UVS
bevy_pbr::prepass_bindings::view.mip_bias,
);
out.normal = vec4(normal * 0.5 + vec3(0.5), 1.0);