1 / 19

Assignment 2

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

norman
Download Presentation

Assignment 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Assignment 2 Rendering Pipeline

  2. Outlines • Phase 1 • Transformation • Backface culling • Projection and Wireframe output • Phase 2 • Shading • Lighting • Scan-Convert

  3. The Data Structure • For a polygon, it should contain the following data • Position of all vertices • Normal of all vertices • Material data

  4. Y Y Y X Z Z X Z X Translate Rotate Phase 1 – Transformation1/4 • Viewing Transformation • World coordinate to View coordinate

  5. 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.

  6. 1 Far -1 1 Near -1 Phase 1 – Transformation3/4 • Perspective Transformation • Normalize the view volume • Perspective view volume to canonical view volume

  7. 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

  8. 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

  9. 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.

  10. 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.

  11. 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(); }

  12. Phase 2 - Shading1/2 • Gouraud shading • The light calculation is done before we apply the perspective transformation. • For each vertex

  13. 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.

  14. Phase 2 - Lighting • Light calculation • The phong model

  15. 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

  16. 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();

  17. 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(…)

  18. 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).

  19. Any Question ?

More Related