diff --git a/include/vsg/vk/State.h b/include/vsg/vk/State.h index 59234bac9d..9ae66a6a34 100644 --- a/include/vsg/vk/State.h +++ b/include/vsg/vk/State.h @@ -223,6 +223,18 @@ namespace vsg value_type f = -proj[1][1]; value_type sc = f * std::sqrt(square(mv[0][0]) + square(mv[1][0]) + square(mv[2][0]) + square(mv[0][1]) + square(mv[1][1]) + square(mv[2][1])) * 0.5; value_type inv_scale = value_type(1.0) / sc; + + // For an orthographic projection the projected size of a bounding sphere is independent of + // its distance from the eye (proj[2][3] == 0: there is no perspective divide). Using the + // eye-space depth as done below for perspective would make LOD selection and small-feature + // culling vary with distance, which is wrong for ortho, so use a constant lod distance + // derived purely from the projection scale. + if (proj[2][3] == value_type(0.0)) + { + lodScale.set(value_type(0.0), value_type(0.0), value_type(0.0), inv_scale); + return; + } + lodScale.set(mv[0][2] * inv_scale, mv[1][2] * inv_scale, mv[2][2] * inv_scale,