mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
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:
parent
ab3b429211
commit
15445c990e
4 changed files with 5 additions and 1 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -131,6 +131,7 @@ fn fragment(
|
|||
#ifdef VERTEX_UVS
|
||||
uv,
|
||||
#endif
|
||||
view.mip_bias,
|
||||
);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue