fix normal prepass (#8890)

# Objective

- Fix broken normals when the NormalPrepass is enabled

## Solution

- Don't use the normal prepass for the world_normal
- Only loadthe normal prepass 
    - when msaa is disabled
- for opaque or alpha mask meshes and only for use it for N not
world_normal
This commit is contained in:
IceSentry 2023-06-21 13:25:20 -04:00 committed by GitHub
parent 0294bb191d
commit 72b4aacf86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View file

@ -682,10 +682,6 @@ impl SpecializedMeshPipeline for MeshPipeline {
let mut shader_defs = Vec::new();
let mut vertex_attributes = Vec::new();
if key.contains(MeshPipelineKey::NORMAL_PREPASS) {
shader_defs.push("LOAD_PREPASS_NORMALS".into());
}
if layout.contains(Mesh::ATTRIBUTE_POSITION) {
shader_defs.push("VERTEX_POSITIONS".into());
vertex_attributes.push(Mesh::ATTRIBUTE_POSITION.at_shader_location(0));
@ -747,6 +743,7 @@ impl SpecializedMeshPipeline for MeshPipeline {
let (label, blend, depth_write_enabled);
let pass = key.intersection(MeshPipelineKey::BLEND_RESERVED_BITS);
let mut is_opaque = false;
if pass == MeshPipelineKey::BLEND_ALPHA {
label = "alpha_blend_mesh_pipeline".into();
blend = Some(BlendState::ALPHA_BLENDING);
@ -783,6 +780,11 @@ impl SpecializedMeshPipeline for MeshPipeline {
// the current fragment value in the output and the depth is written to the
// depth buffer
depth_write_enabled = true;
is_opaque = true;
}
if key.contains(MeshPipelineKey::NORMAL_PREPASS) && key.msaa_samples() == 1 && is_opaque {
shader_defs.push("LOAD_PREPASS_NORMALS".into());
}
if key.contains(MeshPipelineKey::TONEMAP_IN_SHADER) {

View file

@ -109,18 +109,17 @@ fn fragment(in: FragmentInput) -> @location(0) vec4<f32> {
pbr_input.frag_coord = in.frag_coord;
pbr_input.world_position = in.world_position;
#ifdef LOAD_PREPASS_NORMALS
pbr_input.world_normal = prepass_normal(in.frag_coord, 0u);
#else // LOAD_PREPASS_NORMALS
pbr_input.world_normal = prepare_world_normal(
in.world_normal,
(material.flags & STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u,
in.is_front,
);
#endif // LOAD_PREPASS_NORMALS
pbr_input.is_orthographic = is_orthographic;
#ifdef LOAD_PREPASS_NORMALS
pbr_input.N = prepass_normal(in.frag_coord, 0u);
#else
pbr_input.N = apply_normal_mapping(
material.flags,
pbr_input.world_normal,
@ -133,6 +132,8 @@ fn fragment(in: FragmentInput) -> @location(0) vec4<f32> {
uv,
#endif
);
#endif
pbr_input.V = V;
pbr_input.occlusion = occlusion;