Hi!
Here a mesh LOD selection code:
size_t ComputeMeshLODIndex(const Vector3& cameraPosition, const float cameraFOV, const uint32_t viewportHeight, const AxisAlignedBoundingBox& aabb, const size_t lodCount)
{
if (lodCount < 2)
{
return 0;
}
const float cameraToAABBLength = (aabb.ComputeCenter() - cameraPosition).Length();
if (cameraToAABBLength < Math::epsilon)
{
return 0;
}
const size_t lastLODIndex = lodCount - 1;
const float aabbProjectedRadius = (aabb.ComputeRadius() * viewportHeight) / (2.0f * cameraToAABBLength * Math::Tan(0.5f * cameraFOV));
const float screenHeightCoverage = aabbProjectedRadius / viewportHeight;
const float lodIndex = (1.0f - screenHeightCoverage) * lastLODIndex;
return Math::Min(static_cast<size_t>(lodIndex), lastLODIndex);
}
Is there a better recommended way for LOD selection?
Thanks!
EDIT: I just found this link:
https://iquilezles.org/articles/sphereproj/
Can be part of the discussion.