From 6d533105bc0c3f008a91a04df9592bf282763c16 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 4 Oct 2022 23:24:03 +0100 Subject: [PATCH] fix spot dir nan --- crates/bevy_pbr/src/render/pbr_lighting.wgsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_pbr/src/render/pbr_lighting.wgsl b/crates/bevy_pbr/src/render/pbr_lighting.wgsl index ff9451ef302b4..063f7e00ac479 100644 --- a/crates/bevy_pbr/src/render/pbr_lighting.wgsl +++ b/crates/bevy_pbr/src/render/pbr_lighting.wgsl @@ -248,7 +248,7 @@ fn spot_light( // reconstruct spot dir from x/z and y-direction flag var spot_dir = vec3(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; }