SlideShare a Scribd company logo
1 of 32
Computer Graphics Inf4/MSc
1
Computer Graphics
Lecture 5
Hidden Surface Removal and Rasterization
Taku Komura
Computer Graphics Inf4/MSc
2
Hidden surface removal
• Drawing polygonal faces on screen
consumes CPU cycles
– Illumination
• We cannot see every surface in
scene
– We don’t want to waste time rendering
primitives which don’t contribute to
the final image.
Computer Graphics Inf4/MSc
3
Visibility (hidden surface
removal)
• A correct rendering requires correct visibility
calculations
• Correct visibility
– when multiple opaque polygons cover the same
screen space, only the closest one is visible
(remove the other hidden surfaces)
– wrong visibility correct visibility
Computer Graphics Inf4/MSc
4
Visibility of primitives
• A scene primitive can be invisible for 3 reasons:
– Primitive lies outside field of view
– Primitive is back-facing
– Primitive is occluded by one or more objects nearer the
viewer
Computer Graphics Inf4/MSc
5
Visible surface algorithms.
Definitions:
•Object space techniques: applied before vertices are mapped to pixels
•Back face culling, Painter’s algorithm, BSP trees
•Image space techniques: applied while the vertices are rasterized
•Z-buffering
Computer Graphics Inf4/MSc
6
Back face culling.
• The vertices of polyhedra are oriented
in an anticlockwise manner when
viewed from outside – surface normal
N points out.
• Project a polygon.
– Test z component of surface
normal. If negative – cull, since
normal points away from viewer.
– Or if N.V > 0 we are viewing the
back face so polygon is obscured.
Computer Graphics Inf4/MSc
7
Painters algorithm (object space).
• Draw surfaces in back
to front order – nearer
polygons “paint” over
farther ones.
• Supports transparency.
• Key issue is order
determination.
• Doesn’t always work –
see image at right.
Computer Graphics Inf4/MSc
BSP (Binary Space Partitioning) Tree.
•One of class of “list-priority” algorithms – returns
ordered list of polygon fragments for specified view
point (static pre-processing stage).
•Choose polygon arbitrarily
•Divide scene into front (relative to normal) and
back half-spaces.
•Split any polygon lying on both sides.
•Choose a polygon from each side – split scene
again.
•Recursively divide each side until each node
contains only 1 polygon.
3
4
1
2
5
View of scene from above
Computer Graphics Inf4/MSc
19/10/2007
Lecture 9 9
BSP Tree.
•Choose polygon arbitrarily
•Divide scene into front (relative to
normal) and back half-spaces.
•Split any polygon lying on both sides.
•Choose a polygon from each side – split
scene again.
•Recursively divide each side until each
node contains only 1 polygon.
3
3
4
1
2
5
5a
5b
1
2
5a
4
5b
back
front
Computer Graphics Inf4/MSc
BSP Tree.
•Choose polygon arbitrarily
•Divide scene into front (relative to
normal) and back half-spaces.
•Split any polygon lying on both sides.
•Choose a polygon from each side –
split scene again.
•Recursively divide each side until each
node contains only 1 polygon.
3
3
4
1
2
5
5a
5b
4
5b
back
front
2
1
5a
front
Computer Graphics Inf4/MSc
BSP Tree.
•Choose polygon arbitrarily
•Divide scene into front (relative to
normal) and back half-spaces.
•Split any polygon lying on both sides.
•Choose a polygon from each side – split
scene again.
•Recursively divide each side until
each node contains only 1 polygon.
3
3
4
1
2
5
5a
5b
back
front
2
1
5a
front
5b
4
Computer Graphics Inf4/MSc
19/10/2007
Lecture 9 12
Displaying a BSP tree.
• Once we have the regions – need priority list
• BSP tree can be traversed to yield a correct priority list for
an arbitrary viewpoint.
• Start at root polygon.
– If viewer is in front half-space, draw polygons behind root first,
then the root polygon, then polygons in front.
– If polygon is on edge – either can be used.
– Recursively descend the tree.
• If eye is in rear half-space for a polygon – then can back
face cull.
Computer Graphics Inf4/MSc
19/10/2007
Lecture 9 13
BSP Tree.
• A lot of computation required at start.
– Try to split polygons along good dividing plane
– Intersecting polygon splitting may be costly
• Cheap to check visibility once tree is set up.
• Can be used to generate correct visibility for
arbitrary views.
Efficient when objects don’t change very
often in the scene.
Computer Graphics Inf4/MSc
19/10/2007
Lecture 9 14
BSP performance measure
• Tree construction and traversal (object-space
ordering algorithm – good for relatively few static
primitives, precise)
• Overdraw: maximum
• Front-to-back traversal is more efficient
• Record which region has been filled in already
• Terminate when all regions of the screen is filled
in
• S. Chen and D. Gordon. “Front-to-Back Display of BSP Trees.” IEEE
Computer Graphics & Algorithms, pp 79–85. September 1991.
Computer Graphics Inf4/MSc
15
Z-buffering : image space approach
Basic Z-buffer idea:
• rasterize every input polygon
• For every pixel in the polygon interior, calculate
its corresponding z value (by interpolation)
• Track depth values of closest polygon (smallest z)
so far
• Paint the pixel with the color of the polygon
whose z value is the closest to the eye.
Computer Graphics Inf4/MSc
16
Computer Graphics Inf4/MSc
17
Computer Graphics Inf4/MSc
18
Computer Graphics Inf4/MSc
19
Computer Graphics Inf4/MSc
20
Implementation.
• Initialise frame buffer to background colour.
• Initialise depth buffer to z = max. value for
far clipping plane
• For each triangle
– Calculate value for z for each pixel inside
– Update both frame and depth buffer
Computer Graphics Inf4/MSc
Filling in Triangles
• Scan line algorithm
– Filling in the triangle by drawing horizontal
lines from top to bottom
• Barycentric coordinates
– Checking whether a pixel is inside / outside the
triangle
Computer Graphics Inf4/MSc
22
Triangle Rasterization
• Consider a 2D triangle with vertices p0 , p1 , p2.
• Let p be any point in the plane. We can always
find a, b, c such that
• We will have if and only if p is
inside the triangle.
• We call the barycentric coordinates of p.
Computer Graphics Inf4/MSc
23
Computing the baricentric
coordinates of the interior pixels
• (α,β,γ) : barycentric coordinates
• Only if 0<α,β,γ<1, (x,y) is inside the triangle
• Depth can be computed by αZ0 + βZ1 +γZ2
• Can do the same thing for color, normals, textures
• The triangle is composed of 3 points p0 (x0,y0), p1 (x1, y1), p2(x2,y2)
Computer Graphics Inf4/MSc
24
Bounding box of the triangle
• First, identify a rectangular region on the
canvas that contains all of the pixels in the
triangle (excluding those that lie outside the
canvas).
• Calculate a tight bounding box for a triangle:
simply calculate pixel coordinates for each
vertex, and find the minimum/maximum for
each axis
Computer Graphics Inf4/MSc
25
Scanning inside the triangle
• Once we've identified the bounding box,
we loop over each pixel in the box.
• For each pixel, we first compute the
corresponding (x, y) coordinates in the
canonical view volume
• Next we convert these into barycentric
coordinates for the triangle being drawn.
• Only if the barycentric coordinates
are within the range of [0,1], we
plot it (and compute the depth)
Computer Graphics Inf4/MSc
26
Why is z-buffering so popular ?
Advantage
• Simple to implement in hardware.
– Memory for z-buffer is now not expensive
• Diversity of primitives – not just polygons.
• Unlimited scene complexity
• Don’t need to calculate object-object intersections.
Disadvantage
• Extra memory and bandwidth
• Waste time drawing hidden objects
Z-precision errors
• May have to use point sampling
Computer Graphics Inf4/MSc
27
Z-buffer performance
• Brute-force image-space algorithm scores best for
complex scenes – easy to implement and is very
general.
• Storage overhead: O(1)
• Time to resolve visibility to screen precision: O(n)
– n: number of polygons
Computer Graphics Inf4/MSc
19/10/2007
Lecture 9 28
Ex. Architectural scenes
Here there can be an enormous amount of occlusion
Computer Graphics Inf4/MSc
19/10/2007
Lecture 9 29
Occlusion at various levels
Computer Graphics Inf4/MSc
19/10/2007
30
Portal Culling (object-space)
Model scene as a graph:
• Nodes: Cells (or rooms)
• Edges: Portals (or doors)
Graph gives us:
• Potentially visible set
1. Render the room
2. If portal to the next room is visible, render
the connected room in the portal region
3. Repeat the process along the scene graph
A
B
C
D
E
F
G
A
B
D
C E
Computer Graphics Inf4/MSc
Summary
•Z-buffer is easy to implement on hardware and is an
important tool
•We need to combine it with an object-based method
especially when there are too many polygons
BSP trees, portal culling
Computer Graphics Inf4/MSc
32
References for hidden surface removal
• Foley et al. Chapter 15, all of it.
• Introductory text, Chapter 13, all of it
• Baricentric coordinates
www.cs.caltech.edu/courses/cs171/barycent
ric.pdf
• Or equivalents in other texts, look out for:
– (as well as the topics covered today)
– Depth sort – Newell, Newell & Sancha
– Scan-line algorithms

More Related Content

Similar to visible surface detection in 3D objects for viewing

project_PPT_final
project_PPT_finalproject_PPT_final
project_PPT_final
Ranjan Ganguli
 
Double Patterning (4/2 update)
Double Patterning (4/2 update)Double Patterning (4/2 update)
Double Patterning (4/2 update)
Danny Luk
 
3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx
ssuser255bf1
 
hidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmhidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithm
rajivagarwal23dei
 

Similar to visible surface detection in 3D objects for viewing (20)

project_PPT_final
project_PPT_finalproject_PPT_final
project_PPT_final
 
OpenGL for 2015
OpenGL for 2015OpenGL for 2015
OpenGL for 2015
 
Massive Point Light Soft Shadows
Massive Point Light Soft ShadowsMassive Point Light Soft Shadows
Massive Point Light Soft Shadows
 
Fundamentals of Computer Graphics.pdf
Fundamentals of Computer Graphics.pdfFundamentals of Computer Graphics.pdf
Fundamentals of Computer Graphics.pdf
 
Double Patterning (4/2 update)
Double Patterning (4/2 update)Double Patterning (4/2 update)
Double Patterning (4/2 update)
 
B. SC CSIT Computer Graphics Unit 4 By Tekendra Nath Yogi
B. SC CSIT Computer Graphics Unit 4 By Tekendra Nath YogiB. SC CSIT Computer Graphics Unit 4 By Tekendra Nath Yogi
B. SC CSIT Computer Graphics Unit 4 By Tekendra Nath Yogi
 
Deferred shading
Deferred shadingDeferred shading
Deferred shading
 
august23.ppt
august23.pptaugust23.ppt
august23.ppt
 
clipping
clippingclipping
clipping
 
Computer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsComputer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methods
 
3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx
 
CAD/CAM/CAE - Notes
CAD/CAM/CAE - NotesCAD/CAM/CAE - Notes
CAD/CAM/CAE - Notes
 
november29.ppt
november29.pptnovember29.ppt
november29.ppt
 
Computer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmComputer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal Algorithm
 
PlayStation: Cutting Edge Techniques
PlayStation: Cutting Edge TechniquesPlayStation: Cutting Edge Techniques
PlayStation: Cutting Edge Techniques
 
Sr 01-40 good
Sr 01-40 goodSr 01-40 good
Sr 01-40 good
 
Notes04.pdf
Notes04.pdfNotes04.pdf
Notes04.pdf
 
Z-BUFFER.pptx
Z-BUFFER.pptxZ-BUFFER.pptx
Z-BUFFER.pptx
 
hidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmhidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithm
 
Overview of graphics systems.ppt
Overview of graphics systems.pptOverview of graphics systems.ppt
Overview of graphics systems.ppt
 

Recently uploaded

scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 

Recently uploaded (20)

S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Introduction to Geographic Information Systems
Introduction to Geographic Information SystemsIntroduction to Geographic Information Systems
Introduction to Geographic Information Systems
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 

visible surface detection in 3D objects for viewing

  • 1. Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 5 Hidden Surface Removal and Rasterization Taku Komura
  • 2. Computer Graphics Inf4/MSc 2 Hidden surface removal • Drawing polygonal faces on screen consumes CPU cycles – Illumination • We cannot see every surface in scene – We don’t want to waste time rendering primitives which don’t contribute to the final image.
  • 3. Computer Graphics Inf4/MSc 3 Visibility (hidden surface removal) • A correct rendering requires correct visibility calculations • Correct visibility – when multiple opaque polygons cover the same screen space, only the closest one is visible (remove the other hidden surfaces) – wrong visibility correct visibility
  • 4. Computer Graphics Inf4/MSc 4 Visibility of primitives • A scene primitive can be invisible for 3 reasons: – Primitive lies outside field of view – Primitive is back-facing – Primitive is occluded by one or more objects nearer the viewer
  • 5. Computer Graphics Inf4/MSc 5 Visible surface algorithms. Definitions: •Object space techniques: applied before vertices are mapped to pixels •Back face culling, Painter’s algorithm, BSP trees •Image space techniques: applied while the vertices are rasterized •Z-buffering
  • 6. Computer Graphics Inf4/MSc 6 Back face culling. • The vertices of polyhedra are oriented in an anticlockwise manner when viewed from outside – surface normal N points out. • Project a polygon. – Test z component of surface normal. If negative – cull, since normal points away from viewer. – Or if N.V > 0 we are viewing the back face so polygon is obscured.
  • 7. Computer Graphics Inf4/MSc 7 Painters algorithm (object space). • Draw surfaces in back to front order – nearer polygons “paint” over farther ones. • Supports transparency. • Key issue is order determination. • Doesn’t always work – see image at right.
  • 8. Computer Graphics Inf4/MSc BSP (Binary Space Partitioning) Tree. •One of class of “list-priority” algorithms – returns ordered list of polygon fragments for specified view point (static pre-processing stage). •Choose polygon arbitrarily •Divide scene into front (relative to normal) and back half-spaces. •Split any polygon lying on both sides. •Choose a polygon from each side – split scene again. •Recursively divide each side until each node contains only 1 polygon. 3 4 1 2 5 View of scene from above
  • 9. Computer Graphics Inf4/MSc 19/10/2007 Lecture 9 9 BSP Tree. •Choose polygon arbitrarily •Divide scene into front (relative to normal) and back half-spaces. •Split any polygon lying on both sides. •Choose a polygon from each side – split scene again. •Recursively divide each side until each node contains only 1 polygon. 3 3 4 1 2 5 5a 5b 1 2 5a 4 5b back front
  • 10. Computer Graphics Inf4/MSc BSP Tree. •Choose polygon arbitrarily •Divide scene into front (relative to normal) and back half-spaces. •Split any polygon lying on both sides. •Choose a polygon from each side – split scene again. •Recursively divide each side until each node contains only 1 polygon. 3 3 4 1 2 5 5a 5b 4 5b back front 2 1 5a front
  • 11. Computer Graphics Inf4/MSc BSP Tree. •Choose polygon arbitrarily •Divide scene into front (relative to normal) and back half-spaces. •Split any polygon lying on both sides. •Choose a polygon from each side – split scene again. •Recursively divide each side until each node contains only 1 polygon. 3 3 4 1 2 5 5a 5b back front 2 1 5a front 5b 4
  • 12. Computer Graphics Inf4/MSc 19/10/2007 Lecture 9 12 Displaying a BSP tree. • Once we have the regions – need priority list • BSP tree can be traversed to yield a correct priority list for an arbitrary viewpoint. • Start at root polygon. – If viewer is in front half-space, draw polygons behind root first, then the root polygon, then polygons in front. – If polygon is on edge – either can be used. – Recursively descend the tree. • If eye is in rear half-space for a polygon – then can back face cull.
  • 13. Computer Graphics Inf4/MSc 19/10/2007 Lecture 9 13 BSP Tree. • A lot of computation required at start. – Try to split polygons along good dividing plane – Intersecting polygon splitting may be costly • Cheap to check visibility once tree is set up. • Can be used to generate correct visibility for arbitrary views. Efficient when objects don’t change very often in the scene.
  • 14. Computer Graphics Inf4/MSc 19/10/2007 Lecture 9 14 BSP performance measure • Tree construction and traversal (object-space ordering algorithm – good for relatively few static primitives, precise) • Overdraw: maximum • Front-to-back traversal is more efficient • Record which region has been filled in already • Terminate when all regions of the screen is filled in • S. Chen and D. Gordon. “Front-to-Back Display of BSP Trees.” IEEE Computer Graphics & Algorithms, pp 79–85. September 1991.
  • 15. Computer Graphics Inf4/MSc 15 Z-buffering : image space approach Basic Z-buffer idea: • rasterize every input polygon • For every pixel in the polygon interior, calculate its corresponding z value (by interpolation) • Track depth values of closest polygon (smallest z) so far • Paint the pixel with the color of the polygon whose z value is the closest to the eye.
  • 20. Computer Graphics Inf4/MSc 20 Implementation. • Initialise frame buffer to background colour. • Initialise depth buffer to z = max. value for far clipping plane • For each triangle – Calculate value for z for each pixel inside – Update both frame and depth buffer
  • 21. Computer Graphics Inf4/MSc Filling in Triangles • Scan line algorithm – Filling in the triangle by drawing horizontal lines from top to bottom • Barycentric coordinates – Checking whether a pixel is inside / outside the triangle
  • 22. Computer Graphics Inf4/MSc 22 Triangle Rasterization • Consider a 2D triangle with vertices p0 , p1 , p2. • Let p be any point in the plane. We can always find a, b, c such that • We will have if and only if p is inside the triangle. • We call the barycentric coordinates of p.
  • 23. Computer Graphics Inf4/MSc 23 Computing the baricentric coordinates of the interior pixels • (Îą,β,Îł) : barycentric coordinates • Only if 0<Îą,β,Îł<1, (x,y) is inside the triangle • Depth can be computed by ÎąZ0 + βZ1 +ÎłZ2 • Can do the same thing for color, normals, textures • The triangle is composed of 3 points p0 (x0,y0), p1 (x1, y1), p2(x2,y2)
  • 24. Computer Graphics Inf4/MSc 24 Bounding box of the triangle • First, identify a rectangular region on the canvas that contains all of the pixels in the triangle (excluding those that lie outside the canvas). • Calculate a tight bounding box for a triangle: simply calculate pixel coordinates for each vertex, and find the minimum/maximum for each axis
  • 25. Computer Graphics Inf4/MSc 25 Scanning inside the triangle • Once we've identified the bounding box, we loop over each pixel in the box. • For each pixel, we first compute the corresponding (x, y) coordinates in the canonical view volume • Next we convert these into barycentric coordinates for the triangle being drawn. • Only if the barycentric coordinates are within the range of [0,1], we plot it (and compute the depth)
  • 26. Computer Graphics Inf4/MSc 26 Why is z-buffering so popular ? Advantage • Simple to implement in hardware. – Memory for z-buffer is now not expensive • Diversity of primitives – not just polygons. • Unlimited scene complexity • Don’t need to calculate object-object intersections. Disadvantage • Extra memory and bandwidth • Waste time drawing hidden objects Z-precision errors • May have to use point sampling
  • 27. Computer Graphics Inf4/MSc 27 Z-buffer performance • Brute-force image-space algorithm scores best for complex scenes – easy to implement and is very general. • Storage overhead: O(1) • Time to resolve visibility to screen precision: O(n) – n: number of polygons
  • 28. Computer Graphics Inf4/MSc 19/10/2007 Lecture 9 28 Ex. Architectural scenes Here there can be an enormous amount of occlusion
  • 29. Computer Graphics Inf4/MSc 19/10/2007 Lecture 9 29 Occlusion at various levels
  • 30. Computer Graphics Inf4/MSc 19/10/2007 30 Portal Culling (object-space) Model scene as a graph: • Nodes: Cells (or rooms) • Edges: Portals (or doors) Graph gives us: • Potentially visible set 1. Render the room 2. If portal to the next room is visible, render the connected room in the portal region 3. Repeat the process along the scene graph A B C D E F G A B D C E
  • 31. Computer Graphics Inf4/MSc Summary •Z-buffer is easy to implement on hardware and is an important tool •We need to combine it with an object-based method especially when there are too many polygons BSP trees, portal culling
  • 32. Computer Graphics Inf4/MSc 32 References for hidden surface removal • Foley et al. Chapter 15, all of it. • Introductory text, Chapter 13, all of it • Baricentric coordinates www.cs.caltech.edu/courses/cs171/barycent ric.pdf • Or equivalents in other texts, look out for: – (as well as the topics covered today) – Depth sort – Newell, Newell & Sancha – Scan-line algorithms