Taos API Reference
    Preparing search index...

    Class XrDepth

    WebXR depth sensing helper — the real world's per-pixel depth, used for occlusion (real objects hiding virtual ones) and physics-against-the-room.

    Two paths, picked when the session is created (see XrDepth.cpuOptimized / XrDepth.gpuOptimized for the init fragment):

    • CPU-optimizedgetCpuDepth returns an XRCPUDepthInformation with a readable buffer and depthInMeters. Good for sparse queries (place a marker on the floor, test a few points) — a full-frame readback is too slow for per-pixel occlusion.
    • GPU-optimizedgetGpuDepth returns a depth GPUTexture (via the WebGPU XR binding) you can sample in a compositing shader to discard virtual fragments behind real geometry. This is the path for true occlusion, but it is the most experimental corner of WebGPU-WebXR and is not yet widely shipped — guard every call on the returned value.

    Part of the AR half of the WebXR integration — see TODO/webxr-integration.md.

    Index

    Constructors

    Properties

    cpuOptimized: XRDepthStateInit = ...

    depthSensing init fragment for XrSessionOptions requesting the CPU path (readable buffer, sparse queries).

    gpuOptimized: XRDepthStateInit = ...

    depthSensing init fragment requesting the GPU path (sampleable depth texture for shader-side occlusion).

    Accessors

    • get enabled(): boolean

      True once a depth format was negotiated at session creation.

      Returns boolean

    • get usage(): XRDepthUsage | undefined

      The negotiated usage ('cpu-optimized' | 'gpu-optimized'), if any. Accessing depthUsage on a session that wasn't granted the depth-sensing feature throws InvalidStateError (rather than returning undefined), so swallow it and report "not enabled".

      Returns XRDepthUsage | undefined

    Methods

    • CPU-readable depth for one view this frame, or null when unavailable. Query sparse points with depthInMeters; do not read the whole buffer per frame.

      Parameters

      • frame: XRFrame
      • view: XRView

      Returns XRCPUDepthInformation | null

    • GPU depth texture for one view this frame, via the WebGPU XR binding, or null when the binding/feature isn't present. Sample it in a compositing shader (using normDepthBufferFromNormView) to occlude virtual fragments.

      Parameters

      • view: XRView

      Returns XRGPUDepthInformation | null

    • Real-world depth (meters) at normalized view coordinates (x, y) ∈ [0,1]².

      Parameters

      • info: XRCPUDepthInformation
      • x: number
      • y: number

      Returns number