SlideShare a Scribd company logo
1 of 24
an introduction to
WebGL
tony parisi
january 23, 2014
about me
serial entrepreneur
founder, Vizi
co-organizer, SF WebGL Meetup
co-creator, VRML and X3D web standards
designer, glTF
SF WebGL Meetup
author
http://www.meetup.com/WebGL-Developers-Meetup/
contact information
tparisi@gmail.com
skype: auradeluxe
http://twitter.com/auradeluxe
p://www.tonyparisi.com/
http://www.learningwebgl.com/

book source code
https://github.com/tparisi/WebGLBook
https://github.com/tparisi/Programming3DApplications
htt

get the books!
WebGL: Up and Running
http://www.amazon.com/dp/144932357X
Programming 3D Applications with HTML and WebGL
http://www.amazon.com/Programming-ApplicationsHTML5-WebGL-Visualization/dp/1449362966

http://www.tonyparisi.com

1/22/20
14
we live in a 3D world

image: http://www.clermonttaichi.com/

http://www.tonyparisi.com

1/22/20
14
our media is also 3D

(though it’s usually
rendered on flat screens)

http://www.tonyparisi.com

1/22/20
14
built with dedicated computers
and expensive software…

http://www.tonyparisi.com

1/22/20
14
until now.

100,000 Stars Google Experiment
http://workshop.chromeexperiments.com/stars/

http://www.tonyparisi.com

1/22/20
14
breakthrough applications

60FPS

ported in 5 days Unreal native C++ engine -> JavaScriptEmscripten + asm.js
http://www.tonyparisi.com

1/22/20
14
the 3D API standard for the
web
OpenGL ES™ in a browser
JavaScript API bindings
shipped since early 2011
supported in all modern browsers
•
•
•
•
•
•

desktop Safari, Firefox, Chrome, Opera, Internet Explorer
iOS mobile Safari – iAds only
Android – mobile Chrome, mobile Firefox
Amazon Silk Browser, Kindle Fire OS
Blackberry, Tizen, Firefox OS
Surface (Windows 8.1)

over 1B served
http://www.tonyparisi.com

1/22/20
14
how WebGL works
JavaScript drawing API
draw to a canvas element using a special context
low-level drawing – buffers, primitives, textures and shaders
accelerated by graphics hardware (GPU)
can draw 2D as well as 3D graphics

there is no file format; no markup language; no DOM.

http://www.tonyparisi.com

1/22/20
14
a simple WebGL program
1. create a <canvas> element
2. obtain a drawing context
3. initialize the viewport

4. create one or more buffers
5. create one or more matrices
6. create one or more shaders

7. initialize the shaders
8. draw one or more primitives

http://www.tonyparisi.com

1/22/20
14
create the canvas, context and
viewport
function initWebGL(canvas) {
var gl = null;
var msg = "Your browser does not support WebGL, " +
"or it is not enabled by default.";
try
{
gl = canvas.getContext(“webgl");
}
catch (e)
{
msg = "Error creating WebGL Context!: " + e.toString();
}

detect WebGL

if (!gl)
{
alert(msg);
throw new Error(msg);
}
return gl;
}
function initViewport(gl, canvas)
{
gl.viewport(0, 0, canvas.width, canvas.height);
}

set WebGL drawing
region

http://www.tonyparisi.com

1/22/20
14
buffers and typed arrays
var vertexBuffer;
vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
var verts = [
// Front face
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
// Back face
-1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
1.0, 1.0, -1.0,
1.0, -1.0, -1.0,
…

WebGL drawing functions
use buffers of data

new low-level data type
stores arrays of floats
and ints compactly

];
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(verts), gl.STATIC_DRAW);
http://www.tonyparisi.com

1/22/20
14
shaders
var vertexShaderSource =
"
"
"
"
"
"
"
"
"
"
"
"

the vertex shader
attribute vec3 vertexPos;n" +
attribute vec2 texCoord;n" +
transforms model-space
uniform mat4 modelViewMatrix;n" +
positions into screen
uniform mat4 projectionMatrix;n" +
space
varying vec2 vTexCoord;n" +
void main(void) {n" +
// Return the transformed and projected vertex valuen" +
gl_Position = projectionMatrix * modelViewMatrix * n" +
vec4(vertexPos, 1.0);n" +
// Output the texture coordinate in vTexCoordn" +
vTexCoord = texCoord;n" +
}n";
the fragment shader
outputs a color value for
each pixel

var fragmentShaderSource =
" precision mediump float;n" +
" varying vec2 vTexCoord;n" +
" uniform sampler2D uSampler;n" +
" void main(void) {n" +
" // Return the pixel color: always output whiten" +
" gl_FragColor = texture2D(uSampler, vec2(vTexCoord.s, vTexCoord.t));n" +
"}n";
http://www.tonyparisi.com

1/22/20
14
drawing
function draw(gl, obj) {
// clear the background (with black)
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.enable(gl.DEPTH_TEST);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

clear the canvas

// set the shader to use
gl.useProgram(shaderProgram);

set the shader

// connect up the shader parameters: vertex position, texture coordinate,
// projection/model matrices and texture
// set up the buffers
gl.bindBuffer(gl.ARRAY_BUFFER, obj.buffer);
gl.vertexAttribPointer(shaderVertexPositionAttribute, obj.vertSize, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, obj.texCoordBuffer);
gl.vertexAttribPointer(shaderTexCoordAttribute, obj.texCoordSize, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, obj.indices);
gl.uniformMatrix4fv(shaderProjectionMatrixUniform, false, projectionMatrix);
gl.uniformMatrix4fv(shaderModelViewMatrixUniform, false, modelViewMatrix);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, webGLTexture);
gl.uniform1i(shaderSamplerUniform, 0);
// draw the object
gl.drawElements(obj.primtype, obj.nIndices, gl.UNSIGNED_SHORT, 0);
}

set up buffers for
vertices and
texture
coordinates
pass transform
and projection
matrices
to the shader
set the texture and pass to
the shader
draw the object

http://www.tonyparisi.com

1/22/20
14
WT
F

?
http://www.tonyparisi.com

1/22/20
14
engines and frameworks
game engines/IDEs
Goo
Enginehttp://www.gootechnologies.c
om/

rendering libraries/frameworks
Three.js
http://threejs.org/
SceneJS

Verold http://verold.com/
Turbulenz https://turbulenz.com/
PlayCanvas
http://www.playcanvas.com/
Artillery Engine
https://artillery.com/

http://scenejs.org/
BabylonJS
http://www.babylonjs.com/
Vizi
https://github.com/tparisi/Vizi
Voodoo.js
http://www.voodoojs.com/

PhiloGL
Sketchfab https://sketchfab.com/

http://www.senchalabs.org/philogl/

Unreal… ?

tQuery
http://jeromeetienne.github.io/tquery/

Unity… !?
http://www.tonyparisi.com

1/22/20
14
three.js:
a JavaScript 3D engine
https://github.com/mrdoob/three.js/

the most popular WebGL library
renderer = new THREE.WebGLRenderer( { canvas: canvas, antialias: true } );
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 45, canvas.width /
canvas.height, 1, 4000 );
scene.add(camera);
var light = new THREE.DirectionalLight( 0xffffff, 1.5);
scene.add( light );
var mapUrl ="../images/webgl-logo-256.jpg“;
var map = THREE.ImageUtils.loadTexture(mapUrl );
var material = new THREE.MeshPhongMaterial({ map: map });
var geometry = new THREE.CubeGeometry(2, 2, 2);
cube = new THREE.Mesh(geometry, material);
scene.add( cube );

can render to
WebGL,
2D canvas, SVG
and CSS3
represents
WebGL at a
high level using
standard
3D graphics
concepts
http://www.tonyparisi.com

1/22/20
14
three.js flagship projects

http://www.tonyparisi.com

1/22/20
14
3D animation
requestAnimationFrame()
http://www.paulirish.com/2011/requestanimationframe-forsmart-animating/

with JavaScript we can animate anything:
materials, lights, textures…. shaders
three.js has support for key frames, morphs and skins

Tween.js – simple tweening library
https://github.com/sole/tween.js/
var tween = new TWEEN.Tween( { x: 50, y: 0 } )
.to( { x: 400 }, 2000 )
.easing( TWEEN.Easing.Elastic.InOut )
.start();
function animate() {
requestAnimationFrame( animate );
TWEEN.update();
}

create and
start tween

call TWEEN.update()
in your run loop
http://www.tonyparisi.com

1/22/20
14
the content pipeline
still pretty crude – tools and converters under
development
sample work flows
A. OBJ  Three.js JSON with Python command-line tool
•

load into Three.js application; hand-layout, hand-light, handanimate

B. MD2/MD5  Three.js JSON with online tool
•

load into Three.js application; hand-layout, hand-light

C. COLLADA (full scene)
1. export to from Maya, 3ds Max, Blender, Sketchup
2. files contain scene layout, cameras, lights and animations – no
need to do it by hand
3. import into Three.js application and use
4. but COLLADA files are big to download and slow to parse
1/22/20
http://www.tonyparisi.com

14
glTF: a “JPEG for 3D”
full-featured: scene layout, cameras, lights, animations

JSON for scene structure; binary buffers for model data

model from 3drt.com
http://www.tonyparisi.com

1/22/20
14
cross-browser WebGL
desktop
• Safari, Firefox, Chrome, Opera,
Internet Explorer

Building a game or app?
use Ludei
http://ludei.com/

mobile
• iOS - mobile Safari – iAds only
• Android – mobile Chrome
• Amazon Silk, Kindle Fire OS
• Blackberry, Tizen, Firefox OS

http://www.tonyparisi.com

1/22/20
14
2014: the tipping point
Microsoft is fully supporting WebGL
Kindle Fire HDX: at $229, the 7” is probably the best
multimedia device deal on the planet… thanks in part to
WebGL.
Sony built the whole PS4 user interface out of WebGL.
4.2M seats in one whack… and growing.
the 2013 NORAD Tracks Santa site saw 48.8% WebGL
success across all browsers & platforms for 20M
visitors, an increase of 146% over 2012.
Opera Devices SDK – WebGL coming soon to a Bang &
Olufsen TV near you!
tonight: one of the best-ever-attended SFHTML5
meetups. We broke the group’s record for wait list (over
500)!
http://www.tonyparisi.com

1/22/20
14
stay in touch…
contact information
tparisi@gmail.com
skype: auradeluxe
http://twitter.com/auradeluxe
p://www.tonyparisi.com/
http://www.learningwebgl.com/

SF WebGL Meetup
http://www.meetup.com/WebGL-Developers-Meetup/
htt

book source code
https://github.com/tparisi/WebGLBook
https://github.com/tparisi/Programming3DApplications

get Vizi
https://github.com/tparisi/Vizi
get the books!
WebGL: Up and Running
http://www.amazon.com/dp/144932357X
Programming 3D Applications with HTML and WebGL
http://www.amazon.com/Programming-ApplicationsHTML5-WebGL-Visualization/dp/1449362966
http://www.tonyparisi.com

1/22/20
14

More Related Content

Viewers also liked

Introduction to Webgl by Rachel Prudden
Introduction to Webgl by Rachel PruddenIntroduction to Webgl by Rachel Prudden
Introduction to Webgl by Rachel PruddenTechExeter
 
Desenvolvimento de ambientes 3D para Web usando Three JS
Desenvolvimento de ambientes 3D para Web usando Three JSDesenvolvimento de ambientes 3D para Web usando Three JS
Desenvolvimento de ambientes 3D para Web usando Three JSNathalia Sautchuk Patricio
 
3D Image visualization
3D Image visualization3D Image visualization
3D Image visualizationalok ray
 
Introduction to WebGL and Three.js
Introduction to WebGL and Three.jsIntroduction to WebGL and Three.js
Introduction to WebGL and Three.jsJames Williams
 
Computação Gráfica - Introdução ao OpenGL
Computação Gráfica - Introdução ao OpenGLComputação Gráfica - Introdução ao OpenGL
Computação Gráfica - Introdução ao OpenGLTony Alexander Hild
 
Slides prakti gsvc finals-110518
Slides prakti gsvc finals-110518Slides prakti gsvc finals-110518
Slides prakti gsvc finals-110518jdoughertydc
 
BillingViews Facebook Success Index
BillingViews Facebook Success IndexBillingViews Facebook Success Index
BillingViews Facebook Success IndexBillingViews
 
Progetto involucro. Prof.Iovino
Progetto involucro.  Prof.IovinoProgetto involucro.  Prof.Iovino
Progetto involucro. Prof.IovinoAntonella0_91
 
Rpl 7 ppl dan metrik proyek (2)
Rpl 7 ppl dan metrik proyek (2)Rpl 7 ppl dan metrik proyek (2)
Rpl 7 ppl dan metrik proyek (2)Komang Yogi
 
2nd sem portfolio
2nd sem portfolio2nd sem portfolio
2nd sem portfolionutcrackar1
 
προσομοίωση πειράματος φυσικής σε γλώσσα Scratch
προσομοίωση πειράματος φυσικής σε γλώσσα Scratchπροσομοίωση πειράματος φυσικής σε γλώσσα Scratch
προσομοίωση πειράματος φυσικής σε γλώσσα Scratchgeorgefyttas
 
Decisions in communication
Decisions in communicationDecisions in communication
Decisions in communicationTalinChirinian
 

Viewers also liked (17)

Introduction to Webgl by Rachel Prudden
Introduction to Webgl by Rachel PruddenIntroduction to Webgl by Rachel Prudden
Introduction to Webgl by Rachel Prudden
 
Desenvolvimento de ambientes 3D para Web usando Three JS
Desenvolvimento de ambientes 3D para Web usando Three JSDesenvolvimento de ambientes 3D para Web usando Three JS
Desenvolvimento de ambientes 3D para Web usando Three JS
 
3D Image visualization
3D Image visualization3D Image visualization
3D Image visualization
 
Introduction to WebGL and Three.js
Introduction to WebGL and Three.jsIntroduction to WebGL and Three.js
Introduction to WebGL and Three.js
 
Computação Gráfica - Introdução ao OpenGL
Computação Gráfica - Introdução ao OpenGLComputação Gráfica - Introdução ao OpenGL
Computação Gráfica - Introdução ao OpenGL
 
Slides prakti gsvc finals-110518
Slides prakti gsvc finals-110518Slides prakti gsvc finals-110518
Slides prakti gsvc finals-110518
 
BillingViews Facebook Success Index
BillingViews Facebook Success IndexBillingViews Facebook Success Index
BillingViews Facebook Success Index
 
Email Advertising
Email AdvertisingEmail Advertising
Email Advertising
 
Portafolio
PortafolioPortafolio
Portafolio
 
Progetto involucro. Prof.Iovino
Progetto involucro.  Prof.IovinoProgetto involucro.  Prof.Iovino
Progetto involucro. Prof.Iovino
 
Proyecto investigación
Proyecto investigación Proyecto investigación
Proyecto investigación
 
Rpl 7 ppl dan metrik proyek (2)
Rpl 7 ppl dan metrik proyek (2)Rpl 7 ppl dan metrik proyek (2)
Rpl 7 ppl dan metrik proyek (2)
 
2nd sem portfolio
2nd sem portfolio2nd sem portfolio
2nd sem portfolio
 
προσομοίωση πειράματος φυσικής σε γλώσσα Scratch
προσομοίωση πειράματος φυσικής σε γλώσσα Scratchπροσομοίωση πειράματος φυσικής σε γλώσσα Scratch
προσομοίωση πειράματος φυσικής σε γλώσσα Scratch
 
X22686506
X22686506X22686506
X22686506
 
History lesson
History lessonHistory lesson
History lesson
 
Decisions in communication
Decisions in communicationDecisions in communication
Decisions in communication
 

More from 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: Developing for the Immersive Web
WebVR: Developing for the Immersive WebWebVR: Developing for the Immersive Web
WebVR: Developing for the Immersive WebTony Parisi
 
Introduction to WebVR Autodesk Forge 2016
Introduction to WebVR Autodesk Forge 2016Introduction to WebVR Autodesk Forge 2016
Introduction to WebVR Autodesk Forge 2016Tony 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
 
WebGL: The Next Generation
WebGL:  The Next GenerationWebGL:  The Next Generation
WebGL: The Next GenerationTony 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
 
Hacking Reality: Browser-Based VR with HTML5
Hacking Reality: Browser-Based VR with HTML5Hacking Reality: Browser-Based VR with HTML5
Hacking Reality: Browser-Based VR with HTML5Tony 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
 

More from Tony Parisi (20)

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: Developing for the Immersive Web
WebVR: Developing for the Immersive WebWebVR: Developing for the Immersive Web
WebVR: Developing for the Immersive Web
 
Introduction to WebVR Autodesk Forge 2016
Introduction to WebVR Autodesk Forge 2016Introduction to WebVR Autodesk Forge 2016
Introduction to WebVR Autodesk Forge 2016
 
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
 
WebGL: The Next Generation
WebGL:  The Next GenerationWebGL:  The Next Generation
WebGL: The Next Generation
 
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
 
Hacking Reality: Browser-Based VR with HTML5
Hacking Reality: Browser-Based VR with HTML5Hacking Reality: Browser-Based VR with HTML5
Hacking Reality: Browser-Based VR with HTML5
 
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?
 

Recently uploaded

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 

Recently uploaded (20)

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 

An Introduction to WebGL - SFHTML5 Talk January 2014

  • 1. an introduction to WebGL tony parisi january 23, 2014
  • 2. about me serial entrepreneur founder, Vizi co-organizer, SF WebGL Meetup co-creator, VRML and X3D web standards designer, glTF SF WebGL Meetup author http://www.meetup.com/WebGL-Developers-Meetup/ contact information tparisi@gmail.com skype: auradeluxe http://twitter.com/auradeluxe p://www.tonyparisi.com/ http://www.learningwebgl.com/ book source code https://github.com/tparisi/WebGLBook https://github.com/tparisi/Programming3DApplications htt get the books! WebGL: Up and Running http://www.amazon.com/dp/144932357X Programming 3D Applications with HTML and WebGL http://www.amazon.com/Programming-ApplicationsHTML5-WebGL-Visualization/dp/1449362966 http://www.tonyparisi.com 1/22/20 14
  • 3. we live in a 3D world image: http://www.clermonttaichi.com/ http://www.tonyparisi.com 1/22/20 14
  • 4. our media is also 3D (though it’s usually rendered on flat screens) http://www.tonyparisi.com 1/22/20 14
  • 5. built with dedicated computers and expensive software… http://www.tonyparisi.com 1/22/20 14
  • 6. until now. 100,000 Stars Google Experiment http://workshop.chromeexperiments.com/stars/ http://www.tonyparisi.com 1/22/20 14
  • 7. breakthrough applications 60FPS ported in 5 days Unreal native C++ engine -> JavaScriptEmscripten + asm.js http://www.tonyparisi.com 1/22/20 14
  • 8. the 3D API standard for the web OpenGL ES™ in a browser JavaScript API bindings shipped since early 2011 supported in all modern browsers • • • • • • desktop Safari, Firefox, Chrome, Opera, Internet Explorer iOS mobile Safari – iAds only Android – mobile Chrome, mobile Firefox Amazon Silk Browser, Kindle Fire OS Blackberry, Tizen, Firefox OS Surface (Windows 8.1) over 1B served http://www.tonyparisi.com 1/22/20 14
  • 9. how WebGL works JavaScript drawing API draw to a canvas element using a special context low-level drawing – buffers, primitives, textures and shaders accelerated by graphics hardware (GPU) can draw 2D as well as 3D graphics there is no file format; no markup language; no DOM. http://www.tonyparisi.com 1/22/20 14
  • 10. a simple WebGL program 1. create a <canvas> element 2. obtain a drawing context 3. initialize the viewport 4. create one or more buffers 5. create one or more matrices 6. create one or more shaders 7. initialize the shaders 8. draw one or more primitives http://www.tonyparisi.com 1/22/20 14
  • 11. create the canvas, context and viewport function initWebGL(canvas) { var gl = null; var msg = "Your browser does not support WebGL, " + "or it is not enabled by default."; try { gl = canvas.getContext(“webgl"); } catch (e) { msg = "Error creating WebGL Context!: " + e.toString(); } detect WebGL if (!gl) { alert(msg); throw new Error(msg); } return gl; } function initViewport(gl, canvas) { gl.viewport(0, 0, canvas.width, canvas.height); } set WebGL drawing region http://www.tonyparisi.com 1/22/20 14
  • 12. buffers and typed arrays var vertexBuffer; vertexBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); var verts = [ // Front face -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, // Back face -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, … WebGL drawing functions use buffers of data new low-level data type stores arrays of floats and ints compactly ]; gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(verts), gl.STATIC_DRAW); http://www.tonyparisi.com 1/22/20 14
  • 13. shaders var vertexShaderSource = " " " " " " " " " " " " the vertex shader attribute vec3 vertexPos;n" + attribute vec2 texCoord;n" + transforms model-space uniform mat4 modelViewMatrix;n" + positions into screen uniform mat4 projectionMatrix;n" + space varying vec2 vTexCoord;n" + void main(void) {n" + // Return the transformed and projected vertex valuen" + gl_Position = projectionMatrix * modelViewMatrix * n" + vec4(vertexPos, 1.0);n" + // Output the texture coordinate in vTexCoordn" + vTexCoord = texCoord;n" + }n"; the fragment shader outputs a color value for each pixel var fragmentShaderSource = " precision mediump float;n" + " varying vec2 vTexCoord;n" + " uniform sampler2D uSampler;n" + " void main(void) {n" + " // Return the pixel color: always output whiten" + " gl_FragColor = texture2D(uSampler, vec2(vTexCoord.s, vTexCoord.t));n" + "}n"; http://www.tonyparisi.com 1/22/20 14
  • 14. drawing function draw(gl, obj) { // clear the background (with black) gl.clearColor(0.0, 0.0, 0.0, 1.0); gl.enable(gl.DEPTH_TEST); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); clear the canvas // set the shader to use gl.useProgram(shaderProgram); set the shader // connect up the shader parameters: vertex position, texture coordinate, // projection/model matrices and texture // set up the buffers gl.bindBuffer(gl.ARRAY_BUFFER, obj.buffer); gl.vertexAttribPointer(shaderVertexPositionAttribute, obj.vertSize, gl.FLOAT, false, 0, 0); gl.bindBuffer(gl.ARRAY_BUFFER, obj.texCoordBuffer); gl.vertexAttribPointer(shaderTexCoordAttribute, obj.texCoordSize, gl.FLOAT, false, 0, 0); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, obj.indices); gl.uniformMatrix4fv(shaderProjectionMatrixUniform, false, projectionMatrix); gl.uniformMatrix4fv(shaderModelViewMatrixUniform, false, modelViewMatrix); gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, webGLTexture); gl.uniform1i(shaderSamplerUniform, 0); // draw the object gl.drawElements(obj.primtype, obj.nIndices, gl.UNSIGNED_SHORT, 0); } set up buffers for vertices and texture coordinates pass transform and projection matrices to the shader set the texture and pass to the shader draw the object http://www.tonyparisi.com 1/22/20 14
  • 16. engines and frameworks game engines/IDEs Goo Enginehttp://www.gootechnologies.c om/ rendering libraries/frameworks Three.js http://threejs.org/ SceneJS Verold http://verold.com/ Turbulenz https://turbulenz.com/ PlayCanvas http://www.playcanvas.com/ Artillery Engine https://artillery.com/ http://scenejs.org/ BabylonJS http://www.babylonjs.com/ Vizi https://github.com/tparisi/Vizi Voodoo.js http://www.voodoojs.com/ PhiloGL Sketchfab https://sketchfab.com/ http://www.senchalabs.org/philogl/ Unreal… ? tQuery http://jeromeetienne.github.io/tquery/ Unity… !? http://www.tonyparisi.com 1/22/20 14
  • 17. three.js: a JavaScript 3D engine https://github.com/mrdoob/three.js/ the most popular WebGL library renderer = new THREE.WebGLRenderer( { canvas: canvas, antialias: true } ); scene = new THREE.Scene(); camera = new THREE.PerspectiveCamera( 45, canvas.width / canvas.height, 1, 4000 ); scene.add(camera); var light = new THREE.DirectionalLight( 0xffffff, 1.5); scene.add( light ); var mapUrl ="../images/webgl-logo-256.jpg“; var map = THREE.ImageUtils.loadTexture(mapUrl ); var material = new THREE.MeshPhongMaterial({ map: map }); var geometry = new THREE.CubeGeometry(2, 2, 2); cube = new THREE.Mesh(geometry, material); scene.add( cube ); can render to WebGL, 2D canvas, SVG and CSS3 represents WebGL at a high level using standard 3D graphics concepts http://www.tonyparisi.com 1/22/20 14
  • 19. 3D animation requestAnimationFrame() http://www.paulirish.com/2011/requestanimationframe-forsmart-animating/ with JavaScript we can animate anything: materials, lights, textures…. shaders three.js has support for key frames, morphs and skins Tween.js – simple tweening library https://github.com/sole/tween.js/ var tween = new TWEEN.Tween( { x: 50, y: 0 } ) .to( { x: 400 }, 2000 ) .easing( TWEEN.Easing.Elastic.InOut ) .start(); function animate() { requestAnimationFrame( animate ); TWEEN.update(); } create and start tween call TWEEN.update() in your run loop http://www.tonyparisi.com 1/22/20 14
  • 20. the content pipeline still pretty crude – tools and converters under development sample work flows A. OBJ  Three.js JSON with Python command-line tool • load into Three.js application; hand-layout, hand-light, handanimate B. MD2/MD5  Three.js JSON with online tool • load into Three.js application; hand-layout, hand-light C. COLLADA (full scene) 1. export to from Maya, 3ds Max, Blender, Sketchup 2. files contain scene layout, cameras, lights and animations – no need to do it by hand 3. import into Three.js application and use 4. but COLLADA files are big to download and slow to parse 1/22/20 http://www.tonyparisi.com 14
  • 21. glTF: a “JPEG for 3D” full-featured: scene layout, cameras, lights, animations JSON for scene structure; binary buffers for model data model from 3drt.com http://www.tonyparisi.com 1/22/20 14
  • 22. cross-browser WebGL desktop • Safari, Firefox, Chrome, Opera, Internet Explorer Building a game or app? use Ludei http://ludei.com/ mobile • iOS - mobile Safari – iAds only • Android – mobile Chrome • Amazon Silk, Kindle Fire OS • Blackberry, Tizen, Firefox OS http://www.tonyparisi.com 1/22/20 14
  • 23. 2014: the tipping point Microsoft is fully supporting WebGL Kindle Fire HDX: at $229, the 7” is probably the best multimedia device deal on the planet… thanks in part to WebGL. Sony built the whole PS4 user interface out of WebGL. 4.2M seats in one whack… and growing. the 2013 NORAD Tracks Santa site saw 48.8% WebGL success across all browsers & platforms for 20M visitors, an increase of 146% over 2012. Opera Devices SDK – WebGL coming soon to a Bang & Olufsen TV near you! tonight: one of the best-ever-attended SFHTML5 meetups. We broke the group’s record for wait list (over 500)! http://www.tonyparisi.com 1/22/20 14
  • 24. stay in touch… contact information tparisi@gmail.com skype: auradeluxe http://twitter.com/auradeluxe p://www.tonyparisi.com/ http://www.learningwebgl.com/ SF WebGL Meetup http://www.meetup.com/WebGL-Developers-Meetup/ htt book source code https://github.com/tparisi/WebGLBook https://github.com/tparisi/Programming3DApplications get Vizi https://github.com/tparisi/Vizi get the books! WebGL: Up and Running http://www.amazon.com/dp/144932357X Programming 3D Applications with HTML and WebGL http://www.amazon.com/Programming-ApplicationsHTML5-WebGL-Visualization/dp/1449362966 http://www.tonyparisi.com 1/22/20 14