double sided normals: fix apply_normal_mapping calls (#10330)

# Objective

- After #10326, examples `array_texture`, `ssao` and `shader_prepass`
don't render correctly
```
error: failed to build a valid final module: Entry point fragment at Fragment is invalid
   ┌─ crates/bevy_pbr/src/render/pbr_prepass.wgsl:26:22
   │
26 │           let normal =  evy_pbr::pbr_functions::31mapply_normal_mapping(
   │ ╭──────────────────────^
27 │ │             bevy_pbr::pbr_bindings::material.flags,
28 │ │             world_normal,
29 │ │
   · │
36 │ │
37 │ │             bevy_pbr::mesh_view_bindings::view.mip_bias,
   │ ╰───────────────────────────────────────────────────────────────────────────────────────^ invalid function call
   │
   = Call to [9] is invalid
   = Requires 6 arguments, but 4 are provided

```

## Solution

- fix `apply_normal_mapping` calls
This commit is contained in:
François 2023-11-01 17:40:25 +01:00 committed by GitHub
parent d2c754c816
commit 6f8848a6c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -25,11 +25,13 @@ fn fragment(
pbr_input.material.base_color = pbr_input.material.base_color * mesh.color; pbr_input.material.base_color = pbr_input.material.base_color * mesh.color;
#endif #endif
let double_sided = (pbr_input.material.flags & STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u;
pbr_input.frag_coord = mesh.position; pbr_input.frag_coord = mesh.position;
pbr_input.world_position = mesh.world_position; pbr_input.world_position = mesh.world_position;
pbr_input.world_normal = fns::prepare_world_normal( pbr_input.world_normal = fns::prepare_world_normal(
mesh.world_normal, mesh.world_normal,
(pbr_input.material.flags & STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u, double_sided,
is_front, is_front,
); );
@ -38,6 +40,8 @@ fn fragment(
pbr_input.N = fns::apply_normal_mapping( pbr_input.N = fns::apply_normal_mapping(
pbr_input.material.flags, pbr_input.material.flags,
mesh.world_normal, mesh.world_normal,
double_sided,
is_front,
#ifdef VERTEX_TANGENTS #ifdef VERTEX_TANGENTS
#ifdef STANDARDMATERIAL_NORMAL_MAP #ifdef STANDARDMATERIAL_NORMAL_MAP
mesh.world_tangent, mesh.world_tangent,

View file

@ -24,15 +24,19 @@ fn fragment(
#ifdef NORMAL_PREPASS #ifdef NORMAL_PREPASS
// NOTE: Unlit bit not set means == 0 is true, so the true case is if lit // NOTE: Unlit bit not set means == 0 is true, so the true case is if lit
if (material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_UNLIT_BIT) == 0u { if (material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_UNLIT_BIT) == 0u {
let double_sided = (material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u;
let world_normal = pbr_functions::prepare_world_normal( let world_normal = pbr_functions::prepare_world_normal(
in.world_normal, in.world_normal,
(material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u, double_sided,
is_front, is_front,
); );
let normal = pbr_functions::apply_normal_mapping( let normal = pbr_functions::apply_normal_mapping(
material.flags, material.flags,
world_normal, world_normal,
double_sided,
is_front,
#ifdef VERTEX_TANGENTS #ifdef VERTEX_TANGENTS
#ifdef STANDARDMATERIAL_NORMAL_MAP #ifdef STANDARDMATERIAL_NORMAL_MAP
in.world_tangent, in.world_tangent,