CPSC 441: Computer Graphics Hidden Surface Removal Cont' - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

CPSC 441: Computer Graphics Hidden Surface Removal Cont'

Description:

Backface Culling. Painter's algorithm. BSP. Z-buffer. Scan line. Ray casting ... Review: Backface Culling. view direction , draw polygon. 4. Review: Painter's Example ... – PowerPoint PPT presentation

Number of Views:1028
Avg rating:3.0/5.0
Slides: 30
Provided by: symo5
Category:

less

Transcript and Presenter's Notes

Title: CPSC 441: Computer Graphics Hidden Surface Removal Cont'


1
CPSC 441 Computer Graphics Hidden Surface
Removal (Cont.)
  • Dr. Jinxiang Chai

2
Outline
  • Backface Culling
  • Painters algorithm
  • BSP
  • Z-buffer
  • Scan line
  • Ray casting
  • Reading section 9-1 to 9-11, 9-14,9-15

3
Review Backface Culling
, draw polygon
view direction
4
Review Painters Example
Sort by depth Green rect Red circle Blue tri
5
Review Painters Algorithm
  • Sort all objects zmin and zmax
  • If an object is uninterrupted (its zmin and zmax
    are adjacent in the sorted list), it is fine
  • If 2 objects DO overlap
  • 3.1 Check if they overlap in x
  • - If not, they are fine
  • 3.2 Check if they overlap in y
  • - If not, they are fine
  • - If yes, need to split one

6
Review Building a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-1
7-2
b
b
f
4
6
2
b
f
5-2
5-1
7
Review Rendering with a BSP Tree
  • If eye is in front of plane
  • Draw back polygons
  • Draw on polygons
  • Draw front polygons
  • If eye is behind plane
  • Draw front polygons
  • Draw on polygons
  • Draw back polygons
  • Else eye is on plane
  • Draw front polygons
  • Draw back polygons

8
Outline
  • Backface Culling
  • Painters algorithm
  • BSP
  • Z-buffer
  • Scan line
  • Ray casting
  • Reading section 9-1 to 9-11, 9-14,9-15

9
Depth (Z) Buffer
  • Simple modification to scan-conversion
  • Maintain a separate buffer storing the closest
    z value for each pixeldepth buffer
  • Only draw pixel if depth value is closer than
    stored z value
  • Update buffer with closest depth value

10
Z-Buffering Example
NOTE Can draw these shapes in any order
11
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
  • Requires extra storage space (How big?)
  • Still lots of overdraw

12
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
  • Requires extra storage space (How big?)
    (1k1k24bits)
  • Still lots of overdraw

13
Scan Line Algorithm
  • Scan line algorithm for polygon drawing
  • - how can we modify it for hidden surface
    removals?

Scan line
14
Scan Line Algorithm
  • Assume for each line of screen, we have
    scan-lines for all polygons intersecting that
    line
  • For each polygon, keep track of extents of scan
    line
  • Whenever the x-extents of two scan lines overlap,
    determine ordering of two polygons

15
Scan Line Algorithm
  • Scan line algorithm with depth information

Scan line
16
Scan Line Algorithm
  • Scan line algorithm with depth information

Scan line
Z0.18
Z0.38
Scan line spans
Z0.5
Z0.5
17
Scan Line Algorithm
Scan line
Z0.18
Z0.38
Scan line spans
Z0.5
Z0.5
18
Scan Line Algorithm
19
Scan Line Algorithm
20
Scan Line Algorithm
21
Scan Line Algorithm
  • Advantages
  • Takes advantage of coherence resulting in fast
    algorithm
  • Does not require as much storage as depth buffer
  • Only draw visible pixels
  • Commonly in software
  • Disadvantages
  • More complex algorithm
  • Requires all polygons sent to renderer before
    drawing

22
Ray Casting
  • For each pixel enter Pij
  • - Send a ray from eye point, c, through pij
    into scene
  • - Intersect ray with each object
  • - Select nearest intersection

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

24
Ray Casting
  • Implementation
  • - Might parameterize each ray as
  • - Each object Ok returns tkgt0 such that
    first intersection with ok occurs at r(tk)
  • - Q given the set tk, what is the first
    intersection point?

25
Ray Casting
  • Implementation
  • - Might parameterize each ray as
  • - Each object Ok returns tkgt0 such that
    first intersection with ok occurs at r(tk)
  • - Q given the set tk, what is the first
    intersection point?

26
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

27
Hidden Surface removal opengl
  • Backface culling
  • - glEnable(GL_CULL_FACE),
    glDisable(GL_CULL_FACE)
  • - glCullFace(GL_BACK)

, cull polygon
view direction
28
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)

29
Summary
  • Backface Culling
  • Painters algorithm
  • BSP
  • Z-buffer
  • Scan line
  • Ray casting
  • Reading section 9-1 to 9-11,9-14,9-15
Write a Comment
User Comments (0)
About PowerShow.com