Luxar Viewer API Documentation - v2026.9.22
    Preparing search index...

    Module scene/density-guard

    Projected-density guard — the shader keep-fraction ladder.

    Consumes the per-node density the tracker in projected-density.ts measures each frame and, for nodes whose blend mode sums energy (additive / luminous / volumetric — isBlendableMode), thins the DRAW to a keep fraction of the elements: the material's uDensityDrop uniform makes the vertex stage discard every element whose hashed storage index falls below 1 − keep, and applyLodFade multiplies the node's opacity by 1/keep so the composited brightness stays at the unthinned aggregate. Non-blendable modes (max, normal, opaque) are never thinned — a max-projection or an alpha-over surface has no linear brightness knob. Shaded triangle meshes are excluded: they tile a surface rather than stack emissive energy, and their materials do not carry uDensityDrop.

    Why: on element-dense views the frame cost is elements per pixel, not pixels (2026-09 audit: 1.5 M points framed into ~1 600 px → 42 ms at DPR 1, 83 ms at DPR 0.5). Beyond a few elements per pixel every further element is overdraw the eye cannot resolve. The ladder is quantised (1, 1/2, 1/4, … minKeepFraction) with hysteresis so a slow zoom does not flicker between steps, and every step change is a CONTENT change for the adaptive-DPR controller (notifyContentChanged), never per-frame churn.

    Hot-path invariants: no per-frame allocation (the guard mutates the tracker's records and the mesh's own material in place) and idempotent per-frame re-assertion of the uniform, so a material rebuilt or replaced behind the guard's back cannot leave the brightness term without its thinning (or vice versa).

    DensityGuard
    DensityLadderConfig
    DensityGuardDeps
    targetKeepFraction
    nextKeepFraction
    getDensityGuard