All files / src/components/VirtualWalkthrough xr-render-tuning.ts

100% Statements 12/12
100% Branches 0/0
100% Functions 2/2
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                    2x                                         2x                   2x 11x           11x 11x 11x   11x     2x 8x 8x 8x    
/**
 * Render settings applied for the duration of an XR session. Splats rasterize as alpha-blended
 * quads with no early-z rejection, which makes a headset's stereo pixel throughput the binding
 * constraint on framerate long before splat count is.
 */
 
/**
 * Peripheral back-buffer resolution reduction, 0 (off) to 1 (strongest). Ineffective while MSAA is
 * on, which is one reason the application requests `antialias: false`.
 */
export const XR_FIXED_FOVEATION = 1;
 
/**
 * The subset of `GSplatParams` this module writes. Structural rather than the PlayCanvas type so
 * the logic can be exercised against a plain object.
 */
export interface GsplatTuningParams {
  radialSorting: boolean;
  alphaClipForward: number;
  minPixelSize: number;
}
 
/**
 * `radialSorting` orders splats by distance from the camera rather than by depth along its forward
 * axis, which is the more accurate ordering when the camera rotates rather than translates. Sorting
 * runs on a worker and so lags the view by at least a frame; head rotation dominates in a headset,
 * where that lag is what reads as swimming.
 *
 * The other two trade fidelity for fill rate: `alphaClipForward` drops near-transparent splats from
 * the forward pass, and `minPixelSize` drops splats that project to less than a few pixels.
 */
export const XR_GSPLAT_TUNING: GsplatTuningParams = {
  radialSorting: true,
  alphaClipForward: 0.1,
  minPixelSize: 1,
};
 
/**
 * Applies the XR settings, returning the values that were replaced so they can be restored when the
 * session ends. These live on the scene, so leaving them tuned would degrade desktop rendering.
 */
export const applyGsplatTuning = (params: GsplatTuningParams): GsplatTuningParams => {
  const previous: GsplatTuningParams = {
    radialSorting: params.radialSorting,
    alphaClipForward: params.alphaClipForward,
    minPixelSize: params.minPixelSize,
  };
 
  params.radialSorting = XR_GSPLAT_TUNING.radialSorting;
  params.alphaClipForward = XR_GSPLAT_TUNING.alphaClipForward;
  params.minPixelSize = XR_GSPLAT_TUNING.minPixelSize;
 
  return previous;
};
 
export const restoreGsplatTuning = (params: GsplatTuningParams, previous: GsplatTuningParams): void => {
  params.radialSorting = previous.radialSorting;
  params.alphaClipForward = previous.alphaClipForward;
  params.minPixelSize = previous.minPixelSize;
};