CS 480/680 Computer Graphics GLSL Overview.

Slides:



Advertisements
Similar presentations
Perspective aperture ygyg yryr n zgzg y s = y g (n/z g ) ysys y s = y r (n/z r ) zrzr.
Advertisements

CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
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,
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.
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.
GAM532 DPS932 – Week 1 Rendering Pipeline and Shaders.
Cg – C for Graphics Eric Vidal CS 280. History General graphics processing languages – Renderman shading language (1988) Assembly languages for graphics.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
An Introduction to the OpenGL Shading Language Benj Lipchak Rob Simpson Bill Licea-Kane.
A Really (too) Short Introduction to OpenGL Peter Rautek.
CIS 565 Fall 2011 Qing Sun
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
CS 480/680 Computer Graphics Shader Applications Dr. Frederick C Harris, Jr. Fall 2011.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
Shader Basics Chap. 2 of Orange Book. 2 Contents Why write shaders OpenGL programmable processors Language overview System overview.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CS662 Computer Graphics Game Technologies Jim X. Chen, Ph.D. Computer Science Department George Mason University.
OpenGL Shader Language Vertex and Fragment Shading Programs.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shader Applications Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
Shaders in OpenGL Marshall Hahn. Introduction to Shaders in OpenGL In this talk, the basics of OpenGL Shading Language will be covered. This includes.
CS418 Computer Graphics John C. Hart
GLSL OpenGL Programming and Reference Guides, other sources
OpenGL Shading Language (GLSL)
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
OpenGL Shading Language (GLSL)
Vertex Buffer Objects and Shader Attributes. For Further Reading Angel 7 th Ed: –Most parts of Chapter 2. Beginning WebGL: –Chapter 1: vertex Buffer Objects,
GLSL II.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
Programmable Pipelines. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Black Box View Geometry Processor Frame Buffer Fragment Processor.
GLSL I.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
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.
CS 4363/6353 SHADERS/GLSL. ANOTHER LOOK AT THE PIPELINE Vertex Processing Clipping/Assembly Rasterization Fragment Processing.
OpenGL Shading Language
OpenGL Shading Language (GLSL)
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.
OpenGl Shaders Lighthouse3d.com.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
Advanced Texture Mapping Bump Mapping & Environment Mapping (Reflection)
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
Shaders, part 2 alexandri zavodny.
Shader.
CSE 381 – Advanced Game Programming GLSL Syntax
CSE Real Time Rendering
Carl Johan Gribel, PhD student
Objectives Simple Shaders Programming shaders with GLSL
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Introduction to Computer Graphics with WebGL
Day 05 Shader Basics.
UMBC Graphics for Games
Chapter VI OpenGL ES and Shader
Introduction to Computer Graphics with WebGL
Shader Basics Chap. 2 of Orange Book.
Programming with OpenGL Part 3: Shaders
Programming with OpenGL Part 5: More GLSL
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
Programming with OpenGL Part 5: More GLSL
Language Definitions Chap. 3 of Orange Book.
CS 480/680 Part 1: Model Loading.
Introduction to Computer Graphics with WebGL
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

CS 480/680 Computer Graphics GLSL Overview

Vertex Shader Applications Moving Vertices Morphing Wave Motion Fractals Lighting More realistic models Cartoon Shaders

Fragment Shader Applications: Per Vertex Lighting Per Fragment Lighting

Fragment Shader Applications: Texture mapping Smooth shading Environment Mapping Bump Mapping

GLSL OpenGL Shading Language Vertex and Fragment shaders written in GLSL Part of OpeGL 2.0 and up As of OpenGL 3.1, application must use shaders. Example code of a vertex shader: const vec4 red = vec4(1.0, 0.0, 0.0, 1.0); out vec3 color_out; void main(void){ gl_Position = vPosition; color_out = red; }

Vertex & Fragment shader pipeline

Data Types C types: int, float, bool, double, uint Arrays/Vectors: float vec2, vec3, vec4 Also int (ivec) and boolean (bvec) Matrices of floats or doubles: Square matrices: 2x2, 3x3, or 4x4 : mat2, mat3, mat4 Stored by columns Standard referencing m[row][col] non-square matrices: size {2,3,4}x{2,3,4}: mat3x4, dmat4x2 Texture samplers sampler1D, sampler2D, sampler3D for 1, 2, 3D power-of-two textures sampler2DRect for rectangle textures samplerCube for cubemap textures

Data Types Variable declaration and initialization very similar to C-style float a = 1.0; vec3 point = vec3(1.0,1.0,4.0); mat2 mat = mat2(1.0,0.0,0.0,1.0); (matrices are assigned in column major order) C++ style constructors vec3 a = vec3(1.0, 2.0, 3.0) vec2 b = vec2(a)

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 be output from GLSL functions mat3 func(mat3 a)

Qualifiers GLSL has many of the same qualifiers (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 Any time in the program

Passing Values call by value‐return. Two possibilities in: variables copied in out: returned values are copied back inout (deprecated) Example: vertex shader using out const vec4 red = vec4(1.0, 0.0, 0.0, 1.0); out vec3 color_out; void main(void){ gl_Position = vPosition; color_out = red; }

Vertex Attribute Variables Vertex Attribute variables can change at most once per vertex Flows down the pipeline with each vertex Position, color, normal, texture cooddinates There are a few built in variables such as gl_Position but most have been deprecated User defined (in application program) Use in qualifier to get to shader (read only) in float temperature in vec3 velocity layout (location = 0) in vec3 vp;

Uniform parameters Variables that are set by the application but are constant for the entire primitive Transformation matrices, parameters of light sources, textures Can be changed in the application and sent to the shader Cannot be changed in the shader. uniform mat4 projectionMatrix;

Uniform parameters To set parameters, use glGetUniformLocation, glUniform* in application After shader is active, before rendering Example In shader declare uniform float a; In application, set a using GLuint p; //… initialize program p int i=glGetUniformLocation(p,”a”); glUniform1f(i, 1.f);

Some Built-In Variables vertex shader in: int gl_VertexID (for indexed rendering) vertex shader out: vec4 gl_Position (clip space position), - Required float gl_PointSize (pixel width/height for point rendering) Note other out variables will be interpolated during rasterization (texture coordiantes, …) fragment shader in: vec4 gl_FragCoord (location in window space) Note: for user defined variables you Need to have same variable name as output (declared as out) of vertex shader fragment shader out: float gl_FragDepth (fragment depth)

Operators and Functions Standard C functions Trigonometric: cos, sin, tan, etc Arithmetic: log, min, max, abs, etc 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

Swizzling and Selection Can refer to array elements by element using [] or selection (.) operator with x, y, z, w r, g, b, a s, t, p, q vec4 a; a[2], a.b, a.z, a.p are the same Swizzling operator lets us manipulate components a.yz = vec2(1.0, 2.0);

Open GL Quick Reference Card https://www.khronos.org/files/opengl45-quick-reference-card.pdf GLSL starts on page 9