310 likes | 491 Views
Lecture 4: 3D Rendering Pipeline (I). Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Institute of Technology. Interactive Game Loop. Render Triangles (one frame). Game Input (Keyboard, Mouse). Physics Strategy, AI. 30 to 60 frames per second. Exit?.
E N D
Lecture 4: 3D Rendering Pipeline (I) Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Institute of Technology
Interactive Game Loop Render Triangles (one frame) Game Input (Keyboard, Mouse) Physics Strategy, AI 30 to 60 frames per second Exit? Cleanup States
z z z z z y y y y y x x x x x 3D Graphics Rendering Pipeline • Geometry Pipeline • Processing Vertices • Mainly floating-point operations • Rasterization Pipeline • Processing Pixels • Mainly dealing with Integer operations y Geometry Processing Rasterization Processing x y x
z z z z z y y y y y x x x x x 3D Graphics Rendering Pipeline • Geometry Pipeline • Processing Vertices • Mainly floating-point operations • Rasterization Pipeline • Processing Pixels • Mainly dealing with Integer operations • MMX was originally designed to accelerate this functionality MMX ISA y Geometry Processing Rasterization Processing x y x
z z z z z y y y y y x x x x x 3D Graphics Rendering Pipeline • Geometry Pipeline • Processing Vertices • Mainly floating-point operations • SSE/SSE2 were designed for this part • Rasterization Pipeline • Processing Pixels • Mainly dealing with Integer operations • MMX was originally designed to accelerate this functionality SSE/SSE2 ISA MMXISA y Geometry Processing Rasterization Processing x y x
z z z z z y y y y y x x x x x Fixed Function 3D Graphics Pipeline • Geometry Pipeline • Processing Vertices • Mainly floating-point operations • SSE/SSE2 were designed for this part • Rasterization Pipeline • Processing Pixels • Mainly dealing with Integer operations • MMX was originally designed to accelerate this functionality y Geometry Processing Rasterization Processing x Performed by (GP)GPU y x
+y +y +z +x +x +z Right-Handed System Left-Handed System 3D Coordinates • Left-handed system is more common for graphics viewing space • Camera or viewer position can be set up using 3D API
Geometry Format ─ Vertex Coordinates +Y (X2, Y2, Z2) +Z (X3, Y3, Z3) (X1, Y1, Z1) Y1 Z1 +X X1
Geometry Format ─ Vertex Normals +Y (NX2, NY2, NZ2) +Z (NX3, NY3, NZ3) (NX1, NY1, NZ1) +X
Geometry Format ─ Vertex Colors +Y (R2, G2, B2, A2) +Z (R3, B3, B3, G3) (R1, G1, B1, A1) +X
Triangle-based Geometry Representation V1 V4 V4 V5 V2 V5 V5 V4 V3 V2 V3 V6 V7 V3 V1 V9 V1 V8 V2 Triangle List (note the vertex order) Triangle Strip Triangle Fan
Specifying a 3D object • Vertex ordering is critical Triangle list {v1, v3, v2}, {v1, v5, v3}, {v5, v6, v3}, {v4, v3, v6}, {v1, v7, v6}, {v1, v6, v5} V7 V6 V1 V5 Triangle strip {v5, v3, v1, v2}, {v5, v6, v3, v4}, {v7, v6, v1, v5} V4 V2 V3
Specifying a 3D object • Vertex ordering is critical • We will discuss normal computation later in this lecture Triangle list {v1, v2, v7}, {v2, v8, v7}, {v2, v3, v4}, {v2, v4, v8}, {v4, v7, v8}, {v4, v6, v7} V7 V6 V1 Triangle strip {v1, v2, v7, v8}, {v3, v4, v2, v8}, {v6, v7, v4, v8} V8 V4 V2 V3
Clipping Perspective Divide Viewport Transform Projection Transform World Transform View Transform Lighting Backface Culling Rasterization 3D Rendering Pipeline
Transformation Pipeline • World Transformation • Model coordinates World coordinates • View Transformation • World coordinates Camera space • Projection Transformation • Camera space View Plane • These are a series of matrix multiplications
World Transformation • Translation • Rotation • Scaling World Coordinates +y Local model coordinates +z World origin +x Local model coordinates
View Transformation World Coordinates +y +z • Camera position • Look vector +z +y +x World origin +x
Projection Transformation • Set up camera internals • Set up • Field of View (FOV) • View frustum • View planes • Will discuss later
Homogeneous Coordinates • Enable all transformations to be done by “multiplication” • Primarily for translation (See next few slides) • Add one coordinate (w) to a 3D vector • Each vertex has [x, y, z, w] • W will be useful for perspective projection • W should be 1 in a Cartesian Coordinate System
Transformation 1: Translation (Offset) +y +y (xt, yt, zt) +z +z (x, y, z) +x +x
Transformation 2: Scaling +y +y +z +z +x +x
+x +y +z Transformation 3: Rotation +y +z +x
2D Rotation +y +y (x, y) +x +x +y (x’, y’) (x, y) +x Rotate along which axis?
3D Rotation Matrix Rotation along Z axis Rotation along Y axis Rotation along X axis
+y +z +x Non-Commutative Property (1) +y +z +x • Counter-clockwise 90o along y • Clockwise 90o along x • Clockwise 90o along x • Counter-clockwise 90o along y
+y +y +z +z +x +x Non-Commutative Property (1) (x’’, y’’, z’’) = (-z, -x, y) (x’’, y’’, z’’) = (-y, -z, x)
+y +z +x Non-Commutative Property (2) +y +z +x • Translation by (x, y, z) • Scale by 2 times • Scale by 2 times • Translation by (x, y, z)
+y +y +z +z Offsets were scaled as well +x +x Non-Commutative Property (2) (x’’, y’’, z’’) = (x*Rx+Rx*Tx, y*Ry+Ry*Ty, z*Rz+Rz*Tz) (x’’, y’’, z’’) = (x*Rx+Tx, y*Ry+Ty, z*Rz+Tz)
Non-Commutative Property • Ordering matters ! • Be careful when performing matrix multiplication