Introduction to Computer Graphics with WebGL



Similar documents
OpenGL "Hello, world!"

Tutorial 9: Skeletal Animation

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

3D Graphics and Cameras

Parallel Web Programming

The OpenGL ES Shading Language

Introduction to GPGPU. Tiziano Diamanti

Vertex and fragment programs

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

glga: an OpenGL Geometric Application framework for a modern, shader-based computer graphics curriculum

A Pipeline From COLLADA to WebGL for Skeletal Animation

Programmable Graphics Hardware

The OpenGL ES Shading Language

GPGPU Computing. Yong Cao

The OpenGL Shading Language

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

The OpenGL Shading Language

Shader Model 3.0. Ashu Rege. NVIDIA Developer Technology Group

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

C++ Class Library Data Management for Scientific Visualization

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

Chapter 07: Instruction Level Parallelism VLIW, Vector, Array and Multithreaded Processors. Lesson 05: Array Processors

An Incomplete C++ Primer. University of Wyoming MA 5310

Introduction to Computer Graphics

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

Semantic Analysis: Types and Type Checking

Arithmetic and Algebra of Matrices

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

Midgard GPU Architecture. October 2014

Performance Optimization and Debug Tools for mobile games with PlayCanvas

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Shadows. Shadows. Thanks to: Frédo Durand and Seth Teller MIT. Realism Depth cue

Integer Set Library: Manual

Here are some examples of combining elements and the operations used:

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

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

1. Relational database accesses data in a sequential form. (Figures 7.1, 7.2)

VB.NET Programming Fundamentals

An Overview of Java. overview-1

Methodology for Lecture. Review of Last Demo

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

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

CORBA Programming with TAOX11. The C++11 CORBA Implementation

OpenGL Insights. Edited by. Patrick Cozzi and Christophe Riccio

5 Arrays and Pointers

Variable Base Interface

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

A.R.I.S.E. Architectural Real-time Interactive Showing Environment. Supervisor: Scott Chase

QCD as a Video Game?

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

Learning Modern 3D Graphics Programming. Jason L. McKesson

OpenGL & Delphi. Max Kleiner. 1/22

Typical Linear Equation Set and Corresponding Matrices

AP Computer Science Java Subset

3 Multimedia Programming with C++ and Multimedia Frameworks

(!' ) "' # "*# "!(!' +,

Numerical Analysis. Professor Donna Calhoun. Fall 2013 Math 465/565. Office : MG241A Office Hours : Wednesday 10:00-12:00 and 1:00-3:00

Tegra Android Accelerometer Whitepaper

El Dorado Union High School District Educational Services

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Radeon HD 2900 and Geometry Generation. Michael Doggett

OpenGL Performance Tuning

Parameter Passing. Standard mechanisms. Call by value-result Call by name, result

Introduction to Programming (in C++) Multi-dimensional vectors. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

GPU Architecture. Michael Doggett ATI

Introduction to Python

Programming 3D Applications with HTML5 and WebGL

LLVM for OpenGL and other stuff. Chris Lattner Apple Computer

2+2 Just type and press enter and the answer comes up ans = 4

Color correction in 3D environments Nicholas Blackhawk

(67902) Topics in Theory and Complexity Nov 2, Lecture 7

Developer Tools. Tim Purcell NVIDIA

Data Structures using OOP C++ Lecture 1

Programming a truss finite element solver in C

Procedural Shaders: A Feature Animation Perspective

BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering

1 bool operator==(complex a, Complex b) { 2 return a.real()==b.real() 3 && a.imag()==b.imag(); 4 } 1 bool Complex::operator==(Complex b) {

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

MATLAB Basics MATLAB numbers and numeric formats

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

Writing Applications for the GPU Using the RapidMind Development Platform

Appendix: Tutorial Introduction to MATLAB

3.2 Matrix Multiplication

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

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

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

Beyond the Mouse A Short Course on Programming

Object Oriented Software Design II

A Static Analyzer for Large Safety-Critical Software. Considered Programs and Semantics. Automatic Program Verification by Abstract Interpretation

CUDAMat: a CUDA-based matrix class for Python

Moving from CS 61A Scheme to CS 61B Java

C++FA 5.1 PRACTICE MID-TERM EXAM

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Transcription:

Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science Laboratory University of New Mexico 1

Programming with WebGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 2

Data Types C types: int, float, bool Vectors: - float vec2, vec3, vec4 - Also int (ivec) and boolean (bvec) Matrices: mat2, mat3, mat4 - Stored by columns - Standard referencing m[row][column] C++ style constructors - vec3 a =vec3(1.0, 2.0, 3.0) - vec2 b = vec2(a) 3

No Pointers There are no pointers in GLSL We can use C structs which can be copied back from functions Because matrices and vectors are basic types they can be passed into and output from GLSL functions, e.g. mat3 func(mat3 a) variables passed by copying 4

Qualifiers GLSL has many of the same qualifiers such as const as C/C++ Need others due to the nature of the execution model Variables can change - Once per primitive - Once per vertex - Once per fragment - At any time in the application Vertex attributes are interpolated by the rasterizer into fragment attributes 5

Attribute Qualifier Attribute-qualified variables can change at most once per vertex There are a few built in variables such as gl_position but most have been deprecated User defined (in application program) - attribute float temperature - attribute vec3 velocity - recent versions of GLSL use in and out qualifiers to get to and from shaders 6

Uniform Qualified Variables that are constant for an entire primitive Can be changed in application and sent to shaders Cannot be changed in shader Used to pass information to shader such as the time or a bounding box of a primitive or transformation matrices 7

Varying Qualified Variables that are passed from vertex shader to fragment shader Automatically interpolated by the rasterizer With WebGL, GLSL uses the varying qualifier in both shaders varying vec4 color; More recent versions of WebGL use out in vertex shader and in in the fragment shader out vec4 color; //vertex shader in vec4 color; // fragment shader 8

Our Naming Convention Attributes passed to vertex shader have names beginning with v (vposition, vcolor) in both the application and the shader - Note that these are different entities with the same name Fragment variables begin with f (fcolor) in both shaders - must have same name Uniform variables are unadorned and can have the same name in application and shaders 9

Example: Vertex Shader attribute vec4 vposition; attribute vec4 vcolor; varying vec4 fcolor; void main() { gl_position = vposition; fcolor = vcolor; } 1 0

Corresponding Fragment Shader precision mediump float; varying vec4 fcolor; void main() { gl_fragcolor = fcolor; } 1 1

Sending Colors from Application var cbuffer = gl.createbuffer( ); gl.bindbuffer( gl.array_buffer, cbuffer ); gl.bufferdata( gl.array_buffer, flatten( colors ), gl.static_draw ); var vcolor = gl.getattriblocation( program, "vcolor" ); gl.vertexattribpointer( vcolor, 4, gl.float, false, 0, 0 ); gl.enablevertexattribarray( vcolor ); 1 2

Sending a Uniform Variable // in application vec4 color = vec4( 1.0, 0.0, 0.0, 1.0 ); colorloc = gl.getuniformlocation( program, color" ); gl.uniform4f( colorloc, color ); // in fragment shader (similar in vertex shader) uniform vec4 color; void main() { gl_fragcolor = color; } 1 3

Operators and Functions Standard C functions - Trigonometric - Arithmetic - Normalize, reflect, length Overloading of vector and matrix types mat4 a; vec4 b, c, d; c = b*a; // a column vector stored as a 1d array d = a*b; // a row vector stored as a 1d array 1 4