CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.

Slides:



Advertisements
Similar presentations
COMPUTER GRAPHICS CS 482 – FALL 2014 NOVEMBER 10, 2014 GRAPHICS HARDWARE GRAPHICS PROCESSING UNITS PARALLELISM.
Advertisements

GLSL Basics Discussion Lecture for CS 418 Spring 2015 TA: Zhicheng Yan, Sushma S Kini, Mary Pietrowicz.
Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 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.
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.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
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.
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.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
1 Introduction to Computer Graphics SEN Introduction to OpenGL Graphics Applications.
Real-Time High Quality Rendering CSE 291 [Winter 2015], Lecture 4 Brief Intro to Programmable Shaders
Shadow Mapping Chun-Fa Chang National Taiwan Normal University.
OpenGL Shading Language Jian Huang CS594, Spring 2005.
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.
Review of OpenGL Basics
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
OpenGL Shading Language (GLSL)
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)
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
 Learn how you can use the shader through OpenGL ES  Add texture on object and make the object have a different look!!
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
MP3 Frequently Asked Questions (IN OFFICE HOURS).
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.
MP3.. Start at the very beginning. Almost. Either start from nothing yourself, or use the empty template for this MP. Run through the provided files are.
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.
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.
Shader.
Week 2 - Friday CS361.
Real-Time Rendering Buffers in OpenGL 3.3
Programmable Pipelines
Graphics Processing Unit
Deferred Lighting.
Chapter 6 GPU, Shaders, and Shading Languages
The Graphics Rendering Pipeline
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
ICG 2018 Fall Homework1 Guidance
Computer Graphics Practical Lesson 10
Programming with OpenGL Part 3: Shaders
Computer Graphics Introduction to Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
03 | Creating, Texturing and Moving Objects
CS 480/680 Computer Graphics GLSL Overview.
Language Definitions Chap. 3 of Orange Book.
Frame Buffers Fall 2018 CS480/680.
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

CSE 381 – Advanced Game Programming GLSL

Rendering Revisited

In a vertex shader You can write code for tasks such as: –Vertex position transformation using the modelview and projection matrices –Normal transformation, and if required its normalization –Texture coordinate generation and transformation –Lighting per vertex or computing values for lighting per pixel –Color computation

GLSL Vertex Shader Responsibility The vertex shader is responsible for at least writing a variable: gl_Position –usually transforming the vertex with the modelview and projection matrices. A vertex processor has access to OpenGL state –so it can perform operations that involve lighting for instance, and use materials. –It can also access textures (only available in the newest hardware). –There is no access to the frame buffer.

Shader Beware There is no requirement to perform all the necessary operations in your shader –your application may not use lighting for instance. Warning: –once you write a vertex shader you are replacing the full functionality of the vertex processor you can't perform normal transformation and expect the fixed functionality to perform texture coordinate generation –When a vertex shader is used it becomes responsible for replacing all the needed functionality of this stage of the pipeline

The fragment (pixel) shader Is responsible for operations like: –Computing colors, and texture coordinates per pixel –Texture application –Fog computation –Computing normals if you want lighting per pixel

Pixel Shader Responsibilities A fragment shader has two output options: –to discard the fragment, hence outputting nothing –to compute either gl_FragColor (the final color of the fragment), or gl_FragData when rendering to multiple targets. Depth can also be written but it is not required since the previous stage already has computed it. Note: –the fragment shader has no access to the frame buffer. –operations such as blending occur only after the fragment shader has run.

GLSL Use Overview

A note about programs A GLSL “Program” does not refer to your game What is it? –a GLSL “program” –basically a set of shaders

Creating a Shader 1.Create a shader container 2.Define the contents of your shader 3.Compile your shader

Creating a Shader Container First, create the shader container Use: GLhandleARB glCreateShaderObjectARB(GLenum shaderType); Ex: GLhandleARB shaderContainer; shaderContainer = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); … shaderContainer = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

How many shaders can you create? As many as you want to add to a program, NOTE: there can only be: –one main function for the set of vertex shaders AND –one main function for the set of fragment shaders in each single program.

Defining your shader The source code for a shader is a string array, although you can use a pointer to a single string. To set the source code for a shader use: void glShaderSourceARB(GLhandleARB shader, int numOfStrings, const char **strings, int *lenOfStrings); Parameters: –shader - the handle to the shader. –numOfStrings - the number of strings in the array. –strings - the array of strings. –lenOfStrings - an array with the length of each string, or NULL, meaning that the strings are NULL terminated.

Compile the shader Use: void glCompileShaderARB(GLhandleARB program); Parameter: –program - the handle to the program.

Creating a Program 1.Create a program container 2.Attach the shaders to the program 3.Link the program 4.Use the shader

Create a program container What’s a program container? Use: GLhandleARB glCreateProgramObjectARB(void); Returns: –a handle for the container

How many programs? As many programs as you want Once rendering: –you can switch from program to program –go back to fixed functionality during a single frame Ex: –you may want to draw a teapot with refraction and reflection shaders WHILE –having a cube map displayed for background using OpenGL's fixed functionality

Attach the shaders to the program The shaders: –do not need to be compiled at this time –they don't even have to have source code Why is that good? –platform independence To attach a shader to a program: void glAttachObjectARB(GLhandleARB program, GLhandleARB shader); Parameters: –program - the handle to the program –shader - the handle to the shader you want to attach

Dealing with multiple shaders If you have a pair vertex/fragment shaders, you'll need to attach both to the program You can have many shaders of the same type (vertex or fragment) attached to the same program, –just like a C program can have many modules. For each type of shader there can only be one shader with a main function, also as in C. You can attach a shader to multiple programs, for instance if you plan to use the same vertex shader in several programs.

Link the program In order to carry out this step the shaders must be compiled as described previously Use: void glLinkProgramARB(GLhandleARB program); Parameters: –program - the handler to the program. After the link operation, the shader's source can be modified, and the shaders recompiled without affecting the program.

Use a shader program To actually load and use a shader program, use: void glUSeProgramObjectARB(GLhandleARB prog); Parameters: –prog – either: the handle to the program you want to use zero to return to fixed functionality

Notes on using a program Each program is assigned a handle You can have as many programs linked and ready to use as you want –and your hardware allows If a program is in use, and it is linked again, it will automatically be placed in use again –so in this case you don't need to call this function again. –if the parameter is zero then the fixed functionality is activated.

Let’s open up an example Next time: –we’ll examine how to write the shaders

References GLSL Tutorial – OpenGL Shading Language (the orange book) –