graphics pipeline lecture 7 lectures 1 6
play

graphics pipeline lecture 7 (lectures 1-6) clip coordinates - - PowerPoint PPT Presentation

OpenGL pipeline (on the graphics card) graphics pipeline lecture 7 (lectures 1-6) clip coordinates - graphics pipeline (overview) fragments - hidden surface removal clip coordinates "primitive vertex rasterization assembly"


  1. OpenGL pipeline (on the graphics card) graphics pipeline lecture 7 (lectures 1-6) clip coordinates - graphics pipeline (overview) fragments - hidden surface removal clip coordinates "primitive vertex rasterization assembly" fragment - object vs image order processing and clipping processing - back face culling - depth buffer (z buffer) coordinate clipping rasterization - painters algorithm transforms A "fragment" is a potential pixel and the - ray casting data needed to color it, including depth, surface normal. classic vs. modern OpenGL Vertex Processing clip coordinates fragments Suppose you want to make a water wave animation. The surface is a set of triangles, made from clip vertices coordinates fragments vertex "primitive { (x, height(x,z,t)), z } rasterization fragment processing assembly" processing and clipping height() is a little program -- a "vertex shader" vertex "primitive rasterization e.g. a sine wave. fragment processing assembly" processing and clipping In classic OpenGL, the CPU calculates height(x, z, t ) for each x, z and then calls glVertex(). "fixed function" OpenGL "fixed function" hidden hidden 1.0 In modern OpenGL, height(x, z, t) is computed using a "vertex shader", on the graphics card and "fragment "vertex in parallel for different (x, z) and t, . Modern shader" shader" (programmable) OpenGL hidden hidden (programmable) "Primitive Assembly" and Clipping Fragment processing "Particle systems" (vertex processing) e.g. Fire, explosions, smoke, fog, ... glBegin(GL_LINES) // line primitive (data structure) A fragment is a potential pixel. It has an (x,y) coordinate, Calculate geometric transforms on vertices/primitives. glVertex(...) // is assembled after its vertices and information about depth, color, .... glVertex(...) // are mapped to clip coordinates Calculate (time varying) "color" of vertices, too! glEnd() We will discuss fragment processing later in the course. clip clip coordinates coordinates fragments fragments vertex vertex "primitive "primitive rasterization rasterization fragment fragment processing processing assembly" assembly" processing processing and clipping and clipping Careful: no pixels yet !

  2. lecture 7 "object order" methods Part 2 of the course - graphics pipeline (overview) starts here. for each object - hidden surface removal: for each pixel decide if object is visible at that pixel the problem of deciding which polygon/object is visible at each pixel. "image order" methods - object vs image order for each pixel - back face culling for each object - depth buffer (z buffer) decide if object is visible at that pixel - painters algorithm - ray casting In OpenGL, the front face of a polygon is defined Back face culling (object order) (by default) as the side where vertices would be ordered counter clockwise, i.e. if a viewer were on that side. glFrontFace(GL_CCW) // default Choose ordering of vertices for each face as shown so that front faces are seen by a viewer. A polygon is defined by a sequence of vertices. What is the significance of the ordering? glFrontFace(GL_CW) // override default The normal comes out of the front face. "Back Face Culling" (The front face has an "outward pointing normal" = don't draw the back faces! and a back face has an "inward pointing normal". ) [WARNING: In OpenGL, surface normals also In this example, the vertices of each wall of can be explicitly defined defined at vertices. (We the room have opposite ordering as on will see later why.) But these normals have previous slide. This allows a viewer that is For a solid object, back faces shouldn't be visible because nothing to do with front and back faces as just inside the room to see the walls. they are hidden by the front faces. defined.]

  3. Use the sign of the dot product of the outward When is a polygon back vs. front face ? glEnable(GL_CULL_FACE) facing normal and the vector from the viewer to any vertex on the polygon. In camera coordinates, it is subtle. You can't just look at the sign of the z coordinate. If back face culling is "enabled", then the back face is not drawn. In A1, we used glDisable(GL_CULL_FACE). In OpenGL, back face culling is done by the Depth Buffer (z buffer ) rasterizer, hence it is done in normalized device Q: Where is back face culling done ? coordinates . Check the sign of the normal's z coordinate . clip coordinates fragments vertex "primitive rasterization fragment processing assembly" and processing clipping A: In OpenGL it is done by rasterizer. image buffer/ z buffer But in principle, it can be done frame buffer before entering pipeline! glEnable(GL_DEPTH_TEST) (not same as Rule: monitor screen) Hidden surface removal Pseudocode... algorithm (depth buffer) Catmull 1974 clip coordinates for each pixel (x,y): // initialization fragments zbuffer(x,y) = 1 for each polygon P: RGB(x,y) = background color for each pixel (x,y) in P's image projection vertex "primitive rasterization for each polygon: fragment processing assembly" processing if P's depth at (x,y) is less than zbuffer(x,y) and clipping for each pixel (x,y) in the image projection of polygon z := Ax + By + C then Q: Where is the depth buffer algorithm here ? // equation of polygon's plane in SCREEN coordinates update zbuffer(x,y) if z < zbuffer(x,y) : compute color of P at (x,y) and replace A: It is done by the rasterizer. If polygon fails zbuffer(x,y) := z the current color with the new color the depth test at (x,y), then fragment never compute RGB(x,y) gets generated.

  4. Recall last lecture: There is also a depth component to the mapping. Depth buffer typically holds fixed precision (e.g. 24 "window to viewport" transformation bits), not float. i.e. z in [ 0, 1] partitioned into bins of size 1 / 2^24. (x,y, z) in [-1, 1] x [-1, 1] x [-1, 1] Q: Why ? (x,y) in [-1, 1] x [-1, 1] A: Floating point is useful for representing tiny and normalized (2D viewing) window huge numbers, but that's in appropriate here. view volume (x,y, z) in [0, width] x [0, height] x [0, 1] to (2D) viewport (display) window (x,y) in [0, width] x [0, height] Recall glFrustum( __ , __ , __ , __ , near, far) Painter's Algorithm [Newell et al 1972] Painter's Algorithm where near and far are float or double. (older than depth buffer) Q: Why not set: Sort polygons in depth. (Arbitrarily) use the farthest vertex in each polygon as the sorting key. near = .00000...1 e.g 26 polygons [ A, B, C, .... P, Q, .... , Z ] far = 2^ 1023 ? Then draw polygons from "farthest" to "nearest" A: You would divide the huge [near, far] (back to front). interval into 2^24 depth intervals/bins. Most points will fall in one of these intervals http://en.wikipedia.org/wiki/Painter's_algorithm --> useless because they all have same (quantized/rounded) depth Draw farthest polygons first. However, that doesn't always work. Why not ? Typical failure of method on previous slide: Classic failure case (cardboard box): A related common example of failure desired (naive) Painter For this example, there does not exist a 'correct' ordering for drawing the polygons. Problem Solution (cut Q into Q1, Q2) Solution ? Swap order of P and Q in the list ? (That can create other problems.)

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend