How to WebXR in March 2019
3 minute read.
With Construct Arcade my co-founder Florian and I are as close to working with the WebXR API as it gets. To give you some hints on what to look out for with recent browser support, here is an updated version of How to WebXR in July 2018.
Most of the hints in that blog post still apply, so make sure to also read that.
API Shapes and Flavours
There are the many versions and APIs for VR on the flying around. I tried to assemble a table. It is likely incomplete, and support from many browsers is missing
Name | Version | Spec Date | Browsers |
---|---|---|---|
WebVR | 1.0 14 |
|
|
1.1 13 |
|
Firefox 55+ for Windows 11 Firefox 64+ for Mac 12 Chrome 56-62 (+?) 15 Microsoft Edge build 15002+ 16 |
|
WebXR Device API | First Draft | ? | Chrome 66+ 17 |
Second Draft | ? | Chrome 73+ |
It turns out that latest Chrome has some updates to their WebXR implementation that make it follow the latest changes on the WebXR spec. Things like supportsSessionMode are implemented in Chrome 73.
On the one hand this is great news! On the other this breaks all WebXR based applications and games that have been developed with the older versions of the spec that was implemented and available through the origin trials up to and including Chrome 72.
Even frameworks like A-Frame are not quite able to shield you from these breaks.
Backwards Compatibility
For Construct Arcade I will be implementing a backwards compatibility shim/polyfill library that will allow running older WebVR games without updating them manually.
While updating three.js or A-Frame—if you built your game with one of those frameworks— would usually also update the use of browser VR API, that is often not easy because of deprecation and removal of other unrelated features.
(Any future information about this will be added here)
Performance
Upcoming WebGL extensions like WebGL_multi_draw
18 and OVR_multiview2
19 appear to
be the solution to performance with many draw calls. Until these are widespread enough and
implemented in all browsers, we still have to worry about this topic ourselves, though.
With WebXR you target a range of devices from clients on smartphones, standalone VR and desktop. Keep your draw call counts low, meshes and textures small and avoid complex PBR shaders and shadow passes if possible.
If you want to preserve as much visual fidelity as possible, have auto-scaling settings for mobile devices. That can range from using different meshes to disabling rendering features.
With smooth performance, VR is fun immersive! On 5 fps very much not.
Exokit
The open source VR browser Exokit 20 has been very active lately. In case you want to develop a VR app to submit to Google Play or Oculus Platform, you should be able to build on top of Exokit. I plan on trying this and will report back once I know more.
Additionally Exokit is working on Atmos, an XR headset for the web that is likely worth a follow.
References
- 11
- https://www.mozilla.org/en-US/firefox/55.0/releasenotes/
- 12
- https://developer.mozilla.org/en-US/docs/Web/API/WebVR_API#Navigator.getVRDisplays
- 13
- https://immersive-web.github.io/webvr/spec/1.1/
- 14
- Spec is nowhere to be found online. I extracted it from the history of the WebXR GitHub repository for you to download it here as pdf.
- 15
- https://www.chromestatus.com/features/4532810371039232
- 16
- https://developer.microsoft.com/en-us/microsoft-edge/platform/status/webvr/
- 17
- https://developers.google.com/web/fundamentals/vr/status/ or https://www.chromestatus.com/features/5680169905815552
- 18
- https://docs.google.com/presentation/d/1iznxalgXLLSWVNHQ6le9Gzv_TYzsD5R_gg8yT5ckf2A/edit#slide=id.g4c932beacf_1_0
- 19
- https://www.khronos.org/registry/OpenGL/extensions/OVR/OVR_multiview2.txt
- 20
- webmr.io and exokit.org