SlideShare une entreprise Scribd logo
1  sur  55
WebGL:
A Crash Course
Tony Parisi
http://www.tonyparisi.com/
About Me
 Serial entrepreneur
 Founder, stealth web startup
 Consulting architect and CTO
 Web3D Co-Creator, VRML and X3D
 Author
Contact Information
tparisi@gmail.com
Skype: auradeluxe
http://twitter.com/auradeluxe http://www.ton
yparisi.com/
WebGL Book Code
https://github.com/tparisi/WebGLBook
Get the Book!
Amazon
http://www.amazon.com/dp/144932357X
O’Reilly Books
http://shop.oreilly.com/product/0636920024729.do
Skybox Engine
https://github.com/tparisi/Skybox
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Agenda
1. An Introduction to WebGL
2. Your First WebGL Program
3. Graphics
4. Animation
5. Interaction
6. Integrating 2D and 3D
7. WebGL in Production
8. Your First WebGL Game
1. An Introduction to WebGL
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
The New 3D API Standard
 OpenGL ES™ in a browser
 JavaScript API bindings
 Supported in nearly all modern browsers and many mobile
devices
 Shipped since early 2011
…and it’s Awesome.
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
WebGL - A Technical Definition
WebGL is a royalty-free, cross-platform API that brings OpenGL
ES 2.0 to the web as a 3D drawing context within HTML, exposed
as low-level Document Object Model interfaces. It uses the
OpenGL shading language, GLSL ES, and can be cleanly
combined with other web content that is layered on top or
underneath the 3D content. It is ideally suited for dynamic 3D web
applications in the JavaScript programming language, and will be
fully integrated in leading web browsers.
http://www.khronos.org/webgl/
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Deconstructing WebGL
 WebGL is an API
 No file format, no DOM
 Uses new kind of Canvas element drawing context
 WebGL is based on OpenGL ES 2.0
 It’s what’s in your phone
 WebGL combines with other web content
 Integrates seamlessly with other stuff on the page
 WebGL is built for dynamic web applications
 Runtime is the web browser, resources are URLs
 WebGL is cross-platform
 WebGL is royalty-free
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
The Anatomy of a WebGL
Application
 Create a Canvas element
 Obtain a drawing context
 Initialize the viewport
 Create one or more buffers
 Create one or more matrices
 Create one or more shaders
 Initialize the shaders
 Draw one or more primitives
Code
Chapter 1/Example 1-1.html
2. Your First WebGL Program
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Three.js – A JavaScript 3D Engine
 Represents WebGL at a high level using standard 3D graphics
concepts
 Feature Rich – math, graphics, animation, interaction, file
loaders
 Object-oriented
 Renders to 3D WebGL or 2D standard Canvas
 Fast, robust, well-maintained
 Chock full of examples
o Not a game engine
o Not an application framework
https://github.com/mrdoob/three.js/
The Square, Revisited
Here’s That
Square Again.
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
A Real Example
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Using a Light to Shade the Scene
// Create a directional light to show off the object
var light = new
THREE.DirectionalLight( 0xffffff, 1.5);
light.position.set(0, 0, 1);
scene.add( light );
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Creating a Shaded, Texture-
Mapped Cube
// Create a shaded, texture-mapped cube and add it to the scene
// First, create the texture map
var mapUrl = "../images/molumen_small_funny_angry_monster.jpg";
var map = THREE.ImageUtils.loadTexture(mapUrl);
// Now, create a Phong material to show shading; pass in the map
var material = new THREE.MeshPhongMaterial({ map: map });
// Create the cube geometry
var geometry = new THREE.CubeGeometry(1, 1, 1);
// And put the geometry and material together into a mesh
cube = new THREE.Mesh(geometry, material);
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Rotating the Object
// Turn it toward the scene, or we won't see the cube shape!
cube.rotation.x = Math.PI / 5;
cube.rotation.y = Math.PI / 5;
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
The Run Loop and
requestAnimationFrame()
function run()
{
// Render the scene
renderer.render( scene, camera );
// Spin the cube for next frame
if (animating)
{
cube.rotation.y -= 0.01;
}
// Ask for another frame
requestAnimationFrame(run);
}
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Handling the Mouse
function addMouseHandler()
{
var dom = renderer.domElement;
dom.addEventListener( 'mouseup', onMouseUp,
false);
}
function onMouseUp (event)
{
event.preventDefault();
animating = !animating;
}
3. Graphics
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Let’s Build a Solar System
 Meshes: built-in primitives
and custom geometry
 Lighting, materials and
textures
 Transform hierarchy
 Points and lines
 Shaders
4. Animation
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Animation Basics
 Time-based animation (vs. frame-based)
 Interpolation and tweening
 Key frames
 Skinned and articulated animation
Interpolation
var keys = [0, 0.25, 1];
var values = [new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0, 2, 5)];
Sample Key Frame Data
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Creating Tweens with Tween.js
MovingBall.prototype.animate = function()
{
var newpos;
if (this.object3D.position.x > 0)
{
newpos = this.object3D.position.x - 6.667;
}
else
{
newpos = this.object3D.position.x + 6.667;
}
new TWEEN.Tween(this.object3D.position)
.to( {
x: newpos
}, 2000).start();
}
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Animating Transforms, Materials,
Lights and Textures
5. Interaction
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Hit Detection, Picking and
Projection
 WebGL has no built-in hit
detection
 Three.js has hit detection helper
– it does the inverse of 3D->2D
projection to find object under the
mouse
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Implementing Rollovers and Clicks
Control.prototype.handleMouseOver = function(x, y)
{
this.mesh.scale.set(1.05, 1.05, 1.05);
this.mesh.material.ambient.setRGB(.777,.777,.777);
}
Control.prototype.handleMouseOut = function(x, y)
{
this.mesh.scale.set(1, 1, 1);
this.mesh.material.ambient.setRGB(.667, .667, .667);
}
Control.prototype.handleMouseDown = function(x, y, hitPoint)
{
if (!this.selected)
{
this.select();
}
else
{
this.deselect();
}
}
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Implementing Dragging
 PlaneDragger class
 Uses THREE.Projector to find hit point in scene
 Pick against invisible plane geometry
 Use Tween with drag to make UI feel more natural and
intuitive
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Camera-Based Interaction
Trackball Controls for Model
Viewing
First-Person Controls for Scene
Navigation
6. Integrating 2D and 3D
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
WebGL’s Secret Weapon
WebGL is a royalty-free, cross-platform API that brings OpenGL ES 2.0 to the web
as a 3D drawing context within HTML, exposed as low-level Document Object
Model interfaces. It uses the OpenGL shading language, GLSL ES, and can be
cleanly combined with other web content that is layered on top or
underneath the 3D content. It is ideally suited for dynamic 3D web applications
in the JavaScript programming language, and will be fully integrated in leading
web browsers.
Breaks down window boundaries
2D overlaid on 3D
3D overlaid on 2D
Canvas2D as a texture
Video as a texture
The ultimate mashup technology
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Combining Dynamic HTML and
WebGL
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Creating Dynamic Textures with
Canvas 2D and HTML5 Video
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Rendering Dynamically Generated
3D Text
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
WebGL for Ultimate Mashups
7. WebGL in Production
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Engine Choices
 Open Source rendering engines/frameworks
 Three.js
 CubicVR
 SceneGL
 GLGE
 Game engines
 Free/Open Source – Gladius, KickJS, Skybox
 Licensed/Pay Models – PlayCanvas, Goo, Turbulenz
 Roll your own?
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Loading 3D Content
 WebGL has no built-in file format
 Three.js loads several types
 COLLADA (XML-based standard)
 Three.js JSON format
 Three.js binary format
 Three.js JSON scene format
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Art Paths
 Export COLLADA from Maya, 3dsMax
 Export Wavefront OBJ art from blender;
convert OBJ to Three.js
 New JSON-based COLLADA format
under development (‘glTF’)
 FBX converters under development
python <path-to-
three.js>/utils/exporters/convert_
obj_three.py -i alien2.obj -o
alien2.js
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Browser Realities
 Detecting WebGL support in your browser
var canvas = document.createElement("canvas");
var gl = null;
var msg = "Your browser does not support WebGL.";
try
{
gl = canvas.getContext("experimental-webgl");
}
catch (e)
{
msg = "Error creating WebGL Context!: " + e.toString();
}
if (!gl)
{
throw new Error(msg);
}
8.Your First WebGL Game
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Let’s Build a Racing Game
 Camera, Character and Control prototype
 Art direction study
 Model previewer
 Particle system lab
 Sound lab
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Camera, Character and Control
The “Gray Box” Prototype
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Keyboard Controls
 Keyboard handling is DOM-based, like any Web app
 Sim.App defines key codes (see
http://www.javascripter.net/faq/keycodes.htm )
/* key codes
37: left
38: up
39: right
40: down
*/
Sim.KeyCodes = {};
Sim.KeyCodes.KEY_LEFT = 37;
Sim.KeyCodes.KEY_UP = 38;
Sim.KeyCodes.KEY_RIGHT = 39;
Sim.KeyCodes.KEY_DOWN = 40;
 Game object defines onKeyUp(), onKeyDown(), passes it to
Player object
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Updating the Camera
Player.prototype.updateCamera = function()
{
var camerapos = new THREE.Vector3(Player.CAMERA_OFFSET_X,
Player.CAMERA_OFFSET_Y, Player.CAMERA_OFFSET_Z);
camerapos.addSelf(this.object3D.position);
this.camera.position.copy(camerapos);
this.camera.lookAt(this.object3D.position);
// Rotate particle system to view-aligned to avoid nasty alpha sorting
artifacts
if (this.exhaust1)
{
this.exhaust1.object3D.rotation.x = this.camera.rotation.x;
}
if (this.exhaust2)
{
this.exhaust2.object3D.rotation.x = this.camera.rotation.x;
}
}
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Collision Detection
RacingGame.prototype.testCollision = function()
{
var playerpos = this.player.object3D.position;
if (playerpos.x > (Environment.ROAD_WIDTH / 2 - (Car.CAR_WIDTH/2)))
{
this.player.bounce();
this.player.object3D.position.x -= 1;
}
if (playerpos.x < -(Environment.ROAD_WIDTH / 2 - (Car.CAR_WIDTH/2)))
{
this.player.bounce();
this.player.object3D.position.x += 1;
}
var i, len = this.cars.length;
for (i = 0; i < len; i++)
{
var carpos = this.cars[i].object3D.position;
var dist = playerpos.distanceTo(carpos);
if (dist < RacingGame.COLLIDE_RADIUS)
{
this.crash(this.cars[i]);
break;
}
}
}
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Art Direction
The Art Direction Study
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
The Heads-Up Display
 WebGL’s 2D/3D integration in action
 Open source speedometer widget by Marcello Barnaba
 Fully configurable
 All HTML5, CSS, JavaScript!
 https://github.com/vjt/canvas-speedometer
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
A Model Previewer
 Models from Turbosquid
 Previewer to get sizes,
inspect normals, get model
stats
 Overall, Tools and
Exporters Still Primitive
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Building a Particle System
The Particle System Lab
 Three.js has a basic built-in
particle system
 But It’s very basic: No
emitters or physics models
 You have to animate it all
yourself
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Adding Sound
The Sound Lab
 Use new <audio>
Element
 Fairly well supported in
browsers
 Other APIs (Moz,
Chrome) not supported
uniformly
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Putting It All Together
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
The State of the Union
 WebGL is a stable, open, free standard for 3D graphics in your
browser
 OpenGL ES under the hood (It’s what’s running on your phone and
tablet)
 Support by most browsers on desktop, laptop, mobile
 Strong standards group maintaining it (www.khronos.org)
 Low-level API
 Many libraries available
 Open-source scene rendering
 Game engines just coming online
 Production capability is still very crude
 Tools and frameworks are young and evolving
 Export from pro tools lacking
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Where To Go From Here
 WebGL development – not easy; but not rocket science
 Small feature set with huge capabilities
 This talk is the tip of a deep iceberg
 Three.js is one of many frameworks
 Look around, or build your own
 The possibilities are limitless!
WebGL: A Crash Course
February 7, 2013
http://www.tonyparisi.com/
Resources
 WebGL Specification
 http://www.khronos.org/webgl/
 Learning Sites
 http://learningwebgl.com/blog/
 http://learningthreejs.com/
 News and Info
 http://www.reddit.com/r/threejs
 http://www.webgl.com/
 Engines
 https://github.com/mrdoob/three.js/
 http://www.glge.org/
 http://www.scenejs.org/
 http://www.cubicvr.org/
 Demos
 http://www.chromeexperiments.com/
webgl
 https://developer.mozilla.org/en-
US/demos/tag/tech:webgl/
 http://chrysaora.com/
 Tools
 http://www.ambiera.com/copperlicht/i
ndex.html
 http://www.sunglass.io/
Let’s Go~
Contact Information
tparisi@gmail.com
Skype: auradeluxe
http://twitter.com/auradeluxe http://www.ton
yparisi.com/
WebGL Book Code
https://github.com/tparisi/WebGLBook
Get the Book!
Amazon
http://www.amazon.com/dp/144932357X
O’Reilly Books
http://shop.oreilly.com/product/0636920024729.do
Skybox Engine
https://github.com/tparisi/Skybox

Contenu connexe

Tendances

Introduction to WebVR Autodesk Forge 2016
Introduction to WebVR Autodesk Forge 2016Introduction to WebVR Autodesk Forge 2016
Introduction to WebVR Autodesk Forge 2016Tony Parisi
 
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"IT Event
 
VueJS Introduction
VueJS IntroductionVueJS Introduction
VueJS IntroductionDavid Ličen
 
HTML5 Dev Conf 2013 Presentation
HTML5 Dev Conf 2013 PresentationHTML5 Dev Conf 2013 Presentation
HTML5 Dev Conf 2013 PresentationIker Jamardo
 
Getting Groovy With Grails
Getting Groovy With GrailsGetting Groovy With Grails
Getting Groovy With GrailsBryan Basham
 
Learning from the Best jQuery Plugins
Learning from the Best jQuery PluginsLearning from the Best jQuery Plugins
Learning from the Best jQuery PluginsMarc Grabanski
 
Making your Angular.js Application accessible
Making your Angular.js Application accessibleMaking your Angular.js Application accessible
Making your Angular.js Application accessibleDirk Ginader
 
An Introduction to WebVR – or How to make your user sick in 60 seconds
An Introduction to WebVR – or How to make your user sick in 60 secondsAn Introduction to WebVR – or How to make your user sick in 60 seconds
An Introduction to WebVR – or How to make your user sick in 60 secondsGeilDanke
 
What Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 AppsWhat Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 AppsDoris Chen
 
Scalable Front-end Development with Vue.JS
Scalable Front-end Development with Vue.JSScalable Front-end Development with Vue.JS
Scalable Front-end Development with Vue.JSGalih Pratama
 
Goodbye, Flatland! An introduction to React VR and what it means for web dev...
Goodbye, Flatland! An introduction to React VR  and what it means for web dev...Goodbye, Flatland! An introduction to React VR  and what it means for web dev...
Goodbye, Flatland! An introduction to React VR and what it means for web dev...GeilDanke
 
State of jQuery '08
State of jQuery '08State of jQuery '08
State of jQuery '08jeresig
 
Webdriver with Thucydides - TdT@Cluj #18
Webdriver with Thucydides - TdT@Cluj #18Webdriver with Thucydides - TdT@Cluj #18
Webdriver with Thucydides - TdT@Cluj #18Tabăra de Testare
 
Collective.amberjack ploneconf2010
Collective.amberjack ploneconf2010Collective.amberjack ploneconf2010
Collective.amberjack ploneconf2010Massimo Azzolini
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overviewjeresig
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performanceAndrew Rota
 

Tendances (20)

Introduction to WebVR Autodesk Forge 2016
Introduction to WebVR Autodesk Forge 2016Introduction to WebVR Autodesk Forge 2016
Introduction to WebVR Autodesk Forge 2016
 
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
 
VueJS Introduction
VueJS IntroductionVueJS Introduction
VueJS Introduction
 
HTML5 Dev Conf 2013 Presentation
HTML5 Dev Conf 2013 PresentationHTML5 Dev Conf 2013 Presentation
HTML5 Dev Conf 2013 Presentation
 
Getting Groovy With Grails
Getting Groovy With GrailsGetting Groovy With Grails
Getting Groovy With Grails
 
Learning from the Best jQuery Plugins
Learning from the Best jQuery PluginsLearning from the Best jQuery Plugins
Learning from the Best jQuery Plugins
 
Making your Angular.js Application accessible
Making your Angular.js Application accessibleMaking your Angular.js Application accessible
Making your Angular.js Application accessible
 
GWT Reloaded
GWT ReloadedGWT Reloaded
GWT Reloaded
 
An Introduction to WebVR – or How to make your user sick in 60 seconds
An Introduction to WebVR – or How to make your user sick in 60 secondsAn Introduction to WebVR – or How to make your user sick in 60 seconds
An Introduction to WebVR – or How to make your user sick in 60 seconds
 
Meet VueJs
Meet VueJsMeet VueJs
Meet VueJs
 
Introducing GWT Polymer (vaadin)
Introducing GWT Polymer (vaadin)Introducing GWT Polymer (vaadin)
Introducing GWT Polymer (vaadin)
 
Rock GWT UI's with Polymer Elements
Rock GWT UI's with Polymer ElementsRock GWT UI's with Polymer Elements
Rock GWT UI's with Polymer Elements
 
What Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 AppsWhat Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 Apps
 
Scalable Front-end Development with Vue.JS
Scalable Front-end Development with Vue.JSScalable Front-end Development with Vue.JS
Scalable Front-end Development with Vue.JS
 
Goodbye, Flatland! An introduction to React VR and what it means for web dev...
Goodbye, Flatland! An introduction to React VR  and what it means for web dev...Goodbye, Flatland! An introduction to React VR  and what it means for web dev...
Goodbye, Flatland! An introduction to React VR and what it means for web dev...
 
State of jQuery '08
State of jQuery '08State of jQuery '08
State of jQuery '08
 
Webdriver with Thucydides - TdT@Cluj #18
Webdriver with Thucydides - TdT@Cluj #18Webdriver with Thucydides - TdT@Cluj #18
Webdriver with Thucydides - TdT@Cluj #18
 
Collective.amberjack ploneconf2010
Collective.amberjack ploneconf2010Collective.amberjack ploneconf2010
Collective.amberjack ploneconf2010
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overview
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
 

En vedette

The Web Eats Everything In Its Path Fall 2014
The Web Eats Everything In Its Path Fall 2014The Web Eats Everything In Its Path Fall 2014
The Web Eats Everything In Its Path Fall 2014Tony Parisi
 
WebGL Primetime!
WebGL Primetime!WebGL Primetime!
WebGL Primetime!Tony Parisi
 
VR Without Borders RIVER WebVR April 2015
VR Without Borders RIVER WebVR April 2015VR Without Borders RIVER WebVR April 2015
VR Without Borders RIVER WebVR April 2015Tony Parisi
 
Introduction to webGL
Introduction to webGLIntroduction to webGL
Introduction to webGL志鴻 詹
 
WebGL - An Overview
WebGL - An OverviewWebGL - An Overview
WebGL - An OverviewJens Arps
 
3D Image visualization
3D Image visualization3D Image visualization
3D Image visualizationalok ray
 
Kena roots products-superiority-presentation
Kena roots products-superiority-presentationKena roots products-superiority-presentation
Kena roots products-superiority-presentationDr. Hani Malkawi
 
Claims
ClaimsClaims
Claimsaec111
 
Sametova revoluce
Sametova revoluceSametova revoluce
Sametova revolucexxxxj
 
BillingViews Payments Puzzle
BillingViews Payments PuzzleBillingViews Payments Puzzle
BillingViews Payments PuzzleBillingViews
 
Web Site Proposal for Dove Rental Co.
Web Site Proposal for Dove Rental Co.Web Site Proposal for Dove Rental Co.
Web Site Proposal for Dove Rental Co.Robin Horne
 
Sandra yurley garcía monet
Sandra yurley garcía monetSandra yurley garcía monet
Sandra yurley garcía monetCaro Spin
 
The Technion Library as a physical environment - July 2012
The Technion Library as a physical environment - July 2012The Technion Library as a physical environment - July 2012
The Technion Library as a physical environment - July 2012Dalia Dolev
 
Por qué estudiar electrónica
Por qué estudiar electrónicaPor qué estudiar electrónica
Por qué estudiar electrónicaAlex Rosas
 

En vedette (20)

The Web Eats Everything In Its Path Fall 2014
The Web Eats Everything In Its Path Fall 2014The Web Eats Everything In Its Path Fall 2014
The Web Eats Everything In Its Path Fall 2014
 
WebGL Primetime!
WebGL Primetime!WebGL Primetime!
WebGL Primetime!
 
VR Without Borders RIVER WebVR April 2015
VR Without Borders RIVER WebVR April 2015VR Without Borders RIVER WebVR April 2015
VR Without Borders RIVER WebVR April 2015
 
Introduction to webGL
Introduction to webGLIntroduction to webGL
Introduction to webGL
 
WebGL - An Overview
WebGL - An OverviewWebGL - An Overview
WebGL - An Overview
 
3D Image visualization
3D Image visualization3D Image visualization
3D Image visualization
 
Invento
InventoInvento
Invento
 
Kena roots products-superiority-presentation
Kena roots products-superiority-presentationKena roots products-superiority-presentation
Kena roots products-superiority-presentation
 
Claims
ClaimsClaims
Claims
 
Sametova revoluce
Sametova revoluceSametova revoluce
Sametova revoluce
 
BillingViews Payments Puzzle
BillingViews Payments PuzzleBillingViews Payments Puzzle
BillingViews Payments Puzzle
 
Digital Marketing Campaign
Digital Marketing CampaignDigital Marketing Campaign
Digital Marketing Campaign
 
Albrecht Durer
Albrecht DurerAlbrecht Durer
Albrecht Durer
 
Cover
CoverCover
Cover
 
Malmöhus
MalmöhusMalmöhus
Malmöhus
 
Web Site Proposal for Dove Rental Co.
Web Site Proposal for Dove Rental Co.Web Site Proposal for Dove Rental Co.
Web Site Proposal for Dove Rental Co.
 
Popeco
PopecoPopeco
Popeco
 
Sandra yurley garcía monet
Sandra yurley garcía monetSandra yurley garcía monet
Sandra yurley garcía monet
 
The Technion Library as a physical environment - July 2012
The Technion Library as a physical environment - July 2012The Technion Library as a physical environment - July 2012
The Technion Library as a physical environment - July 2012
 
Por qué estudiar electrónica
Por qué estudiar electrónicaPor qué estudiar electrónica
Por qué estudiar electrónica
 

Similaire à WebGL Crash Course

WebGL: The Next Generation
WebGL:  The Next GenerationWebGL:  The Next Generation
WebGL: The Next GenerationTony Parisi
 
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony ParisiWT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony ParisiAMD Developer Central
 
Developing Web Graphics with WebGL
Developing Web Graphics with WebGLDeveloping Web Graphics with WebGL
Developing Web Graphics with WebGLTony Parisi
 
WebGL - It's GO Time
WebGL - It's GO TimeWebGL - It's GO Time
WebGL - It's GO TimeTony Parisi
 
Debugging War Stories & Strategies to Survive on RejectJS 2014
Debugging War Stories & Strategies to Survive on RejectJS 2014Debugging War Stories & Strategies to Survive on RejectJS 2014
Debugging War Stories & Strategies to Survive on RejectJS 2014Johannes Weber
 
WebGL, HTML5 and How the Mobile Web Was Won
WebGL, HTML5 and How the Mobile Web Was WonWebGL, HTML5 and How the Mobile Web Was Won
WebGL, HTML5 and How the Mobile Web Was WonTony Parisi
 
WebGL demos showcase
WebGL demos showcaseWebGL demos showcase
WebGL demos showcaseYukio Andoh
 
Leaving Flatland: Getting Started with WebGL- SXSW 2012
Leaving Flatland: Getting Started with WebGL- SXSW 2012Leaving Flatland: Getting Started with WebGL- SXSW 2012
Leaving Flatland: Getting Started with WebGL- SXSW 2012philogb
 
140716 : 同業前端聚會分享 - webgl 與 three.js
140716 : 同業前端聚會分享 - webgl 與 three.js140716 : 同業前端聚會分享 - webgl 與 three.js
140716 : 同業前端聚會分享 - webgl 與 three.jsangelliya00
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webpjcozzi
 
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]JavaScript Meetup HCMC
 
WebGL For Game Development 2012
WebGL For Game Development 2012WebGL For Game Development 2012
WebGL For Game Development 2012Tony Parisi
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web TechnologiesPerttu Myry
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Domkaven yan
 
MeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analystsMeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analystsSimo Ahava
 
Building Rich Internet Applications with HTML5 and WebGL
Building Rich Internet Applications with HTML5 and WebGLBuilding Rich Internet Applications with HTML5 and WebGL
Building Rich Internet Applications with HTML5 and WebGLTony Parisi
 
HTML5DevConf 2013 (October): WebGL is a game changer!
HTML5DevConf 2013 (October): WebGL is a game changer!HTML5DevConf 2013 (October): WebGL is a game changer!
HTML5DevConf 2013 (October): WebGL is a game changer!Iker Jamardo
 

Similaire à WebGL Crash Course (20)

WebGL: The Next Generation
WebGL:  The Next GenerationWebGL:  The Next Generation
WebGL: The Next Generation
 
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony ParisiWT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
 
Developing Web Graphics with WebGL
Developing Web Graphics with WebGLDeveloping Web Graphics with WebGL
Developing Web Graphics with WebGL
 
WebGL - It's GO Time
WebGL - It's GO TimeWebGL - It's GO Time
WebGL - It's GO Time
 
Intro to Three.js
Intro to Three.jsIntro to Three.js
Intro to Three.js
 
Debugging War Stories & Strategies to Survive on RejectJS 2014
Debugging War Stories & Strategies to Survive on RejectJS 2014Debugging War Stories & Strategies to Survive on RejectJS 2014
Debugging War Stories & Strategies to Survive on RejectJS 2014
 
WebGL, HTML5 and How the Mobile Web Was Won
WebGL, HTML5 and How the Mobile Web Was WonWebGL, HTML5 and How the Mobile Web Was Won
WebGL, HTML5 and How the Mobile Web Was Won
 
WebGL demos showcase
WebGL demos showcaseWebGL demos showcase
WebGL demos showcase
 
WebGL Awesomeness
WebGL AwesomenessWebGL Awesomeness
WebGL Awesomeness
 
WebGL and three.js
WebGL and three.jsWebGL and three.js
WebGL and three.js
 
Leaving Flatland: Getting Started with WebGL- SXSW 2012
Leaving Flatland: Getting Started with WebGL- SXSW 2012Leaving Flatland: Getting Started with WebGL- SXSW 2012
Leaving Flatland: Getting Started with WebGL- SXSW 2012
 
140716 : 同業前端聚會分享 - webgl 與 three.js
140716 : 同業前端聚會分享 - webgl 與 three.js140716 : 同業前端聚會分享 - webgl 與 three.js
140716 : 同業前端聚會分享 - webgl 與 three.js
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open web
 
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
 
WebGL For Game Development 2012
WebGL For Game Development 2012WebGL For Game Development 2012
WebGL For Game Development 2012
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web Technologies
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 
MeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analystsMeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
 
Building Rich Internet Applications with HTML5 and WebGL
Building Rich Internet Applications with HTML5 and WebGLBuilding Rich Internet Applications with HTML5 and WebGL
Building Rich Internet Applications with HTML5 and WebGL
 
HTML5DevConf 2013 (October): WebGL is a game changer!
HTML5DevConf 2013 (October): WebGL is a game changer!HTML5DevConf 2013 (October): WebGL is a game changer!
HTML5DevConf 2013 (October): WebGL is a game changer!
 

Plus de Tony Parisi

The New Fine Arts
The New Fine ArtsThe New Fine Arts
The New Fine ArtsTony Parisi
 
Face the Future: Computing in an Augmented World
Face the Future: Computing in an Augmented WorldFace the Future: Computing in an Augmented World
Face the Future: Computing in an Augmented WorldTony Parisi
 
Powering the VR/AR Ecosystem 2017-01-17
Powering the VR/AR Ecosystem 2017-01-17Powering the VR/AR Ecosystem 2017-01-17
Powering the VR/AR Ecosystem 2017-01-17Tony Parisi
 
WebVR Ecosystem and API Update
WebVR Ecosystem and API UpdateWebVR Ecosystem and API Update
WebVR Ecosystem and API UpdateTony Parisi
 
Foundations of the Immersive Web
Foundations of the Immersive WebFoundations of the Immersive Web
Foundations of the Immersive WebTony Parisi
 
The Immersive Web
The Immersive WebThe Immersive Web
The Immersive WebTony Parisi
 
Virtually Anyone
Virtually AnyoneVirtually Anyone
Virtually AnyoneTony Parisi
 
React-VR: An Early Experiment with React and WebGL for VR Development
React-VR: An Early Experiment with React and WebGL for VR DevelopmentReact-VR: An Early Experiment with React and WebGL for VR Development
React-VR: An Early Experiment with React and WebGL for VR DevelopmentTony Parisi
 
Vrml, or There and Back Again
Vrml, or There and Back AgainVrml, or There and Back Again
Vrml, or There and Back AgainTony Parisi
 
The Coming Distribution War
The Coming Distribution WarThe Coming Distribution War
The Coming Distribution WarTony Parisi
 
Browser-Based Virtual Reality April 2015
Browser-Based Virtual Reality April 2015Browser-Based Virtual Reality April 2015
Browser-Based Virtual Reality April 2015Tony Parisi
 
glTF and the WebGL Art Pipeline March 2015
glTF and the WebGL Art Pipeline March 2015glTF and the WebGL Art Pipeline March 2015
glTF and the WebGL Art Pipeline March 2015Tony Parisi
 
An Introduction to Web VR January 2015
An Introduction to Web VR January 2015An Introduction to Web VR January 2015
An Introduction to Web VR January 2015Tony Parisi
 
Up And Running With Web VR Fall 2014
Up And Running With Web VR Fall 2014Up And Running With Web VR Fall 2014
Up And Running With Web VR Fall 2014Tony Parisi
 
WebGL, WebVR and the Metaverse
WebGL, WebVR and the MetaverseWebGL, WebVR and the Metaverse
WebGL, WebVR and the MetaverseTony Parisi
 
And Who Shall Control the Metaverse?
And Who Shall Control the Metaverse?And Who Shall Control the Metaverse?
And Who Shall Control the Metaverse?Tony Parisi
 
Virtually Anywhere
Virtually AnywhereVirtually Anywhere
Virtually AnywhereTony Parisi
 
The Browser As Console - HTML5 and WebGL for Game Development
The Browser As Console - HTML5 and WebGL for Game DevelopmentThe Browser As Console - HTML5 and WebGL for Game Development
The Browser As Console - HTML5 and WebGL for Game DevelopmentTony Parisi
 
glTF Update with Tony Parisi WebGL Meetup August 2013
glTF Update with Tony Parisi WebGL Meetup August 2013glTF Update with Tony Parisi WebGL Meetup August 2013
glTF Update with Tony Parisi WebGL Meetup August 2013Tony Parisi
 

Plus de Tony Parisi (19)

The New Fine Arts
The New Fine ArtsThe New Fine Arts
The New Fine Arts
 
Face the Future: Computing in an Augmented World
Face the Future: Computing in an Augmented WorldFace the Future: Computing in an Augmented World
Face the Future: Computing in an Augmented World
 
Powering the VR/AR Ecosystem 2017-01-17
Powering the VR/AR Ecosystem 2017-01-17Powering the VR/AR Ecosystem 2017-01-17
Powering the VR/AR Ecosystem 2017-01-17
 
WebVR Ecosystem and API Update
WebVR Ecosystem and API UpdateWebVR Ecosystem and API Update
WebVR Ecosystem and API Update
 
Foundations of the Immersive Web
Foundations of the Immersive WebFoundations of the Immersive Web
Foundations of the Immersive Web
 
The Immersive Web
The Immersive WebThe Immersive Web
The Immersive Web
 
Virtually Anyone
Virtually AnyoneVirtually Anyone
Virtually Anyone
 
React-VR: An Early Experiment with React and WebGL for VR Development
React-VR: An Early Experiment with React and WebGL for VR DevelopmentReact-VR: An Early Experiment with React and WebGL for VR Development
React-VR: An Early Experiment with React and WebGL for VR Development
 
Vrml, or There and Back Again
Vrml, or There and Back AgainVrml, or There and Back Again
Vrml, or There and Back Again
 
The Coming Distribution War
The Coming Distribution WarThe Coming Distribution War
The Coming Distribution War
 
Browser-Based Virtual Reality April 2015
Browser-Based Virtual Reality April 2015Browser-Based Virtual Reality April 2015
Browser-Based Virtual Reality April 2015
 
glTF and the WebGL Art Pipeline March 2015
glTF and the WebGL Art Pipeline March 2015glTF and the WebGL Art Pipeline March 2015
glTF and the WebGL Art Pipeline March 2015
 
An Introduction to Web VR January 2015
An Introduction to Web VR January 2015An Introduction to Web VR January 2015
An Introduction to Web VR January 2015
 
Up And Running With Web VR Fall 2014
Up And Running With Web VR Fall 2014Up And Running With Web VR Fall 2014
Up And Running With Web VR Fall 2014
 
WebGL, WebVR and the Metaverse
WebGL, WebVR and the MetaverseWebGL, WebVR and the Metaverse
WebGL, WebVR and the Metaverse
 
And Who Shall Control the Metaverse?
And Who Shall Control the Metaverse?And Who Shall Control the Metaverse?
And Who Shall Control the Metaverse?
 
Virtually Anywhere
Virtually AnywhereVirtually Anywhere
Virtually Anywhere
 
The Browser As Console - HTML5 and WebGL for Game Development
The Browser As Console - HTML5 and WebGL for Game DevelopmentThe Browser As Console - HTML5 and WebGL for Game Development
The Browser As Console - HTML5 and WebGL for Game Development
 
glTF Update with Tony Parisi WebGL Meetup August 2013
glTF Update with Tony Parisi WebGL Meetup August 2013glTF Update with Tony Parisi WebGL Meetup August 2013
glTF Update with Tony Parisi WebGL Meetup August 2013
 

WebGL Crash Course

  • 1. WebGL: A Crash Course Tony Parisi http://www.tonyparisi.com/
  • 2. About Me  Serial entrepreneur  Founder, stealth web startup  Consulting architect and CTO  Web3D Co-Creator, VRML and X3D  Author Contact Information tparisi@gmail.com Skype: auradeluxe http://twitter.com/auradeluxe http://www.ton yparisi.com/ WebGL Book Code https://github.com/tparisi/WebGLBook Get the Book! Amazon http://www.amazon.com/dp/144932357X O’Reilly Books http://shop.oreilly.com/product/0636920024729.do Skybox Engine https://github.com/tparisi/Skybox
  • 3. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Agenda 1. An Introduction to WebGL 2. Your First WebGL Program 3. Graphics 4. Animation 5. Interaction 6. Integrating 2D and 3D 7. WebGL in Production 8. Your First WebGL Game
  • 5. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ The New 3D API Standard  OpenGL ES™ in a browser  JavaScript API bindings  Supported in nearly all modern browsers and many mobile devices  Shipped since early 2011 …and it’s Awesome.
  • 6. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ WebGL - A Technical Definition WebGL is a royalty-free, cross-platform API that brings OpenGL ES 2.0 to the web as a 3D drawing context within HTML, exposed as low-level Document Object Model interfaces. It uses the OpenGL shading language, GLSL ES, and can be cleanly combined with other web content that is layered on top or underneath the 3D content. It is ideally suited for dynamic 3D web applications in the JavaScript programming language, and will be fully integrated in leading web browsers. http://www.khronos.org/webgl/
  • 7. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Deconstructing WebGL  WebGL is an API  No file format, no DOM  Uses new kind of Canvas element drawing context  WebGL is based on OpenGL ES 2.0  It’s what’s in your phone  WebGL combines with other web content  Integrates seamlessly with other stuff on the page  WebGL is built for dynamic web applications  Runtime is the web browser, resources are URLs  WebGL is cross-platform  WebGL is royalty-free
  • 8. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ The Anatomy of a WebGL Application  Create a Canvas element  Obtain a drawing context  Initialize the viewport  Create one or more buffers  Create one or more matrices  Create one or more shaders  Initialize the shaders  Draw one or more primitives Code Chapter 1/Example 1-1.html
  • 9. 2. Your First WebGL Program
  • 10. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Three.js – A JavaScript 3D Engine  Represents WebGL at a high level using standard 3D graphics concepts  Feature Rich – math, graphics, animation, interaction, file loaders  Object-oriented  Renders to 3D WebGL or 2D standard Canvas  Fast, robust, well-maintained  Chock full of examples o Not a game engine o Not an application framework https://github.com/mrdoob/three.js/
  • 11. The Square, Revisited Here’s That Square Again.
  • 12. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ A Real Example
  • 13. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Using a Light to Shade the Scene // Create a directional light to show off the object var light = new THREE.DirectionalLight( 0xffffff, 1.5); light.position.set(0, 0, 1); scene.add( light );
  • 14. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Creating a Shaded, Texture- Mapped Cube // Create a shaded, texture-mapped cube and add it to the scene // First, create the texture map var mapUrl = "../images/molumen_small_funny_angry_monster.jpg"; var map = THREE.ImageUtils.loadTexture(mapUrl); // Now, create a Phong material to show shading; pass in the map var material = new THREE.MeshPhongMaterial({ map: map }); // Create the cube geometry var geometry = new THREE.CubeGeometry(1, 1, 1); // And put the geometry and material together into a mesh cube = new THREE.Mesh(geometry, material);
  • 15. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Rotating the Object // Turn it toward the scene, or we won't see the cube shape! cube.rotation.x = Math.PI / 5; cube.rotation.y = Math.PI / 5;
  • 16. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ The Run Loop and requestAnimationFrame() function run() { // Render the scene renderer.render( scene, camera ); // Spin the cube for next frame if (animating) { cube.rotation.y -= 0.01; } // Ask for another frame requestAnimationFrame(run); }
  • 17. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Handling the Mouse function addMouseHandler() { var dom = renderer.domElement; dom.addEventListener( 'mouseup', onMouseUp, false); } function onMouseUp (event) { event.preventDefault(); animating = !animating; }
  • 19. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Let’s Build a Solar System  Meshes: built-in primitives and custom geometry  Lighting, materials and textures  Transform hierarchy  Points and lines  Shaders
  • 21. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Animation Basics  Time-based animation (vs. frame-based)  Interpolation and tweening  Key frames  Skinned and articulated animation Interpolation var keys = [0, 0.25, 1]; var values = [new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, 1, 0), new THREE.Vector3(0, 2, 5)]; Sample Key Frame Data
  • 22. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Creating Tweens with Tween.js MovingBall.prototype.animate = function() { var newpos; if (this.object3D.position.x > 0) { newpos = this.object3D.position.x - 6.667; } else { newpos = this.object3D.position.x + 6.667; } new TWEEN.Tween(this.object3D.position) .to( { x: newpos }, 2000).start(); }
  • 23. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Animating Transforms, Materials, Lights and Textures
  • 25. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Hit Detection, Picking and Projection  WebGL has no built-in hit detection  Three.js has hit detection helper – it does the inverse of 3D->2D projection to find object under the mouse
  • 26. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Implementing Rollovers and Clicks Control.prototype.handleMouseOver = function(x, y) { this.mesh.scale.set(1.05, 1.05, 1.05); this.mesh.material.ambient.setRGB(.777,.777,.777); } Control.prototype.handleMouseOut = function(x, y) { this.mesh.scale.set(1, 1, 1); this.mesh.material.ambient.setRGB(.667, .667, .667); } Control.prototype.handleMouseDown = function(x, y, hitPoint) { if (!this.selected) { this.select(); } else { this.deselect(); } }
  • 27. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Implementing Dragging  PlaneDragger class  Uses THREE.Projector to find hit point in scene  Pick against invisible plane geometry  Use Tween with drag to make UI feel more natural and intuitive
  • 28. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Camera-Based Interaction Trackball Controls for Model Viewing First-Person Controls for Scene Navigation
  • 30. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ WebGL’s Secret Weapon WebGL is a royalty-free, cross-platform API that brings OpenGL ES 2.0 to the web as a 3D drawing context within HTML, exposed as low-level Document Object Model interfaces. It uses the OpenGL shading language, GLSL ES, and can be cleanly combined with other web content that is layered on top or underneath the 3D content. It is ideally suited for dynamic 3D web applications in the JavaScript programming language, and will be fully integrated in leading web browsers. Breaks down window boundaries 2D overlaid on 3D 3D overlaid on 2D Canvas2D as a texture Video as a texture The ultimate mashup technology
  • 31. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Combining Dynamic HTML and WebGL
  • 32. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Creating Dynamic Textures with Canvas 2D and HTML5 Video
  • 33. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Rendering Dynamically Generated 3D Text
  • 34. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ WebGL for Ultimate Mashups
  • 35. 7. WebGL in Production
  • 36. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Engine Choices  Open Source rendering engines/frameworks  Three.js  CubicVR  SceneGL  GLGE  Game engines  Free/Open Source – Gladius, KickJS, Skybox  Licensed/Pay Models – PlayCanvas, Goo, Turbulenz  Roll your own?
  • 37. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Loading 3D Content  WebGL has no built-in file format  Three.js loads several types  COLLADA (XML-based standard)  Three.js JSON format  Three.js binary format  Three.js JSON scene format
  • 38. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Art Paths  Export COLLADA from Maya, 3dsMax  Export Wavefront OBJ art from blender; convert OBJ to Three.js  New JSON-based COLLADA format under development (‘glTF’)  FBX converters under development python <path-to- three.js>/utils/exporters/convert_ obj_three.py -i alien2.obj -o alien2.js
  • 39. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Browser Realities  Detecting WebGL support in your browser var canvas = document.createElement("canvas"); var gl = null; var msg = "Your browser does not support WebGL."; try { gl = canvas.getContext("experimental-webgl"); } catch (e) { msg = "Error creating WebGL Context!: " + e.toString(); } if (!gl) { throw new Error(msg); }
  • 41. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Let’s Build a Racing Game  Camera, Character and Control prototype  Art direction study  Model previewer  Particle system lab  Sound lab
  • 42. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Camera, Character and Control The “Gray Box” Prototype
  • 43. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Keyboard Controls  Keyboard handling is DOM-based, like any Web app  Sim.App defines key codes (see http://www.javascripter.net/faq/keycodes.htm ) /* key codes 37: left 38: up 39: right 40: down */ Sim.KeyCodes = {}; Sim.KeyCodes.KEY_LEFT = 37; Sim.KeyCodes.KEY_UP = 38; Sim.KeyCodes.KEY_RIGHT = 39; Sim.KeyCodes.KEY_DOWN = 40;  Game object defines onKeyUp(), onKeyDown(), passes it to Player object
  • 44. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Updating the Camera Player.prototype.updateCamera = function() { var camerapos = new THREE.Vector3(Player.CAMERA_OFFSET_X, Player.CAMERA_OFFSET_Y, Player.CAMERA_OFFSET_Z); camerapos.addSelf(this.object3D.position); this.camera.position.copy(camerapos); this.camera.lookAt(this.object3D.position); // Rotate particle system to view-aligned to avoid nasty alpha sorting artifacts if (this.exhaust1) { this.exhaust1.object3D.rotation.x = this.camera.rotation.x; } if (this.exhaust2) { this.exhaust2.object3D.rotation.x = this.camera.rotation.x; } }
  • 45. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Collision Detection RacingGame.prototype.testCollision = function() { var playerpos = this.player.object3D.position; if (playerpos.x > (Environment.ROAD_WIDTH / 2 - (Car.CAR_WIDTH/2))) { this.player.bounce(); this.player.object3D.position.x -= 1; } if (playerpos.x < -(Environment.ROAD_WIDTH / 2 - (Car.CAR_WIDTH/2))) { this.player.bounce(); this.player.object3D.position.x += 1; } var i, len = this.cars.length; for (i = 0; i < len; i++) { var carpos = this.cars[i].object3D.position; var dist = playerpos.distanceTo(carpos); if (dist < RacingGame.COLLIDE_RADIUS) { this.crash(this.cars[i]); break; } } }
  • 46. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Art Direction The Art Direction Study
  • 47. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ The Heads-Up Display  WebGL’s 2D/3D integration in action  Open source speedometer widget by Marcello Barnaba  Fully configurable  All HTML5, CSS, JavaScript!  https://github.com/vjt/canvas-speedometer
  • 48. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ A Model Previewer  Models from Turbosquid  Previewer to get sizes, inspect normals, get model stats  Overall, Tools and Exporters Still Primitive
  • 49. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Building a Particle System The Particle System Lab  Three.js has a basic built-in particle system  But It’s very basic: No emitters or physics models  You have to animate it all yourself
  • 50. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Adding Sound The Sound Lab  Use new <audio> Element  Fairly well supported in browsers  Other APIs (Moz, Chrome) not supported uniformly
  • 51. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Putting It All Together
  • 52. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ The State of the Union  WebGL is a stable, open, free standard for 3D graphics in your browser  OpenGL ES under the hood (It’s what’s running on your phone and tablet)  Support by most browsers on desktop, laptop, mobile  Strong standards group maintaining it (www.khronos.org)  Low-level API  Many libraries available  Open-source scene rendering  Game engines just coming online  Production capability is still very crude  Tools and frameworks are young and evolving  Export from pro tools lacking
  • 53. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Where To Go From Here  WebGL development – not easy; but not rocket science  Small feature set with huge capabilities  This talk is the tip of a deep iceberg  Three.js is one of many frameworks  Look around, or build your own  The possibilities are limitless!
  • 54. WebGL: A Crash Course February 7, 2013 http://www.tonyparisi.com/ Resources  WebGL Specification  http://www.khronos.org/webgl/  Learning Sites  http://learningwebgl.com/blog/  http://learningthreejs.com/  News and Info  http://www.reddit.com/r/threejs  http://www.webgl.com/  Engines  https://github.com/mrdoob/three.js/  http://www.glge.org/  http://www.scenejs.org/  http://www.cubicvr.org/  Demos  http://www.chromeexperiments.com/ webgl  https://developer.mozilla.org/en- US/demos/tag/tech:webgl/  http://chrysaora.com/  Tools  http://www.ambiera.com/copperlicht/i ndex.html  http://www.sunglass.io/
  • 55. Let’s Go~ Contact Information tparisi@gmail.com Skype: auradeluxe http://twitter.com/auradeluxe http://www.ton yparisi.com/ WebGL Book Code https://github.com/tparisi/WebGLBook Get the Book! Amazon http://www.amazon.com/dp/144932357X O’Reilly Books http://shop.oreilly.com/product/0636920024729.do Skybox Engine https://github.com/tparisi/Skybox