COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.

Slides:



Advertisements
Similar presentations
COMPUTER GRAPHICS CS 482 – FALL 2014 NOVEMBER 10, 2014 GRAPHICS HARDWARE GRAPHICS PROCESSING UNITS PARALLELISM.
Advertisements

CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
 The success of GL lead to OpenGL (1992), a platform-independent API that was  Easy to use  Close enough to the hardware to get excellent performance.
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 5 : GLSL Shaders Topics: Shader syntax, passing textures into shaders, per-pixel lighting,
Introduction to Shader Programming
GLSL I May 28, 2007 (Adapted from Ed Angel’s lecture slides)
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
The programmable pipeline Lecture 10 Slide Courtesy to Dr. Suresh Venkatasubramanian.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Shaders Feb 18, 2011 Creative Commons Attribution 3.0 (Except copyrighted.
GPU Graphics Processing Unit. Graphics Pipeline Scene Transformations Lighting & Shading ViewingTransformations Rasterization GPUs evolved as hardware.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
Enhancing GPU for Scientific Computing Some thoughts.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Real-time Graphical Shader Programming with Cg (HLSL)
Geometric Objects and Transformations. Coordinate systems rial.html.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
GPU Shading and Rendering Shading Technology 8:30 Introduction (:30–Olano) 9:00 Direct3D 10 (:45–Blythe) Languages, Systems and Demos 10:30 RapidMind.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Chris Kerkhoff Matthew Sullivan 10/16/2009.  Shaders are simple programs that describe the traits of either a vertex or a pixel.  Shaders replace a.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
The programmable pipeline Lecture 3.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
CS 480/680 Intro Dr. Frederick C Harris, Jr. Fall 2014.
A Closer Look At GPUs By Kayvon Fatahalian and Mike Houston Presented by Richard Stocker.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
OpenGL Shader Language Vertex and Fragment Shading Programs.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
Ray Tracing using Programmable Graphics Hardware
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Mesh Skinning Sébastien Dominé. Agenda Introduction to Mesh Skinning 2 matrix skinning 4 matrix skinning with lighting Complex skinning for character.
Mapping Computational Concepts to GPUs Mark Harris NVIDIA.
OpenGL Shading Language
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
GPU Computing for GIS James Mower Department of Geography and Planning University at Albany.
An Introduction to the Cg Shading Language Marco Leon Brandeis University Computer Science Department.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Computer Science – Game DesignUC Santa Cruz Tile Engine.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 5 Examples 1.
Our Graphics Environment Landscape Rendering. Hardware  CPU  Modern CPUs are multicore processors  User programs can run at the same time as other.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Graphics Processing Unit
Introduction to OpenGL
Chapter 6 GPU, Shaders, and Shading Languages
Lecture 13: OpenGL Shading Language (GLSL)
Introduction to Computer Graphics with WebGL
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Day 05 Shader Basics.
UMBC Graphics for Games
Chapter VI OpenGL ES and Shader
Graphics Processing Unit
Computer Graphics Practical Lesson 10
Programming with OpenGL Part 3: Shaders
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
Computer Graphics Introduction to Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
03 | Creating, Texturing and Moving Objects
Introduction to OpenGL
CS 480/680 Computer Graphics GLSL Overview.
Language Definitions Chap. 3 of Orange Book.
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
CIS 6930: Chip Multiprocessor: GPU Architecture and Programming
Presentation transcript:

COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016

COMP 175 | COMPUTER GRAPHICS Remco Chang2/XX13 – GLSL  Last week, we discussed the many of the new “tricks” in Graphics require low-level access to the Graphics pipeline  For example, using textures, which is a pain in regular OpenGL. Motivation

COMP 175 | COMPUTER GRAPHICS Remco Chang3/XX13 – GLSL Graphics History  Software Rendering  Old-fashioned way (Use ray casting)  Fixed-Function  Immediate Mode (What we have used)  Programmable Pipeline (~2001)  GL Shading Language (What we will learn)  CUDA/OpenCL (GPGPU) (~2008)  General Purpose GPU Programming

COMP 175 | COMPUTER GRAPHICS Remco Chang4/XX13 – GLSL Ray Casting (Software Rendering)  Wolfenstein  Quake 1

COMP 175 | COMPUTER GRAPHICS Remco Chang5/XX13 – GLSL Fixed-Function  Quake 3  Half-Life

COMP 175 | COMPUTER GRAPHICS Remco Chang6/XX13 – GLSL Programmable Pipeline (Shaders)  Doom 3  Far Cry

COMP 175 | COMPUTER GRAPHICS Remco Chang7/XX13 – GLSL GPGPU  General Purpose Graphics Processing Unit  Utilize graphics card for computation  Do work other than graphics

COMP 175 | COMPUTER GRAPHICS Remco Chang8/XX13 – GLSL Old Fixed-Function

COMP 175 | COMPUTER GRAPHICS Remco Chang9/XX13 – GLSL Programmable Pipeline

COMP 175 | COMPUTER GRAPHICS Remco Chang10/XX13 – GLSL Accessing Programmable Pipeline Introducing Shaders! 4/15/

COMP 175 | COMPUTER GRAPHICS Remco Chang11/XX13 – GLSL  CPU: Typical C++ code  GPU: OpenGL Shading Language (GLSL)  CPU passes data to GPU  Some processing happens on the CPU:  Get mouse movement  Load and parse data from disk  Some processing happens on the GPU:  Transform point from Object to World space  Solve lighting equation  Render CPU + GPU

COMP 175 | COMPUTER GRAPHICS Remco Chang12/XX13 – GLSL  Most common:  Vertex  Fragment (Pixel)  Newer:  Geometry  Tessellation  Compute Types of Shaders

COMP 175 | COMPUTER GRAPHICS Remco Chang13/XX13 – GLSL  OpenGL Shading Language (GLSL)  Syntax  Sequence and processes  Vertex Shader  Pixel Shader  Communication between CPU and GPU  What type of information can be passed  How to pass information  Note that you also need to know how to load a shader program, but that’s “magic incantation” that (mostly) stays the same every time. Two Things to Learn:

COMP 175 | COMPUTER GRAPHICS Remco Chang14/XX13 – GLSL

COMP 175 | COMPUTER GRAPHICS Remco Chang15/XX13 – GLSL Interfacing with the GPU  Modern OpenGL  Mobile/Web Programming  Direct3D  Compute Languages  Stream, OpenCL, CUDA  Future

COMP 175 | COMPUTER GRAPHICS Remco Chang16/XX13 – GLSL Client/Server Architecture  Think of like a network  Client = the CPU  Server = the GPU  The less they talk, the better  Less waiting for memory to transfer  Bandwidth is almost always the bottleneck  Send data over once, and have it ready to go

COMP 175 | COMPUTER GRAPHICS Remco Chang17/XX13 – GLSL Optimizations Available  Vertex Array  Display Lists  Vertex Buffer Objects  Pixel Buffers  Frame Buffer Objects Michael Shah

COMP 175 | COMPUTER GRAPHICS Remco Chang18/XX13 – GLSL Immediate Mode  Every ‘gl’ command is being sent to the GPU every iteration.  Very inefficient  Think of it like having an interpreter versus a compiler for C++ Michael Shah

COMP 175 | COMPUTER GRAPHICS Remco Chang19/XX13 – GLSL Vertex Array  No more glBegin/glEnd  Store Vertices, indices, normals, colors, texture coordinates in an array  Minimizes OpenGL calls on Client (CPU)  Data still being passed from Client to Server every frame  A little better because it’s all at once  Stylistically, much cleaner code as well Michael Shah

COMP 175 | COMPUTER GRAPHICS Remco Chang20/XX13 – GLSL  Compiled geometry  Send it to the Server(GPU) once, and it is stored in memory on Server  Geometry cannot be updated, without deleting display list. someGeometryDisplayList = glGenLists(1); glNewList(someGeometryDisplayList,GL_COMPILE); drawShape(); glEndList(); Display List 4/22/2014 Michael Shah 20

COMP 175 | COMPUTER GRAPHICS Remco Chang21/XX13 – GLSL Vertex Buffer Object (VBO)  Improves upon Vertex Array  We can store data on the Server (GPU)  Just like display lists!  We get a pointer into the Server (GPU) so that we can update it!  As good as display lists!  Because we have a pointer to the data, multiple clients can access data.  Multiple instances of a program can access data 4/22/2014 Michael Shah 21

COMP 175 | COMPUTER GRAPHICS Remco Chang22/XX13 – GLSL Modifiers to Variables Uniform/Varying/Attribute  Uniform – Read only data passed into vertex/fragment shaders  Attributes – Input value which change every vertex.  Read only – Used only in vertex shader  Depending on GLSL version:  GLSL <3.0: Varying – Pass data from vertex to fragment shader.  GLSL >=3.0: in / out – in is the variable being passed in, out is the variable being passed out  Read-only in fragment shader.  Read/Write in Vertex Shader

COMP 175 | COMPUTER GRAPHICS Remco Chang23/XX13 – GLSL OpenGL Shading Language

COMP 175 | COMPUTER GRAPHICS Remco Chang24/XX13 – GLSL GLSL  C-Like Language  Made for GPU Architecture  Because GPU’s are different than CPU’s  Still Cross Platform  Debugging – Still as difficult  Domain Specific Language  Compiled at runtime

COMP 175 | COMPUTER GRAPHICS Remco Chang25/XX13 – GLSL GLSL Primitives  float, int, bool Example: float f = 10.0; or float f = float(10); (Casting not allowed, choose your type wisely!)

COMP 175 | COMPUTER GRAPHICS Remco Chang26/XX13 – GLSL GLSL Types  Vector: vec2, vec3, vec4  Overloaded to take in each type  Example: vec4 temp= vec4(1.0, 1.0, 1.0, 1.0)  Matrix: mat2, mat3, mat4  Example: glModelViewMatrix is a mat4 type  Access first column with: mat[0]  Access second column with: mat[1]  Example: mat[1] = vec3(1.0, 1.0, 1.0);  Access individual element: mat[2][1];

COMP 175 | COMPUTER GRAPHICS Remco Chang27/XX13 – GLSL Some more examples  Pass in vec3 into a vec4 vec3 color = vec3(1.0,0.5,0.25) vec4 temp = vec4(color, 1.0)  Get components of vector  color.x = 1.0; or color[0] = 1.0  color.y = 1.0; or color[1] = 1.0;

COMP 175 | COMPUTER GRAPHICS Remco Chang28/XX13 – GLSL Swizzling [1][1]  Swizzling is the ability to rearrange a vectors components  vec2 pos = temp.xy; // retrieve x and y component, or any of xyzw  vec2 pos = temp.yz;  vec4 = color.agbr; // opposite of rgba

COMP 175 | COMPUTER GRAPHICS Remco Chang29/XX13 – GLSL  Note that some of these default keywords might not be there depending on GLSL version number (for example: gl_ModelViewMatrix isn’t there any more) More GLSL Keywords [1][2]12

COMP 175 | COMPUTER GRAPHICS Remco Chang30/XX13 – GLSL Write a Simple Shader Basic Vertex and Fragment Shader

COMP 175 | COMPUTER GRAPHICS Remco Chang31/XX13 – GLSL Writing a Shader  Writing a shader, compiling a shader, and loading a shader  Compile at runtime  So we do not need to recompile entire source, if we only modify shader.

COMP 175 | COMPUTER GRAPHICS Remco Chang32/XX13 – GLSL

COMP 175 | COMPUTER GRAPHICS Remco Chang33/XX13 – GLSL Simple Vertex Shader

COMP 175 | COMPUTER GRAPHICS Remco Chang34/XX13 – GLSL Simple Fragment Shader

COMP 175 | COMPUTER GRAPHICS Remco Chang35/XX13 – GLSL The cpp file

COMP 175 | COMPUTER GRAPHICS Remco Chang36/XX13 – GLSL Drawing with immediate mode for now

COMP 175 | COMPUTER GRAPHICS Remco Chang37/XX13 – GLSL Final Image