Add LOD system with UE-style screen-size computation, pre-computed distance thresholds, and mesh streaming culling#66
Draft
Add LOD system with UE-style screen-size computation, pre-computed distance thresholds, and mesh streaming culling#66
Conversation
New files: - render/lod/LodGroup.h: Core LOD data structures and screen-size calculation - render/lod/MeshLodGroup.h/.cpp: LOD group container for multiple mesh LOD levels - test/core/LodTest.cpp: Unit tests for LOD selection logic Modified files: - MeshRenderer.h/.cpp: Add LOD group support and UpdateLod method - MeshFeatureProcessor.h/.cpp: Add per-frame LOD evaluation from camera view - StaticMeshComponent.h/.cpp: Add LOD mesh configuration and bias settings Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
… LOD - Remove unused screenHeight parameter from LOD calculation API - Compute combined AABB across all primitives for LOD selection - Remove hardcoded 1080.0f screen height from MeshFeatureProcessor Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add a new LOD system implementation
Add screen-size based LOD system for static meshes
Feb 16, 2026
…tion - Add LodPolicy enum (SCREEN_SIZE, DISTANCE) to LodGroup.h - Add distance field to LodLevel struct - Add CalculateDistance() for distance-based LOD - Add SelectLodByDistance() and SelectLodByScreenSize() functions - Add SelectLodLevel() overload that dispatches by policy - Update MeshLodGroup with AddLodMesh(mesh, screenSize, distance) overload - Update MeshLodGroup with SetLodPolicy() method - Update StaticMeshComponent with LodPolicy support and serialization - Add comprehensive unit tests for distance-based LOD selection Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Copilot
AI
changed the title
Add screen-size based LOD system for static meshes
Add LOD policy support for distance-based and screen-size based selection
Feb 16, 2026
…ction Replace the dual LodPolicy (SCREEN_SIZE/DISTANCE) system with a unified approach: users author LOD thresholds as screen-size values, which are pre-computed into squared-distance thresholds. At runtime, LOD selection only needs a cheap distance² comparison instead of expensive screen-size calculation (which requires tan, division, sqrt). Key changes: - Add ScreenSizeToDistance() conversion and PreComputeDistances() - Add CalculateDistanceSq() for squared-distance (avoids sqrt) - SelectLodLevel(config, worldBound, viewPos) uses pre-computed distances - Remove LodPolicy enum, distance field from LodLevel - MeshLodGroup::PreComputeDistances(radius, fov) pre-computes cache - MeshRenderer::UpdateLod() no longer needs fov parameter - MeshFeatureProcessor::UpdateLod() no longer extracts FOV from projection - StaticMeshComponent simplified: removes policy/distance fields - Tests verify pre-computed distances match screen-size LOD selection Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
…anceSq) Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Copilot
AI
changed the title
Add LOD policy support for distance-based and screen-size based selection
Pre-compute distance thresholds from screen-size for O(1) runtime LOD selection
Feb 16, 2026
…tation Replace FOV-based screen-size calculation with UE's projection-matrix-based approach using ComputeBoundsScreenSize: - GetScreenMultiple(projMatrix): extracts max(0.5*M[0][0], 0.5*M[1][1]) - ComputeBoundsScreenSize(radius, dist, screenMultiple): UE-style formula - CalculateScreenSize now takes Matrix4 projMatrix instead of float fov - ScreenSizeToDistance uses screenMultiple instead of halfTanFov - PreComputeDistances takes Matrix4 projMatrix instead of float fov - MeshLodGroup::PreComputeDistances updated to take Matrix4 projMatrix - Tests updated with MakePerspective and new aspect ratio test Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Copilot
AI
changed the title
Pre-compute distance thresholds from screen-size for O(1) runtime LOD selection
Add LOD system with UE-style screen-size computation and pre-computed distance thresholds
Feb 16, 2026
When a mesh is beyond all LOD thresholds (INVALID_LOD_LEVEL), it is now culled by removing its primitives from the render scene. When the camera moves closer and the mesh comes back into LOD range, it is restored (streamed back in) by re-adding its primitives to the scene. Changes: - MeshRenderer: add isVisible/culledByLod tracking, ShowPrimitives/HidePrimitives - MeshRenderer::UpdateLod: cull on INVALID_LOD_LEVEL, restore on re-entry - MeshRenderer::Reset: reset visibility state - Tests: LodCullingWhenBeyondAllThresholds, LodCullingTransition, LodCullingWithScreenSizeFallback, LodCullingWithBias Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Copilot
AI
changed the title
Add LOD system with UE-style screen-size computation and pre-computed distance thresholds
Add LOD system with UE-style screen-size computation, pre-computed distance thresholds, and mesh streaming culling
Feb 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implements a complete LOD system for mesh rendering: screen-size thresholds authored per LOD level, pre-computed into squared-distance thresholds at setup, evaluated at runtime via cheap distance² comparison. Meshes beyond all LOD thresholds are culled from the scene and streamed back in when re-entering range.
Core LOD (
LodGroup.h)ComputeBoundsScreenSizeusing projection matrix coefficients (max(0.5*M[0][0], 0.5*M[1][1])) — handles FOV + aspect ratio nativelyPreComputeDistances(config, radius, projMatrix)— inverts screen-size thresholds into squared-distance cache at setup timeSelectLodLevel(config, worldBound, viewPos)— runtime path, distance² only, no trig/sqrt per frameINVALID_LOD_LEVELwhen beyond all thresholds (enables culling)Mesh LOD Group (
MeshLodGroup)LodConfig+ per-LODRDMeshPtrPreComputeDistances(sphereRadius, projMatrix)bakes the distance cacheSelectLod(worldBound, viewPos)delegates to pre-computed pathMesh Streaming & Culling (
MeshRenderer)HidePrimitives()/ShowPrimitives()— remove/re-add primitives to the render sceneUpdateLod()— onINVALID_LOD_LEVEL, culls mesh; on re-entry, restores itisVisible/culledByLodstate tracking with public gettersComponent Integration (
StaticMeshComponent)LodMeshAssetDataholds mesh UUID + screen-size threshold per LODlodBiasruntime tuning, JSON serialization for LOD mesh arrayRuntime flow
Tests
16 test cases covering screen-size calculation, LOD selection with bias, pre-computed distance equivalence, aspect ratio handling, culling transitions (visible → culled → streamed back), and bias-affected culling thresholds.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.