bevy_pbr2: Fix shadow logic (#3186)

# Objective

- Shadow maps should only be sampled if the mesh is a shadow receiver AND shadow mapping is enabled for the light

## Solution

- Fix the logic in the shader
This commit is contained in:
Robert Swain 2021-11-26 13:16:11 +00:00
parent 73fd6a6f6f
commit f3d4be316d

View file

@ -501,7 +501,7 @@ fn fragment(in: FragmentInput) -> [[location(0)]] vec4<f32> {
let light = lights.point_lights[i];
var shadow: f32;
if ((mesh.flags & MESH_FLAGS_SHADOW_RECEIVER_BIT) != 0u
|| (light.flags & POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) {
&& (light.flags & POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) {
shadow = fetch_point_shadow(i, in.world_position, in.world_normal);
} else {
shadow = 1.0;
@ -513,7 +513,7 @@ fn fragment(in: FragmentInput) -> [[location(0)]] vec4<f32> {
let light = lights.directional_lights[i];
var shadow: f32;
if ((mesh.flags & MESH_FLAGS_SHADOW_RECEIVER_BIT) != 0u
|| (light.flags & DIRECTIONAL_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) {
&& (light.flags & DIRECTIONAL_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) {
shadow = fetch_directional_shadow(i, in.world_position, in.world_normal);
} else {
shadow = 1.0;