48
The Power of WebGL @raphamundi HACKING YOUR GPU WITH JAVASCRIPT

The Power of WebGL - Hackeando sua GPU com JavaScript

Embed Size (px)

Citation preview

Page 1: The Power of WebGL - Hackeando sua GPU com JavaScript

The Power of WebGL

@raphamundiHACKING YOUR GPU WITH JAVASCRIPT

Page 2: The Power of WebGL - Hackeando sua GPU com JavaScript

RAPHAEL AMORIM

raphamundi raphamorim

raphamorim.com

Page 3: The Power of WebGL - Hackeando sua GPU com JavaScript
Page 4: The Power of WebGL - Hackeando sua GPU com JavaScript

Shaders

Page 5: The Power of WebGL - Hackeando sua GPU com JavaScript

Graphic procedures

e.g: surfacing and texturing, lighting and shadowing, texture and geometry generation.

Page 6: The Power of WebGL - Hackeando sua GPU com JavaScript

The "3D" Effect

* A thanks Jaume Sanchez for the awesome resource!

Page 7: The Power of WebGL - Hackeando sua GPU com JavaScript

[ -1, -1, 0 ], [ 1, -1, 0 ], [ 1, 1, 0 ], [ -1, 1, 0 ]

Page 8: The Power of WebGL - Hackeando sua GPU com JavaScript

Vertex shader takes this data, and some other values

(model-view and projection matrix, and others)

and turns the 4 points into 4 projected points

Page 9: The Power of WebGL - Hackeando sua GPU com JavaScript

We need to specify how to draw it: points, wireframe or solid

Page 10: The Power of WebGL - Hackeando sua GPU com JavaScript

The solid projected square gets "discretised" base on the output display

Page 11: The Power of WebGL - Hackeando sua GPU com JavaScript

The system fills the space connecting these dots and calculates what pixels on your display

need to be drawn

Page 12: The Power of WebGL - Hackeando sua GPU com JavaScript

The rest is up to the fragment shader

It gets called for each of these small squares, and the correct output color is calculated.

Page 13: The Power of WebGL - Hackeando sua GPU com JavaScript

GPUGraphics Processing Unit

Page 14: The Power of WebGL - Hackeando sua GPU com JavaScript

GPURun! Run! As fast as you can!

Page 15: The Power of WebGL - Hackeando sua GPU com JavaScript

WebGLWeb Graphics Library

Page 16: The Power of WebGL - Hackeando sua GPU com JavaScript
Page 17: The Power of WebGL - Hackeando sua GPU com JavaScript

<canvas/>WebGL Context

Define the Geometry and Store it in the Buffer Objects

Create and Compile the Shaders( Vertex && Fragment )

Page 18: The Power of WebGL - Hackeando sua GPU com JavaScript

Atributes

Page 19: The Power of WebGL - Hackeando sua GPU com JavaScript

Atributes

Uniforms

Page 20: The Power of WebGL - Hackeando sua GPU com JavaScript

Atributes

Uniforms

Varyings

Page 21: The Power of WebGL - Hackeando sua GPU com JavaScript

WebGL Waterhttp://madebyevan.com/webgl-water/

Page 22: The Power of WebGL - Hackeando sua GPU com JavaScript

WebGL Blossomhttp://www.bongiovi.tw/experiments/

webgl/blossom/

Page 23: The Power of WebGL - Hackeando sua GPU com JavaScript

Google Maps Cubehttp://www.playmapscube.com/

Page 24: The Power of WebGL - Hackeando sua GPU com JavaScript

WebGL is very hotDamn God!“ ”

Page 25: The Power of WebGL - Hackeando sua GPU com JavaScript
Page 26: The Power of WebGL - Hackeando sua GPU com JavaScript

~= 80ºC!!!

Page 27: The Power of WebGL - Hackeando sua GPU com JavaScript

~= 80ºC!!!WebGL makes your macbook hot. Yeah,

literally.

Page 28: The Power of WebGL - Hackeando sua GPU com JavaScript

FPSFrame Per Second

Page 29: The Power of WebGL - Hackeando sua GPU com JavaScript
Page 30: The Power of WebGL - Hackeando sua GPU com JavaScript

Where are the graphics costs?

Page 31: The Power of WebGL - Hackeando sua GPU com JavaScript

The first rule of any optimization is to find

where the performance problem is.

Page 32: The Power of WebGL - Hackeando sua GPU com JavaScript

Strategies for optimizing for GPU vs. CPU are quite different.

Page 33: The Power of WebGL - Hackeando sua GPU com JavaScript

CPU optimization

Page 34: The Power of WebGL - Hackeando sua GPU com JavaScript

GPU: Optimizing Model Geometry

Page 35: The Power of WebGL - Hackeando sua GPU com JavaScript

GPU: Texture Compression and Mipmaps

Page 36: The Power of WebGL - Hackeando sua GPU com JavaScript

DrawCalls

Page 37: The Power of WebGL - Hackeando sua GPU com JavaScript

WebVRBringing Virtual Reality to the Web

Page 38: The Power of WebGL - Hackeando sua GPU com JavaScript
Page 39: The Power of WebGL - Hackeando sua GPU com JavaScript

Okay, we already tried a lot.

Page 40: The Power of WebGL - Hackeando sua GPU com JavaScript

till now:

Page 41: The Power of WebGL - Hackeando sua GPU com JavaScript

WebVR is an APIhttp://mzl.la/1IK6pnf

Page 42: The Power of WebGL - Hackeando sua GPU com JavaScript

WebVR• Sechelt (http://mozvr.com/projects/sechelt/)

• Quake III (http://media.tojicode.com/q3bsp/)

• vizor.io (http://vizor.io/fthr/vr_cube/edit)

• Primoseeditor (https://www.primroseeditor.com/#fullscreen)

• Inspirit (http://inspirit.unboring.net/)

Page 43: The Power of WebGL - Hackeando sua GPU com JavaScript

MozVRmozvr.com

Page 44: The Power of WebGL - Hackeando sua GPU com JavaScript

bit.ly/1lDsdLR

Page 45: The Power of WebGL - Hackeando sua GPU com JavaScript

Thanks! :)

Page 46: The Power of WebGL - Hackeando sua GPU com JavaScript

References:• Shaders! What are they and what can they do for me? -

Jaume Sanchez (https://www.clicktorelease.com/talks/scotlandjs-2015/)

• Dive into 0.016 seconds of WebGL - @yomotsu (https://speakerdeck.com/yomotsu/dive-into-0-dot-016-seconds-of-webgl)

• Getting started with three.js and WebGL - Jaume Sanchez (https://www.clicktorelease.com/talks/jsconfbp-2015/)

Page 47: The Power of WebGL - Hackeando sua GPU com JavaScript

References:• The Road To WebVR • Replacing reality with JavaScript -

Jaume Sanchez (https://www.clicktorelease.com/talks/fullstackfest-2015/slides/#0)

• WebGL tutorial MDN (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Tutorial)

• The Rise and Fall and Rise of Virtual Reality (http://www.theverge.com/a/virtual-reality/oral_history)

Page 48: The Power of WebGL - Hackeando sua GPU com JavaScript

References:

• 6 Virtual Reality Devices From the Past (http://www.cheatsheet.com/technology/a-trip-down-virtual-reality-road-6-systems-of-the-past.html )