bringing virtual reality to the web: vr, webgl and css – together at last!

45
WebVR Vladimir Vukicevic Mozilla

Upload: fitc

Post on 22-Nov-2014

505 views

Category:

Internet


4 download

DESCRIPTION

Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last! with Vladimir Vukicevic presented on September 17 2014 at FITC Web Unleashed Toronto 2014 Virtual Reality development has become very active recently, with the availability of low cost and high quality headsets, motion tracking equipment, and sensors. However, most VR app development is happening natively — users are stuck in the days of needing to download the right binary, trust a third-party that their code isn’t malicious and fix compatibility issues. Developers need to target multiple platforms, thus often ignoring those with fewer users. Instead, wouldn’t it be great if high quality VR content could be delivered through the Web? In this session, Vladimir Vukicevic will address additions to HTML, CSS, and WebGL that Mozilla is experimenting with which allow Web developers to create immersive VR experiences. Everything from pure VR WebGL content to responsive HTML and CSS that can shift from mobile to tablet to desktop to VR will be covered. Additionally, Vladimir will discuss delivering VR video via the Web, as well as how to mix WebGL and CSS content in a true 3D space. OBJECTIVE To show how VR and the Web work together, and the techniques for bringing VR content to the Web. TARGET AUDIENCE Web developers and designers ASSUMED AUDIENCE KNOWLEDGE Some knowledge of at least one of WebGL, CSS 3D Transforms, or modern 3D graphics would be helpful. FIVE THINGS AUDIENCE MEMBERS WILL LEARN An overview of current VR devices, their capabilities and how they can interface with the Web. How to render WebGL content to a VR device. How to create documents using HTML and CSS that can be projected in VR. How to create responsive documents that can shift in and out of VR based on user choice. How WebGL and CSS content can be mixed, providing interactive 3D graphics but with the full power of HTML for non-3D elements.

TRANSCRIPT

Page 1: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

WebVRVladimir Vukicevic

Mozilla

Page 2: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Why WebVR?

Web is a highly connected environment

The “Metaverse” is a VR-rich concept

.. we’re already very close! It’s just 2D!

Page 3: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Why WebVR?

In practical terms, VR will succeed or fail based oncontent and how easy it is to access that content.

There is no easier or more ubiquitous contentdelivery mechanism than the Web.

It had better be able to deliver VR.

Page 4: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

VR Basics

Quick Overview of VR

Page 5: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Immersion

Sensory Immersion(Focus on Visual Immersion)

Input Immersion

Page 6: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Visual Immersion

Page 7: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Per-Eye Rendering

Page 8: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Device-Specific Distortion

Page 9: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Input Immersion

Page 10: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

WebVR Overview

What is WebVR?What does WebVR enable?

Page 11: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

WebVR

Render Web Content in VR

Access to devices being used for Virtual Reality

Device-agnostic VR in browser

Focus on Head-Mounted Displays (HMDs)and Sensor devices

Page 12: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Web Content in VR

Focus on Visual ImmersionProvide Input, But Up to App to Handle

Support both WebGL and HTML/CSS Content

Goals:Allow High-End Experiences with VR in the browser

(asm.js, Emscripten, game engines, etc.)

Allow Web Experiences with VR(responsive sites, CSS 3D, VR browsing, etc.)

Page 13: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Device-agnostic VR

Challenge: Unify varied devicesProvide consistent API

Page 14: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Device-agnostic VR

Even worse situation in sensors!

Page 15: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

WebVR API

Nuts & Bolts

Page 16: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Basic Interface

Call getVRDevices(), which returns a Promise:

navigator.getVRDevices().then(vrDeviceCallback)

The callback receives a list of all available VR devices:

function vrDeviceCallback(vrDevices) {

…}

Page 17: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

VR Devices

For every device:

hardwareUnitIdUnique identifier per hardware device

deviceIdUnique identifier for specific sensor/device on hardware

deviceNameUser-readable name identifying the sensor

Page 18: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

VR Devices

For example, with an Oculus Rift connected, getVRDevices() will return a list with...

(1)HMDVRDevicea)hardwareDeviceId: oculus-1b)deviceId: 12345c)deviceName: “Oculus Rift HMD”

(1)SensorVRDevicea)hardwareDeviceId: oculus-1b)deviceId: abcdec)deviceName: “Oculus Rift Sensor”

Same hardware Device ID

Page 19: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

VR Devices: HMDs

HMDs have configuration and data for rendering

setFieldOfView(left, right, zNear, zFar)Configure the field of view that rendering will use

getRecommendedEyeFieldOfView(whichEye)getMaximumEyeFieldOfView(whichEye)getCurrentEyeFieldOfView(whichEye)

Get the recommended and maximum FOV that thisdevice can render

Page 20: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Configuring HMDs

hmd.setFieldOfView({ upDegrees: 65,downDegrees: 65,leftDegrees: 65,rightDegrees: 45 },

…);

Human eye field of view (Wikipedia)60° upwards75° downwards95° away from nose60° towards nose

Viewing parameters are needed for properdistortion and WebGL rendering

Ve

rtica

l FO

V

Horizontal FOV

Left Degrees

Right Degrees

Up Degrees

Down Degrees

Asymmetrical Projection

Page 21: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

VR Devices: HMDs

getEyeTranslation(whichEye)Get the eye translation offset for the given eye

getRecommendedEyeRenderRect(whichEye)Get the render rectangle where content for the given

eye should go

Page 22: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Configuring HMDs

hmd.getRecommendedEyeRenderRect(“left”)

Mainly useful for WebGL, defines where and how big the eye’s scene should be rendered.

WebGL CanvasLeft Eye Render Rect

Page 23: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

VR Devices: Sensors

getState(timeOffset = 0.0)Get the state of this sensor, at the given optional time offset.

Returns a dictionary containing position, orientation, as well aslinear and angular velocity and acceleration.

zeroSensor()Reset the sensor, making the current state the zero position

Page 24: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Getting State

hmdSensor.getState()

Obtain the current state of the sensor.

Call per frame.

Future: a particular per-frame state may be provided

Helps the browser know exactly what state was used to render

For proper WebGL + CSS syncFor Oculus Timewarp rendering

{orientation: {w:0, x:0, y:0, z:0},angularAcceleration: {x:0, y:0, z:0},angularVelocity: {x:0, y:0, z:0},

position: {x:0, y:0, z:0},linearAcceleration: {x:0, y:0, z:0},linearVelocity: {x:0, y:0, z:0},

timeStamp: 0}

Page 25: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Entering VR Mode

requestFullScreen call is extended to take an options dictionary

One option specifies the VR Display to go fullscreen on;also activates VR Rendering

var container = document.getElementById(“container”);container.mozRequestFullScreen({ vrDisplay: hmd });

Fullscreen is the only way to enter VR Mode

Page 26: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

WebVR and WebGL

Page 27: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

WebVR with WebGL

Most similar to traditional 3D/VR development

App code does all rendering

Final presentation steps done by browser

Quick integration with existing WebGL content and engines

Page 28: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Relevant WebVR API

HMD: setFieldOfView()Browser needs to know exact FOV settings

that content is rendering with

HMD: getRecommendedEyeRenderRect()Browser needs to know where the left/right eye

content is present

Sensors: getState()Content rendering should take into accountposition/orientation of HMD, and any other

sensors that are supported

Page 29: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Engine Integration

Natural extension to WebGL Content

e.g.: multiple WebVR Renderers for three.js existthat use the WebVR API

Working on adding support to UE4, Unity, etc.

Lots of interest among Mozilla Games project

Page 30: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

WebVR and CSS

Page 31: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Why HTML/CSS with VR?

Modern CSS has lots of features3D Transforms

TransitionsAnimationsGradients

Complex Backgrounds

HTML/CSS is well-suited for a lot of contente.g. placing informative content in a VR space

HTML/CSS + VR can move us to Responsive DesignWeb sites can adapt to “Browsing in VR”

Page 32: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

CSS 3D Transforms

transform-style: preserve-3d;transform: translateZ(-200px);

Page 33: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

CSS 3D Transforms in VR

No perspective property used:VR creates its own space

Defined by the VR HMD FOV

CSS Origin is Top LeftVR Origin is Center

… this may be controversial(... and may not be even needed)

Page 34: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Handling Position/Orientation in CSS

Present

Per-frame, set a transform on anelement that acts as the “camera”

Use position/orientation from state togenerate a transformation matrix

var state = hmdSensor.getState();camera.style.transform = stateToCSSTransform(state);

Page 35: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Handling Position/Orientation in CSS

Future

Use a CSS property

#camera {transform: vr-orientation() vr-position();

}

Automatic application of position/orientationfrom fullscreen HMD device

Allows for code-free VR

Page 36: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Responsive Design

@media screen and (min-width: 400px) and (orientation: portrait){ /* phone UI rules */ }

@media screen and (min-width: 800px){ /* desktop and large tablet rules */ }

@media vr{

#camera {transform: vr-orientation() vr-position();

}#contentArea {

width: 100cm;height: 80cm;transform: translateZ(50cm);

}}

Page 37: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

WebVR Current Status

Page 38: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

WebVR Status

Experimental Firefox and Chrome BuildsImplement the API described here

WebGL Rendering Works Well In Both

CSS Rendering Only In Firefox

Everything Subject To Change!(Still R&D!)

Page 39: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

WebVR Status

Core API with no CSS support willlikely be first to ship

Will enable WebGL VR rendering

Will enable Emscripten/asm.js-based portingof VR content and demos

Page 40: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

WebVR Status

Oculus Rift support onlyDesktop only

Google Carboard coming soon

Android coming soon

Additional input devices coming soon

Page 41: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

WebVR Status

Web toolmakers adding support(especially in gaming space)

Working on adding support to Emscripten

CSS 3D designers also experimenting

Page 42: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Browsing in VR

Page 43: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

Hiro

Mozilla exploration of VR browsing

VR-based Interaction

Browsing existing sites in VR

Browsing VR sites smoothlyfrom a HUD/controller

Input issues(e.g. URLs? Usernames/passwords?)

First demo soon, rapid updates

Page 44: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!

For more information...

web-vr-discuss mailing listhttps://mail.mozilla.org/listinfo/web-vr-discuss

(search for web-vr-discuss!)

@vvukI’ll generally announce new builds,

etc. to Twitter.

@joshcarpenterFor work on Hiro and VR

design and UX

Page 45: Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!