GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.

Slides:



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

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
The Programmable Graphics Hardware Pipeline Doug James Asst. Professor CS & Robotics.
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.
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.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
An Introduction to the OpenGL Shading Language Benj Lipchak Rob Simpson Bill Licea-Kane.
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.
A Crash Course in HLSL Matt Christian.
CS 480/680 Computer Graphics Shader Applications Dr. Frederick C Harris, Jr. Fall 2011.
CSE 690: GPGPU Lecture 6: Cg Tutorial Klaus Mueller Computer Science, Stony Brook University.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shadow Mapping Chun-Fa Chang National Taiwan Normal University.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
CS662 Computer Graphics Game Technologies Jim X. Chen, Ph.D. Computer Science Department George Mason University.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center 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.
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)
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.
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.
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.
OpenGl Shaders Lighthouse3d.com.
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Models and Architectures 靜宜大學 資訊工程系 蔡奇偉 副教授 2012.
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.
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.
Programmable Pipelines
CSE Real Time Rendering
Carl Johan Gribel, PhD student
Graphics Processing Unit
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
ICG 2018 Fall Homework1 Guidance
Computer Graphics Practical Lesson 10
Programming with OpenGL Part 3: Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
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
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

GLSL I

 Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global illumination effects ▪ Ray tracing. ▪…▪… Multiple Normal Map Refraction/ reflection Subsurface scattering composing Make the Graphics Effects Possible & Real-time !!

 Vertex Shader  Skinning Mesh  Tessellation  Terrain Generation  Geometry Shader  Surface details  Fragment Shader  Advance shading

 Shader language  The language itself.  Runtime environment  How to co-work with OpenGL/D3D  Architecture  The role of the shaders.

 2000  Asambly, (nVidia)  2002  CG 1.0 (nVidia) ▪ C for graphcis  Vertex/fragment extension (OpenGL )  HLSL (High Level Shading Language, M$)  2003  GLSL (OpenGL)  2004  GPGPU Applications  Uniform GPU architecture for both VS and FS, (ATI)  2008  Direct Computing, CUDA,  2009  OpenCL

 Currently 3 major shading languages  - Cg (Nvidia)  - HLSL (Microsoft) ▪ Derived from Cg  - GLSL (OpenGL)  Main influences are  - C language  - Pre-existing Shading languages developed in university and industry.

 1.1+  Vertex/Fragment Shader  1.5+  Geometry Shader  4.0  Tessellation Shader

Rasterizer Screen Vertices3D modelColor Pixels Transform & Lighting Transform & Lighting Transform & Lighting Transform & Lighting Transform & Lighting Transform & Lighting Pixel Op. Pixels Scene Setting

10 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Vertex Shader Applications Moving vertices ­Morphing ­Wave motion ­Fractals Lighting ­More realistic models ­Cartoon shaders

11 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Fragment Shader Applications Per fragment lighting calculations per vertex lighting per fragment lighting

12 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 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

13 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Simple Vertex Shader const vec4 red = vec4(1.0, 0.0, 0.0, 1.0); void main(void) { gl_Position = gl_ProjectionMatrix *gl_ModelViewMatrix*gl_Vertex; gl_FrontColor = red; }

14 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Execution Model

15 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Simple Fragment Program void main(void) { gl_FragColor = gl_FrontColor; }

16 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Execution Model

17 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Data Types C types: int, float, bool Vectors: ­float vec2, vec 3, 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)

18 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 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. matrix3 func(matrix3 a)

19 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 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

20 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 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

21 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 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 the bounding box of a primitive

22 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Varying Qualified Variables that are passed from vertex shader to fragment shader Automatically interpolated by the rasterizer Built in ­Vertex colors ­Texture coordinates User defined ­Requires a user defined fragment shader

23 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 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; }

24 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Required Fragment Shader varying vec3 color_out; void main(void) { gl_FragColor = color_out; }

25 A Quick Review What are the qualifier (attribute, uniform, varying) for the following cases? If variables change… ­Once per primitive  (uniform? attribute?...) ­Once per vertex  ? ­Once per fragment  ? Vertex attributes are interpolated by the rasterizer into fragment attributes

26 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Passing values call by value-return Variables are copied in Returned values are copied back Three possibilities ­in ­out ­inout

27 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 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

28 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 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);

29 For More Information… Tutorials available online (see the course webpage, Reference section) ­At ­At