an introduction to gpus and webgl - drexel cci · an introduction to gpus and webgl patrick cozzi...

52
An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi [email protected] Analytical Graphics, Inc. University of Pennsylvania

Upload: truonganh

Post on 19-Oct-2018

237 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

An Introduction to GPUs and WebGL

Patrick Cozzi @pjcozzi [email protected]

Analytical Graphics, Inc. University of Pennsylvania

Page 2: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

About Me

See http://www.seas.upenn.edu/~pcozzi/

Page 3: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Analytical Graphics, Inc.

n A few videos

Page 4: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

University of Pennsylvania

n A few CIS 565 projects

Hao Wu Mikey Chen Vimanyu Jain

Ishaan Singh Yingting Xiao Xiaoyan Zhu

Page 5: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Today

n Graphics Pipeline n GPU design n WebGL

Page 6: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Part I: Graphics Pipeline

Page 7: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Graphics Review: Rendering

Image from http://www.cs.cmu.edu/afs/cs.cmu.edu/academic/class/15869-f11/www/lectures/01_intro.pdf 7

Page 8: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Graphics Review: Rendering

n Rendering ¨ Goal: Assign color to pixels

n Two Parts ¨ Visible surfaces

n  What is in front of what for a given view ¨ Shading

n  Simulate the interaction of material and light to produce a pixel color

8

Page 9: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Graphics Pipeline Walkthrough

Vertex Shader

Primitive Assembly

Fragment Shader

Rasterizer

Per-Fragment Tests

Blend

Vertex Assembly

Framebuffer

Images from http://www.cs.cmu.edu/afs/cs.cmu.edu/academic/class/15869-f11/www/lectures/01_intro.pdf 9

Page 10: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Vertex Shader

Vertex Shader

Primitive Assembly

Fragment Shader

Rasterizer

Per-Fragment Tests

Blend

Vertex Assembly

Framebuffer Pclip = (Mmodel-view-projection)(Pmodel)

•  Transform incoming vertex position from model to clip coordinates

•  Perform additional per-vertex computations; modify, add, or remove attributes passed down the pipeline

•  Formerly called the Transform and Lighting (T&L) stage. Why?

Vertex Shader

Pmodel

Pclip

Vertex Shader

vertex

modified vertex

10

Page 11: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Transforms in the Pipeline

Page 12: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Vertex Shader

Vertex Shader

Primitive Assembly

Fragment Shader

Rasterizer

Per-Fragment Tests

Blend

Vertex Assembly

Framebuffer

•  Example: Textures can provide height maps for displacement mapping

Images from http://developer.nvidia.com/content/vertex-texture-fetch 12

Page 13: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Rasterization

Vertex Shader

Primitive Assembly

Fragment Shader

Rasterizer

Per-Fragment Tests

Blend

Vertex Assembly

Framebuffer

•  Determine what pixels a primitive overlaps

•  How would you implement this?

•  What about aliasing?

•  What happens to non-position vertex attributes during rasterization?

•  What is the triangle-to-fragment ratio?

13

Page 14: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Fragment Shader

Vertex Shader

Primitive Assembly

Fragment Shader

Rasterizer

Per-Fragment Tests

Blend

Vertex Assembly

Framebuffer

•  Shades the fragment by simulating the interaction of light and material

•  Loosely, the combination of a fragment shader and its uniform inputs is a material

•  Also called a Pixel Shader (D3D)

•  What exactly is the fragment input? •  What are examples of useful uniforms? Useful

textures?

Fragment Shader

fragment

fragment’s color

uniforms

textures

14

Page 15: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Fragment Shader

Vertex Shader

Primitive Assembly

Per-Fragment Tests

Blend

Vertex Assembly

Framebuffer

Image from http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter05.html

float diffuse = max(dot(N, L), 0.0);

Fragment Shader

Rasterizer

15

Page 16: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Fragment Shader

Vertex Shader

Primitive Assembly

Per-Fragment Tests

Blend

Vertex Assembly

Framebuffer

•  Another example: Texture Mapping

Image from http://www.realtimerendering.com/

Fragment Shader

Rasterizer

16

Page 17: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Fragment Shader

Vertex Shader

Primitive Assembly

Per-Fragment Tests

Blend

Vertex Assembly

Framebuffer

•  Lighting and texture mapping

Fragment Shader

Rasterizer

Image from http://www.virtualglobebook.com/ 17

Page 18: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Fragment Shader

Vertex Shader

Primitive Assembly

Per-Fragment Tests

Blend

Vertex Assembly

Framebuffer

•  Another example: Bump mapping

Fragment Shader

Rasterizer

18

Page 19: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Fragment Shader

Vertex Shader

Primitive Assembly

Per-Fragment Tests

Blend

Vertex Assembly

Framebuffer

•  Another example: Bump mapping

Fragment Shader

Rasterizer

19

Page 20: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Depth Test

Vertex Shader

Primitive Assembly

Fragment Shader

Rasterizer

Per-Fragment Tests

Blend

Vertex Assembly

Framebuffer

•  Finds visible surfaces •  Once called “ridiculously expensive” •  Also called the z-test

•  Does it need to be after fragment shading?

Scissor Test

Stencil Test

Depth Test

20

Page 21: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Depth Test

Image from http://www.virtualglobebook.com/ 21

Page 22: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Depth Test

Image from http://www.virtualglobebook.com/ 22

Page 23: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Part II: GPU design

Page 24: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Early 90s – Pre GPU

Slide from http://s09.idav.ucdavis.edu/talks/01-BPS-SIGGRAPH09-mhouston.pdf 24

Page 25: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

AMD Toyshop Demo

http://www.youtube.com/watch?v=LtxvpS5AYHQ

Page 26: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

AMD Leo Demo

http://www.youtube.com/watch?v=zYweEn6DFcU

Page 27: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

GPU Compute + Rendering

http://www.nvidia.com/object/GTX_400_games_demos.html

Page 28: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

CPU and GPU Trends

Chart from: http://proteneer.com/blog/?p=263

Page 29: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Why GPUs?

n Exploit Parallelism ¨ CPU and GPU executing in parallel ¨ Data-parallel ¨ Pipeline parallel

n Hardware: texture filtering, rasterization, MAD, sqrt, etc.

29

Page 30: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

NVIDIA GeForce 256 (1999)

Vertex Shader

Primitive Assembly

Fragment Shader

Rasterizer

Per-Fragment Tests

Blend

Vertex Assembly

Framebuffer

Hardware

Image from http://en.wikipedia.org/wiki/File:VisionTek_GeForce_256.jpg

In hardware: •  Fixed-function vertex shading (T&L) •  Multi-texturing: bump maps, light maps, etc. •  10 million polygons per second •  Direct3D 7 •  AGP bus

30

Page 31: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

NVIDIA GeForce 8 (2006)

Vertex Shader

Primitive Assembly

Fragment Shader

Rasterizer

Per-Fragment Tests

Blend

Vertex Assembly

Framebuffer

•  Ground-up GPU redesign •  Geometry Shaders •  Transform-feedback •  OpenGL 3 / Direct3D 10 •  Unified shader processors •  Support for GPU Compute

Geometry Shader

31

Page 32: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Why Unify Shader Processors?

Slide from http://s08.idav.ucdavis.edu/luebke-nvidia-gpu-architecture.pdf

32

Page 33: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Evolution of the Programmable Graphics Pipeline

Slide from Mike Houston: http://s09.idav.ucdavis.edu/talks/01-BPS-SIGGRAPH09-mhouston.pdf 33

Page 34: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Part III: WebGL

Page 35: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

n The web has text, images, and video ¨ What is the next media-type?

n We want to support ¨ Windows, Linux, Mac ¨ Desktop and mobile

WebGL

35

Page 36: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Bring 3D to the Masses

n Put it in on a webpage ¨ Does not require a plugin or install

n Make it run on most GPUs

36

Page 37: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

WebGL

Image from http://www.khronos.org/assets/uploads/developers/library/2011-siggraph-mobile/Khronos-and-the-Mobile-Ecosystem_Aug-11.pdf

n OpenGL ES 2.0 for JavaScript ¨ Seriously, JavaScript

37

Page 38: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

WebGL Performance

Image from http://openglinsights.com/

32x32 64x64 128x128 C++ 1.9 ms 6.25 ms 58.82 ms Chrome 18 27.77 ms 111.11 ms 454.54 ms x slowdown 14.62 17.78 7.73

32x32 64x64 128x128 C++ 3.33 ms 9.43 ms 37.03 ms Chrome 18 12.82 ms 22.72 ms 41.66 ms x slowdown 3.85 2.41 1.13

CPU-intensive

GPU-intensive (256 draws per frame) 38

Page 39: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

High-Profile WebGL Uses

Page 40: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

More Cesium WebGL Apps

Page 41: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

WebGL in Teaching

Page 42: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Penn Student Work

Page 43: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

WebGL Globe

Rohith Chandran

Page 44: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Ray Marching Distance Fields

Nop Jiarathanakul

Page 45: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

Procedural Infinite City

Alice Yang

Page 46: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

WebGL Hot-Air Balloons

Yuanhui Chen

Page 47: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

WebGL Deferred Shading

Hao Wu and Guanyu He

Page 48: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

WebGL Deferred Shading

Sijie Tian and Yuqin Shao

Page 49: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

WebGL Tools – Web Apps

Page 50: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

WebGL Tools – Web Apps

Page 51: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

WebGL Tools - Firefox

Page 52: An Introduction to GPUs and WebGL - Drexel CCI · An Introduction to GPUs and WebGL Patrick Cozzi @pjcozzi pjcozzi@siggraph.org Analytical Graphics, Inc. University of Pennsylvania

WebGL Tools - Chrome