Skip to content

Add LODBudgetController and runtime LOD distance factor for TerrainLODManager - #90

Open
eastagile-tracker wants to merge 1 commit into
makepath:masterfrom
eastagile-tracker:agile-board/lod-budget-controller
Open

eastagile-tracker wants to merge 1 commit into
makepath:masterfrom
eastagile-tracker:agile-board/lod-budget-controller

Conversation

@eastagile-tracker

Copy link
Copy Markdown

This PR proposes adding LODBudgetController and a runtime set_lod_distance_factor() on TerrainLODManager, steps 1 and 3 of the implementation plan in #82. We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/1413. You can sign in with your GitHub ID to claim ownership of the project.

What changed

#82 asks for a feedback loop between frame time and LOD thresholds, and its plan starts with a pure-logic controller in rtxpy/lod.py plus a way for TerrainLODManager to take a new lod_distance_factor. At current master (9e3abdf) neither exists: from rtxpy.lod import LODBudgetController raises ImportError, and TerrainLODManager only reads lod_distance_factor in __init__ (the stored _lod_distance_factor is never used again), so the thresholds are fixed for the life of the manager.

LODBudgetController follows the API sketched in the issue (target_fps, min_factor, max_factor, alpha, dead_band, step_scale, update(frame_time_ms), current_factor, ema_frame_time). It keeps an EMA of frame time, leaves the factor alone inside the dead band, and otherwise scales it by step_scale * relative_error, clamped to max_step (default 5%, as in the issue) per frame and to [min_factor, max_factor]. Two additive keyword arguments: max_step, and initial_factor (default 3.0, the manager's default). It also exposes target_frame_time, a direction property (+1 / -1 / 0) for the HUD indicator described in the issue, and an enabled flag: when it is off, the EMA keeps tracking but the factor stays at its last value, matching "no snap back to default". Non-finite or non-positive samples are ignored, and bad constructor arguments raise ValueError.

TerrainLODManager gains a lod_distance_factor property and set_lod_distance_factor(factor). The threshold and culling-range math that was inline in __init__ moved into _apply_lod_distance_factor(), which both paths now call, so the constructor computes exactly what it did before. Setting a new factor recomputes _lod_distances, _max_dist and _streaming_max_dist and clears _last_update_pos, so the next update() re-evaluates tiles even with the camera standing still. Tile meshes stay cached because only the LOD assignment changes. Setting the same factor again is a no-op that returns False and keeps the movement throttle in place.

I left out the viewer wiring (frame timing in engine.py, the Shift+B toggle, the HUD line) and the #80/#81 hooks. Those only run inside the OptiX viewer, and I had no GPU to check them on. With this API in place, the tick-loop side would be mgr.set_lod_distance_factor(ctrl.update(frame_ms)).

Verification

Reproduction at HEAD:

$ python -c "from rtxpy.lod import LODBudgetController"
ImportError: cannot import name 'LODBudgetController' from 'rtxpy.lod'

The new tests are in rtxpy/tests/test_lod.py. TestLODBudgetController covers EMA seeding and smoothing, the step direction, proportional steps, the per-frame clamp, the min/max bounds, the dead band, ignored invalid samples, enable/disable, and parameter validation, and it runs a closed-loop simulation that settles inside the dead band. TestTerrainLODManagerDistanceFactor checks that a runtime change gives the same thresholds and culling distances as a freshly constructed manager. It also checks that a larger factor sends every tile to LOD 0 and a smaller one coarsens them on the next update() with no camera movement, that setting the same factor is a no-op, that invalid factors are rejected, and that the controller drives the manager. They use the existing _FakeRTX stub, so none of them needs a GPU. If I keep the new methods but revert only the lines that apply the new factor, 12 of these tests fail. With the change in place, test_lod.py goes from 117 to 154 passing.

I ran the full pytest rtxpy/tests before and after on a machine with no NVIDIA driver. The only stub was for the optix extension import, which rtx.py pulls in at import time and which the LOD code never calls. Before: 273 passed, with 190 failures/errors, all of them tests that need a CUDA device. After: 310 passed, and the set of failing tests is identical. ruff check reports nothing new on the changed lines except the F401 re-export in rtxpy/__init__.py, the same warning the neighbouring .lod re-exports already get.

How this was managed

This work was tracked as https://eastagiletracker.com/projects/1413/stories/1419426 on https://eastagiletracker.com/projects/1413. That board was imported from this repository's issues and pull requests (77 stories) and was used to manage this change.

board

If you'd rather not receive contributions like this, reply no-more-prs on this pull request and we won't open any further ones on your repositories.


Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com

…Manager

LODBudgetController is a frame-time driven proportional controller
(EMA-smoothed, dead band, per-frame step clamp, min/max bounds) that
returns an adjusted lod_distance_factor. TerrainLODManager gains a
lod_distance_factor property and set_lod_distance_factor(), which
recomputes the LOD thresholds and culling range and re-evaluates tiles
on the next update() without requiring camera movement.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant