mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
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:
parent
0294bb191d
commit
72b4aacf86
2 changed files with 11 additions and 8 deletions
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue