WebVR Polyfill
A JavaScript implementation of the WebVR spec. This project lets you use
WebVR today, without requiring a special browser build. It also
lets you view the same content without requiring a virtual reality viewer.
Take a look at basic WebVR samples that use this polyfill.
Implementation
The polyfill decides which VRDisplays to provide, depending on the configuration
of your browser. Mobile devices provide the CardboardVRDisplay
. Desktop devices
use the MouseKeyboardVRDisplay
.
CardboardVRDisplay
uses DeviceMotionEvents to implement a complementary
filter which does sensor fusion and pose prediction to provide
orientation tracking. It can also render in stereo mode, and includes mesh-based
lens distortion. This display also includes user interface elements in VR mode
to make the VR experience more intuitive, including:
- A gear icon to select your VR viewer.
- A back button to exit VR mode.
- An interstitial which only appears in portrait orientation, requesting you switch
into landscape orientation (if orientation lock is not available).
MouseKeyboardVRDisplay
uses mouse events to allow you to do the equivalent of
mouselook. It also uses keyboard arrows keys to look around the scene
with the keyboard.
Configuration
The polyfill can be configured and debugged with various options. The following
are supported:
WebVRConfig = {
CARDBOARD_UI_DISABLED: false,
FORCE_ENABLE_VR: true,
K_FILTER: 0.98,
ROTATE_INSTRUCTIONS_DISABLED: false,
PREDICTION_TIME_S: 0.040,
TOUCH_PANNER_DISABLED: false,
YAW_ONLY: true,
MOUSE_KEYBOARD_CONTROLS_DISABLED: true,
DEFER_INITIALIZATION: true,
ENABLE_DEPRECATED_API: true,
BUFFER_SCALE: 0.5,
DIRTY_SUBMIT_FRAME_BINDINGS: true
}
Performance
Performance is critical for VR. If you find your application is too sluggish,
consider tweaking some of the above parameters. In particular, keeping
BUFFER_SCALE
at 0.5 (the default) will likely help a lot.
Development
If you'd like to contribute to the webvr-poyfill
library, check out
the repository and install
Node and the dependencies:
git clone https://github.com/borismus/webvr-polyfill
cd webvr-polyfill
npm install
License
This program is free software for both commercial and non-commercial use,
distributed under the Apache 2.0 License.