Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.

  • Published on
    30-Dec-2015

  • View
    212

  • Download
    0

Transcript

<ul><li><p>Triangle Scan Conversion</p></li><li><p>*Angel: Interactive Computer Graphics 5E Addison-Wesley 2009RasterizationRasterization (scan conversion)Determine which pixels that are inside primitive specified by a set of verticesProduces a set of fragmentsFragments have a location (pixel location) and other attributes such color and texture coordinates that are determined by interpolating values at verticesPixel colors determined later using color, texture, and other vertex properties</p><p>Angel: Interactive Computer Graphics 5E Addison-Wesley 2009</p></li><li><p>Triangle Area Filling AlgorithmsWhy do we care about triangles?Edge EquationsEdge Walking</p></li><li><p>Do something easier!Instead of polygons, lets do something easy!TRIANGLES! Why?1) All polygons can be broken into triangles2) Easy to specify3) Always convex4) Going to 3D is MUCH easier</p></li><li><p>Polygons can be broken downTriangulate - Dividing a polygon into triangles.</p><p>Is it always possible? Why?</p></li><li><p>Any object can be broken down into polygons</p></li><li><p>Specifying a modelFor polygons, we had to worry about connectivity AND vertices.How would you specify a triangle? (What is the minimum you need to draw one?)Only vertices(x1,y1) (x2,y2) (x3,y3)No ambiguityLine equationsA1x1+B1y1+C1=0A2x2+B2y2+C2=0A3x3+B3y3+C3=0</p></li><li><p>Triangles are always convexWhat is a convex shape?An object is convex if and only if any line segment connecting two points on its boundary is contained entirely within the object or one of its boundaries. Think about scan lines again!</p></li><li><p>Scan Converting a TriangleRecap what we are trying to doTwo main ways to rasterize a triangleEdge EquationsA1x1+B1y1+C1=0A2x2+B2y2+C2=0A3x3+B3y3+C3=0Edge Walking</p></li><li><p>Types of TrianglesWhat determines the spans? Can you think of an easy way to compute spans?What is the special vertex here?</p></li><li><p>Edge Walking1. Sort vertices in y and then x2. Determine the middle vertex3. Walk down edges from P04. Compute spans</p><p>P0P1P2</p></li><li><p>Edge Walking Pros and ConsProsFastEasy to implement in hardware</p><p>ConsSpecial CasesInterpolation can be tricky</p></li><li><p>Color InterpolatingP0P1P2(?, ?, ?)(?, ?, ?)</p></li><li><p>Edge EquationsA1x1+B1y1+C1=0A2x2+B2y2+C2=0A3x3+B3y3+C3=0</p><p>How do you go from:x1, y1 - x2, y2 toA1x1+B1y1+C1?P0P1P2</p></li><li><p>Given 2 points, compute A,B,CC = x0y1 x1y0A = y0 y1B = x1 x0</p></li><li><p>Edge EquationsWhat does the edge equation mean?A1x1+B1y1+C1=0Pt1[2,1], Pt2[6,11]A=-10, B=4, C=16What is the value of the equation for the: gray partyellow partthe boundary lineWhat happens when we reverse P0 and P1?P0P1</p></li><li><p>Combining all edge equations1) Determine edge equations for all three edges2) Find out if we should reverse the edges3) Create a bounding box4) Test all pixels in the bounding box whether they too reside on the same side P2P1P0</p></li><li><p>Edge Equations: Interpolating ColorGiven redness at the 3 vertices, set up the linear system of equations:</p><p>The solution works out to:</p></li><li><p>Edge Equations:Interpolating ColorNotice that the columns in the matrix are exactly the coefficients of the edge equations!</p><p>So the setup cost per parameter is basically a matrix multiplyPer-pixel cost (the inner loop) cost equates to tracking another edge equation value (which is?)A: 1 add</p></li><li><p>Pros and Cons of Edge EquationsProsIf you have the right hardware (PixelPlanes) then it is very fastFast testsEasy to interpolate colors</p><p>ConsCan be expensive if you dont have hardware50% efficient</p></li><li><p>RecapP0P1P2P1P2P0</p></li><li><p>*Angel: Interactive Computer Graphics 5E Addison-Wesley 2009Scan Conversion of Line SegmentsStart with line segment in window coordinates with integer values for endpointsAssume implementation has a write_pixel functiony = mx + h</p><p>Angel: Interactive Computer Graphics 5E Addison-Wesley 2009</p></li><li>*Angel: Interactive Computer Graphics 5E Addison-Wesley 2009DDA AlgorithmDigital Differential AnalyzerDDA was a mechanical device for numerical solution of differential equationsLine y=mx+ h satisfies differential equation where m = Dy/Dx = y2-y1/x2-x1Along scan line Dx = 1 at each iteration of the loopFor(x=x1; x</li><li><p>*Angel: Interactive Computer Graphics 5E Addison-Wesley 2009ProblemDDA = for each x plot pixel at closest yProblems for steep lines</p><p>Angel: Interactive Computer Graphics 5E Addison-Wesley 2009</p></li><li><p>*Angel: Interactive Computer Graphics 5E Addison-Wesley 2009Using SymmetryUse for 1 m 0For m &gt; 1, swap role of x and yFor each y, plot closest x</p><p>Angel: Interactive Computer Graphics 5E Addison-Wesley 2009</p></li><li><p>*Angel: Interactive Computer Graphics 5E Addison-Wesley 2009Bresenhams AlgorithmDDA requires one floating point addition per stepWe can eliminate all fp through Bresenhams algorithmConsider only 1 m 0Other cases by symmetryAssume pixel centers are at half integersIf we start at a pixel that has been written, there are only two candidates for the next pixel to be written into the frame buffer</p><p>Angel: Interactive Computer Graphics 5E Addison-Wesley 2009</p></li><li><p>*Angel: Interactive Computer Graphics 5E Addison-Wesley 2009Candidate Pixels1 m 0last pixelcandidates</p><p>Angel: Interactive Computer Graphics 5E Addison-Wesley 2009</p></li><li><p>*Angel: Interactive Computer Graphics 5E Addison-Wesley 2009Decision Variable-d = Dx(b-a)d is an integerd &gt; 0 use upper pixeld &lt; 0 use lower pixel</p><p>Angel: Interactive Computer Graphics 5E Addison-Wesley 2009</p></li><li>*Angel: Interactive Computer Graphics 5E Addison-Wesley 2009Incremental FormMore efficient if we look at dk, the value of the decision variable at x = kdk+1= dk 2Dy, if dk </li></ul>

Recommended

View more >