Repository navigation
Add LODBudgetController and runtime LOD distance factor for TerrainLODManager - #90
Open
eastagile-tracker wants to merge 1 commit into
Open
eastagile-tracker wants to merge 1 commit into
eastagile-tracker wants to merge 1 commit into
Conversation
…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
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.
This PR proposes adding
LODBudgetControllerand a runtimeset_lod_distance_factor()onTerrainLODManager, 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.pyplus a way forTerrainLODManagerto take a newlod_distance_factor. At currentmaster(9e3abdf) neither exists:from rtxpy.lod import LODBudgetControllerraisesImportError, andTerrainLODManageronly readslod_distance_factorin__init__(the stored_lod_distance_factoris never used again), so the thresholds are fixed for the life of the manager.LODBudgetControllerfollows 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 bystep_scale * relative_error, clamped tomax_step(default 5%, as in the issue) per frame and to[min_factor, max_factor]. Two additive keyword arguments:max_step, andinitial_factor(default 3.0, the manager's default). It also exposestarget_frame_time, adirectionproperty (+1 / -1 / 0) for the HUD indicator described in the issue, and anenabledflag: 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 raiseValueError.TerrainLODManagergains alod_distance_factorproperty andset_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_distand_streaming_max_distand clears_last_update_pos, so the nextupdate()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 returnsFalseand 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 bemgr.set_lod_distance_factor(ctrl.update(frame_ms)).Verification
Reproduction at HEAD:
The new tests are in
rtxpy/tests/test_lod.py.TestLODBudgetControllercovers 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.TestTerrainLODManagerDistanceFactorchecks 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 nextupdate()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_FakeRTXstub, 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.pygoes from 117 to 154 passing.I ran the full
pytest rtxpy/testsbefore and after on a machine with no NVIDIA driver. The only stub was for theoptixextension import, whichrtx.pypulls 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 checkreports nothing new on the changed lines except the F401 re-export inrtxpy/__init__.py, the same warning the neighbouring.lodre-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.
If you'd rather not receive contributions like this, reply
no-more-prson 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