Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix prepass normal_mapping #8978

Merged
merged 1 commit into from Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/shaders/array_texture.wgsl
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions crates/bevy_pbr/src/render/pbr.wgsl
Expand Up @@ -131,6 +131,7 @@ fn fragment(
#ifdef VERTEX_UVS
uv,
#endif
view.mip_bias,
);
#endif

Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_pbr/src/render/pbr_functions.wgsl
Expand Up @@ -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
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_pbr/src/render/pbr_prepass.wgsl
Expand Up @@ -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);
Expand Down