Skip to content

Commit

Permalink
fix spot dir nan bug (bevyengine#6167)
Browse files Browse the repository at this point in the history
# Objective

fix error with pbr shader's spotlight direction calculation when direction.y ~= 0

## Solution

in pbr_lighting.wgsl, clamp `1-x^2-z^2` to `>= 0` so that we can safely `sqrt` it
  • Loading branch information
robtfm authored and ItsDoot committed Feb 1, 2023
1 parent 7155a51 commit 1cbee47
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/render/pbr_lighting.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fn spot_light(

// reconstruct spot dir from x/z and y-direction flag
var spot_dir = vec3<f32>(light.light_custom_data.x, 0.0, light.light_custom_data.y);
spot_dir.y = sqrt(1.0 - spot_dir.x * spot_dir.x - spot_dir.z * spot_dir.z);
spot_dir.y = sqrt(max(0.0, 1.0 - spot_dir.x * spot_dir.x - spot_dir.z * spot_dir.z));
if ((light.flags & POINT_LIGHT_FLAGS_SPOT_LIGHT_Y_NEGATIVE) != 0u) {
spot_dir.y = -spot_dir.y;
}
Expand Down

0 comments on commit 1cbee47

Please sign in to comment.