DOC PREVIEW
UTK CS 594 - OpenGL Shading Language

This preview shows page 1-2-3-4-5-32-33-34-35-64-65-66-67-68 out of 68 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

OpenGL Shading LanguageWhy the need?Why the need? (cont.)Software RendersCgOpenGL Shading Language (GLSL)The Graphics PipelineFixed Functionality – Vertex TransformationFixed Functionality – Primitive Assembly and RasterizationFixed Functionality – Fragment Texturing and ColoringFixed Functionality – Raster OperationsFixed FunctionalityReplacing Fixed FunctionalitiesVertex ProcessorsSlide 15Slide 16Fragment ProcessorsSlide 18Using GLSLThe Overall ProcessCreating a ShaderSlide 22Slide 23Creating a ProgramSlide 25Slide 26Using a ProgramSetting up - setShadersCleaning UpGetting ErrorGLSL Data TypesSlide 32GLSL VariablesSlide 34Slide 35GLSL Variable QualifiersGLSL StatementsSlide 38GLSL FunctionsSlide 40GLSL Varying VariablesSlide 42Slide 43More Setup for GLSL- Uniform VariablesSlide 45Slide 46Slide 47Slide 48Slide 49More Setup for GLSL- Attribute VariablesSlide 51Slide 52AppendixIvory – vertex shaderIvory – fragment shaderGooch – vertex shaderGooch – fragment shaderGooch – fragment shader (2)Built-in variablesSpecial built-insAttributesBuilt-in UniformsSlide 63Built-in VaryingsBuilt-in functionsSlide 66Slide 67Slide 68OpenGL Shading LanguageJian HuangCS594, Spring 2005Why the need?•Until late 90’s, when it comes to OpenGL programming (hardware accelerated graphics), an analogy as below was mostly true:–A machinery operator turns a few knobs and sets a few switches, and then push a button called “render”. Out of the other end of a magical black box, images come out•All the controls offered by the OpenGL API comes as just knobs and switches•Although knowing more about the intrinsic OGL states, one could (become a professional knob operator and) achieve better performance (but few new functionality could the operator discover)Why the need? (cont.)•But the graphics industry is mostly driven to create “new” and “newer” effects, so to get more leverage on graphics hardware, programmers started to perform multi-pass rendering and spend more and more time to tweak a few standard knobs for tasks beyond the original scope of design, e.g.–to compute shading using texture transformation matrices–to combine multi-texture unit lookups using equations beyond just blending or modulatingSoftware Renders•During the early days of graphics special effects creation (when there was no OpenGL), Pixar developed their own in-house software renderer, RenderMan•What’s unique about RenderMan is its interface that allows highly programmable control over the appearance of each fragment•This part of RenderMan was later opened up to public and is nowadays widely known as RenderMan shading languageCg•When graphics hardware vendors started to develop an interface to expose inner controls/programmability of their hardware …–Like the birth of every domain specific programming/scripting language, a shading language seemed to be a logical choice•nVidia was the first vendor to do so, and their shading language is called Cg.•Cg was an immense success and became a widely adopted cutting edge tool throughout the whole industryOpenGL Shading Language (GLSL)•A few years after the success of Cg, in loom of a highly diverse and many times confusing set of languages or extensions to write shaders with, the industry started its effort of standardization.•The end result is OpenGL Shading Language, which is a part of the OpenGL 2.0 standard•GLSL is commonly referred to as “GLslang”•GLSL and Cg are quite similar, with GLSL being a lot closer to OpenGLThe Graphics Pipeline•If GLSL and Cg are both just an interface, what do they expose?–The graphics pipeline•Here is a very simplified viewFixed Functionality – Vertex Transformation•A vertex is a set of attributes such as its location in space, color, normal, texture coordinates, etc. •Inputs: individual vertices attributes. •Operations: –Vertex position transformation –Lighting computations per vertex –Generation and transformation of texture coordinatesFixed Functionality – Primitive Assembly and Rasterization•Inputs: transformed vertices and connectivity information •Op 1: clipping against view frustum and back face culling•Op 2: the actual rasterization determines the fragments, and pixel positions of the primitive. •Output: –position of the fragments in the frame buffer –interpolated attributes for each fragmentFixed Functionality – Fragment Texturing and Coloring•Input: interpolated fragment information •A color has already been computed in the previous stage through interpolation, and can be combined with a texel •Texture coordinates have also been interpolated in the previous stage. Fog is also applied at this stage. •Output: a color value and a depth for each fragment.Fixed Functionality – Raster Operations•Inputs: –pixels location –fragments depth and color values •Operations:–Scissor test –Alpha test –Stencil test –Depth testFixed Functionality•A summary (common jargons: T&L, Texturing etc.)Replacing Fixed Functionalities•Vertex Transformation stage: vertex shaders •Fragment Texturing and Coloring stage: fragment shaders•Obviously, if we are replacing fixed functionalities with programmable shaders, “stage” is not a proper term any more•From here on, let’s call them vertex processors and fragment processorsVertex Processors•The vertex processor is where the vertex shaders are run•Input: the vertex data, namely its position, color, normals, etc, depending on what the OpenGL application sends•A piece of code that sends the inputs to vertex shader:glBegin(...); glColor3f(0.2,0.4,0.6); glVertex3f(-1.0,1.0,2.0); glColor3f(0.2,0.4,0.8); glVertex3f(1.0,-1.0,2.0); glEnd();Vertex Processors•In vertex shaders, sample tasks to perform include:–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 • Note:– it is not required that your vertex shader does any particular task– no matter what vertex shader is provided, you have already replaced the entire fixed functionality for vertex transformation stageVertex Processors•The vertex processor processes vertices individually and has no information regarding connectivity, no operations that require topological knowledge can't be performed in here.


View Full Document

UTK CS 594 - OpenGL Shading Language

Documents in this Course
Load more
Download OpenGL Shading Language
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view OpenGL Shading Language and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view OpenGL Shading Language 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?