Use direction between camera origin and AABB center to calculate minimum support for LOD selection #92290
+59
−107
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #81995
Fixes: #76436
Supersedes #82000
Builds on #92287 but introduces riskier changes.
This PR simplifies and improves the LOD selection logic by calculating the depth as the distance to the closest AABB corner.
The old logic used the camera z direction to calculate the min and max supports. This was flawed as it meant that rotating the camera could drastically change which supports were chosen and (as pointed out in #81995) if the camera looked slightly past an AABB, it could cause the supports to change and then jump LOD levels.
This change fixes that by basing the support on the camera's origin point instead of view direction. This ensures that the lod_distance never changes based on rotation.
A second improvement is the removal of support_max. It used to be used for two things:
Now, support_min is guaranteed to be the closest support point and we check if the point is inside the AABB manually, so there is no reason to keep support_max.
I also moved the entire calculation outside the loop since everything depends on the instance. It doesn't need to be recalculated for the surface.
Opening as a draft for now as I want to test this with more MRPs from #57416 as I suspect the combination of #92287 and this will fix a number of issues.