Skip to content

Commit

Permalink
bevy_pbr2: Fix shadow logic (bevyengine#3186)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
superdump committed Nov 26, 2021
1 parent 73fd6a6 commit f3d4be3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pipelined/bevy_pbr2/src/render/pbr.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit f3d4be3

Please sign in to comment.