1 / 35

CSCE 441: Computer Graphics Hidden Surface Removal (Cont.)

CSCE 441: Computer Graphics Hidden Surface Removal (Cont.). Jinxiang Chai. Outline. Backface Culling Painter’s algorithm BSP Z-buffer Ray casting Reading: section 16-1 to 16-11, 16-14,16-15. Depth (“Z”) Buffer. Simple modification to scan-conversion

rbest
Download Presentation

CSCE 441: Computer Graphics Hidden Surface Removal (Cont.)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCE 441: Computer Graphics Hidden Surface Removal (Cont.) Jinxiang Chai

  2. Outline • Backface Culling • Painter’s algorithm • BSP • Z-buffer • Ray casting • Reading: section 16-1 to 16-11, 16-14,16-15

  3. Depth (“Z”) Buffer • Simple modification to scan-conversion • Maintain a separate buffer storing the closest “z” value for each pixel—depth buffer • Only draw pixel if depth value is closer than stored “z” value • Update buffer with closest depth value • Work in normalized coordinate space [0.0…1.0]

  4. z = 0.7 z = 0.7 z = 0.3 z = 0.1 z = 0.1 z = 0.1 z = 1.0 z = 0.3 z = 0.3 z = 1.0 z = 1.0 z = 0.3 z = 1.0 Z-Buffering Example NOTE: Can draw these shapes in any order

  5. Depth Buffer Algorithm • Initialize the depth buffer and frame buffer for every pixel - depthBuff(x,y)=1.0; - frameBuff(x,y)=backgndColor; • Process each polygon in a scene, one at a time. - for each pixel (x,y), calculate the depth z (if not already known). - if z <depthBuff(x,y), compute the surface color at (x,y) and set depthBuff(x,y)=z; frameBuff(x,y)=surfColor(x,y);

  6. How to Calculate “z”? • This is easy to implement for polygon surfaces v0 p=[x,y,z] v1 v2 Given the pixel coordinates (x,y), how to calculate the z value? use plane normal

  7. How to Calculate “z”? • This is easy to implement for polygon surfaces v0 p=[x,y,z] v1 v2 Plane normal (p-v0)∙((v2-v0)x(v1-v0))=0 Plane equation: Ax+By+Cz+D=0 P=[x,y,z]

  8. How to Calculate “z”? • This is easy to implement for polygon surfaces • How can we speed up the calculation? Plane equation: Ax+By+Cz+D=0 p=[x,y,z]

  9. How to Calculate “z”? • This is easy to implement for polygon surfaces • How can we speed up the calculation? - scan line conversion Plane equation: Ax+By+Cz+D=0 p=[x,y,z]

  10. Scanline Conversion Normalized project space view direction

  11. How to Calculate “z”? • Solution: update “z” values using scan line conversion algorithm p=[x,y,z]

  12. How to Calculate “z”? • Update “z” values using scan line conversion algorithm

  13. How to Calculate “z”? • Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0

  14. How to Calculate “z”? • Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0

  15. How to Calculate “z”? • Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0

  16. How to Calculate “z”? • Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0

  17. How to Calculate “z”? • Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0

  18. How to Calculate “z”? • Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0 What’s the x,y,z value for this pixel?

  19. How to Calculate “z”? • Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0 What’s the xk+1,yk+1,zk+1 values for the next horizontal pixel?

  20. Depth (“Z”) Buffer • Advantages • Always works. The nearest object always determines the color of a pixel • Polygon drawn in any order • Commonly in hardware • Disadvantages • Needs a whole extra buffer (depth buffer) • Requires extra storage space • Still lots of overdraw

  21. Z-buffer: opengl • In opengl, depth values are normalized to [0.0,1.0] - Specify depth-buffer operations glutInitDisplayMode // with argument GLUT_DEPTH - Specify initial depth-buffer value glClear(GL_DEPTH_BUFFER_BIT) // initialize depth-buffer values to 1.0 glClearDepth (depth) // specify an initial depth-buffer value - Activate depth-testing operations glEnable (GL_DEPTH_TEST)

  22. Hidden Surface Removal: opengl • Backface culling - glEnable(GL_CULL_FACE), glDisable(GL_CULL_FACE) - glCullFace(GL_BACK) , cull polygon view direction

  23. Outline • Backface Culling • Painter’s algorithm • BSP • Z-buffer • Ray casting • Reading: section 9-1 to 9-11, 9-14,9-15

  24. Ray Casting • Key idea: for every pixel, cast a ray, find the closest point on the object and draw the point

  25. Ray Casting • For each pixel enter Pij - Send a ray from eye point, c, through pij into scene - Intersect ray with each object - Select the nearest intersection • Effective for scenes with curved surfaces, particularly sphere

  26. Ray Casting • Implementation - Might parameterize each ray as - Each object Ok returns tk>0 such that first intersection with ok occurs at r(tk)

  27. Ray Casting • Implementation - Might parameterize each ray as - Each object Ok returns tk>0 such that first intersection with ok occurs at r(tk) Intersection with polygons?

  28. Ray Casting • Implementation - Might parameterize each ray as - Each object Ok returns tk>0 such that first intersection with ok occurs at r(tk) Intersection with polygons? Ray equation: Plane equation: Ax+By+Cz+D=0 Plug in and calculate the parameter value t!

  29. Ray Casting • Implementation - Might parameterize each ray as - Each object Ok returns tk>0 such that first intersection with ok occurs at r(tk) Intersection with spheres? Plug in and calculate the parameter value t!

  30. Ray Casting • Implementation - Might parameterize each ray as - Each object Ok returns tk>0 such that first intersection with ok occurs at r(tk) Intersection with spheres? Ray equation: Sphere equation: (x-x0)2+(y-y0)2+(z-z0)2=r2 Plug in and calculate the parameter value t!

  31. Ray Casting • Implementation - Might parameterize each ray as - Each object Ok returns tk>0 such that first intersection with ok occurs at r(tk) Intersection with curved surfaces? Ray equation: Curved surface equation: f(x,y,z)=0 Plug in and calculate the parameter value t!

  32. Ray Casting • Implementation - Might parameterize each ray as - Each object Ok returns tk>0 such that first intersection with ok occurs at r(tk) - Q: given the set {tk}, what is the first intersection point?

  33. Ray Casting • Implementation - Might parameterize each ray as - Each object Ok returns tk>0 such that first intersection with ok occurs at r(tk) - Q: given the set {tk}, what is the first intersection point?

  34. Ray Casting • Ray casting properties: - process pixels one at a time - draw each visible pixel once - efficient algorithm needed for ray-object intersection - may (not) use pixel coherence - simple but generally not used

  35. Summary • Backface Culling • Painter’s algorithm • BSP • Z-buffer • Ray casting

More Related