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

Slides:



Advertisements
Similar presentations
POST-PROCESSING SET09115 Intro Graphics Programming.
Advertisements

MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
1 Building Models. 2 Objectives Introduce simple data structures for building polygonal models ­Vertex lists ­Edge lists OpenGL vertex arrays.
GLSL Basics Discussion Lecture for CS 418 Spring 2015 TA: Zhicheng Yan, Sushma S Kini, Mary Pietrowicz.
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,
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Today: - Make sure everyone is set up with an OpenGL environment - OpenGL basics:
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.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
GAM532 DPS932 – Week 1 Rendering Pipeline and Shaders.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Geometric Objects and Transformations. Coordinate systems rial.html.
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.
WebGL: in-browser 3D graphics Nick Whitelegg Maritme and Technology Faculty Southampton Solent University.
CSE 690: GPGPU Lecture 6: Cg Tutorial Klaus Mueller Computer Science, Stony Brook University.
Lecture by: Martin Deschamps CSE 4431
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
GPU Shading and Rendering: OpenGL Shading Language Marc Olano UMBC.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
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.
Shaders in OpenGL Marshall Hahn. Introduction to Shaders in OpenGL In this talk, the basics of OpenGL Shading Language will be covered. This includes.
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)
Geometry Shader (GLSL)
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.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
 Learn how you can use the shader through OpenGL ES  Add texture on object and make the object have a different look!!
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
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.
Background image by chromosphere.deviantart.com Fella in following slides by devart.deviantart.com DM2336 Programming hardware shaders Dioselin Gonzalez.
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.
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.
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.
GLSL Basics Slides by : Wei-Wen Feng.
How to use a Pixel Shader CMT3317. Pixel shaders There is NO requirement to use a pixel shader for the coursework though you can if you want to You should.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Shaders, part 2 alexandri zavodny.
Shader.
The Basics: HTML5, Drawing, and Source Code Organization
Chapter 6 GPU, Shaders, and Shading Languages
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.
Chapter VI OpenGL ES and Shader
Introduction to Shaders
Introduction to Computer Graphics with WebGL
ICG 2018 Fall Homework1 Guidance
Programming with OpenGL Part 3: Shaders
Hw03 : shader.
Computer Graphics Introduction to Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
CS 480/680 Computer Graphics GLSL Overview.
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 4 : GLSL Shaders Topics: Shader programs, vertex & fragment shaders, passing data into shaders, passing textures into shaders, shader syntax

MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Bypassing fixed-functionality OpenGL gives you hardware accelerated methods to position geometry in space and to render that geometry to the screen GLSL gives you more control over the positioning and rendering. Vertex shaders allow you to a) reposition the vertices of your geometry b) to quickly calculate information based on the position, normals, color, and texture coordinates of your geometry information from the vertex shader is passed to the fragment shader Fragment shaders give you complete control over the pixels in the geometry specified by the vertices.

MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Vertex shader the information passed from the vertex shader to the fragment shader is automatically interpolated across the geometry. In the fixed-functionality pipeline, this happens automatically with the position, the color, the normals, and the texture coordinates. In the vertex shader you can create your own interpolated variables by defining and writing to a special type of data called “varying” At the very least, you must specify a built-in varying variable called “gl_Position” which indicates how the geometry is projected onto the 2D screen. The vertex shader has access to the modelview matrix and the projection matrix, or you can call ftransform() to automatically mimic the fixed-functionality pipeline. Vertex shaders are used for particle effects, deformations, etc

MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Fragment shader The fragment shader ultimately defines the color of every pixel of the geometry. You use a combination of global (“uniform”) and interpolated (“varying”) data to determine how to color the pixels. Fragment shaders commonly are used for lighting models, image processing techniques, blurring, glow filters, light scattering effects, etc. Fragment shaders run for every pixel, whereas vertex shaders run only once per vertex. So if possible, put the necessary logic in the vertex shader. In some cases, the automatic interpolation of values may not be sufficient, and some or all logic may have to be placed in the fragment shader.

MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Installing a shader program 1. Create a shader program programID = glCreateProgram(); 2. Create the vertex and fragment shaders vertexID = glCreateShader(GL_VERTEX_SHADER); fragmentID = glCreateShader(GL_FRAGMENT_SHADER); 3. Load source code from a file glShaderSource(vertexID, numLines, vertexSource, lineLengths, 0); glShaderSource(fragmentID, numLines, fragmentCode, lineLengths, 0); 4. Compile the shader glCompileShader(vertexID); glCompileShader(fragmentID); 5. Attach the shaders to the program glAttachShader(programID, vertexID); glAttachShader(programID, fragmentID); 6. Link the program to the OpenGL context glLinkProgram(programID);

MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Using a shader program 1. Bind the program within your display loop to bypass fixed-functionality glUseProgram(programID); 2. Pass “uniform” data into the shaders uniformID = glGetUniformLocation(programID, variableName); glUniform...(uniformID, values...); 3. Pass texture data into the shaders glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE#); glBindTexture(GL_TEXTURE_2D, textureID); uniformID = glGetUniformLocation(programID, textureVariableName); glUniform1i(textureVariableName, #); 3. Draw geometry (passing in “attribute” data if necessary) attributeID = glGetAttribLocation(programID, variableName); glBegin(GL_POINTS); glVertexAttrib...(attributeID, values...); glVertex3f(x, y, z); glEnd(); 4. Unbind the program to return to fixed-functionality pipeline glUseProgram(0);

MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes OpenGL  GLSL data types Uniform data = Data that is global to the entire shader program e.g. textures, timestamp, counters, blending value, states, filter kernels Vertex Attribute data = Data that is specific to a particular vertex e.g. position offsets, color offsets, texture coordinates glColor, glNormal, glVertex, glTexCoord are all automatically available

MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes GLSL data types Uniform data = global data passed in from OpenGL, read-only and available in the vertex shaders and the fragment shaders Attribute data = vertex specific data passed in from OpenGL, read-only, available only in the vertex shader Varying data = data interpolated between vertices, writable in the vertex shader and read-only in fragment shader

MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Simple example This example mimcs fixed-functionality with no lighting and no texturing. simple.vert //passes the position to the fragment shader void main() { gl_Position = ftransform(); //gl_Position must ALWAYS be set } simple.frag //interpolates the colors of the vertices void main() { gl_FragColor = gl_Color; //gl_FragColor must ALWAYS be set }