Skip to content

Commit 15445c9

Browse files
authored
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.
1 parent ab3b429 commit 15445c9

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

assets/shaders/array_texture.wgsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ fn fragment(
4444
#endif
4545
#endif
4646
mesh.uv,
47+
view.mip_bias,
4748
);
4849
pbr_input.V = fns::calculate_view(mesh.world_position, pbr_input.is_orthographic);
4950

crates/bevy_pbr/src/render/pbr.wgsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ fn fragment(
131131
#ifdef VERTEX_UVS
132132
uv,
133133
#endif
134+
view.mip_bias,
134135
);
135136
#endif
136137

crates/bevy_pbr/src/render/pbr_functions.wgsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ fn apply_normal_mapping(
7070
#ifdef VERTEX_UVS
7171
uv: vec2<f32>,
7272
#endif
73+
mip_bias: f32,
7374
) -> vec3<f32> {
7475
// NOTE: The mikktspace method of normal mapping explicitly requires that the world normal NOT
7576
// be re-normalized in the fragment shader. This is primarily to match the way mikktspace
@@ -94,7 +95,7 @@ fn apply_normal_mapping(
9495
#ifdef VERTEX_UVS
9596
#ifdef STANDARDMATERIAL_NORMAL_MAP
9697
// Nt is the tangent-space normal.
97-
var Nt = textureSampleBias(pbr_bindings::normal_map_texture, pbr_bindings::normal_map_sampler, uv, view_bindings::view.mip_bias).rgb;
98+
var Nt = textureSampleBias(pbr_bindings::normal_map_texture, pbr_bindings::normal_map_sampler, uv, mip_bias).rgb;
9899
if (standard_material_flags & pbr_types::STANDARD_MATERIAL_FLAGS_TWO_COMPONENT_NORMAL_MAP) != 0u {
99100
// Only use the xy components and derive z for 2-component normal maps.
100101
Nt = vec3<f32>(Nt.rg * 2.0 - 1.0, 0.0);

crates/bevy_pbr/src/render/pbr_prepass.wgsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ fn fragment(in: FragmentInput) -> FragmentOutput {
107107
#ifdef VERTEX_UVS
108108
in.uv,
109109
#endif // VERTEX_UVS
110+
bevy_pbr::prepass_bindings::view.mip_bias,
110111
);
111112

112113
out.normal = vec4(normal * 0.5 + vec3(0.5), 1.0);

0 commit comments

Comments
 (0)