WebGL. WebGL. Bring 3D to the Masses. WebGL. The web has text, images, and video. We want to support. Put it in on a webpage

Similar documents
WebGL. Announcements. WebGL for Graphics Developers. WebGL for Web Developers. Homework 5 due Monday, 04/16. Final on Tuesday, 05/01

Ciril Bohak. - INTRODUCTION TO WEBGL

Visual HTML5. Human Information Interaction for Knowledge Extraction, Interaction, Utilization, Decision making HI-I-KEIUD

WebGL (Web Graphics Library) is the new standard for 3D graphics on the Web, designed for rendering 2D graphics and interactive 3D graphics.

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

Rendering Objects. Need to transform all geometry then

Khronos and the Mobile Ecosystem

Lecture 13: OpenGL Shading Language (GLSL)

PROFESSIONAL. WebGL Programming DEVELOPING 3D GRAPHICS FOR THE WEB. Andreas Anyuru WILEY. John Wiley & Sons, Ltd.

HTML5 Evolution and Development. Matt Spencer UI & Browser Marketing Manager

Mining the Rendering Power in Web Browsers. Jianxia Xue Jan. 28, 2014

OpenGL BOF Siggraph 2011

CS475/CS675 - Computer Graphics. OpenGL Drawing

Profiling and Debugging Games on Mobile Platforms

Rasterization-based pipeline

CS450/550. Pipeline Architecture. Adapted From: Angel and Shreiner: Interactive Computer Graphics6E Addison-Wesley 2012

We assume that you are familiar with the following:

GPGPU Applications. for Hydrological and Atmospheric Simulations. and Visualizations on the Web. Ibrahim Demir

Shaders. Slide credit to Prof. Zwicker

GWT + HTML5 Can Do What!? Ray Cromwell, Stefan Haustein, Joel Webber May 2010

WebGL Meetup GDC Copyright Khronos Group, Page 1

Dave Shreiner, ARM March 2009

BCA611 Video Oyunları için 3B Grafik

We will use WebGL 1.0. WebGL 2.0 is now being supported by most browsers but requires a better GPU so may not run on older computers or on most cell

SIGGRAPH Briefing August 2014

Copyright Khronos Group Page 1

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

Bringing it all together: The challenge in delivering a complete graphics system architecture. Chris Porthouse

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012

Mobile AR Hardware Futures

Next Generation OpenGL Neil Trevett Khronos President NVIDIA VP Mobile Copyright Khronos Group Page 1

Copyright Khronos Group 2012 Page 1. OpenCL 1.2. August 2012

Qiufeng Zhu Advanced User Interface Spring 2017

Coding OpenGL ES 3.0 for Better Graphics Quality

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL

Mobile Application Programing: Android. OpenGL Operation

SpiderGL. A JavaScript 3D Graphics for Next-Generation WWW. Visual Computing Lab ISTI CNR. Marco Di Benedetto

Mobile Graphics Ecosystem. Tom Olson OpenGL ES working group chair

Mali Developer Resources. Kevin Ho ARM Taiwan FAE

Mobile Performance Tools and GPU Performance Tuning. Lars M. Bishop, NVIDIA Handheld DevTech Jason Allen, NVIDIA Handheld DevTools

Water Simulation on WebGL and Three.js

Free Downloads OpenGL ES 3.0 Programming Guide

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

WebGL, WebCL and Beyond!

The Graphics Pipeline

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York

Programming with OpenGL Complete Programs Objectives Build a complete first program

WebGL: Hands On. DevCon5 NYC Kenneth Russell Software Engineer, Google, Inc. Chair, WebGL Working Group

NVIDIA Parallel Nsight. Jeff Kiel

POWERVR MBX & SGX OpenVG Support and Resources

GPU Memory Model. Adapted from:

Programming with WebGL Part 1: Background. CS 432 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Objectives. Programming with WebGL Part 1: Background. Retained vs. Immediate Mode Graphics. Early History of APIs. PHIGS and X.

Mobile Graphics Trends: Applications. Marco Agus, KAUST & CRS4

GeForce3 OpenGL Performance. John Spitzer

Models and Architectures. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

last time put back pipeline figure today will be very codey OpenGL API library of routines to control graphics calls to compile and load shaders

Pro JavaScript. Development. Coding, Capabilities, and Tooling. Den Odell. Apress"

CS452/552; EE465/505. Image Processing Frame Buffer Objects

Mobile Application Programing: Android. OpenGL Operation

WebGL, WebCL and OpenCL

CS452/552; EE465/505. Overview of Computer Graphics

DECLARATIVE AR IN THE WEB WITH XML3D & XFLOW. By Felix Klein

Lewis Weaver. Nell Waliczek. Software Engineering Lead. Program github.

CS452/552; EE465/505. Image Formation

Mention driver developers in the room. Because of time this will be fairly high level, feel free to come talk to us afterwards

Working with Metal Overview

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

Hardware Accelerated Graphics for High Performance JavaFX Mobile Applications

OpenGL on Android. Lecture 7. Android and Low-level Optimizations Summer School. 27 July 2015

Final Project Writeup

Many rendering scenarios, such as battle scenes or urban environments, require rendering of large numbers of autonomous characters.

ArcGIS Runtime: Maximizing Performance of Your Apps. Will Jarvis and Ralf Gottschalk

Mobile HW and Bandwidth

Why modern versions of OpenGL should be used Some useful API commands and extensions

EE 4702 GPU Programming

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

IGME-330. Rich Media Web Application Development I Week 1

Programming shaders & GPUs Christian Miller CS Fall 2011

LPGPU Workshop on Power-Efficient GPU and Many-core Computing (PEGPUM 2014)

Developing the Roadmap - Director Next Survey

I Can t Believe It s Not

Copyright Khronos Group, Page 1. Khronos Overview. Taiwan, February 2012

Blis: Better Language for Image Stuff Project Proposal Programming Languages and Translators, Spring 2017

Khronos Updates GDC 2017 Neil Trevett Vice President Developer Ecosystem, NVIDIA President,

The Application Stage. The Game Loop, Resource Management and Renderer Design

Applications and Implementations

Invest in the future, build for the web!

Open Standards for Today s Gaming Industry

Optimizing and Profiling Unity Games for Mobile Platforms. Angelo Theodorou Senior Software Engineer, MPG Gamelab 2014, 25 th -27 th June

<Insert Picture Here> JavaFX 2.0

WebGL Seminar: O3D. Alexander Lokhman Tampere University of Technology

Mapbox GL. Modern, Robust, Open Source Maps on Mobile & Web. I did a talk like this at OSB 15, but today we ve realized the promise of a lot of this.

Com S 336 Final Project Ideas

CS452/552; EE465/505. Shadow Mapping in WebGL

Interactive webmaps with ArcGIS. Kristel Meikas, AlphaGIS

UI, Graphics & EFL. Carsten Haitzler Principal Engineer Samsung Electronics Korea Founder/Leader Enlightenment / EFL

Hands-On Workshop: 3D Automotive Graphics on Connected Radios Using Rayleigh and OpenGL ES 2.0

Introduction to Computer Graphics. Hardware Acceleration Review

Transcription:

WebGL WebGL Patrick Cozzi University of Pennsylvania CIS 565 - Fall 2012 The web has text, images, and video What is the next media-type? We want to support Windows, Linux, Mac Desktop and mobile 2 Bring 3D to the Masses Put it in on a webpage Does not require a plugin or install Does not require administrator rights Make it run on most GPUs WebGL OpenGL ES 2.0 for JavaScript Seriously, JavaScript 3 4 Image from http://www.khronos.org/assets/uploads/developers/library/2011-siggraph-mobile/khronos-and-the-mobile- Ecosystem_Aug-11.pdf 1

WebGL Includes Vertex shaders Fragment shaders Vertex buffers Textures Framebuffers Render states Does not include Geometry shaders Tessellation shaders Vertex Array Objects Multiple render targets Floating-point textures Compressed textures FS depth writes 5 See http://www.khronos.org/registry/webgl/specs/latest/ WebGL If you know OpenGL, you already know WebGL If you know C++, the real learning curve is JavaScript 6 WebGL Alternatives? Flash Silverlight Java Applets Unity WebGL Creating a context is easy: // HTML: <canvas id="glcanvas" width="1024" height="768"></canvas> 7 // JavaScript: var gl = document.getelementbyid("glcanvas").getcontext("experimental-webgl"); 8 2

WebGL The rest is similar to desktop OpenGL: //... gl.bindbuffer(/*... */); gl.vertexattribpointer(/*... */); gl.useprogram(/*... */); gl.drawarrays(/*... */); WebGL Create an animation loop: (function tick(){ //... GL calls to draw scene window.requestanimationframe(tick); })(); 9 Checkout http://learningwebgl.com/ 10 You want this to work cross-browser. See http://paulirish.com/2011/requestanimationframe-for-smart-animating/ WebGL Performance Performance can be very good. Why? WebGL Performance Performance can be very good. Why? The GPU is still doing the rendering Batch! Draw multiple objects with one draw call Sort by texture Push work into shaders Push work into web workers 11 12 See http://www.youtube.com/watch?v=rfq8rkgtvlg 3

WebGL Performance WebGL and other APIs 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 CPU-intensive 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 GPU-intensive (256 draws per frame) 13 Image from http://openglinsights.com/ Take advantage of other web APIs: HTML5 <video> 2D <canvas> CSS transforms Composite UI elements Web workers Typed Arrays 14 HTML5 on Mobile Touch events Test with http://www.snappymaria.com/misc/toucheventtest_v2.html Geolocation Device orientation and motion The future of HTML5 and WebGL on mobile is very promising 15 WebGL support is good, and it is getting better 16 4

WebGL Stats In October, 2012 Desktop WebGL Support In October, 2012-3 rd Party Plugins available http://webglstats.com/ 17 18 See http://www.khronos.org/webgl/wiki/getting_a_webgl_implementation Android WebGL Support In October, 2012 Mobile WebGL Support In October, 2012 Stock Browser Demo at SIGGRAPH 2011 In ios 5 for iad developers For Cesium, see our mobile page 19 20 See http://news.cnet.com/8301-30685_3-20071902-264/apple-signs-up-for-webgl-graphics-in-iads/ 5

WebGL on Your System Desktop WebGL Support http://www.webglreport.com Windows No OpenGL driver installed? Old driver? Only 35% of Windows XP machines have GL 2 drivers Buggy driver? No problem: ANGLE Almost Native Graphics Layer Engine OpenGL ES 2.0 Direct3D 9 21 22 See http://code.google.com/p/angleproject/ WebCL OpenCL bindings for JavaScript are coming. Browser Architecture Single Process N-Body Simulation http://www.youtube.com/watch?v=f7ysqxz3j7o http://www.khronos.org/webcl/ Prototypes for Firefox and WebKit are available 23 24 See http://www.khronos.org/assets/uploads/developers/library/2010_siggraph_bof_webgl/webgl-bof-2-webgl-in-chrome_siggraph-jul29.pdf 6

Browser Architecture Chrome s Multi-process Browser Architecture Chrome s Multi-process 25 See http://www.khronos.org/assets/uploads/developers/library/2010_siggraph_bof_webgl/webgl-bof-2-webgl-in-chrome_siggraph-jul29.pdf 26 See http://www.khronos.org/assets/uploads/developers/library/2010_siggraph_bof_webgl/webgl-bof-2-webgl-in-chrome_siggraph-jul29.pdf Browser Architecture Chrome s Multi-process Questions In a multi-process is gl.get* slow? Why? What about security? 27 See http://www.khronos.org/assets/uploads/developers/library/2010_siggraph_bof_webgl/webgl-bof-2-webgl-in-chrome_siggraph-jul29.pdf 28 7

Cross-Origin Resource Sharing Images can t always be used as texture sources. Why? Cross-Origin Resource Sharing Same domain is OK: var img = new Image(); img.onload = function() { gl.teximage2d(/*... */, img); img.src = "image.png"; 29 30 Cross-Origin Resource Sharing Another domain requires CORS if supported: var img = new Image(); img.onload = function() { gl.teximage2d(/*... */, img); img.crossorigin = "anonymous"; img.src = "http://another-domain.com/image.png"; 31 Cross-Origin Resource Sharing Not all servers support CORS: www.your-domain.com html/js/css files Browser www.another-domain.com Images files used for textures 32 8

Cross-Origin Resource Sharing Use a proxy server: www.another-domain.com www.your-domain.com html/js/css files Images files used for textures Images files used for textures proxy.php?http://anotherdomain.com/image.png" Denial of Service Attacks Long draw calls Complicated shaders Big vertex buffers Solutions Kill long draw calls Forbid further rendering Browser 33 See http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jshelp/ags_proxy.htm 34 Lots of WebGL security info: http://learningwebgl.com/blog/?p=3890 WebGL Libraries WebGL Resources Three.js: https://github.com/mrdoob/three.js/ Cesium: http://cesium.agi.com/ Many more: http://www.khronos.org/webgl/wiki/user_contributions WebGL Camps: http://www.webglcamp.com Learning WebGL: http://learningwebgl.com 35 36 9

The Joys of JavaScript JavaScript is weakly typed 37 Skip the next 30 slides if you already know JavaScript 38 JavaScript Type System short, int, float, double. Who needs them? var n = 1; JavaScript Type System JavaScript has numbers, strings, and booleans: var n = 1; var s = WebGL ; var b = true; 39 40 10

JavaScript Type System This compiles: var n = 1; var s = WebGL ; var b = true; JavaScript is a functional language var sum = n + s + b; 41 42 JavaScript Functions Looks familiar: function add(x, y) { return x + y; } var sum = add(1, 2); Functions are first-class objects, so JavaScript Functions Functions are objects: var add = function(x, y) { return x + y; var sum = add(1, 2); 43 44 11

JavaScript Functions Pass functions to functions: var add = function //... JavaScript Anonymous Functions Why name functions? function execute(op, x, y) //... function execute(op, x, y) { return op(x, y); } var sum = execute(function(x, y) { return x + y; }, 1, 2); var sum = execute(add, 1, 2); 45 46 JavaScript Closures Why limit scope? var z = 3; var sum = execute(function(x, y) { return x + y + z; }, 1, 2); JavaScript is a dynamic language 47 48 12

JavaScript Object Literals Who needs struct? Create objects on the fly: var position = { x : 1.0, y : 2.0 JavaScript Object Literals Why not add fields on the fly too? var position = { x : 1.0, y : 2.0 position.z = 3.0; 49 50 JavaScript Object Literals Who needs class? JavaScript Object Literals Who needs class? Create functions too: var position = { x : 1.0, y : 2.0, min : function() { return Math.min(this.x, this.y); } 51 52 13

JavaScript Object Literals Why not change min()? JavaScript Object Literals Useful for passing to functions. Why? position.z = 3.0; position.min = function() { return Math.min(this.x, this.y, this.z); 53 54 JavaScript Object Literals JavaScript Object Literals Useful for passing to functions. Why? Useful for passing to functions. Why? What do these arguments mean? What do these arguments mean? pick(322, 40, 5, 4); 55 pick({ x : 322, y : 40, width : 5, height : 4 }); 56 14

JavaScript Constructor Functions JavaScript does object-oriented function Vector(x, y) { this.x = x; this.y = y; } var v = new Vector(1, 2); 57 58 JavaScript Constructor Functions Objects can have functions: function Vector(x, y) { this.x = x; this.y = y; this.min = function() { return Math.min(this.x, this.y); } 59 JavaScript Constructor Functions Objects have prototypes: function Vector(x, y) { this.x = x; this.y = y; } Vector.prototype.min = function() { return Math.min(this.x, this.y); 60 15

JavaScript Polymorphism No need for virtual functions function draw(model) { model.setrenderstate(); model.render(); } JavaScript Polymorphism No need for virtual functions var level = { setrenderstate : function() //... render : function() //... draw(level); // Just works 61 62 JavaScript Build Pipeline Different than C++ Goal: fast downloads Common: JavaScript Advice Use JSHint Have excellent test coverage Use the Chrome and Firefox debuggers.js files Concatenate One.js file Minify Compressed.js file Alternative: fine-grain modules How do you deploy shaders? 63 See http://www.julienlecomte.net/blog/2007/09/16/ 64 16

JavaScript Resources 65 I promise I do not work for O'Reilly or Yahoo 17