Exploring the OpenGL Programmable Graphics Pipeline: Functions and Operations
220 likes | 357 Vues
This review delves into the key components of the OpenGL programmable pipeline, including vertex and fragment operations, rasterization, texture memory, and pixel manipulation. We discuss per-vertex transformations, shading, clipping, and the importance of perspective-correct texture coordinate interpolation. Key processes such as fragment generation, blending, and anti-aliasing are explored, with insights into applying these techniques using GLSL shaders. By understanding the intricate workings of these operations, developers can enhance graphics quality in their applications.
Exploring the OpenGL Programmable Graphics Pipeline: Functions and Operations
E N D
Presentation Transcript
Week 2: Review of graphics API Programmable pipeline
OpenGL block diagram Generation Traversal Xformation Rasteriz. & tex. Display Display list Per-vertex operations & Primitive assembly Per- fragment operations Frame buffer Video display Evaluator Rasterization Application generation Application traversal Texture memory Pixel operations Application & higher level graphics libraries OpenGL implementation
Per-vertex operations • Transform vertex coords. (modelview m.) • Transform and renormalize normals • Generate and transform texture coords. • Lighting calculations Display list Per-vertex operations & Primitive assembly Per- fragment operations Frame buffer Video display Evaluator Rasterization Application generation Application traversal Texture memory Pixel operations
Primitive assembly • Flat shading • Clipping • Projection transformations • Viewport and depth-range operations • Culling Display list Per-vertex operations & Primitive assembly Per- fragment operations Frame buffer Video display Evaluator Rasterization Application generation Application traversal Texture memory Pixel operations
Rasterization • Convert each primitive into fragments • Fragment: “transient data structures” • position (x,y); depth; color; texture coordinates; coverage; … Display list Per-vertex operations & Primitive assembly Per- fragment operations Frame buffer Video display Evaluator Rasterization Application generation Application traversal Texture memory Pixel operations
Interpolation issues http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt
p1 P1’ p p L P2’ p2 Linear Interpolation Issues • Linear interpolation takes place in screen space • Problems can happen when projecting • Texture coordinates • Colors • Positions are okay. • Cannot recover p’s color and texture coordinates from linear Interpolation Lerp(Cp1’,Cp2’) along L != Cp • Need perspective correct interpolation for unprojected values http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt
More explanations • Equal spacing in screen (pixel) space is not the same as in texture space in perspective projection • Perspective foreshortening from Hill courtesy of H. Pfister http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt
Perspective-Correct Texture Coordinate Interpolation • Interpolate (tex_coord/w) over the polygon, then do perspective divide after interpolation • Compute at each vertex after perspective transformation • “Numerators” s/w, t/w • “Denominator” 1/w http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt
Perspective-Correct Texture Coordinate Interpolation • Linearly interpolate 1/w, s/w, and t/w across the polygon • At each pixel • Perform perspective division of interpolated texture coordinates (s/w, t/w) by interpolated 1/w (i.e., numerator over denominator) to get (s, t) http://www.cse.ohio-state.edu/~hwshen/781/pipeline.ppt
Perspective-Correct Interpolation • That fixed it!
Rasterization • Convert each primitive into fragments • Fragment: “transient data structures” • position (x,y); depth; color; texture coordinates; coverage; … Display list Per-vertex operations & Primitive assembly Per- fragment operations Frame buffer Video display Evaluator Rasterization Application generation Application traversal Texture memory Pixel operations
Per fragment operations (I) • Generate texel for every fragment • Fog calculations • Coverage (antialiasing) values application Display list Per-vertex operations & Primitive assembly Per- fragment operations Frame buffer Video display Evaluator Rasterization Application generation Application traversal Texture memory Pixel operations
Per fragment operations (II) • Scissoring • Alpha test • Stencil test • Depth-buffer test • Blending • Dithering and logical operation • Masking Display list Per-vertex operations & Primitive assembly Per- fragment operations Frame buffer Video display Evaluator Rasterization Application generation Application traversal Texture memory Pixel operations
Hello world Per- vertex Operations Per- fragment Operations (I)
Vertex shader • Is run once every time a vertex position is specified • glVertex, glDrawArrays, … • Must compute gl_Position • May compute gl_ClipVertex or gl_PointSize
Fragment shader • Is run once for every fragment produced • Has access to the interpolated value for each varying variable • Color, normal, texture coordinates, arbitrary values • Output goes to the fixed pipeline • gl_FragColor – computed R, G, B, A for the fragment • gl_FragDepth – computed depth value for the fragment • gl_FragData[n] – arbitrary data per fragment, stored in multiple render targets