190 likes | 284 Views
Assignment 2. Rendering Pipeline. Outlines. Phase 1 Transformation Backface culling Projection and Wireframe output Phase 2 Shading Lighting Scan-Convert. The Data Structure. For a polygon, it should contain the following data Position of all vertices Normal of all vertices
E N D
Assignment 2 Rendering Pipeline
Outlines • Phase 1 • Transformation • Backface culling • Projection and Wireframe output • Phase 2 • Shading • Lighting • Scan-Convert
The Data Structure • For a polygon, it should contain the following data • Position of all vertices • Normal of all vertices • Material data
Y Y Y X Z Z X Z X Translate Rotate Phase 1 – Transformation1/4 • Viewing Transformation • World coordinate to View coordinate
Phase 1 – Transformation2/4 • The translate matrix • Translate the eye point to origin • The rotate matrix • Rotate view direction to –Z-axis • For vertices, apply both two matrices, for normal, apply the rotate matrix.
1 Far -1 1 Near -1 Phase 1 – Transformation3/4 • Perspective Transformation • Normalize the view volume • Perspective view volume to canonical view volume
Height/2 1 -Width/2 Width/2 -Height/2 -1 1 -1 Phase 1 – Transformation4/4 • Viewport Transformation • Scale the X and Y axis to the window size
Phase 1 – Backface Culling1/2 • Backface Culling • The backface test equation • ni is the normal of vertex i • vi is the position of vertex i • e is the eye point
Phase 1 – Backface Culling2/2 • Since we translate the eye point to origin, the equation can be rewritten as • Backface test of a polygon • A polygon is backface if and only if all it’s vertices sarisfy backface test equation.
Phase 1 – Projection1/2 • Projection (using OpenGL) • Since the view volume is scaled to the window size, we should use gluOrtho2D(-width/2, width/2, -height/w, height/2); command to fit our view volume.
Phase 1 – Projection2/2 • The code gluOrthi2D(-width/2,width/2,-height/2,height/2); for each polygon { glBegin(GL_LINE_LOOP); for all vertex of this polygon glVertex2i(position_X, position_Y); glEnd(); }
Phase 2 - Shading1/2 • Gouraud shading • The light calculation is done before we apply the perspective transformation. • For each vertex
Phase 2 – Shading2/2 • Phong shading • The light calculation is done when apply scan convert to get the point (pixel) on screen. • Inverse the transformation to get the correct relation between this point, light, and eye point. • For each point (pixel) when scan convert.
Phase 2 - Lighting • Light calculation • The phong model
V3 Y V2 x=j Vy1 y=i y=i Vy2 Vy1 Vx Vy2 V1 X Phase 2 - Scan-Convert1/4 • Scan convert • Use scan-line approach
Phase 2 - Scan-Convert2/4 • The position of Vx in our view volume is • Vx(x, y, z) = (screen_X, screen_y, Z_interpolated); • For gouraud shading • Use scan-line to get the color of Vx. • Draw the point using OpenGL command glBegin(GL_POINTS); glColor3fv(color_of_Vx); glVertex3fv(Vx); glEnd();
Phase 2 - Scan-Convert3/4 • For phong shading • Use scan-line to get the normal of Vx. • Apply inverse transform to Vx (and light) back to perspective view volume. • Calculate the color of Vx and render it as what gouraud shading do. • We need to set the view volume in OpenGL to fit our view volume as in phase 1. • glOrtho2D(…)
Phase 2 - Scan-Convert4/4 • Hidden Surface Removal • We use glVertex3f() to render Vx, since there is Z-component in it, OpenGL will apply the HSR by Z-buffer itself (you should enable GL_DEPTH_TEST first).