Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to 3D Graphics Lecture 6: Real-Time Rendering Anthony Steed University College London.

Similar presentations


Presentation on theme: "Introduction to 3D Graphics Lecture 6: Real-Time Rendering Anthony Steed University College London."— Presentation transcript:

1 Introduction to 3D Graphics Lecture 6: Real-Time Rendering Anthony Steed University College London

2 Overview n Scanning Polygons –Filling Pixels n Gouraud and Phong Shading n Visibility Culling Re-Visited –Z-buffer n Texture Mapping

3 Recall Point in Polygon Test n Ray shooting is fast, but why not find the actual span for each line –I.E. use the intersection points we would have found and directly draw them (point coherency) +1

4 Scan-Line Coherency n Intersection points of polygon edges with scan lines change little on a line by line basis y = i-1 y = i x i x i-1

5 Overview of Active Edge Table n For each scan-line in a polygon only certain edges need considering n Keep an ACTIVE edge table –Update this edge table based upon the vertical extent of the edges n From the AET extract the required spans

6 Setting Up n “fix” edges –make sure y1<y2 for each (x1,y1) (x2,y2) n Form an ET –Bucket sort all edges on minimum y value –1 bucket might contain several edges –Each edge element contains n (max Y, start X, X increment)

7 Maintaining the AET n For each scan line –Remove all edges whose y2 is equal to current line –Update the x value for each remaining edge –Add all edges whose y1 is equal to current line

8 Drawing the AET n Sort the active edges on x intersection n Pairs of edges are the spans we require n Caveats (discussed in the notes) –Don’t consider horizontal lines –Maximum vertices are not drawn –Plenty of special cases when polygons share edges

9 Example 0 1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 0 a b c d

10 Setup n Edges are n Edge Table Contains Edge LabelCoordinatesy1Structure a (1,1) to (4,7)1(7,1,0.5) b (7,2) to (4,7)2(7,7,-0.6) c (7,2) to (4,4)2(4,7,-1.5) d (1,1) to (4,4)1(4,1,1) y1Sequence of Edges 1(7,1,0.5), (4, 1, 1) 2(7,7,-0.6), (4, 7,-1.5)

11 On Each Line Line Active Edge Table Spans 0 empty 1 (7,1,0.5), (4,1,1) 1 to 1 2 (7,1.5,0.5), (4,2,1), (7,7,-0.6), (4,7,-1.5) 1.5 to 2, 7 to 7 3 (7,2.0,0.5), (4,3,1), (4,5.5,-1.5), (7,6.4,-0.6) 2.0 to 3, 5.5 to 6.4 4 (7,2.5,0.5), (7,5.8,-0.6) 2.5 to 5.8 5 (7,3.0,0.5), (7,5.2,-0.6) 3.0 to 5.2 6 (7,3.5,0.5), (7,4.6,-0.6) 3.5 to 4.6 7 empty 8 empty

12 Overview n Scanning Polygons –Filling Pixels n Gouraud and Phong Shading n Visibility Culling Re-Visited –Z-buffer n Texture Mapping

13 Gouraud Shading n Recall simple model for local diffuse reflection n Gouraud interpolates this colour down edges and across scan-lines in the same manner as we just did for depth

14 Gouraud Details n ET now contains –(y2,x1,dx,z1,dz,r1,dr,g1,dg,b1,db) n (we are running out of registers!) n Problems –not constant colour on rotation of points –misses specular highlights

15 Phong Shading n Include specular component n Interpolate normals across the scan-line instead of colours –Expensive square root to re-normalise n Recaptures highlights in the centre of polygons

16 Overview n Scanning Polygons –Filling Pixels n Gouraud and Phong Shading n Visibility Culling Re-Visited –Z-buffer n Texture Mapping

17 Visibility Problem n Solution 1 (scan-line visibility): –Test spans in the AET and draw front-most –Requires non-intersecting polygons n Solution 2 (pixel visibility): –Do the test for every pixel

18 Z-buffer n Allocate a full screen-sized buffer that stores depth (between near and far clip) n When scan-converting a polygon –For each pixel in each polygon n If z < ZBUF[x,y] –set CBUF[x,y] = polygon_colour –set ZBUF[x,y] = z –At the beginning of each frame n Initialise buffer to Z_MAX

19 Z-buffer Details n Can do this in several ways n 1D z-buffer re-used on each scan line –Process each polygon with separate AET –Use as adjunct to extended AET for multiple polygons n Problems –Aliasing on depth (z-buffer tearing)

20 Scanning Depth into the Z-buffer n Now we have to write a z-value for each point –directly from plane equation (re-calculate for each point) –interpolate …

21 Interpolating Depth n Interpolate z along edges AND interpolate between edges on each scan-line (bi-linear interpolation) (X1,Y1,Z1) (X2,Y2,Z2) (XL,YL,ZL) (XR,YR,ZR)

22 Zbuffer Fill Example 0 12345678 0 1 2 3 4 5 6 a b c 7 n General form of ET –(y2,x1,dx/dy,z1,dz/d y) n ET[1] = –ac (7,3,1/6,1,3/6) –ab (4,3,4/3,1,1/3) n ET[4] = –cb (7,7,-1,2,2/3) a=(3,1,1) b=(7,4,2) c=(4,7,4)

23 …Contents of AET n Scanline y=1 –ac (7,3,1/6,1,3/6) –ab (4,3,4/3,1,1/3) zspans 1 to 1 n y=2 –ac (7,3.166,1/6,1.5,3/6) –ab (4,4.333,4/3, 1.333, 1/3) zspans 1.5 to 1.333 n y3 –ac (7,3.333,1/6,2.0,3/6) –ab (4,5.666, 4/3, 1.666, 1/3) zspans 2 to 1.666

24 Trade-Offs n Z-buffer can be inaccurate with few bits –really simple to implement though! n Scan-line AET good for large polygons –good coherency across lines –requires non-intersecting polygons n Z-buffer good for small, sparse polygons –AET more time consuming to maintain

25 Overview n Scanning Polygons –Filling Pixels n Gouraud and Phong Shading n Visibility Culling Re-Visited –Z-buffer n Texture Mapping

26 Texture Mapping n Why? –Approximation for surface colouring –Efficient packing of flat detail n Standard texture mapping modifies diffuse mapping –Pasting a picture onto the polygon

27 Inverse Mapping n Each vertex is associated with a point on an image (u,v)

28 Quick and Dirty Solution n Yet more parameters in the ET! n Bilinear interpolation of u&v down scene edges, and across scan-lines n Works, but is very ugly –Does not consider fore-shortening of image in depth

29 The Problem n Same problem exists with phong and gouraud shading, but it much less noticeable z correct z incorrect

30 The Solution n Need to compensate for fore-shortening by interpolating over 1/z n Interpolate (u’,v’,q) where q=1/z –At vertices we know (u 1,v 1,z 1 ), (u 2,v 2,z 2 ) –Interpolate between (u 1* z 1,v 1 * z 1,1/z 1 ) and (u 2* z 2,v 2 * z 2,1/z 2 ) to get (u’,v’,q) –Restore u,v, by dividing u’ and v’ by q

31 Sanity Check p0=(10,5,10,0,0) p1=(15,15,20,0, 1) (x, y, z,u,v) scanlines Y=5 Y=10 Y=15 n At p0 (u’,v’,q) = (0,0.1,0.1) n At p1 (u’,v’,q) = (0,0,0.05) n On scanline 5 (u’,v’,q) = (0,0.05,0.075) (u,v) = 0.6666 z = 1/0.075 = 13.33

32 Minor Issues n Now have two divides per pixel! n Some optimisations –only do the divide at end of the spans and interpolate across spans –or only do the divide every n pixels n Remaining problem –we have not touched upon how to clip u,v values in 3D or 2D!

33 Major Issues n Picking your pixel! image

34 Sampling n A pixel maps to a non-rectangular region n Usually only perform map on centre of pixel n Still have a problem of over-sampling (same texel maps to several pixels) or under-sampling the image (pixels only sparsely sample the texels)

35 Filtering n Nearest neighbour n Pick pixel with closest centre n Bilinear n Weighted average based on distance to pixel centre

36 Filtering n Bilinear filtering solves (partially) the oversampling problem since it provides smooth shading between pixels scanline

37 Mip-Mapping n When undersampling we use mip- mapping n Resample image at lower resolution n Create a “pyramid” of textures. n Interpolate texture between two adjacent layers

38 Texture Pyramid 128x128 64x64 32x32 1x1...

39 Sampling n Choose two layers based on texel span –Choice is made selecting the two levels where the du and dv for dx and dy are closest to one n Interpolate between four pixels in higher layer and one in lower layer

40 Conclusion n A real-time pipeline that is fairly close to silicon n Note the liberties we have taken: –Screen space approximations –Interpolation schemes –Paucity of modelling presentations n The future is probably not polygonal!


Download ppt "Introduction to 3D Graphics Lecture 6: Real-Time Rendering Anthony Steed University College London."

Similar presentations


Ads by Google