developing interactive 3d experiences in html5 with carlos ulloa

193
Developin Interactive 3D Experiences in HTML5 Carlos Ulloa HelloEnjoy.com FITC Amsterdam 2014

Upload: fitc

Post on 24-May-2015

1.268 views

Category:

Design


0 download

DESCRIPTION

Presented live at FITC Amsterdam 2014 on Feb 24-25, 2014 More details can be found at www.FITC.ca Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa Modern web browsers are capable of producing some amazing audiovisual candy, through new capabilities like HTML5, fast JavaScript, WebGL and Web Audio API. In this session, Carlos talks in detail about his work developing interactive 3D experiences using these technologies. He will take an in-depth look at the production of high-end WebGL projects including Lights, HelloRun and Racer-S, to discuss the graphics, audio and input development techniques used. He shows how to take advantage of the three.js engine to deliver immersive 3D visuals running at high performance on desktop and mobile browsers. This presentation will also cover music visualization and sound effects, using Web Audio API for sound processing and analysis. Carlos also discusses the integration of a broad range of input technologies like touch, mouse, keyboard, accelerometer and Leap Motion controller, along with some interesting lessons learned.

TRANSCRIPT

Page 1: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Developin! Interactive3D Experiences in HTML5

Carlos UlloaHelloEnjoy.com

FITC Amsterdam 2014

Page 2: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

C4RL05@

Page 3: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 4: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 10: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

AUDIOGFX INPUT

Page 11: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Developin!Interactive 3D Experiences inHTML5

Page 12: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 13: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 14: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

1-CLICK

Page 15: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

WORKFLOW

Page 16: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Workflow first& then performance

Page 17: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Test earlyFirst build in 2 weeks

Page 18: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Test oftenOne or two builds per week

Page 19: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

PrototypeFrom concept & design

Page 20: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

GFX

Page 21: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

GAME LOOP

Page 22: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Optimiseyour game loop

Page 23: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Object PoolingMinimise garbage collection

Page 24: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Spread& interpolate over frames

Page 25: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

TIME

Page 26: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Frame RateIndependent

Page 27: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

requestAnimationFrame

Page 28: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

deltaTimeSince the last frame

Page 29: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Multiply by

deltaTimeto update values

per secondinstead of per frame

Page 30: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Cap deltaTime< 0.1 second

Page 31: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

timeScaleMultiplies deltaTime

Page 32: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Keep Syncwith music & video

Page 33: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

THREE.JS

Page 34: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Examplesthreejs.org/examples

Page 37: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

ASSET PIPELINE

Page 38: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 39: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 40: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 42: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

MATH

Page 43: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

QUATVEC MTRX

Page 44: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

VECTORS

Page 45: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

VectorsRepresent position, direction,

velocity, acceleration, forces…

Page 46: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

( x, y, z )Not very intuitive on multiple axes

Page 47: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

object.positionLocal position

Page 48: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

object.scaleLocal scale

Page 49: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

|a|Magnitude

Page 50: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

|a| = 1Normalized

Page 51: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

+

Page 52: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

DOT PRODUCT

Page 53: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 54: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 55: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Dot Product

Page 56: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

|a| |b| cosDot Product

Page 57: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

CROSS PRODUCT

+

Page 58: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 59: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 60: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Cross Product

Page 61: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

|a| |b| sinCross Product

Page 62: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

QUATERNIONS

Page 63: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

QuaternionsRepresent rotations

Page 64: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

object.quaternionLocal rotation

Page 65: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Multiply quaternionsto rotate a vector or another rotation

Page 66: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Slerp quaternionsto interpolate rotations

Page 67: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Avoid Euleron multiple axes

Page 68: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

MATRICES

Page 69: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

MatricesRepresent transformationsi.e. position, rotation, scale

Page 70: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

object.matrixLocal transform

Page 71: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

object.matrixWorldGlobal transform

Page 72: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Multiply matricesto transform a vector or another matrix

Page 73: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Transform methodslookAt, translateXYZ, rotateXYZ,

localToWorld, worldToLocal

Page 74: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

OBJECTS

Page 75: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

HIERARCHY

Page 76: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

GROUPS

Page 77: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

PIVOTS

Page 78: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Children methodsgetDescendants, traverse

Page 79: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Helper ObjectsArrow, Axis, Bounding Box,

Camera, Grid, Lights

Page 80: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

MESHES

Page 81: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

GeometryBuild your own

Page 82: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Vertex ColorPaint, bake or create in code

Page 83: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 84: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

TEXTURES

Page 85: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Mip MapsSmaller versions of the texture

Page 86: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Offset & RepeatTransform textures

Page 87: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

AnisotropyFix mip map artifacts

Page 88: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

WrapRepeat, Clamp, Mirror

Page 89: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Clamp WrapFix artifacts on texture seams

Page 90: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

RGBAUse all channels

Page 91: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 92: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

LIGHTS

Page 93: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Dynamic LightsReal-time surface illumination

Page 94: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Baked LightsBetter quality & performance

Page 95: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

LightmapsGlobal illumination

Page 96: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Vertex BakeQuality depends on geometry

Page 97: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

CAMERA

Page 98: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Avoiddefault camera settings

Page 99: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Near PlaneOcclusion & fill rate performance

Page 100: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Far PlaneHorizon pop up & removed geometry

Page 101: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

FRUSTUMCULLING

Page 102: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Near Far

Page 103: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 104: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 105: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Boundin!Sphere

Page 106: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 107: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 108: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 109: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

FOVVertical angle

Page 110: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

FOV

Page 111: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

FOVDifferent for each scene

Page 112: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

POST PROCESSING

Page 113: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

FXAA

Page 114: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

8X

Page 115: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

8X

Page 116: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

SSAO

Page 117: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Cry En!ine

Page 118: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

GLOW

Page 119: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 120: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

VIGNETTE

Page 121: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 122: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 123: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

OPTIMISE

Page 124: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Profile & measureUnderstand what’s going on

Page 125: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

GPU CPU

Page 126: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

GPU

Page 127: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

GPU?Faster in lower res

Page 128: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

GPUMany pixels, fill rate bound

Page 129: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

CPU

Page 130: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

CPU?Faster with objects disabled

Page 131: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

CPUMany objects, many draw calls

Page 132: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

DRAW CALLS

Page 133: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Minimisestate changes & draw calls

Page 134: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

BatchingCombine meshes with same material

Page 135: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Batch StaticAlways combine static objects

Page 136: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Combine MaterialsUse vertex & textures to differentiate

Page 137: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Texture AtlasCombine textures

Page 138: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 139: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Multiple PassesMultiple draw calls

Page 140: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

SHADERS

Page 141: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Objects < Vertices < Pixels

Page 142: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

VertexInstead of fragment

Page 143: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

PrecissionColors & normals

Page 144: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Alpha TestInstead of Alpha Blend

Page 145: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Fragment MathAvoid pow, sin, cos

Page 146: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Vector MathDot & Cross Product

Page 147: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

LOD

Page 148: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Level of detailSimpler far away objects

Page 149: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Optimisedgeometries or materials

Page 150: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Sprites& particle systems

Page 151: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Skybox & Ringsfor very distant objects

Page 152: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

MOBILE

Page 153: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Mobile < Desktop

Page 154: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Low Polycount> 500

Page 155: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

OverdrawDepends on the GPU

Page 156: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Fill RatedevicePixelRatio

Page 157: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

UpscaleFor higher resolutions

Page 158: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

DownscaleFor higher quality renders

Page 159: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Simple ShadersMinimise fragment complexity

Page 160: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

No BumpsAvoid normal mapping

Page 161: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

No LightsAvoid dynamic lighting or shadows

Page 162: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

No FogOnly on vertex shader

Page 163: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

No PostAvoid full screen effects

Page 164: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

lowpgetShaderPrecisionFormat

Page 165: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

AUDIO

Page 166: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

WEB AUDIO

Page 167: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

AudioProcessing & analysis

Page 168: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Audio NodeWeb Audio API building block

Page 169: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 170: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 171: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Panner Nodefor positional audio

Page 172: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Logarithmicscale for spectrum analysis

Page 173: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa
Page 174: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

INPUT

Page 175: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

KEYBOARD

Page 176: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

AnalogSimulate key pressure

Page 177: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Each keyon its own

Page 178: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Combinekeys to create axes

Page 179: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

MOUSE

Page 180: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Pointer LockRelative mouse movement

Page 181: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Relative MouseAccumulated deltas

Page 182: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

DPI& different screen sizes

Page 183: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

SensitivityUsers ignore settings

Page 184: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

TOUCH

Page 185: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Relativetouch controls

Page 186: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

OrientationHow users hold the device?

Page 187: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

Secondarytouch support

Page 188: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

LEAP MOTION

Page 189: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

SmoothIntroduces lag

Page 190: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

CalibrationDon’t leave it to the user

Page 191: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

RelativeReal time calibration

Page 193: Developing Interactive 3D Experiences in HTML5 with Carlos Ulloa

DANK U

helloenjoy.com