3D Rendering Pipeline Hidden Surface Removal 3D Primitives 3D Modeling Coordinates Model Transformation 3D World Coordinates Lighting 3D World Coordinates Viewing Transformation 3D Viewing Coordinates Projection Transformation 2D Projection Coordinates Clipping Hidden Surface Removal 2D Projection Coordinates Viewport Transformation 2D Device Coordinates Scan Conversion 2D Device Coordinates Image cgvr.korea.ac.kr
Mapping to viewport Mapping positions within a rectangular view volume to a 3D rectangular viewport is done with combination of scaling & translation as: Where Dx, Dy, Dz are ratios of the dimensions of the viewport and rectangular parallelopiped view volume in the x, y and z directions. cgvr.korea.ac.kr
Viewport Clipping 6-bit region codes are assigned that identifies the relative position of the point w.r.t. the viewport. For a line endpoint at position (x,y,z), we assign the bit positions in the region code from right to left as, bit 1 = 1, if x<xvmin (left) bit 2 = 1, if x>xvmax (right) bit 3 = 1, if y<yvmin (below) bit 4 = 1, if y>yvmax (above) bit 5 = 1, if z<zvmin (front) bit 6 = 1, if z>zvmax (back) cgvr.korea.ac.kr
If result is non-zero then both endpoints lie outside the viewport. If either endpoint doesnot have a region code 000000, we perform logical AND operation on both endpoints. If result is non-zero then both endpoints lie outside the viewport. Else Calculate intersections with bounding planes. cgvr.korea.ac.kr
If P1 = (x1, y1, z1) and P2 = (x2, y2, z2), parametric line equation is x = x1 + (x2 – x1)u, y = y1 + (y2 – y1)u, z = z1 + (z2 – z1)u, 0<=u<=1 (x, y, z) represent any point on the line between the two endpoints. At u = 0, we have the point P1 and u =1 puts us at P2. To find intersection of line with a plane of the viewport, we substitute the coordinate value for that plane into the appropriate parametric expression above and solve for u. eg. Suppose we test for a line against the zvmin plane of the viewport. cgvr.korea.ac.kr
When calculated value of u is not in range 0 to 1, line segment does not intersect the plane under consideration at any point between endpoints P1 & P2. If calculated value is within the range, calculate intersections x and y coordinates as: If either xI or yI is not in the range of the boundaries of the viewport, then this line intersects the front plane beyond the boundaries of the volume. cgvr.korea.ac.kr
Hidden Surface Removal
Hidden Surface Removal Motivation Algorithms for HSR Back-face detection Painter’s algorithm Ray casting Scan-line Z-buffer Area subdivision Tradeoffs cgvr.korea.ac.kr
Motivation Surfaces may be Back-Facing: Surfaces may be Occluding: Polygon Viewer Viewer Occluding Polygon Occluded Polygon cgvr.korea.ac.kr
Motivation Surfaces may be Overlapping: Surfaces may be Intersecting: Viewer Viewer cgvr.korea.ac.kr
Visible surface detection algorithms are of 2 types: Whether they deal with object definitions directly (object space methods): compares objects & parts of objects to each other within the scene definition to determine which surfaces as a whole we should label as visible. Whether they deal with their projected images (image-space methods): visibility is decided point by point at each pixel position on the projection plane. cgvr.korea.ac.kr
Algorithms Back-Face Detection Z-Buffer Painter’s Algorithm Ray Casting Scan-Line Area Subdivision cgvr.korea.ac.kr
Viewing Transformation Back-Face Detection Do not Render any Surface Oriented Away from Viewer yv xv zv V N=(A,B,C) Back-Facing Polygon V N Model Transformation Lighting Viewing Transformation 3D Primitives Viewer Polygon is back-facing to the viewer if V•N > 0 cgvr.korea.ac.kr
Back-Face Detection xv yv zv V Uses inside outside test for identifying the back faces of a polyhedron. A point (x,y,z) is inside a polygon surface with plane parameters A, B, C, D if Ax + By + Cz + D < 0 When an inside point is along the line of sight to the surface, the polygon must be a back face Consider the normal vector N to a polygon surface, which has Cartesian components (A, B, C). In general if V is a vector in the viewing direction from the eye (or camera) position then this polygon is a back face if V.N >0 yv xv zv V N=(A,B,C) cgvr.korea.ac.kr
Back-Face Detection xv yv zv V If object descriptions have been converted to projection coordinates and our viewing direction is parallel to the viewing zv axis, then V=(0, 0, Vz) & V.N = VzC Thus we need to consider the sign of C, the z component of the normal vector N. In a right handed viewing system with viewing direction along the negative zv axis the polygon is a back face if C<0. also we cannot see any face whose normal has z component C = 0, since our viewing direction is grazing that polygon. Therefore any polygon is a back face if its normal vector has a z-component value C<=0 yv xv zv V N=(A,B,C) cgvr.korea.ac.kr
Z-Buffer or Depth-Buffer Method Algorithm: Store color and depth of closest surface for each pixel in frame buffer As scan convert, update only pixels whose (interpolated) depth is closer than the depth stored in the frame buffer z=3 z=1 Viewport Transformation Scan Conversion Image z=5 z=4 z=2 z=5 z=5 cgvr.korea.ac.kr
Z-Buffer Initialize the depth buffer and refresh buffer so that for all buffer positions (x, y) depth(x,y) =0, refresh(x,y) = Ibackground For each position on each polygon surface, compare depth values to previously stored values in the depth buffer to determine visibility. Calculate the depth z for each (x,y) position on the polygon If z>depth(x,y) then set depth(x,y) =z, refresh(x,y) = Isurf(x,y) Where Ibackground is the value of background intensity and Isurf(x,y) is the projected intensity value for the surface at pixel position (x,y). After all surfaces have been processed, the depth buffer contains depth values for the visible surfaces and the refresh buffer contains the corresponding intensity values for those surfaces. cgvr.korea.ac.kr
Depth value for a surface position (x,y) are calculated from the plane equation for each surface: z=(-Ax-By-D)/C For any scan line adjacent horizontal positions across line differ by 1 & vertical y value on adjacent scan line differs by 1. If depth of position (x,y) is z, then depth z’ of the next position (x+1,y) is z’= (-A(x+1)-By-D)/C=z-A/C Ratio -A/C is constant for each surface, so successive depth values across a scan line are obtained from preceding values with a single addition On each scan line we start by calculating the depth on a left edge of the polygon that intersects that scan line. Depth values at each successive position across the scan are then calculated cgvr.korea.ac.kr
Depth values are then obtained recursively as z’=z+(A/m + B)/C First determine the y-coordinate extents of each polygon and process the surface from the topmost scan line to the bottom scan line. Starting at a top vertex, recursively calculate x positions down a left edge of the polygon as x’=x-1/m, Depth values are then obtained recursively as z’=z+(A/m + B)/C If the processing is down a vertical edge, the slope is infinite & the recursive calculations reduce to z’=z+B/C cgvr.korea.ac.kr
Z-Buffer Comments Polygons can be rasterized in any order Requires lots of memory Requires per pixel processing, Commonly implemented in hardware cgvr.korea.ac.kr
Viewing Transformation Ray Casting Algorithm: Cast ray from viewpoint through each pixel to find front-most surface Model Transformation Lighting Viewing Transformation 3D Primitives A D E Viewer C View Plane B cgvr.korea.ac.kr
Ray Casting Comments O(plogn) for p pixels May (or may not) utilize pixel-to-pixel coherence Conceptually simple, but not generally used cgvr.korea.ac.kr
Viewport Transformation Scan-Line Algorithm: For each scan line, construct spans and sort by depth z=3 z=1 z=5 Scan Line z=4 z=2 Viewport Transformation Scan Conversion Image z=5 z=5 z=1.8 z=3.8 Example: Spans z=5 z=5 cgvr.korea.ac.kr
Scan-Line Comments Fully compute only front-most pixels Coherence along scan lines Commonly implemented in software cgvr.korea.ac.kr
Conclusion Hidden surface algorithms Hardware Software Back-face detection Depth sort Ray casting Z-buffer Scan-line Area subdivision Hardware Software cgvr.korea.ac.kr