XRSession: depthDataFormat property

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The read-only depthDataFormat property of an immersive-ar XRSession describes which depth sensing data format is used.

Value

This property can return the following values:

luminance-alpha

2-byte unsigned integer data buffers (LUMINANCE_ALPHA GLEnum). CPU usage: interpret XRCPUDepthInformation.data as Uint8Array. GPU usage: inspect Luminance and Alpha channels to reassemble single value.

float32

4-byte floating point data buffers (R32F GLEnum). CPU usage: interpret XRCPUDepthInformation.data as Float32Array. GPU usage: inspect Red channel and use the value.

Examples

To request the desired data format, you need to specify a dataFormatPreference when requesting a session using XRSystem.requestSession(). Here, the caller is able to handle both "luminance-alpha" and "float32" formats. The order indicates preference for "luminance-alpha":

js
navigator.xr.requestSession("immersive-ar", {
  requiredFeatures: ["depth-sensing"],
  depthSensing: {
    usagePreference: ["cpu-optimized", "gpu-optimized"],
    formatPreference: ["luminance-alpha", "float32"],
  },
});

To check which data format was selected by the user agent, you can call the depthDataFormat property:

js
console.log(session.depthDataFormat); // either "luminance-alpha" or "float32"

Specifications

Specification
WebXR Depth Sensing Module
# dom-xrsession-depthdataformat

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
depthDataFormat
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.