509 webgl df - apple inc. · webgl creating interactive content with webgl session 509 dean jackson...

241
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. #WWDC14 WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media

Upload: others

Post on 31-May-2020

95 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC14

WebGLCreating Interactive Content with WebGL

Session 509 Dean Jackson and Brady Eidson WebKit Engineers

Media

Page 2: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 3: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 4: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 5: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 6: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

JavaScript

Page 7: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 8: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 9: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 10: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 11: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 12: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 13: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 14: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 15: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 16: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 17: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 18: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 19: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 20: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 21: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

AngryBots by Unity

Page 22: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

AngryBots by Unity

Page 23: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Swooop by PlayCanvas

Page 24: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Swooop by PlayCanvas

Page 25: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 26: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

What You Will Learn

Page 27: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

What You Will Learn

Setting up WebGL in your page

Page 28: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

What You Will Learn

Setting up WebGL in your page

How to do basic drawing

Page 29: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

What You Will Learn

Setting up WebGL in your page

How to do basic drawing

Advanced rendering and animation

Page 30: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

What You Will Learn

Setting up WebGL in your page

How to do basic drawing

Advanced rendering and animation

Relationship to other HTML features

Page 31: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 32: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 33: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 34: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 35: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 36: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 37: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 38: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 39: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 40: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

three.js

Turbulenz Cesium

Goo Engine

MontageJS

CopperlichtBabylon JS

Page 41: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Motivation

Page 42: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Motivation

Powerful graphics in Web content

Page 43: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Motivation

Powerful graphics in Web content

Interoperability through Open Standard

Page 44: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 45: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

BEGIN { print "Hello, world!" }display dialog "Hello, world!"

#include <stdio.h> int main() { printf("Hello, world!\n"); return 0; }

#include <iostream> int main() { std::cout << "Hello, world!" << std::endl; return 0; }

PRINT "Hello, world!"

DISPLAY 'Hello, world!'. STOP RUN.

package main import "fmt" func main() { fmt.Println("Hello, world!") }

public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } }

(princ "Hello, world!")

HAI CAN HAS STDIO? VISIBLE "HAI WORLD!" KTHXBYE

#import <Foundation/Foundation.h> int main(void) { NSLog(@"Hello, world!\n"); return 0; }

program HelloWorld; begin WriteLn('Hello, world!'); end.

<?php echo 'Hello, world!'; ?>

%!PS /Courier 72 selectfont 20 20 moveto (Hello World!) show showpage

print "Hello, world!"

puts "Hello, world!"

Page 46: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 47: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 48: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 49: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 50: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 51: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 52: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 53: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 54: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Creating, Configuring, and Drawing

Page 55: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 56: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 57: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 58: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 59: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 60: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 61: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Somewhere to DrawCanvas

Page 62: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Somewhere to DrawCanvas

<canvas> element

Or create one via JavaScript: var canvas = document.createElement("canvas");

Page 63: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Somewhere to DrawCanvas

var canvas = document.querySelector("canvas");

Page 64: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Somewhere to DrawCanvas

var canvas = document.querySelector("canvas"); !

canvas.width = 600 * window.devicePixelRatio; canvas.height = 400 * window.devicePixelRatio;

Page 65: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 66: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 67: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Something to Draw WithCreating the WebGLRenderingContext

Page 68: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Something to Draw WithCreating the WebGLRenderingContext

var gl = canvas.getContext("webgl");

Page 69: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 70: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 71: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Configuring the SystemCreating and setting up the resources

Page 72: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Configuring the SystemCreating and setting up the resources

Before we can do the actual draw operation:

Page 73: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Configuring the SystemCreating and setting up the resources

Before we can do the actual draw operation:• Create some buffers

Page 74: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Configuring the SystemCreating and setting up the resources

Before we can do the actual draw operation:• Create some buffers

• Create a program to use while drawing

Page 75: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 76: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 77: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

(-0.8, -0.3)

(0.55, 0.75)

(0.7, -0.8)

Page 78: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

(-0.8, -0.3)

(0.55, 0.75)

(0.7, -0.8)

Page 79: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

-0.8 -0.3 0.7 -0.8 0.55 0.75

(-0.8, -0.3)

(0.55, 0.75)

(0.7, -0.8)

Page 80: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

-0.8 -0.3 0.7 -0.8 0.55 0.75

(-0.8, -0.3)

(0.55, 0.75)

(0.7, -0.8)

Page 81: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

-0.8 -0.3 0.7 -0.8 0.55 0.75

(-0.8, -0.3)

(0.55, 0.75)

(0.7, -0.8)

Page 82: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertices = new Float32Array([ -0.8, -0.3, 0.7, -0.8, 0.55, 0.75 ]);

Page 83: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertices = new Float32Array([ -0.8, -0.3, 0.7, -0.8, 0.55, 0.75 ]);

Page 84: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertices = new Float32Array([ -0.8, -0.3, 0.7, -0.8, 0.55, 0.75 ]);

Page 85: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertices = new Float32Array([ -0.8, -0.3, 0.7, -0.8, 0.55, 0.75 ]); !

var triangleBuffer = gl.createBuffer();

Page 86: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertices = new Float32Array([ -0.8, -0.3, 0.7, -0.8, 0.55, 0.75 ]); !

var triangleBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer); gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);

Page 87: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 88: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

JavaScript

Page 89: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

JavaScript

Page 90: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

JavaScript

Page 91: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

JavaScript

WebGL Rendering Pipeline

Page 92: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

WebGL Rendering Pipeline

Page 93: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Primitive ProcessingPrimitive Assembly

Vertex ShaderRasterizerFragment ShaderDepth / Stencil

Color Buffer BlendDitherWebGL

Rendering Pipeline

Page 94: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Primitive Processing

Primitive Assembly

Vertex Shader Rasterizer Fragment

ShaderDepth/ Stencil

Color Buffer Blend

Dither

Page 95: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Primitive Processing

Primitive Assembly Rasterizer Depth/

Stencil

Color Buffer Blend

DitherVertex Shader

Fragment Shader

Page 96: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader

Fragment Shader

JavaScript

Page 97: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader

Fragment Shader

JavaScript

Page 98: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader

Fragment Shader

Program

JavaScript

Page 99: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader

-0.8 -0.3 0.7 -0.8 0.55 0.75

Page 100: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

-0.8 -0.3 0.7 -0.8 0.55 0.75

Vertex Shader

Vertex Shader

Vertex Shader

Page 101: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader

Vertex Shader

Vertex Shader

-0.8 -0.3 0.7 -0.8 0.55 0.75

Page 102: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader

Vertex Shader

Vertex Shader

Fragment Shader

Fragment Shader

Fragment Shader

Fragment Shader

Fragment Shader

Fragment Shader

Fragment Shader

Fragment Shader

-0.8 -0.3 0.7 -0.8 0.55 0.75

Page 103: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertexShader = gl.createShader(gl.VERTEX_SHADER); gl.shaderSource(vertexShader, "... source code ..."); gl.compileShader(vertexShader);

Page 104: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertexShader = gl.createShader(gl.VERTEX_SHADER); gl.shaderSource(vertexShader, "... source code ..."); gl.compileShader(vertexShader);

Page 105: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertexShader = gl.createShader(gl.VERTEX_SHADER); gl.shaderSource(vertexShader, "... source code ..."); gl.compileShader(vertexShader);

Page 106: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertexShader = gl.createShader(gl.VERTEX_SHADER); gl.shaderSource(vertexShader, "... source code ..."); gl.compileShader(vertexShader); !

var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER); gl.shaderSource(fragmentShader, "... source code ..."); gl.compileShader(fragmentShader);

Page 107: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertexShader = gl.createShader(gl.VERTEX_SHADER); gl.shaderSource(vertexShader, "... source code ..."); gl.compileShader(vertexShader); !

var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER); gl.shaderSource(fragmentShader, "... source code ..."); gl.compileShader(fragmentShader); !

var program = gl.createProgram();

Page 108: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertexShader = gl.createShader(gl.VERTEX_SHADER); gl.shaderSource(vertexShader, "... source code ..."); gl.compileShader(vertexShader); !

var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER); gl.shaderSource(fragmentShader, "... source code ..."); gl.compileShader(fragmentShader); !

var program = gl.createProgram(); gl.attachShader(program, vertexShader); gl.attachShader(program, fragmentShader);

Page 109: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertexShader = gl.createShader(gl.VERTEX_SHADER); gl.shaderSource(vertexShader, "... source code ..."); gl.compileShader(vertexShader); !

var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER); gl.shaderSource(fragmentShader, "... source code ..."); gl.compileShader(fragmentShader); !

var program = gl.createProgram(); gl.attachShader(program, vertexShader); gl.attachShader(program, fragmentShader); gl.linkProgram(program);

Page 110: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertexShader = gl.createShader(gl.VERTEX_SHADER); gl.shaderSource(vertexShader, "... source code ..."); gl.compileShader(vertexShader); !

var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER); gl.shaderSource(fragmentShader, "... source code ..."); gl.compileShader(fragmentShader); !

var program = gl.createProgram(); gl.attachShader(program, vertexShader); gl.attachShader(program, fragmentShader); gl.linkProgram(program); !

gl.useProgram(program);

Page 111: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 112: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 113: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 114: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var positionAttribute = gl.getAttribLocation(program, "aPosition"); gl.enableVertexAttribArray(positionAttribute);

Page 115: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var positionAttribute = gl.getAttribLocation(program, "aPosition"); gl.enableVertexAttribArray(positionAttribute); !

gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer); gl.vertexAttribPointer(positionAttribute, 2, gl.FLOAT, false, 0, 0);

Page 116: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var positionAttribute = gl.getAttribLocation(program, "aPosition"); gl.enableVertexAttribArray(positionAttribute); !

gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer); gl.vertexAttribPointer(positionAttribute, 2, gl.FLOAT, false, 0, 0);

Page 117: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var positionAttribute = gl.getAttribLocation(program, "aPosition"); gl.enableVertexAttribArray(positionAttribute); !

gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer); gl.vertexAttribPointer(positionAttribute, 2, gl.FLOAT, false, 0, 0); !

gl.drawArrays(gl.TRIANGLES, 0, 3);

Page 118: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 119: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

<!DOCTYPE html> <head> <title>WebGL Triangle</title> <style> canvas { width: 600px; height: 400px; } </style> </head> <script id="vertexShaderSource" type="text/glsl"> // Simple vertex shader. Simply returns the position it was provided. attribute vec4 position; void main() { gl_Position = position; } </script> <script id="fragmentShaderSource" type="text/glsl"> // Extremely simple fragment shader. Draws every pixel red. #ifdef GL_ES precision mediump float; #endif !void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);

Page 120: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

// Load the vertex data into the buffer. gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer); gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); ! // ---- DRAWING ---- ! // Clear to black. gl.clearColor(0, 0, 0, 1); gl.clear(gl.COLOR_BUFFER_BIT); ! // Bind the vertex attributes for the draw operation. We first make // sure we're talking to the correct buffer, then we're going to // associate that buffer with the vertex attribute from the program. // Our buffer is an array of (x,y) points, so 2 floating point values // per vertex. gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer); gl.vertexAttribPointer(positionAttribute, 2, gl.FLOAT, false, 0, 0); ! // The actual draw call. We know there are 3 points in the buffer // (a triangle). gl.drawArrays(gl.TRIANGLES, 0, 3); } !window.addEventListener("load", drawTriangle, false); </script> <body>

Page 121: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Shaders

Page 122: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

GLSL

Page 123: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

GLSL

C-like language designed for parallel graphics

Page 124: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

GLSL

C-like language designed for parallel graphics

Primitives: Vectors, matrices

Page 125: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

GLSL

C-like language designed for parallel graphics

Primitives: Vectors, matrices

Built-in functions: Trigonometry, vector math, smoothing, and clamping

Page 126: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader

Vertex Shader

Vertex Shader

Fragment Shader

Fragment Shader

Fragment Shader

Fragment Shader

Fragment Shader

Fragment Shader

Fragment Shader

Fragment Shader

-0.8 -0.3 0.7 -0.8 0.55 0.75

Page 127: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader

Fragment Shader

-0.8 -0.3 0.7 -0.8 0.55 0.75

Page 128: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

-0.8 -0.3 0.7 -0.8 0.55 0.75

1 100 2 987 3 46

Vertex Shader

Fragment Shader

Page 129: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Global Constants (uniforms)

-0.8 -0.3 0.7 -0.8 0.55 0.75

1 100 2 987 3 46

Vertex Shader

Fragment Shader

Page 130: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Global Constants (uniforms)

gl_Position

-0.8 -0.3 0.7 -0.8 0.55 0.75

1 100 2 987 3 46

Vertex Shader

Fragment Shader

Page 131: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Global Constants (uniforms)

gl_Position

gl_FragColor

-0.8 -0.3 0.7 -0.8 0.55 0.75

1 100 2 987 3 46

Vertex Shader

Fragment Shader

Page 132: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader Source Code

attribute vec4 aPosition; !void main() { gl_Position = aPosition; }

Page 133: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader Source Code

attribute vec4 aPosition; !void main() { gl_Position = aPosition; }

Page 134: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader Source Code

attribute vec4 aPosition; !void main() { gl_Position = aPosition; }

Page 135: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Fragment Shader Source Code

precision mediump float; !void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }

Page 136: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Fragment Shader Source Code

precision mediump float; !void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }

Page 137: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Fragment Shader Source Code

precision mediump float; !void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }

Page 138: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Fragment Shader Source Code

precision mediump float; !void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); } red green blue alpha

Page 139: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

DemoLive Shader Editor

Page 140: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Shaders

C-like programs that run on the GPU

Control over vertex positions and pixel colors

Extremely powerful

Page 141: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Advanced RenderingMerging WebGL with the rest of HTML

Brady Eidson WebKit Engineer

Page 142: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 143: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 144: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 145: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 146: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 147: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 148: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 149: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 150: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 151: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 152: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 153: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 154: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 155: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 156: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 157: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 158: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 159: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 160: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 161: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 162: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 163: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertices = new Float32Array([ -0.8, -0.3, 0.7, -0.8, 0.55, 0.75 ]); !

var triangleBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer); gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);

Page 164: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertices = new Float32Array([ ... ]); !

var discBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, discBuffer); gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);

Page 165: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertices = new Float32Array([ -0.020478, 28.7138, 0.149324, -0.020478, 70.3138, 0.149324, 17.830223, 28.7138, 0.149324, 17.830223, 28.7138, 0.149324, 17.830223, 70.3138, 0.149324, 17.830223, 70.3138, 0.149324, 15.438682, 28.7138, -8.776026, 15.438682, 28.7138, -8.776026, 15.438682, 70.3138, -8.776026, 15.438682, 70.3138, -8.776026, 8.904872, 28.7138, -15.309836, 8.904872, 28.7138, -15.309836, 8.904872, 70.3138, -15.309836, 8.904872, 70.3138, -15.309836, -0.020478, 28.7138, -17.701376, -0.020478, 28.7138, -17.701376, -0.020478, 70.3138, -17.701376, -0.020478, 70.3138, -17.701376, -8.945828, 28.7138, -15.309836, -8.945828, 28.7138, -15.309836,

Page 166: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

1.862177, 40.359541, 326.208471, -30.006249, 40.359541, 324.66346, -60.997415, 40.359541, 320.124634, -90.967013, 40.359541, 312.736303, -119.770729, 40.359541, 302.642778, -147.264255, 40.359541, 289.988371, -173.303279, 40.359541, 274.91739, -197.743491, 40.359541, 257.574148, -220.44058, 40.359541, 238.102954, -241.250235, 40.359541, 216.64812, -260.028146, 40.359541, 193.353956, -276.630002, 40.359541, 168.364772, -290.911493, 40.359541, 141.82488, -302.728307, 40.359541, 113.878589, -311.936135, 40.359541, 84.670211, -318.390665, 40.359541, 54.344056, -321.092812, 40.359541, 33.576897, -322.637823, 40.359541, 1.708471, -321.092812, 40.359541, -30.159955, -316.553985, 40.359541, -61.151122, -309.165655, 40.359541, -91.120719, -299.07213, 40.359541, -119.924436, -286.417722, 40.359541, -147.417961, -271.346742, 40.359541, -173.456985,

Page 167: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 168: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Any Data You Want

Page 169: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Any Data You Wantfor Any Point You Want

Page 170: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 171: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 172: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 173: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 174: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 175: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 176: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var vertices = new Float32Array([ -0.020478, 28.7138, 0.149324, -0.020478, 70.3138, 0.149324, 17.830223, 28.7138, 0.149324, 17.830223, 28.7138, 0.149324, 17.830223, 70.3138, 0.149324, 17.830223, 70.3138, 0.149324, 15.438682, 28.7138, -8.776026, 15.438682, 28.7138, -8.776026, 15.438682, 70.3138, -8.776026, 15.438682, 70.3138, -8.776026, … ]); !

var geometryBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, geometryBuffer); gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);

Page 177: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

var textureCoords = new Float32Array([ 0.498234, 0.530450 0.498234, 0.600143 0.512222, 0.530450 0.512222, 0.530450 0.512222, 0.600143 0.512222, 0.600143 0.509996, 0.530450 0.509996, 0.530450 0.509996, 0.600143 0.509996, 0.600143 … ]); !

var textureBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, textureBuffer); gl.bufferData(gl.ARRAY_BUFFER, textureCoords, gl.STATIC_DRAW);

Page 178: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Configuring Our Shaders

var positionAttribute = gl.getAttribLocation(program, "aPosition"); gl.enableVertexAttribArray(positionAttribute); !

gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer); gl.vertexAttribPointer(positionAttribute, 3, gl.FLOAT, false, 0, 0);

Page 179: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Configuring Our Shaders

var positionAttribute = gl.getAttribLocation(program, "aPosition"); gl.enableVertexAttribArray(positionAttribute); gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer); gl.vertexAttribPointer(positionAttribute, 3, gl.FLOAT, false, 0, 0); !

var textureAttribute = gl.getAttribLocation(program, "aTextureCoord"); gl.enableVertexAttribArray(textureAttribute); !

Page 180: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Configuring Our Shaders

var positionAttribute = gl.getAttribLocation(program, "aPosition"); gl.enableVertexAttribArray(positionAttribute); gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer); gl.vertexAttribPointer(positionAttribute, 3, gl.FLOAT, false, 0, 0); !

var textureAttribute = gl.getAttribLocation(program, "aTextureCoord"); gl.enableVertexAttribArray(textureAttribute); gl.bindBuffer(gl.ARRAY_BUFFER, textureBuffer); gl.vertexAttribPointer(textureAttribute, 2, gl.FLOAT, false, 0, 0);

Page 181: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader Source Code

attribute vec4 aPosition; !

void main() { gl_Position = aPosition; }

Page 182: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader Source Code

attribute vec4 aPosition; attribute vec2 aTextureCoord; !

void main() { gl_Position = aPosition; }

Page 183: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader Source Code

attribute vec4 aPosition; attribute vec2 aTextureCoord; !

varying vec2 vTextureCoord; !

void main() { gl_Position = aPosition; }

Page 184: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Vertex Shader Source Code

attribute vec4 aPosition; attribute vec2 aTextureCoord; !

varying vec2 vTextureCoord; !

void main() { gl_Position = aPosition; vTextureCoord = aTextureCoord; }

Page 185: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Fragment Shader Source Code

precision mediump float; !

void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }

Page 186: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Fragment Shader Source Code

precision mediump float; !

varying vec2 vTextureCoord; !

void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }

Page 187: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Configuring Our Shaders

var positionAttribute = gl.getAttribLocation(program, "aPosition"); gl.enableVertexAttribArray(positionAttribute); gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer); gl.vertexAttribPointer(positionAttribute, 3, gl.FLOAT, false, 0, 0); !

var textureAttribute = gl.getAttribLocation(program, "aTextureCoord"); gl.enableVertexAttribArray(textureAttribute); gl.bindBuffer(gl.ARRAY_BUFFER, textureBuffer); gl.vertexAttribPointer(textureAttribute, 2, gl.FLOAT, false, 0, 0);

Page 188: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Configuring Our Shaders

var positionAttribute = gl.getAttribLocation(program, "aPosition"); gl.enableVertexAttribArray(positionAttribute); gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer); gl.vertexAttribPointer(positionAttribute, 3, gl.FLOAT, false, 0, 0); !

var textureAttribute = gl.getAttribLocation(program, "aTextureCoord"); gl.enableVertexAttribArray(textureAttribute); gl.bindBuffer(gl.ARRAY_BUFFER, textureBuffer); gl.vertexAttribPointer(textureAttribute, 2, gl.FLOAT, false, 0, 0); !

var samplerUniform = gl.getUniformLocation(program, "sampler");

Page 189: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Fragment Shader Source Code

precision mediump float; !

varying vec2 vTextureCoord; !

void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }

Page 190: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Fragment Shader Source Code

precision mediump float; !

varying vec2 vTextureCoord; !

uniform sampler2D sampler; !

void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }

Page 191: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Fragment Shader Source Code

precision mediump float; !

varying vec2 vTextureCoord; !

uniform sampler2D sampler; !

void main() { gl_FragColor = texture2D(sampler, vTextureCoord); }

Page 192: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Texture Sources

Page 193: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Texture Sources

<img> element

Page 194: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Texture Sources

<img> elementXMLHttpRequest

Page 195: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Texture Sources

<img> elementXMLHttpRequest<video> element

Page 196: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Texture Sources

<img> elementXMLHttpRequest<video> element<canvas> element

Page 197: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

<img id=“TextureImage” src=“FlatCompass.png”>

Page 198: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

<img id=“TextureImage” src=“FlatCompass.png”> !

<script type=“text/javascript”> var texture = gl.createTexture(); </script>

Page 199: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

<img id=“TextureImage” src=“FlatCompass.png”> !

<script type=“text/javascript”> var texture = gl.createTexture(); gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, texture); </script>

Page 200: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

<img id=“TextureImage” src=“FlatCompass.png”> !

<script type=“text/javascript”> var texture = gl.createTexture(); gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, texture); !

var image = document.getElementById(“TextureImage”); </script>

Page 201: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

<img id=“TextureImage” src=“FlatCompass.png”> !

<script type=“text/javascript”> var texture = gl.createTexture(); gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, texture); !

var image = document.getElementById(“TextureImage”); !

gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); </script>

Page 202: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

<img id=“TextureImage” src=“FlatCompass.png”> !

<script type=“text/javascript”> var texture = gl.createTexture(); gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, texture); !

var image = document.getElementById(“TextureImage”); !

gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); </script>

Page 203: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

<img id=“TextureImage” src=“FlatCompass.png”> !

<script type=“text/javascript”> var texture = gl.createTexture(); gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, texture); !

var image = document.getElementById(“TextureImage”); !

gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); gl.uniform1i(samplerUniform, 0); </script>

Page 204: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 205: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 206: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

DemoBuilding a compass

Page 207: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 208: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 209: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

The Web Platform

Page 210: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

The Web Platform

Page 211: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

The Web Platform

Page 212: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

The Web Platform

Page 213: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

The Web Platform

Page 214: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 215: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 216: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 217: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 218: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 219: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 220: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots
Page 221: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

When to Draw

Page 222: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

FIXME: The contents of www.apple.com/safari will likely be different

later on June 2nd, should update the video

Page 223: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

FIXME: The contents of www.apple.com/safari will likely be different

later on June 2nd, should update the video

Page 224: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Do Not Use Timers!

Page 225: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

requestAnimationFrame()

Page 226: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

requestAnimationFrame()

Call “requestAnimationFrame()” with a callback1

Page 227: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

requestAnimationFrame()

var drawingCallback = function() { … }

Call “requestAnimationFrame()” with a callback1

Page 228: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

requestAnimationFrame()

var drawingCallback = function() { … } !

requestAnimationFrame(drawingCallback);

Call “requestAnimationFrame()” with a callback1

Page 229: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

requestAnimationFrame()

Draw your scene2

var drawingCallback = function() { … } !

requestAnimationFrame(drawingCallback);

Page 230: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

requestAnimationFrame()

var drawingCallback = function() { updatePhysics(); drawCompass(); drawTerrain(); } !

requestAnimationFrame(drawingCallback);

Draw your scene2

Page 231: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

requestAnimationFrame()

var drawingCallback = function() { updatePhysics(); drawCompass(); drawTerrain(); } !

requestAnimationFrame(drawingCallback);

Request the next callback3

Page 232: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

requestAnimationFrame()

var drawingCallback = function() { updatePhysics(); drawCompass(); drawTerrain(); … requestAnimationFrame(drawingCallback); } !

requestAnimationFrame(drawingCallback);

Request the next callback3

Page 233: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

DemoGrand finale

Page 234: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Wrapping Up

Page 235: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Wrapping Up

Rich, powerful, fast graphics

Page 236: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Wrapping Up

Rich, powerful, fast graphics

WebGL available in Safari on OS X Yosemite and iOS 8

Page 237: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Wrapping Up

Rich, powerful, fast graphics

WebGL available in Safari on OS X Yosemite and iOS 8

Also available in WKWebView

Page 238: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

More Information

Evangelism [email protected]

!

Safari for Developers http://developer.apple.com/safari/

WebKit http://webkit.org/

Developer Technical Support http://developer.apple.com/contact

Apple Developer Forums http://devforums.apple.com

Page 239: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Related Sessions

• Introducing the Modern WebKit API Nob Hill Tuesday 2:00PM

• Web Inspector and Modern JavaScript Russian Hill Thursday 10:15AM

Page 240: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots

Labs

• Safari and WebKit Lab Media Lab B Wednesday 4:30PM

• Safari and WebKit Lab Media Lab B Thursday 2:00PM

Page 241: 509 WebGL DF - Apple Inc. · WebGL Creating Interactive Content with WebGL Session 509 Dean Jackson and Brady Eidson WebKit Engineers Media. JavaScript. AngryBots by Unity. AngryBots