1 / 10

The Vertex Shader

The Vertex Shader. CS418 Computer Graphics John C. Hart. Graphics Pipeline. Model Coords. Model Xform. World Coords. Viewing Xform. Viewing Coords. Perspective Distortion. Still Clip Coords. Clipping. Clip Coords. Homogeneous Divide. Window Coordinates. Window to Viewport.

Download Presentation

The Vertex Shader

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Vertex Shader CS418 Computer Graphics John C. Hart

  2. Graphics Pipeline ModelCoords ModelXform WorldCoords ViewingXform ViewingCoords PerspectiveDistortion StillClipCoords. Clipping ClipCoords. Homogeneous Divide Window Coordinates Window to Viewport Viewport Coordinates

  3. Graphics Pipeline ModelCoords ModelXform WorldCoords ViewingXform ViewingCoords PerspectiveDistortion StillClipCoords. Clipping ClipCoords. Homogeneous Divide Window Coordinates Window to Viewport Viewport Coordinates

  4. Graphics Pipeline ModelCoords ModelXform WorldCoords ViewingXform ViewingCoords PerspectiveDistortion StillClipCoords. Clipping ClipCoords. Homogeneous Divide Window Coordinates Window to Viewport Viewport Coordinates

  5. Graphics Pipeline glMatrixMode(GL_PROJECTION); glFrustum(left,right,bottom,top,near,far); glMatrixMode(GL_MODELVIEW); gluLookAt(…); …modeling transformations in reverse order…

  6. Vertex Shader ModelCoords ModelXform WorldCoords ViewingXform ViewingCoords PerspectiveDistortion StillClipCoords. Clipping ClipCoords. Homogeneous Divide Window Coordinates Window to Viewport Viewport Coordinates

  7. Vertex Programming Languages OpenGL GLSL C-like language with some convenient C++ constructs Little language devoted to shaders (inspired by Pixar’s Renderman) Device/OS independent, as opposed to Cg or HLSL Direct access into OpenGL state including matrices • NVIDIA: Cg • Microsoft: HLSL • OpenGL: GLSL • ATI: RenderMonkey • Assembly Language • Register Combiners • Multipass Processing

  8. GLSL Vertex Shader GLcharvertexShaderCode = “ void main() { glPosition = gl_ProjectionMatrix*gl_ModelViewMatrix*glVertex; } “; GLuintvertexShaderObj = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertexShaderObj, 1, vertexShaderCode, NULL); glCompileShader(vertexShaderObj); /* Converts to GPU code */ GLuintprogramObj = glCreateProgram(); glAttachObject(programObj,vertexShaderObj); glLinkProgram(programObj); /* Connects shaders & variables */ glUseProgram(programObj); /* OpenGL now uses the shader */

  9. GLSL Variables Variable Types • Vectors • vec4 eye = vec4(1.0,2.0,3.0,1.0); • eye.x, eye.y, eye.z, eye.w • also eye.r, eye.g, eye.b, eye.a • Matrices • mat4 mv = glModelViewMatrix; • elements: mv[1][2] • mv[1] is a vec4 • mv * eye gives matrix vector product • Swizzling • eye.xz = eye.zx Variable Qualifiers • Const • Unchanged by the shader • Uniform • Set once per triangle • Set outside begin, end • Attribute • Set once per vertex • Varying • Interpolated across triangle

  10. Passing Variables GLcharvertexShaderCode = “ const amp = 0.1; uniform float phase; attribute float pos; void main() { glVertex.y += amp*sin(pos + phase); glPosition = gl_ModelViewProjectionMatrix*glVertex; } “; GLintphaseParam = glGetUniformLocation(programObj,”phase”); GLintposAttrib = glGetAttribLocation(programObj,”pos”); glUniform1f(programObj,phaseParam,time); glBegin(…) glVertexAttrib1f(posAttrib,x*z);

More Related