summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
authorHendrik Brucker <hendrik.brucker@mail.de>2023-01-24 01:08:32 +0100
committerHendrik Brucker <hendrik.brucker@mail.de>2023-01-24 01:08:32 +0100
commit4bd01a93dc82b4ac5734ac2a4af70d49b4559496 (patch)
tree8c31f94cc0869c21c5c198f8a02907247d39530b /scene/3d
parentc3539b4561f9b4d7dc4ba1c5859217e7fbf9c6fe (diff)
Fix some SpotLight3D issues (clustering artifacts, light leak)
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/light_3d.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/scene/3d/light_3d.cpp b/scene/3d/light_3d.cpp
index 77073ff763..cca84c2b85 100644
--- a/scene/3d/light_3d.cpp
+++ b/scene/3d/light_3d.cpp
@@ -157,9 +157,16 @@ AABB Light3D::get_aabb() const {
return AABB(Vector3(-1, -1, -1) * param[PARAM_RANGE], Vector3(2, 2, 2) * param[PARAM_RANGE]);
} else if (type == RenderingServer::LIGHT_SPOT) {
- real_t len = param[PARAM_RANGE];
- real_t size = Math::tan(Math::deg_to_rad(param[PARAM_SPOT_ANGLE])) * len;
- return AABB(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len));
+ real_t cone_slant_height = param[PARAM_RANGE];
+ real_t cone_angle_rad = Math::deg_to_rad(param[PARAM_SPOT_ANGLE]);
+
+ if (cone_angle_rad > Math_PI / 2.0) {
+ // Just return the AABB of an omni light if the spot angle is above 90 degrees.
+ return AABB(Vector3(-1, -1, -1) * cone_slant_height, Vector3(2, 2, 2) * cone_slant_height);
+ }
+
+ real_t size = Math::sin(cone_angle_rad) * cone_slant_height;
+ return AABB(Vector3(-size, -size, -cone_slant_height), Vector3(2 * size, 2 * size, cone_slant_height));
}
return AABB();