openxr_passthrough.rst 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. .. _doc_openxr_passthrough:
  2. The OpenXR passthrough
  3. ======================
  4. Passthrough is a technique where camera images are used to present the environment of the user as the background.
  5. This turns a VR headset into an AR headset, often referred to as Mixed Reality or MR.
  6. .. note::
  7. As passthrough is relatively new there isn't a singular way this is implemented across platforms.
  8. There may be additions in the future so this is a work in progress.
  9. Passthrough extension
  10. ---------------------
  11. OpenXR has a vendor extension for passthrough submitted by Meta.
  12. Currently this extension is only supported on Quest and PICO but may be adopted by other headsets in the future.
  13. :ref:`XRInterface <class_xrinterface>` has entry points for passthrough so different interfaces can implement this feature.
  14. For :ref:`OpenXRInterface <class_openxrinterface>` the meta passthrough extension is implemented here.
  15. In code you can call ``is_passthrough_supported`` to check if this extension is available.
  16. If so you can simply enable passthrough by calling ``start_passthrough``.
  17. You can call ``stop_passthrough`` to disable passthrough.
  18. You do need to make sure the background is transparent.
  19. You need to enable the ``transparent_bg`` property on the viewport.
  20. Some background environment settings will still fill the background with an opaque color,
  21. you can use a ``custom color`` with a color that has alpha set to 0.
  22. The OpenXR runtime will display the camera image as the background.
  23. .. note::
  24. For privacy reasons **no access** is given to the camera image.
  25. .. warning::
  26. After passthrough is enabled it is possible to change settings that will break passthrough.
  27. Be sure not to disable the ``transparent_bg`` setting or change the environment blend mode.
  28. This will result in the camera image no longer being visible but you still incur the overhead.
  29. Always use ``stop_passthrough`` if you wish to turn off passthrough.
  30. Finally, for using passthrough on the Quest you must set the following export property:
  31. .. image:: img/xr_export_passthrough.webp
  32. Passthrough through AR
  33. ----------------------
  34. Some of the headsets recently adding OpenXR support have taken a different approach.
  35. They simply mimic being an AR device. The Lynx R1 is such a device but others may be doing the same.
  36. The following thus applies to both passthrough devices that mimic AR, and actual AR devices.
  37. If ``is_passthrough_supported`` returns false the next step is to call ``get_supported_environment_blend_modes``.
  38. This will return a list of supported blend modes for submitting the main render image to OpenXR.
  39. We need to check if ``XR_ENV_BLEND_MODE_ALPHA_BLEND`` is present in this list.
  40. If so we can tell OpenXR to expect an image that can be alpha blended with a background.
  41. To do this, we simply call ``set_environment_blend_mode(xr_interface.XR_ENV_BLEND_MODE_ALPHA_BLEND)``.
  42. We must also set ``transparent_bg`` to true and adjust the environment to ensure we submit the right image.
  43. Putting it together
  44. -------------------
  45. Putting the above together we can use the following code as a base:
  46. .. code-block:: gdscript
  47. func enable_passthrough() -> bool:
  48. var xr_interface: XRInterface = XRServer.primary_interface
  49. if xr_interface and xr_interface.is_passthrough_supported():
  50. if !xr_interface.start_passthrough():
  51. return false
  52. else:
  53. var modes = xr_interface.get_supported_environment_blend_modes()
  54. if xr_interface.XR_ENV_BLEND_MODE_ALPHA_BLEND in modes:
  55. xr_interface.set_environment_blend_mode(xr_interface.XR_ENV_BLEND_MODE_ALPHA_BLEND)
  56. else:
  57. return false
  58. get_viewport().transparent_bg = true
  59. return true