Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.

Slides:



Advertisements
Similar presentations
MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 4 : GLSL Shaders Topics: Shader programs, vertex & fragment shaders, passing data into.
Advertisements

MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 5 : GLSL Shaders Topics: Shader syntax, passing textures into shaders, per-pixel lighting,
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
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 Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
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.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
OpenGL Shading Language Jian Huang CS594, Spring 2005.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
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.
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.
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
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
OpenGL Shading Language (GLSL)
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
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.
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.
CS 480/680 Computer Graphics Programming with Open GL Part 5: Putting it all together Dr. Frederick C Harris, Jr. Fall 2011.
GLSL I.
Programming with OpenGL Part 5: More GLSL Isaac Gang University of Mary Hardin-Baylor E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley.
 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.
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.
Programmable Pipelines
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
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.
Chapter VI OpenGL ES and Shader
Introduction to Computer Graphics with WebGL
Introduction to Shaders
ICG 2018 Fall Homework1 Guidance
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 -
Programming with OpenGL Part 5: More GLSL
CS 480/680 Computer Graphics GLSL Overview.
Language Definitions Chap. 3 of Orange Book.
CS 480/680 Part 1: Model Loading.
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
Programmable Pipelines
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 172 Shading Languages Pixar’s RenderMan shading language is the first to look at shaders as mathematical expressions Expressions involve variables, constants, and operations among them Some of these are available from the graphics environment Some common shading languages:  OpenGL Shading Language (GLSL)  Cg (C for Graphics)

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 173 OpenGL Shading Language Vertex shaders Fragment shaders Part of OpenGL 2.0

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 174 Vertex shaders Replaces the fixed-function operations performed by the vertex processor with operations defined by the shader Executed on each vertex as it passes down the graphics pipeline Must output the information the rasterizer needs to do its job Minimum information that needs to be output:  Vertex position

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 175 What happens to vertices? Vertex positions are defined in object (world) space Transformed first by the model-view matrix into eye coordinates Then transformed by the projection matrix into clip coordinates Thus, vertex shaders must perform this set of transformations Vertex program can access the OpenGL state

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 176 Simple vertex shader /* pass through vertex shader */ void main (void) { gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; }

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 177 A second simple vertex shader /* simple vertex shader */ const vec4 red = vec4(1.0, 0.0, 0.0, 1.0); void main (void) { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; gl_FrontColor = red; }

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 178 Fragment shaders Same syntax as vertex shaders Executed after the rasterizer Operate on each fragment rather than on each vertex

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 179 Simple fragment shader /* simple fragment shader */ void main (void) { gl_FragColor = glFrontColor; }

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 1710 GLSL data types Vectors  vec2, vec3, vec4 (floating-point)  ivec2, ivec3, ivec4 (integer)  bvec2, bvec3, bvec4 (Boolean)  Can be indexed by position (x,y,z,w), color (r,g,b,a), or texture coordinates (s,t,p,q) Matrices  mat2, mat3, mat4  Always square and floating point

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 1711 GLSL qualifiers const – makes the variable unchangeable by the shader attribute – used by vertex shaders for variables that change at most once per vertex in the vertex shader uniform – used for variables that are set in the application program for an entire primitive (variables whose values are assigned outside the scope of a glBegin and a glEnd ) varying – provide the mechanism for conveying data from a vertex shader to a fragment shader (defined on a per-vertex basis but are interpolated over the primitive by the fragment shader)

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 1712 GLSL operators Operations are overloaded so you can do matrix and vector operations (such as multiplication using *) Swizzling allows selection of multiple components from a matrix or vector  Example: if a is declared as a vec4, then a.xy=a.yx; swaps the x and y values of a

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 1713 GLSL functions GLSL contains the usual math and trig functions, such as sin, cos, tan, sqrt, abs, etc. Additional functions to help with geometric calculations involving vectors, such as length, distance, normalize, and reflect

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 1714 Linking shaders to OpenGL programs Need a program object that can hold the shaders: GLunit myProgObj; myProgObj = glCreateProgram(); Need an object to hold the shader: GLunit myVertexObj; myVertexObj = glCreateShader(GL_VERTEX_SHADER);

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 1715 Linking shaders to OpenGL programs Need tell OpenGL where the shader source is: glShaderSource(myVertexObj, 1, vertexProg, NULL); where vertexProg contains the shader code Need to compile the shader: glCompileShader(myVertexObj); Need to attach the shader to the program object: glAttachObject(myProgObj, myVertexObj);

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 1716 Linking shaders to OpenGL programs Need to identify which program object to use: glUseProgram(myProgObj); where vertexProg contains the shader code Need to link everything together: glLinkProgram(myProgObj);

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 1717 Example program shader.c is an example program that demonstrates a simple OpenGL shader

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 1718 Shader to move vertices sinusoidally uniform float time; /* value provided by application program */ void main() { float s; s = *sin(time); gl_Position = vec4(s, s, s, 1.0) * (gl_ModelViewProjectionMatrix * gl_Vertex); }

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 1719 Aligning variables with shaders Need to align variables used in shaders with variables used in application program so information can be passed between them We’ll increment a time variable in our idle callback function that needs to be passed to the vertex shader just described

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 1720 Aligning variables with shaders Shader variables are indexed in the main program through tables that are set up during linking Need to get the location of the variable in the table: Glint timeParam; timeParam = glGetUniformLocation (program, “time”);

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 1721 Aligning variables with shaders Now you can send the value of the program variable (let’s say it’s myTime ) to the shader: glUniform1f (timeParam, myTime);

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 1722 Example program Program movingShader.c demonstrates the passing of variables to shaders