
| Use cases | Depth API | Scene API |
|---|---|---|
Static Occlusion: the occluding real-world environment remains immobile (static) throughout the lifetime of the app, i.e. no moving objects such as hands, people or chairs. | ✔ | ✔ |
Dynamic Occlusion: the occluding real-world environment contains mobile (dynamic) elements, e.g. the users hands, other people, pets. | ✔ | ✖ |
Raycasting: Computing intersection of a ray and real-world surfaces. Supports use cases like content placement. | ✔ | ✔ |
Physics/Collisions: interactions between virtual content and the real-world, like a virtual ball bouncing off of a physical couch. | ✖ | ✔ |
com.oculus.permission.USE_SCENE) before accessing any of the functions in the XR_META_environment_depth extension. See the Spatial Data Permission guide for how to set up the app and how to request this permission.XR_META_environment_depth OpenXR extension. All extensions should be explicitly listed when creating an XrInstance. Include XR_META_ENVIRONMENT_DEPTH_EXTENSION_NAME in this list to enable the Depth API extension:std::vector<const char*> extensions = {XR_META_ENVIRONMENT_DEPTH_EXTENSION_NAME};
XrInstanceCreateInfo instanceCreateInfo = {XR_TYPE_INSTANCE_CREATE_INFO};
instanceCreateInfo.enabledExtensionCount = extensions.size();
instanceCreateInfo.enabledExtensionNames = extensions.data();
XrInstance instance = XR_NULL_HANDLE;
xrCreateInstance(&instanceCreateInfo, &instance);
SampleXrFramework/Src/XrApp.cpp.xrGetSystemProperties to query for a XrSystemEnvironmentDepthPropertiesMETA struct and check that supportsEnvironmentDepth is true.xrGetInstanceProcAddr in the OpenXR spec.PFN_xrCreateEnvironmentDepthProviderMETA xrCreateEnvironmentDepthProviderMETA = nullptr; PFN_xrDestroyEnvironmentDepthProviderMETA xrDestroyEnvironmentDepthProviderMETA = nullptr; PFN_xrStartEnvironmentDepthProviderMETA xrStartEnvironmentDepthProviderMETA = nullptr; PFN_xrStopEnvironmentDepthProviderMETA xrStopEnvironmentDepthProviderMETA = nullptr; PFN_xrCreateEnvironmentDepthSwapchainMETA xrCreateEnvironmentDepthSwapchainMETA = nullptr; PFN_xrDestroyEnvironmentDepthSwapchainMETA xrDestroyEnvironmentDepthSwapchainMETA = nullptr; PFN_xrEnumerateEnvironmentDepthSwapchainImagesMETA xrEnumerateEnvironmentDepthSwapchainImagesMETA = nullptr; PFN_xrGetEnvironmentDepthSwapchainStateMETA xrGetEnvironmentDepthSwapchainStateMETA = nullptr; PFN_xrAcquireEnvironmentDepthImageMETA xrAcquireEnvironmentDepthImageMETA = nullptr; PFN_xrSetEnvironmentDepthHandRemovalMETA xrSetEnvironmentDepthHandRemovalMETA = nullptr; xrGetInstanceProcAddr( instance, "xrCreateEnvironmentDepthProviderMETA", reinterpret_cast<PFN_xrVoidFunction*>(&xrCreateEnvironmentDepthProviderMETA)); xrGetInstanceProcAddr( instance, "xrDestroyEnvironmentDepthProviderMETA", reinterpret_cast<PFN_xrVoidFunction*>(&xrDestroyEnvironmentDepthProviderMETA)); xrGetInstanceProcAddr( instance, "xrStartEnvironmentDepthProviderMETA", reinterpret_cast<PFN_xrVoidFunction*>(&xrStartEnvironmentDepthProviderMETA)); xrGetInstanceProcAddr( instance, "xrStopEnvironmentDepthProviderMETA", reinterpret_cast<PFN_xrVoidFunction*>(&xrStopEnvironmentDepthProviderMETA)); xrGetInstanceProcAddr( instance, "xrCreateEnvironmentDepthSwapchainMETA", reinterpret_cast<PFN_xrVoidFunction*>(&xrCreateEnvironmentDepthSwapchainMETA)); xrGetInstanceProcAddr( instance, "xrDestroyEnvironmentDepthSwapchainMETA", reinterpret_cast<PFN_xrVoidFunction*>(&xrDestroyEnvironmentDepthSwapchainMETA)); xrGetInstanceProcAddr( instance, "xrEnumerateEnvironmentDepthSwapchainImagesMETA", reinterpret_cast<PFN_xrVoidFunction*>(&xrEnumerateEnvironmentDepthSwapchainImagesMETA)); xrGetInstanceProcAddr( instance, "xrGetEnvironmentDepthSwapchainStateMETA", reinterpret_cast<PFN_xrVoidFunction*>(&xrGetEnvironmentDepthSwapchainStateMETA)); xrGetInstanceProcAddr( instance, "xrAcquireEnvironmentDepthImageMETA", reinterpret_cast<PFN_xrVoidFunction*>(&xrAcquireEnvironmentDepthImageMETA)); xrGetInstanceProcAddr( instance, "xrSetEnvironmentDepthHandRemovalMETA", reinterpret_cast<PFN_xrVoidFunction*>(&xrSetEnvironmentDepthHandRemovalMETA));
xrCreateEnvironmentDepthProviderMETA function. This function creates and returns a XrEnvironmentDepthProvider handle to a depth provider instance. Maximum one depth provider is allowed to exist per app at any given time. The handle is unique per process and cannot be shared across processes.xrCreateEnvironmentDepthProviderMETA function is as follows:XrResult xrCreateEnvironmentDepthProviderMETA(
XrSession session,
const XrEnvironmentDepthProviderCreateInfoMETA* createInfo,
XrEnvironmentDepthProviderMETA* environmentDepthProvider);
XrEnvironmentDepthProviderCreateInfoMETA struct containing creation flags.typedef struct XrEnvironmentDepthProviderCreateInfoMETA {
XrStructureType type;
const void* XR_MAY_ALIAS next;
XrEnvironmentDepthProviderCreateFlagsMETA createFlags;
} XrEnvironmentDepthProviderCreateInfoMETA;
createFlags must be zero, but it might be extended in the future.xrDestroyEnvironmentDepthProviderMETA:XrResult xrDestroyEnvironmentDepthProviderMETA(
XrEnvironmentDepthProviderMETA environmentDepthProvider);
xrGetSystemProperties to query for a XrSystemEnvironmentDepthPropertiesMETA struct and check that supportsHandRemoval is true.xrSetEnvironmentDepthHandRemovalMETA function:XrResult xrSetEnvironmentDepthHandRemovalMETA(
XrEnvironmentDepthProviderMETA environmentDepthProvider,
const XrEnvironmentDepthHandRemovalSetInfoMETA* setInfo);
XrEnvironmentDepthHandRemovalSetInfoMETA argument which is defined as:typedef struct XrEnvironmentDepthHandRemovalSetInfoMETA {
XrStructureType type;
const void* XR_MAY_ALIAS next;
XrBool32 enabled;
} XrEnvironmentDepthHandRemovalSetInfoMETA;
XrEnvironmentDepthSwapchainMETA. This type is similar to XrSwapchain but supports a different set of operations and is intended to be read instead of written to by the app.xrCreateEnvironmentDepthSwapchainMETA:XrResult xrCreateEnvironmentDepthSwapchainMETA(
XrEnvironmentDepthProviderMETA environmentDepthProvider,
const XrEnvironmentDepthSwapchainCreateInfoMETA* createInfo,
XrEnvironmentDepthSwapchainMETA* swapchain);
XrEnvironmentDepthSwapchainCreateInfoMETA struct specifying options for creating the swapchain:typedef struct XrEnvironmentDepthSwapchainCreateInfoMETA {
XrStructureType type;
const void* XR_MAY_ALIAS next;
XrEnvironmentDepthSwapchainCreateFlagsMETA createFlags;
} XrEnvironmentDepthSwapchainCreateInfoMETA;
createFlags must be zero, but it might be extended in the future.xrGetEnvironmentDepthSwapchainStateMETA:XrResult xrGetEnvironmentDepthSwapchainStateMETA(
XrEnvironmentDepthSwapchainMETA swapchain,
XrEnvironmentDepthSwapchainStateMETA* state);
XrEnvironmentDepthSwapchainStateMETA is defined as:typedef struct XrEnvironmentDepthSwapchainStateMETA {
XrStructureType type;
void* XR_MAY_ALIAS next;
uint32_t width;
uint32_t height;
} XrEnvironmentDepthSwapchainStateMETA;
XrSwapchain, the XrEnvironmentDepthSwapchainMETA needs to be “enumerated” into a graphics API specific array of texture handles. This is done by calling xrEnumerateEnvironmentDepthSwapchainImagesMETA that has the same semantics as xrEnumerateSwapchainImages:XrResult xrEnumerateEnvironmentDepthSwapchainImagesMETA(
XrEnvironmentDepthSwapchainMETA swapchain,
uint32_t imageCapacityInput,
uint32_t* imageCountOutput,
XrSwapchainImageBaseHeader* images);
xrDestroyEnvironmentDepthSwapchainMETA:XrResult xrDestroyEnvironmentDepthSwapchainMETA(
XrEnvironmentDepthSwapchainMETA swapchain);
xrStartEnvironmentDepthProviderMETA:XrResult xrStartEnvironmentDepthProviderMETA(
XrEnvironmentDepthProviderMETA environmentDepthProvider);
xrStopEnvironmentDepthProviderMETA:XrResult xrStopEnvironmentDepthProviderMETA(
XrEnvironmentDepthProviderMETA environmentDepthProvider);
xrBeginFrame and xrEndFrame calls. To acquire a lock on the latest available depth map in the swapchain, as well as retrieve metadata needed to parse the depth, apps need to call xrAcquireEnvironmentDepthImageMETA. Once a depth swapchain has been acquired it is locked for the entire duration of the frame. You shouldn’t call xrAcquireEnvironmentDepthImageMETA more than once per frame.XrResult xrAcquireEnvironmentDepthImageMETA(
XrEnvironmentDepthProviderMETA environmentDepthProvider,
const XrEnvironmentDepthImageAcquireInfoMETA* acquireInfo,
XrEnvironmentDepthImageMETA* environmentDepthImage);
XrEnvironmentDepthImageAcquireInfoMETA struct that needs to be populated with some required parameters:typedef struct XrEnvironmentDepthImageAcquireInfoMETA {
XrStructureType type;
const void* XR_MAY_ALIAS next;
XrSpace space;
XrTime displayTime;
} XrEnvironmentDepthImageAcquireInfoMETA;
XrSpace you want the space to be of the returned pose which the depth map was rendered from. The displayTime field should be set to the displayTime of the current rendered frame as it’s used to compute the pose in case it is time dependent.XrEnvironmentDepthImageMETA struct defined as:typedef struct XrEnvironmentDepthImageMETA {
XrStructureType type;
const void* XR_MAY_ALIAS next;
uint32_t swapchainIndex;
float nearZ;
float farZ;
XrEnvironmentDepthImageViewMETA views[2];
} XrEnvironmentDepthImageMETA;
typedef struct XrEnvironmentDepthImageViewMETA {
XrStructureType type;
const void* XR_MAY_ALIAS next;
XrFovf fov;
XrPosef pose;
} XrEnvironmentDepthImageViewMETA;
nearZ and farZ are the near and far planes defined in an OpenGL projection matrix, and are needed to convert the depth map’s pixel values into metric distances. The format and convention is the same as for regular OpenGL depth textures.[ -1 -2*nearZ ] [ -1 0 ]
XrSamples/XrPassthroughOcclusion sample where this method is used to render a scene with Depth API based occlusions.