OpenGL Shading Language

Slides:



Advertisements
Similar presentations
GLSL Basics Discussion Lecture for CS 418 Spring 2015 TA: Zhicheng Yan, Sushma S Kini, Mary Pietrowicz.
Advertisements

Introduction to GLSL Patrick Cozzi University of Pennsylvania CIS Fall 2014.
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 4 : GLSL Shaders Topics: Shader programs, vertex & fragment shaders, passing data into.
MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 5 : GLSL Shaders Topics: Shader syntax, passing textures into shaders, per-pixel lighting,
Announcments Project 1 Project 2 Midterm Project 3.
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
Announcments Sign up for crits!. Reading for Next Week FvD – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.
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.
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.
CIS 565 Fall 2011 Qing Sun
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
WebGL: in-browser 3D graphics Nick Whitelegg Maritme and Technology Faculty Southampton Solent University.
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.
Lecture by: Martin Deschamps CSE 4431
Shader Basics Chap. 2 of Orange Book. 2 Contents Why write shaders OpenGL programmable processors Language overview System overview.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
OpenGL Shader Language Vertex and Fragment Shading Programs.
Wilf Comp Shaders. Wilf Comp 4002 Shaders Shaders are programs that you can download onto the card Can be used.
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.
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.
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
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.
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.
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.
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 Real Time Rendering
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
Carl Johan Gribel, PhD student
Chapter 6 GPU, Shaders, and Shading Languages
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
Programming with OpenGL Part 3: Shaders
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
CS 480/680 Computer Graphics GLSL Overview.
Language Definitions Chap. 3 of Orange Book.
CS 480/680 Part 1: Model Loading.
Introduction to Computer Graphics with WebGL
Programmable Pipelines
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

OpenGL Shading Language GLSL I OpenGL Shading Language

Objectives Shader applications Programming shaders Vertex shaders Fragment shaders Programming shaders Cg GLSL GLSL 1

Vertex Shader Applications Moving vertices Morphing Wave motion Fractals Lighting More realistic models Cartoon shaders GLSL 1

Fragment Shader Applications Per fragment lighting calculations per vertex lighting per fragment lighting GLSL 1

Fragment Shader Applications Texture mapping smooth shading environment mapping bump mapping GLSL 1

Writing Shaders First programmable shaders assembly-like OpenGL extensions added for vertex and fragment shaders Cg (C for graphics): C-like language for programming shaders Works with both OpenGL and DirectX Interface to OpenGL complex OpenGL Shading Language (GLSL) GLSL 1

GLSL OpenGL Shading Language Part of OpenGL 2.0 High level C-like language New data types Matrices Vectors Samplers OpenGL state available through built-in variables GLSL 1

Simple Vertex Shader const vec4 red = vec4(1.0, 0.0, 0.0, 1.0); void main(void) { gl_Position = gl_ProjectionMatrix *gl_ModelViewMartrix*gl_Vertex; gl_FrontColor = red; } GLSL 1

Execution Model GLSL 1

Simple Fragment Program void main(void) { gl_FragColor = gl_Color; } GLSL 1

Execution Model GLSL 1

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) GLSL 1

Pointers No pointers in GLSL Can use C structs can be copied back from functions matrices and vectors are basic types  can be passed into output from GLSL functions, e.g., matrix3 func(matrix3 a) GLSL 1

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

Attribute Qualifier Attribute-qualified variables can change at most once per vertex Cannot be used in fragment shaders Built in (OpenGL state variables) gl_Color gl_ModelViewMatrix User defined (in application program) attribute float temperature attribute vec3 velocity GLSL 1

Uniform Qualified Variables that are constant for an entire primitive Can be changed in application outside scope of glBegin and glEnd Cannot be changed in shader Used to pass information to shader such as bounding box of primitive GLSL 1

Varying Qualified Variables passed from vertex shader to fragment shader Automatically interpolated by rasterizer Built in Vertex colors Texture coordinates User defined Requires user defined fragment shader GLSL 1

Example: Vertex Shader const vec4 red = vec4(1.0, 0.0, 0.0, 1.0); varying vec3 color_out; void main(void) { gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex; color_out = red; } GLSL 1

Required Fragment Shader varying vec3 color_out; void main(void) { gl_FragColor = color_out; } GLSL 1

Passing values call by value-return Variables copied in Returned values copied back Three possibilities in out inout GLSL 1

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; // column vector stored as 1d array d = a*b; // row vector stored as 1d array GLSL 1

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 a[2], a.b, a.z, a.p are the same Swizzling operator lets us manipulate components vec4 a; a.yz = vec2(1.0, 2.0); GLSL 1

Swizzling To convert external names, array indices, or references within a data structure into address pointers when the data structure is brought into main memory from external storage (also called "pointer swizzling"); this may be done for speed in chasing references or to simplify code (e.g. by turning lots of name lookups into pointer dereferences). The converse operation is sometimes termed "unswizzling". GLSL 1