Agenda. Rendering pipeline Boilerplate for minimal application Obtaining rendering context Uploading data to GPU Transformations Shaders Textures

Similar documents
Introduction to Computer Graphics with WebGL

Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

Introduction to Computer Graphics

CS418 GLSL Shader Programming Tutorial (I) Shader Introduction. Presented by : Wei-Wen Feng 3/12/2008

CSE 564: Visualization. GPU Programming (First Steps) GPU Generations. Klaus Mueller. Computer Science Department Stony Brook University

Programming 3D Applications with HTML5 and WebGL

OpenGL "Hello, world!"

OpenGL Performance Tuning

Game Development in Android Disgruntled Rats LLC. Sean Godinez Brian Morgan Michael Boldischar

OpenGL Insights. Edited by. Patrick Cozzi and Christophe Riccio

Performance Optimization and Debug Tools for mobile games with PlayCanvas

Parallel Web Programming

How To Teach Computer Graphics

Introduction to Computer Graphics

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

Introduction to GPGPU. Tiziano Diamanti

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

NVPRO-PIPELINE A RESEARCH RENDERING PIPELINE MARKUS TAVENRATH MATAVENRATH@NVIDIA.COM SENIOR DEVELOPER TECHNOLOGY ENGINEER, NVIDIA

Tutorial 9: Skeletal Animation

3D Augmented Reality Mobile Application Prototype for Visual Planning Support

Shader Model 3.0. Ashu Rege. NVIDIA Developer Technology Group

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

QCD as a Video Game?

A Pipeline From COLLADA to WebGL for Skeletal Animation

OpenGL Shading Language Course. Chapter 5 Appendix. By Jacobo Rodriguez Villar jacobo.rodriguez@typhoonlabs.com

Web Based 3D Visualization for COMSOL Multiphysics

3D Graphics and Cameras

Visualizing Data: Scalable Interactivity

Silverlight for Windows Embedded Graphics and Rendering Pipeline 1

Color correction in 3D environments Nicholas Blackhawk

Optimizing Unity Games for Mobile Platforms. Angelo Theodorou Software Engineer Unite 2013, 28 th -30 th August

Recent Advances and Future Trends in Graphics Hardware. Michael Doggett Architect November 23, 2005

Introduction to WebGL

GPU Architecture. Michael Doggett ATI

Vertex and fragment programs

Computer Applications in Textile Engineering. Computer Applications in Textile Engineering

OpenGL & Delphi. Max Kleiner. 1/22

DATA VISUALIZATION OF THE GRAPHICS PIPELINE: TRACKING STATE WITH THE STATEVIEWER

Institutionen för systemteknik Department of Electrical Engineering

GPGPU Computing. Yong Cao

GUI GRAPHICS AND USER INTERFACES. Welcome to GUI! Mechanics. Mihail Gaianu 26/02/2014 1

Computer Graphics Hardware An Overview

L20: GPU Architecture and Models

A Hybrid Visualization System for Molecular Models

Realtime 3D Computer Graphics Virtual Reality

INTRODUCTION TO RENDERING TECHNIQUES

Methodology for Lecture. Review of Last Demo

Computer Graphics on Mobile Devices VL SS ECTS

GPU(Graphics Processing Unit) with a Focus on Nvidia GeForce 6 Series. By: Binesh Tuladhar Clay Smith

NVFX : A NEW SCENE AND MATERIAL EFFECT FRAMEWORK FOR OPENGL AND DIRECTX. TRISTAN LORACH Senior Devtech Engineer SIGGRAPH 2013

Writing Applications for the GPU Using the RapidMind Development Platform

NVIDIA Corporation 2701 San Tomas Expressway Santa Clara, CA

A Short Introduction to Computer Graphics

Programmable Graphics Hardware

Lecture Notes, CEng 477

Masters of Science in Software & Information Systems

Learning Modern 3D Graphics Programming. Jason L. McKesson

BRINGING UNREAL ENGINE 4 TO OPENGL Nick Penwarden Epic Games Mathias Schott, Evan Hart NVIDIA

Chapter 2 - Graphics Programming with JOGL

How To Understand The Power Of Unity 3D (Pro) And The Power Behind It (Pro/Pro)

Beginning Android 4. Games Development. Mario Zechner. Robert Green

Introduction to Computer Graphics. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Finger Paint: Cross-platform Augmented Reality

Computer Graphics CS 543 Lecture 12 (Part 1) Curves. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Bachelor of Games and Virtual Worlds (Programming) Subject and Course Summaries

Low power GPUs a view from the industry. Edvard Sørgård

COMP175: Computer Graphics. Lecture 1 Introduction and Display Technologies

Optimization for DirectX9 Graphics. Ashu Rege

The Evolution of Computer Graphics. SVP, Content & Technology, NVIDIA

Radeon HD 2900 and Geometry Generation. Michael Doggett

How To Use An Amd Graphics Card In Greece And (Amd) With Greege (Greege) With An Amd Greeper 2.2.

IT 386: 3D Modeling and Animation. Review Sheet. Notes from Professor Nersesian s IT 386: 3D Modeling and Animation course

Nicolas P. Rougier PyConFr Conference 2014 Lyon, October 24 25

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. M.Sc. in Advanced Computer Science. Friday 18 th January 2008.

Web-Based Enterprise Data Visualization a 3D Approach. Oleg Kachirski, Black and Veatch

Touchstone -A Fresh Approach to Multimedia for the PC

Advanced Visual Effects with Direct3D

GPUs Under the Hood. Prof. Aaron Lanterman School of Electrical and Computer Engineering Georgia Institute of Technology

Cortona3D Viewer. User's Guide. Copyright ParallelGraphics

The Future Of Animation Is Games

Developer Tools. Tim Purcell NVIDIA

Introduction GPU Hardware GPU Computing Today GPU Computing Example Outlook Summary. GPU Computing. Numerical Simulation - from Models to Software

AMD GPU Architecture. OpenCL Tutorial, PPAM Dominik Behr September 13th, 2009

Graphics Cards and Graphics Processing Units. Ben Johnstone Russ Martin November 15, 2011

Computer Graphics. Anders Hast

CMSC 427 Computer Graphics Programming Assignment 1: Introduction to OpenGL and C++ Due Date: 11:59 PM, Sept. 15, 2015

Introduction to Visualization with VTK and ParaView

CPIT-285 Computer Graphics

3D Modeling and Simulation using Image Stitching

Vector Web Mapping Past, Present and Future. Jing Wang MRF Geosystems Corporation

Optimizing AAA Games for Mobile Platforms

Blender addons ESRI Shapefile import/export and georeferenced raster import

Using WPF for Computer Graphics

TEACHING GRAPHICS PROGRAMMING ON MOBILE DEVICES

GearVRf Developer Guide

The OpenGL R Graphics System: A Specification (Version 3.3 (Core Profile) - March 11, 2010)

Blender Notes. Introduction to Digital Modelling and Animation in Design Blender Tutorial - week 9 The Game Engine

A Crash Course on Programmable Graphics Hardware

JW Player Quick Start Guide

Firefox for Android. Reviewer s Guide. Contact us: press@mozilla.com

Transcription:

WebGL

Agenda Rendering pipeline Boilerplate for minimal application Obtaining rendering context Uploading data to GPU Transformations Shaders Textures

A bit of background! WebGL is a low-level, rendering API for use within browsers. Provides access to the GPU Requires quite a bit of code overhead Current version WebGL is 1.0 (specification for 2.0 is ready) Based of OpenGL ES 2.0 Programmable pipeline! THREE.js examples http://threejs.org/examples/

Rendering pipeline Image credit : Gregg Tavares

Rasterization WebGL, OpenGL, DirectX are what we call rasterizers We specify data in continuous space that gets rasterized (digitized) Image credit : Jason L. McKesson

A Simple Program Any WebGL program will have similar structure Create context Upload and compile shaders Upload drawing data into buffers Render! All these processes share similar syntax of gl.createx(), gl.bindx()

A Simple Program

Rendering Context Creation Rendering context can be obtained through HTML <canvas> element

webgl-utils.js Small useful utility from google Context creation Animation ( later ) Single line setup! Download

Shaders Basically what the graphics programming is all about WebGL has two types of shaders Vertex Shaders Fragment Shaders Can be specified within the HTML a <script> tag, as well as outside in their own files Written in WebGL Shading Language Compiled and linked as your C program

WebGL Shading Language Similar to C Standard flow control Some additional data structures vec2, vec3, vec4, mat3, mat4 Standard operators should work on these types Component-wise matrix multiplication matrixcompmult(mat x, mat y) Vector comparison functions - greaterthan(t x, T y), Geometrical functions (dot(t x, T y), cross(vec3 x, vec3 y), etc.) Swizzling vec4 v1(1.0, 2.0, 1.0, 0.0); vec2 v2 = v1.zz; Very good summation of the language features : WebGL Reference Card

Vertex Shader Small program run per vertex of your input geometry JavaScript application will upload data to Vertex Shader attributes Attribute is data that you store per vertex position, color, normal, etc. outputs special gl_position variable

Fragment Shader Small program run per each fragment Most of the magic happens here ShaderToy - all fragment shaders! Outputs the gl_fragcolor, which might become the color of your pixel

Shading Language variable qualifiers attribute Linkage between a vertex shader and per-vertex data uniform Value does not change across the primitive being processed, constant for all the vertices. varying Link between the vertex shader and the fragment shader for interpolated data

Access Point to Shader variables How to get access to the input variables in shaders? Required when drawing! For attributes we need to Query attribute location ( by name specified in the shader ) Tell WebGL that we intending on using it For uniforms Query attribute location ( by name specified in the shader )

Compiling shaders Create both shaders gl.createshader( gl.vertex_shader ) gl.createshader( gl.fragment_shader ) Set the source file - gl.shadersource( shaderobj, src ) gl.shadercompile( shaderobj ) After fragment and vertex shaders are compiled, we attach them to a shader program gl.createprogram() gl.attachshader( shaderprogram, shaderobj ) Then we need to link the program to be able to use it. gl.linkprogram( shaderprogram ) gl.useprogram( shaderprogram )

Transferring data Need to define link between data in application memory and GPU memory Transferring bytes Tell GPU how to read this data Bit tedious process, but only have to do it once Done through Vertex Buffer Objects (VBO) Create buffer of required size ( gl.createbuffer( ) ) Bind it, so it is actually used ( gl.bindbuffer( ) ) Fill the bound buffer with data ( gl.bufferdata( ), gl.buffersubdata( ) )

Transferring data

Drawing We are almost able to draw the triangle! Exciting! Still a couple of steps Need to bind the buffer we are drawing Need to explain to WebGL how to read data off the buffer normalize or take as-is (boolean) space between elements (bytes) starting offset (bytes) gl.vertexattribpointer( attriblocation, attribsize, type, normalize, stride, offset) location from shader program number of components per vertex type of the data ( gl.float )

Drawing Based on the way your data is stored you can draw it by invoking void gl.drawarrays ( enum mode, int first, long count) void gl.drawelements ( enum mode, long count, enum type, long offset ) mode : POINTS, LINE_STRIP, LINE_LOOP, LINES, TRIANGLE_STRIP, TRIANGLE_FAN, TRIANGLE type : UNSIGNED_BYTE, UNSIGNED_SHORT gl.drawarrays( ) just reads the values as take come from the buffer gl.drawelements( ) requires ELEMENT_ARRAY_BUFFER to be bound to specify reading order

Transformations We specify our data in 3D space, while the end result is 2D image We need to perform series of transformation Model matrix - objects in 3D has its own transformation matrix View matrix - camera has position and orientation Projection matrix - camera s intrinsic parameters These three matrices model how your data will be displayed JavaScript library for vector/matrix operations : link Matrix manipulation Useful constructors - perspective camera, orthographical camera

Transformations Understanding the transformations between each coordinate space is crucial for graphic programming Good tutorial on the topic : link Image credit : http://www.opengl-tutorial.org

Adding 3D to our app We need to modify our buffers with 3D data. We can use ELEMENT_ARRAY_BUFFER to specify exact triangle indices.

Animation In the examples we use requestanimframe() Does not refresh if tab is not active Defines rendering loop

User Interaction - Arcball Arcball is an interaction method to translate {x,y} screen locations to a motion of an object Obtain two pairs of {x,y} screen coordinates. Normalize them to [-1,1] range. Treat them as positions on hemisphere of radius 1 Calculate z form sphere equation. Gives vectors Compute rotation angle Compute rotation axis rotaxis exists in camera coordinates, need to move it to model coordinates!! where V rot is rotation part of view matrix, and M rot is rotation part of model matrix Your matrix library should be able to generate rotation matrix from pair.

Texture Mapping Process similar to buffer creation: Create texture gl.createtexture( ) Bind texture gl.bindtexture( ) Configure texture ( a lot of options ) gl.teximage2d( ) - explain image data gl.texparameteri( ) - texture filtering options Texture units Specify current set of active textures - gl.activetexture(gl.texturex) Need to explicitly state which we use Modify mesh data with per vertex texture coordinates

Texture Mapping

Texture Shader Texture is 2D image, rendered to a part of your output We need to sample our texture to get correct pixel values in the output image sampler2d object and texture2d( ), are the functions you need to use in your shader

Three.js

Thanks!