Skip to content

Conversation

@zuedev
Copy link

@zuedev zuedev commented Oct 23, 2025

Resolves #111723

SDFGI dynamic lights are incorrectly culled when positioned at high or low Y coordinates (e.g., Y=±200) with non-100% Y scale settings.

Root Cause

SDFGI stores cascade positions in Y-scaled grid space. When a world position is processed, it's transformed by multiplying Y by y_mult:

world_position.y *= y_mult;  // Enter Y-scaled grid space
cascade.position = ...; // Stored in Y-scaled space

When converting back to world space for bounds checking, the inverse transform * Vector3(1, 1.0 / y_mult, 1) must be applied. This pattern is used correctly throughout the codebase (e.g., get_pending_region_data() at line ~2101).

However, pre_process_gi() at line ~1931 was missing this inverse transform when constructing the cascade_aabb for light culling:

cascade_aabb.position = Vector3(...) * cascade.cell_size;
// Missing: * Vector3(1, 1.0 / y_mult, 1)

This caused cascade_aabb (in Y-scaled grid space) and light_aabb (in world space) to be compared in different coordinate systems, resulting in incorrect culling.

The Fix

Apply the inverse Y-scale transform to convert cascade bounds to world space:

cascade_aabb.position = Vector3(...) * cascade.cell_size * Vector3(1, 1.0 / y_mult, 1);
cascade_aabb.size = Vector3(...) * cascade.cell_size * Vector3(1, 1.0 / y_mult, 1);

This matches the pattern used in get_pending_region_data() and ensures both AABBs are in the same coordinate space for intersection testing.

Note: This bug was masked when y_mult=1.0 (100% Y-scale), as the inverse transform becomes a no-op.

@zuedev zuedev requested a review from a team as a code owner October 23, 2025 20:41
@Calinou Calinou added bug topic:rendering topic:3d cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release labels Oct 23, 2025
@Calinou Calinou added this to the 4.6 milestone Oct 23, 2025
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected.

@zuedev zuedev requested a review from Calinou October 23, 2025 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release topic:rendering topic:3d

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDFGI Ignores Dynamic Lights at High/Low Y Positions

2 participants