1. CS 354 Graphics Math Mark Kilgard University of Texas February 2, 2012
2.
3.
4.
5.
6.
7. A Simplified Graphics Pipeline Application Vertex batching & assembly Triangle assembly Triangle clipping Triangle rasterization Fragment shading Depth testing Color update Application- OpenGL API boundary Framebuffer NDC to window space Depth buffer several operations left out for simplicity in explaining the simple_triangle example
8. A few more steps expanded Application Vertex batching & assembly Lighting View frustum clipping Triangle rasterization Fragment shading Depth testing Color update Application- OpenGL API boundary Framebuffer NDC to window space Depth buffer Vertex transformation User defined clipping Back face culling Perspective divide Triangle assembly Texture coordinate generation was just “triangle clipping” before
9. Conceptual Vertex Transformation glVertex* API commands Modelview matrix User-defined clip planes View-frustum clip planes to primitive rasterization object-space coordinates (x o ,y o ,z o ,w o ) eye-space coordinates (x e ,y e ,z e ,w e ) clipped eye-space coordinates clipped clip-space coordinates Perspective division Projection matrix Viewport + Depth Range transformation (x c ,y c ,z c ,w c ) window-space coordinates (x w ,y w ,z w ,1/w c ) normalized device coordinates (NDC) (x n ,y n ,z n ,1/w c ) clip-space coordinates (x c ,y c ,z c ,w c ) (x e ,y e ,z e ,w e ) (x e ,y e ,z e ,w e )
10.
11.
12.
13.
14.
15.
16.
17. NDC Space Clip Cube (-1,-1,-1) (+1,-1,-1) (+1,+1,-1) (-1,+1,-1) (-1,-1,+1) (+1,+1,+1) (+1,-1,+1) (-1,+1,+1) Post-perspective divide puts the region surviving clipping within the [-1,+1] 3
18. Clip Space Clip Cube (x min /w,y min /w,z min /w) Pre-perspective divide puts the region surviving clipping within -w ≤ x ≤ w, -w ≤ y ≤ w, -w ≤ z ≤ w (x max /w,y min /w,z min /w) (x max /w,y min /w,z max /w) (x min /w,y min /w,z max /w) (x max /w,y max /w,z max /w) (x max /w,y max /w,z min /w) (x min /w,y max /w,z min /w) (x min /w,y max /w,z max /w) Constraints x min = -w x max = w y min = -w y max = w z min = -w z max = w w>0
24. Box Corners in Clip Space Observe: result is “corners” of clip space (and NDC) clip cube Think of glOrtho as a transform parameterization to map an axis-aligned box to the clip cube 8 “eye space” corners in column vector (position) form
25. Orientation of OpenGL’s Eye-space Coordinate System -Z direction “ looking into the screen” +X -X +Y -Y +Z direction “ poking out of the screen”
26.
27.
28.
29.
30.
31. Box Corners in Clip Space 8 “eye space” corners in column vector (position) form
40. Correspondence of Eye Space to NDC Space Eye space Normalized Device Coordinate (NDC) space “ behind the eye” “ beyond the far clip plane” “ between eye and near clip plane” “ rendered (visible) region” [Eric Lengyel]
41.
42. Conceptual Vertex Transformation glVertex* API commands Modelview matrix User-defined clip planes View-frustum clip planes to primitive rasterization object-space coordinates (x o ,y o ,z o ,w o ) eye-space coordinates (x e ,y e ,z e ,w e ) clipped eye-space coordinates clipped clip-space coordinates Perspective division Projection matrix Viewport + Depth Range transformation (x c ,y c ,z c ,w c ) window-space coordinates (x w ,y w ,z w ,1/w c ) normalized device coordinates (NDC) (x n ,y n ,z n ,1/w c ) clip-space coordinates (x c ,y c ,z c ,w c ) (x e ,y e ,z e ,w e ) (x e ,y e ,z e ,w e )
43. Vertex Shaders in the Pipeline Geometry Program 3D Application or Game OpenGL API GPU Front End Vertex Assembly Vertex Shader Clipping, Setup, and Rasterization Fragment Shader Texture Fetch Raster Operations Framebuffer Access Memory Interface CPU – GPU Boundary OpenGL 3.3 Attribute Fetch Primitive Assembly Parameter Buffer Read programmable fixed-function Legend So far, we’ve discussed “fixed-function” vertex transformation Modern GPUs make vertex processing programmable Via vertex shaders!