750 likes | 942 Views
Chapter 8. Implementation of a Renderer. Rendering as a Black Box. Object-Oriented v.s Image-Oriented. for(each_object) render (object);. for(each_pixel) assign_a_color(pixel);. Four Major Tasks. Modeling Geometric processing Rasterization Display. Modeling.
E N D
Chapter 8 Implementation of a Renderer
Object-Oriented v.s Image-Oriented for(each_object) render (object); for(each_pixel) assign_a_color(pixel);
Four Major Tasks Modeling Geometric processing Rasterization Display
Modeling Chapter 6: modeling of a sphere Chapter 9: hierarchical modeling Chapter 10: curves and surfaces Chapter 11: procedural modeling Can be combined with clipping to reduce the burden of the renderer
Geometric Processing Normalization Clipping Hidden-Surface Removal(visible surface determination) Shading (combined with normals and lighting information to compute the color at each vertex)
Rasterizatoin Also called scan-conversion Texture value is not needed until rasterization
Display Usually this is not the concern of the application program Dealing with aliasing is one possible task at this stage Half-toning (dithering) Color-correction
Implementation of Transformation Object (world) coordinates Eye (camera) coordinates Clip coordinates Normalized device coordinates Window (screen) coordinates
Line-Segment Clipping Primitives pass through the clipper are accepted, Otherwise they are rejected or culled.
Cohen-Sutherland Clipping Replace most of the expensive floating-point multiplications and divisions with a combination of floating-point subtractions and bit operations
Breaking Up Spaces Each region is represented by a 4-bit outcode b0b1b2b3:
Four Possible Cases Given a line segment, let o1=outcode(x1,y1), o2=outcode(x2, y2) (o1=o2=0) it is in the clipping window (AB) (o10, o2=0; or vice versa) one or two intersections must be computed, and the outcode of the intersection point is re-examined (CD) (o1&o20) it is on the same outside sides of the window (EF) (o1&o2=0) Cannot tell, find the outcode of one intersection point (GH, IJ)
Discussion Cohen-Sutherland algorithm works best when there are many line segments but few are actually displayed The main disadvantage is it must be used recursively How to compute intersection?y=mx+h (cannot represent a vertical line)
Liang-Barsky Clipping Represent parametrically a line segment: Note that this form is robust and needs no changes for horizontal or vertical lines
Examples 4 4 2 3 3 2 1 1 1>4> 3> 2> 1>0 1>4> 2> 3> 1>0
Avoid Computing Intersections For intersecting with the top: All the tests required by the algorithm can be done by comparing ymax and y. Only if an intersection is needed, because a segment has to be shortened, is the division done. This way, we could avoid multiple shortening of line segments and the re-execution of the clipping algorithm.
Polygon Clipping Creation of a single polygon
Dealing with Concave Polygons Forbid the use of concave polygons or tessellate them.
Sutherland-Hodgeman Algorithm A line-segment clipper can be envisioned as a black box
Clipping of Other Primitives Bounding Boxes and Volumes Curves, Surfaces, and Text Clipping in the Frame Buffer
Bounding Boxes and Volumes Axis-aligned bounding box (Extent) Can be used in collision detection!
Clipping for Curves and Surfaces Avoid complex intersection computation by approximating curves with line segments and surfaces with planar polygons and only perform the calculation when it’s necessary
Clipping for Text • Text can be treated as bitmaps and dealt with in the frame buffer • Or defined as any other geometric object, and processed through the standard viewing pipeline • OpenGL allows both • Pixel operations on bitmapped characters • Standard primitives for stroke characters
Clipping the Frame Buffer It’s usually known as scissoring It’s usually better to clip geometric entities before the vertices reach the frame buffer Thus clipping within the frame buffer is only required for raster objects (blocks of pixels)
Cohen-Sutherland 3D Clipping Replace the 4-bit outcode with a 6-bit outcode
Liang-Barsky and Pipe-line Clipper Liang-Barsky: add the equation Pipe-line Clipper: add the clippers for the front and back faces
Intersections in 3D Requires six multiplications and one division
Clipping for Different Viewings Oblique Viewing Orthographic Viewing Only need six divisions!
Hidden-Surface Removal Object-Space Approaches Image-Space Approaches
Object-Space Approach O(k2)! A completely obscures B from the camera; we display only A B obscures A; we display only B A and B both are completely visible; we display both A and B A and B partially obscure each other; we must calculate the visible parts of each polygon
Image-Space Approach Assuming nm pixels, then using the Z-buffer algorithm takes nmk running time, which is O(k) May create more jagged rendering result
Back-Face Removal In normalized device coordinates: If the polygon is on the surface ax+by+cz+d=0, we just need to check The sign of c. In OpenGL, use glCullFace() to turn on back-face removal
The z-Buffer Algorithm The frame buffer is initialized to the background color. The depth buffer is initialized to the farthest distance. Normalization may affect the depth accuracy. Use glDepthFunc() to determine what to do if distances are equal.
Painter’s Algorithm Back-to-front rendering
Two Troublesome Cases for Depth Sorting May resolve these cases by partitioning/clipping
The Scan-Line Algorithm Scan-line by scan-line or polygon by polygon?
DDA (digital differential analyzer) Algo. Pseudo code: m float, y float, x int For (ix=x1; ix<=x2; ix++) { y+=m; write_pixel(x, round(y), line_color); }
Using Symmetry With symmetry to handle the case where m>1 Without using symmetry
Bresenham’s Algorithm – 1/4 The DDA algorithm, although simple, still requires floating point addition for each pixel generated Bresenham derived a line-rasterization algorithm that avoids all floating-point calculation and has become the standard algorithm used in hardware and software rasterizers
Bresenham’s Algorithms – 2/4 – Assume 0m 1 And assume we have placed a pixel at (i+1/2, j+1/2) Assume y=mx+h At x=i+1/2, this line must pass within one-half the length of the pixel at (i+1/2, j+1/2)