The Road To WebVR

Replacing reality with JavaScript



Jaume Sanchez | @thespite

A brief history of Virtual Reality

Virtual reality is an umbrella term, really

But it's esentially a familiar concept to most people

1980 AD

3:47 in the afternoon

VR in the past

Bulky headsets

Laggy rigs

Lo-fi graphics

Dizziness

Expensive experience

Fragmented content

VR now

Developing for VR

Unity and Unreal Engine 4

360 video
Immersive experiences
Gaming

Ok! So what IS WebVR?

Is WebVR just an idea?

Is it a collection of patterns describing
how to bring VR content to the web?

Is it a browser in VR with pages
flying around cyberspace?

Web VR is VR in the web

A page using a stereo renderer and updating
the view with a DeviceOrientation event

WebVR is an API

Enables the web to be a platform for VR
using JavaScript and a browser.

Provides purpose-built interfaces to VR hardware to allow
developers to build compelling, comfortable VR experiences.

WebVR is different from VR:

no need to install content

can unify content from competing platforms
on many devices, universally

URLs enable connectivity

Some examples

Quake III viewer - Brandon Jones
Vizor.io
Sechelt - Josh Carpenter / Mr.doob
Primrose - Sean T. McBeth
Shadertoy
Inspirit - Unboring
VR Video - Pedrofe + mery project

MozVR project
WebVR.info

MDN: WebVR API on MDN
SPEC: WebVR Spec on GH

Vladimir Vukicevic from Mozilla (@vvuk)
Brandon Jones from Google (tojiro)

Browser builds with WebVR:
Firefox Nightly
Chromium

WebVR is a very simple API

A WebVR app has to handle
I/O to dedicated hardware

navigator.getVRDevices().then( function( devices ) { /* ... */ } )

We get an array of devices:

HMDVRDevice {}
	deviceId: "1"
	deviceName: "Oculus Rift DK2, Oculus VR"
	hardwareUnitId: "1"
PositionSensorVRDevice {}
	deviceId: "2"
	deviceName: "Oculus Rift DK2, Oculus VR"
	hardwareUnitId: "1"

There'll be a "Mockulus Rift" if there's no HMD attached

HMDVRDevice MDN

HMDVRDevice.getEyeParameters( 'left' | 'right' )

Returns current parameters for the eye specified, as VREyeParameters

VRFieldOfView currentFieldOfView
VRFieldOfView minimumFieldOfView
VRFieldOfView maximumFieldOfView
VRFieldOfView recommendedFieldOfView
DOMPoint eyeTranslation
DOMRect renderRect

HMDVRDevice.setFieldOfView( leftFOV, rightFOV, zNear, zFar )

Sets the field of view for both eyes

PositionSensorVRDevice MDN

Returns the current state of the position sensor, as VRPositionState

DOMPoint angularAcceleration
DOMPoint angularVelocity
DOMPoint linearAcceleration
DOMPoint linearVelocity
DOMPoint orientation
DOMPoint position (will be a DOMQuarternion)
timestamp

You don't have to worry about most of this

Three.js has your back!

Github repo

VREffect
VRControls


threejs.org | @mrdoob

Code three.js

var renderer = new THREE.WebGLRenderer( { antialias: true } );

document.body.appendChild( renderer.domElement );

var scene = new THREE.Scene();
var width = window.innerWidth, height = window.innerHeight;
var camera = new THREE.PerspectiveCamera( 75, width, height, 1, 10000 );

var controls = new THREE.OrbitControls( camera );

createWorld();

function render() {
	
	controls.update();
	renderer.render( scene, camera );

	requestAnimationFrame( render );

}

render();

Demo

Code WebVR with three.js

var renderer = new THREE.WebGLRenderer( { antialias: true } );

document.body.appendChild( renderer.domElement );

var scene = new THREE.Scene();
var width = window.innerWidth, height = window.innerHeight;
var camera = new THREE.PerspectiveCamera( 75, width, height, 1, 10000 );

var controls = new THREE.VRControls( camera );

var effect = new THREE.VREffect( renderer );
effect.setSize( width, height );

createWorld();

function render() {
	
	controls.update();
	effect.render( scene, camera );

	requestAnimationFrame( render );

}

render();

document.body.addEventListener( 'dblclick', function() {
	effect.setFullScreen( true );
});

Demo

Things to remember

In 3D, units are just a convention
In VR, they are THE LAW

Units are physically meaningful:
1 unit = 1 meter

Things to remember

Don't ever move the camera unless initiated by the user!

(Another reason why low latency is very important)

We want people to enjoy VR,
not having their breakfast revisited!

Or if you are a seasoned veteran...

What about cardboard?

Chrome Experiments for Virtual Reality

var renderer = new THREE.WebGLRenderer( { antialias: true } );

document.body.appendChild( renderer.domElement );

var scene = new THREE.Scene();
var width = window.innerWidth, height = window.innerHeight;
var camera = new THREE.PerspectiveCamera( 75, width, height, 1, 10000 );

var controls = new THREE.DeviceOrientationControls( camera );
var effect = new THREE.StereoEffect( renderer );
effect.eyeSeparation = 10;
effect.setSize( width, height );

createWorld();

function render() {
	
	controls.update();
	effect.render( scene, camera );

	requestAnimationFrame( render );

}

render();

Demo

Now that we're talking about Cardboard

More accessible, more available.
Works with Nexus, iPhone, etc.

Limitations of the web and the browsers:
wake, touch, performance, lens distortion, sensors.

Responsive WebVR

Responsive WebVR, headset optional - Boris Mus @borismus

Write once, run in any VR headset

Enter WebVR boilerplate

GitHub page

"new starting point for building responsive web VR experiences
that work on popular VR headsets
and degrace gracefully on other platforms"

Works with three.js VRControl and VREffect.

webvr-polyfill

CardboardHMDDevice
GyroPositionSensorVRDevice
MouseKeyboardPositionSensorVRDevice

WebVR manager

Common UI elements, VR best practices and transitions to fullscreen.

Cube demo | Sechelt

Input devices

Most of the devices for VR will be processed as PositionSensorVRDevice.

But there's many other options:

Keyboard and mouse
Leap Motion, Myo
gamepad controllers
scrolling (PowerMater) Physics I and Physics II

New patterns for click, select, link, etc.

What about cardboard?

Improve the "shake" detection in Gen1
Work around the limitations of Gen2

Computer vision
Voice recognition
WebRTC controls

(Most of this only applies to Android)
*sad trombone*

On the topic of transforming the camera

var width = window.innerWidth, height = window.innerHeight;
var camera = new THREE.PerspectiveCamera( 75, width, height, 1, 10000 );
var controls = new THREE.VRControls( camera );

var effect = new THREE.VREffect( renderer );
effect.setSize( width, height );

To move the camera (the user) away from the origin:

var cameraDummy = new THREE.Object3D();
cameraDummy.add( camera );
scene.add( cameraDummy );

/* Move it around */
cameraDummy.position.set( 100, 0, 100 );

/* or use controls */
var dummyControls = new THREE.GamepadController( cameraDummy );

3D Sound

We have Web Audio API!

Spatial audio and web VR - Boris Smus
Mixing Positional Audio and WebGL - Ilmari Heikkinen

What about cardboard?

Yes!

Even iOS!

Future and challenges

Performance: 90Hz under 20ms latency is HARD

Do we need a declarative WebVR, with HTML/CSS?

We need tools and libraries for developers

We need to figure out best practices,
create bidirectional patterns of communication

Security concerns on an immersive VR-enabled web

Hardware is in flux, API is in flux, implementations are in flux

There are NO consumer headsets out there yet!

The hardware hasn't found a userbase yet

And yet there's a ton of content

It's truly a new world to invent

Go and create!

It might induce nausea.

It might make you hallucinate.

But it makes you feel all warm and fuzzy inside

Jaume Sanchez

Technical Director / Creative Technologist @ B-REEL

clicktorelease.com

Thanks!

Slides online and GitHub

Questions?
Hit me up on twitter!
@thespite