Added small optimisation and comments

feat/shadows
hheik 2023-12-02 17:21:11 +02:00
parent ddce5075ce
commit ca65416c73
1 changed files with 6 additions and 2 deletions

View File

@ -318,6 +318,8 @@ fn get_light_geometry(
true
});
// FIXME: light source may not always be at bounding box center
// for example: optimal spot light bounding box
let center = aabb.center();
points.sort_unstable_by(|a, b| {
f32::atan2(a.y - center.y, a.x - center.x)
@ -328,12 +330,14 @@ fn get_light_geometry(
// Build visibility polygon
let mut polygon: Vec<_> = vec![];
for point in points.drain(..) {
// We shoot 2 rays offset by this angle from the point.
/// We shoot 2 rays offset by this angle from the edge to catch what is beyond it.
const ANGLE_OFFSET: f32 = 0.0001;
/// Multiplier for hypotenuse when the other two sides are the same length. Or sqrt(2).
const HYPOTENUSE_MULT: f32 = 1.4142135623730951;
offset_cast(
aabb.center(),
(point - aabb.center()).normalize_or_zero(),
aabb.size().max_element(),
aabb.half_size().max_element() * HYPOTENUSE_MULT,
true,
filter,
ANGLE_OFFSET,