Skip to content

Commit fdc235f

Browse files
committed
Merge pull request #110884 from Kaleb-Reid/fix-spotlight-aabb
Use correct AABB for SpotLight3Ds when `spot_angle > 90`
2 parents 36b76fc + 91167c3 commit fdc235f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

drivers/gles3/storage/light_storage.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,14 @@ AABB LightStorage::light_get_aabb(RID p_light) const {
350350
switch (light->type) {
351351
case RS::LIGHT_SPOT: {
352352
float len = light->param[RS::LIGHT_PARAM_RANGE];
353-
float size = Math::tan(Math::deg_to_rad(light->param[RS::LIGHT_PARAM_SPOT_ANGLE])) * len;
353+
float angle = Math::deg_to_rad(light->param[RS::LIGHT_PARAM_SPOT_ANGLE]);
354+
355+
if (angle > Math::PI * 0.5) {
356+
// Light casts backwards as well.
357+
return AABB(Vector3(-1, -1, -1) * len, Vector3(2, 2, 2) * len);
358+
}
359+
360+
float size = Math::sin(angle) * len;
354361
return AABB(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len));
355362
};
356363
case RS::LIGHT_OMNI: {

servers/rendering/renderer_rd/storage_rd/light_storage.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,14 @@ AABB LightStorage::light_get_aabb(RID p_light) const {
432432
switch (light->type) {
433433
case RS::LIGHT_SPOT: {
434434
float len = light->param[RS::LIGHT_PARAM_RANGE];
435-
float size = Math::tan(Math::deg_to_rad(light->param[RS::LIGHT_PARAM_SPOT_ANGLE])) * len;
435+
float angle = Math::deg_to_rad(light->param[RS::LIGHT_PARAM_SPOT_ANGLE]);
436+
437+
if (angle > Math::PI * 0.5) {
438+
// Light casts backwards as well.
439+
return AABB(Vector3(-1, -1, -1) * len, Vector3(2, 2, 2) * len);
440+
}
441+
442+
float size = Math::sin(angle) * len;
436443
return AABB(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len));
437444
};
438445
case RS::LIGHT_OMNI: {

0 commit comments

Comments
 (0)