This document summarizes a lecture on graphics transformations, clipping, and culling. It discusses how vertex positions are transformed from object space to normalized device coordinates space using the modelview and projection matrices. It also covers generalized clipping against the view frustum and user-defined clip planes, as well as back face culling. The lecture provides examples of translation, rotation, scaling, orthographic, and perspective transformations.
1. CS 354 Transformation, Clipping, and Culling Mark Kilgard University of Texas January 31, 2012
2.
3.
4.
5.
6.
7.
8.
9. 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
10. 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
11. 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 )
12. User Clip Planes in Practice [ParaView] [IVoR] Primarily used scientific visualization and Computer Aided Design (CAD) applications
13. Remember Back to clipspace Example Six user-defined clip planes enabled to clip teapot to left scene’s clip space view Without user clip planes
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27. EXT_direct_state_access Versions of Matrix Commands Convetions All f -suffixed entry points have d -suffixed versions for double precision too All selector-free routines take a GLenum matrix mode parameter, same as glMatrixMode glMatrixMultTransposefEXT glMultTransposeMatrixf glMatrixLoadTransposefEXT glLoadTransposeMatrixf glMatrixPopEXT glPopMatrix glMatrixPushEXT glPushMatrix glMatrixFrustumEXT glFrustumf glMatrixOrthoEXT glOrthof glMatrixTranslatefEXT glTranslatef glMatrixScalefEXT glScalef glMatrixRotatefEXT glRotatef glMatrixLoadIdentityEXT glLoadIdentity glMatrixMultfEXT glMultMatrixf glMatrixLoadfEXT glLoadMatrixf Selector-free DSA Command Conventional Command
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38. 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 )
39.
40. Clipped Triangle Visualized Clipped and Rasterized Normally Visualization of NDC space Notice triangle is “poking out” of the cube; this is the reason that should be clipped
41. Break Clipped Triangle into Two Triangles But how do we find these “new” vertices? The edge clipping the triangle is the line at X = -1 so we know X = -1 at these points—but what about Y?
42. Use Ratios to Interpolate Clipped Positions (-1.8, 0.8, 0.3, 1) (-0.8, 0.8, -0.2,1) (0, -0.8, -0.2) origin at (0,0,0,1) X = -1 Y = (1.8/2.6)×0.8 + (0.8/2.6)×0.8 = 0.8 Z = (1.8/2.6)×0.3 + (0.8/2.6)×-0.2 = 0.1461538 W = (1.8/2.6)×1 + (0.8/2.6)×1 = 1 -1-(-1.8)=0.8 0.8-(-1)=1.8 0.8-(-1.8)=2.6 (-1,0.8,0.146153,1) Straightforward because all the edges are orthogonal Weights: 1.8/2.6 0.8/2.6, sum to 1
43. Use Ratios to Interpolate Clipped Positions (-1.8, 0.8, 0.3) (-0.8, 0.8, -0.2) (0, -0.8, -0.2) origin at (0,0,0) 0-(-1.8) = 1.8 0-(-1) = 1 X = -1 Y = (1/1.8)×0.8 + (0.8/1.8)×-0.8 = 0.08888… Z = (1/1.8)×0.3 + (0.8/1.8)×-0.2 = 0.07777… (-1,0.0888,0.0777) -1-(-1.8) = 0.8 Weights: 1/1.8 0.8/1.8, sum to 1
44.
45.
46.
47.
48.
49. 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 ,w w ) normalized device coordinates (NDC) (x n ,y n ,z n ,w n ) 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 )
50. 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!