Hidden Surfaces Dr. Scott Schaefer.

Slides:



Advertisements
Similar presentations
Visible-Surface Detection(identification)
Advertisements

Collisions and Intersections When objects move, test for collision. When projecting surfaces, check for intersections. (Many slides adapted from Amitabh.
03/12/02 (c) 2002 University of Wisconsin, CS559 Last Time Some Visibility (Hidden Surface Removal) algorithms –Painter’s Draw in some order Things drawn.
David Luebke5/11/2015 CS 551 / 645: Introductory Computer Graphics David Luebke
CAP4730: Computational Structures in Computer Graphics Visible Surface Determination.
CECS461 Computer Graphics II University of Missouri at Columbia Hidden Surface Removal.
Hidden Surface Removal Why make the effort?  Realistic models.  Wasted time drawing. OpenGL and HSR  OpenGL does handle HSR using the depth buffer.
Visibility in Computer Graphics Toni Sellarès Unversitat de Girona
Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a.
Korea Univ. Graphics Lab. 3D Game Engine Design Chapter 12. Spatial Sorting Chung Ji Hye
UBI 516 Advanced Computer Graphics
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Clipping II, Hidden Surfaces.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
1 Dr. Scott Schaefer Hidden Surfaces. 2/62 Hidden Surfaces.
CS 4731: Computer Graphics Lecture 18: Hidden Surface Removal Emmanuel Agu.
A lion in the desert How do you find a lion in the desert? How about when you have a predicate that tells you if the lion is in front or behind a separating.
Hidden Surface Elimination Wen-Chieh (Steve) Lin Institute of Multimedia Engineering I-Chen Lin’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals.
1 CSCE 441: Computer Graphics Hidden Surface Removal (Cont.) Jinxiang Chai.
Now Playing: Big Bird Eddie Floyd from The Complete Stax-Volt Singles Volume 1 ( ) Released April 30, 1991.
Visible-surface Detection Computer Graphics Seminar MUM
A lion in the desert How do you find a lion in the desert? How about when you have a predicate that tells you if the lion is in front or behind a separating.
Vertices and Fragments III Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Spatial Data Structure: Quadtree, Octree,and BSP tree Mengxia Zhu Fall 2007.
Hidden Surface Removal
Visible Surface Determination
Graphics Pipeline Hidden Surfaces CMSC 435/634. Visibility We can convert simple primitives to pixels Which primitives (or parts of primitives) should.
Graphics Pipeline Hidden Surface CMSC 435/634. Visibility We can convert simple primitives to pixels/fragments How do we know which primitives (or which.
10/29/02 (c) 2002 University of Wisconsin, CS559 Today Hidden Surface Removal Exact Visibility.
CS 450: COMPUTER GRAPHICS VISIBLE SURFACE DETECTION SPRING 2015 DR. MICHAEL J. REALE.
The BSP-tree from Prof. Seth MIT.. Motivation for BSP Trees: The Visibility Problem We have a set of objects (either 2d or 3d) in space. We have.
Visible-Surface Detection Jehee Lee Seoul National University.
Hidden Surface Removal 1.  Suppose that we have the polyhedron which has 3 totally visible surfaces, 4 totally invisible/hidden surfaces, and 1 partially.
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Binary Space Partitioning Trees Ray Casting Depth Buffering
CS 376 Introduction to Computer Graphics 03 / 21 / 2007 Instructor: Michael Eckmann.
Hidden Surface Removal
Implementation II.
Where We Stand At this point we know how to: –Convert points from local to window coordinates –Clip polygons and lines to the view volume –Determine which.
Presented by: Bhavna Agarwal. Given a bunch of 3D objects predefined in x,y,z; order them in geometry.
Computer Graphics I, Fall 2010 Implementation II.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
01/28/09Dinesh Manocha, COMP770 Visibility Computations Visible Surface Determination Visibility Culling.
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 5 Hidden Surface Removal and Rasterization Taku Komura.
Visible surface determination. Problem outline Given a set of 3D objects and a viewing specification, we wish to determine which lines or surfaces are.
1 Computer Graphics Week11 : Hidden Surface Removal.
Learning Objectives Classification of Visible Surface Detection Algorithms Classification of Visible Surface Detection Algorithms Back-Face Detection Back-Face.
Visible-Surface Detection Methods. To identify those parts of a scene that are visible from a chosen viewing position. Surfaces which are obscured by.
Hidden Surface Removal. 2 Goal: Determine which surfaces are visible and which are not. Z-Buffer is just one of many hidden surface removal algorithms.
Computer Graphics Implementation II
(c) 2002 University of Wisconsin, CS559
Solid Area Scan Conversion or Visible Surface Detection
Hidden Surface Removal
CSC418 Computer Graphics Back Faces Visibility Algorithms.
CSCE 441: Computer Graphics Hidden Surface Removal (Cont.)
BSP Trees Binary space partitioning trees.
© University of Wisconsin, CS559 Fall 2004
Graphics Pipeline Hidden Surfaces
CSCE 441: Computer Graphics Hidden Surface Removal
Implementation II Ed Angel Professor Emeritus of Computer Science
Visibility (hidden surface removal)
CSCE 441: Computer Graphics Hidden Surface Removal (Cont.)
Hidden Surface Removal
CSCE 441: Computer Graphics Hidden Surface Removal (Cont.)
Introduction to Computer Graphics with WebGL
Hidden Surface Removal
The Framebuffer 1 Lecture 37 Fri, Nov 30, 2007.
Hidden Surface Removal
Implementation II Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

Hidden Surfaces Dr. Scott Schaefer

Hidden Surfaces

Hidden Surfaces

Hidden Surfaces

Backface Culling

Backface Culling view direction

Backface Culling view direction

Backface Culling , draw polygon view direction

Backface Culling , cull polygon view direction

Backface Culling

counter clock-wise orientation, draw polygon Backface Culling counter clock-wise orientation, draw polygon

clock-wise orientation, cull polygon Backface Culling clock-wise orientation, cull polygon

Backface Culling Advantages Improves rendering speed by removing roughly half of polygons from scan conversion Disadvantages Assumes closed surface with consistently oriented polygons NOT a true hidden surface algorithm!!!

Backface Culling Is this all we have to do?

Backface Culling Is this all we have to do? No! Can still have 2 (or more) front faces that map to the same screen pixel

Backface Culling Is this all we have to do? No! Can still have 2 (or more) front faces that map to the same screen pixel Which actually gets drawn?

Painter’s Algorithm Sort polygons according to distance from viewer Draw from back to front How do we sort polygons?

Painter’s Example Sort by depth: Green rect Red circle Blue tri z = 0.7 z = 0.3 z = 0.1 Sort by depth: Green rect Red circle Blue tri z = 0

Painter’s Algorithm

Painter’s Algorithm Sometimes there is NO ordering that produces correct results!!!

Painter’s Algorithm Sort all objects’ zmin and zmax

Painter’s 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

Painter’s 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 yes, need to split one

Painter’s Algorithm The splitting step is the tough one - Need to find a plane to split one polygon by so that each new polygon is entirely in front of or entirely behind the other - Polygons may actually intersect, so then need to split each polygon by the other

Painter’s Algorithm The splitting step is the tough one - Need to find a plane to split one polygon by so that each new polygon is entirely in front of or entirely behind the other - Polygons may actually intersect, so then need to split each polygon by the other After splitting, you can resort the list and should be fine

Painter’s Algorithm-Summary Advantages Simple algorithm for ordering polygons Disadvantages Sorting criteria difficult to produce Redraws same pixel many times Sorting can also be expensive

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

Depth (“Z”) Buffer Advantages Simple to implement Allows for a streaming approach to polygon drawing Disadvantages Requires extra storage space Still lots of overdraw

Binary Space Partitioning Trees BSP tree: organize all of space (hence partition) into a binary tree - Preprocess: overlay a binary tree on objects in the scene - Runtime: correctly traversing this tree enumerates objects from back to front - Idea: divide space recursively into half-spaces by choosing splitting planes Splitting planes can be arbitrarily oriented

BSP Trees: Objects 9 8 6 7 5 4 1 2 3

BSP Trees: Objects 9 - 8 6 7 + 5 4 1 2 3

BSP Trees: Objects + - - + Put front objects in the left branch 9 8 6 7 + 1 2 3 4 5 6 7 8 9 5 4 1 2 3

BSP Trees: Objects + - + - + - Put front objects in the left branch 9 8 6 7 + - + - 5 4 1 2 3 4 5 6 7 8 9 1 2 3

BSP Trees: Objects + - + - + - + - + - + - Put front objects in the left branch + - 9 8 6 7 + - + - 5 4 1 + - + - + - 1 2 3 2 4 3 5 6 7 9 8

BSP Trees: Objects + - + - + - + - + - + - + - + - Put front objects in the left branch + - 9 8 6 7 + - + - 5 4 1 + - + - + - 1 2 3 3 5 6 8 + 2 - 6 + - 2 4 7 9

BSP Trees: Objects + - + - + - + - + - + - + - + - Put front objects in the left branch + - 9 8 6 7 + - + - 5 4 1 + - + - + - 1 2 3 3 5 6 8 + 2 - 6 + - 2 4 7 9 When to stop the recursion?

Object Splitting No bunnies were harmed in my example But what if a splitting plane passes through an object? - Split the object; give half to each node: - Worst case: can create up to O(n3) objects! Ouch

Building a BSP Tree Choose a splitting polygon Sort all other polygons as Front Behind Crossing On Add “front” polygons to front child, “behind” to back child Split “crossing” polygons with infinite plane Add “on” polygons to root Recur

Building a BSP Tree 6 7 3 5 1 2 4

Building a BSP Tree 6 7 3 5 1 2 4 1 b 2,3,4,5,6,7

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-2,6, 5-2 f b 7-2,6, 5-2 2,4,5-1,7-1

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-1 7-2,6, 5-2 2 f b 7-1 7-2,6, 5-2 f b 2 4, 5-1

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-1 7-2,6, 5-2 4 2 f b 7-1 7-2,6, 5-2 f b 4 2 b 5-1

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-1 7-2,6, 5-2 4 2 f b 7-1 7-2,6, 5-2 f b 4 2 b 5-1

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-1 7-2,6, 5-2 4 2 f b 7-1 7-2,6, 5-2 f b 4 2 b 5-1

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-2 7-1 4 6, 5-2 2 f b 7-2 7-1 b f b 4 6, 5-2 2 b 5-1

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-2 7-1 6 4 2 5-2 f b 7-2 7-1 b f b 6 4 b 2 b 5-2 5-1

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-2 7-1 6 4 2 5-1 f b 7-2 7-1 b f b 6 4 b 2 b 5-1 5-2

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-2 7-1 6 4 2 5-1 f b 7-2 7-1 b f b 6 4 b 2 b 5-1 5-2

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 Else eye is on plane

BSP Trees: Objects + - + - + - + - + - + - + - + - Correctly traversing this tree enumerates objects from back to front + - 9 8 6 7 + - + - 5 4 1 + - + - + - 1 2 3 3 5 6 8 + 2 - 6 + - 2 4 7 9 Traversal order?

BSP Trees: Objects + - + - + - + - + - + - + - + - Correctly traversing this tree enumerates objects from back to front + - 9 8 6 7 + - + - 5 4 1 + - + - + - 1 2 3 3 5 6 8 + 2 - 6 + - 2 4 7 9 Traversal order: 8->9->7->6->5->3->4->2->1

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-2 7-1 6 4 f b 7-2 7-1 b f b 6 4 Traversal order: b 2 b 5-1 5-2

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-2 7-1 6 4 f b 7-2 7-1 b f b 6 4 Traversal order: 6->(5-2)->(7-2)->3->(5-1)->4->(7-1)->2->1 b 2 b 5-1 5-2

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-2 7-1 6 4 f b 7-2 7-1 b f b 6 4 Traversal order: b 2 b 5-1 5-2

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-2 7-1 6 4 f b 7-2 7-1 b f b 6 4 Traversal order: 1->2->(7-1)->4->(5-1)->3->(7-2)->(5-2)->6 b 2 b 5-1 5-2

Building a BSP Tree 6 7-2 5-2 3 7-1 5-1 1 2 4 1 3 7-2 7-1 6 4 f b 7-2 7-1 b f b 6 4 Traversal order? b 2 b 5-1 5-2

Rendering with a BSP Tree Advantages No depth comparisons needed Polygons split and ordered automatically Disadvantages Computationally intense preprocess stage restricts algorithm to static scenes Splitting increases polygon count Redraws same pixel many times Choosing splitting plane not an exact science

Improved BSP Rendering Take advantage of view direction to cull away polygons behind viewer

Improved BSP Rendering Take advantage of view direction to cull away polygons behind viewer View frustum

Improved BSP Rendering Take advantage of view direction to cull away polygons behind viewer

OpenGL and Hidden Surfaces glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glCullFace ( GL_BACK );

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

Scan Line Algorithm

Scan Line Algorithm

Scan Line Algorithm

Scan Line Algorithm Advantages Takes advantage of coherence resulting in fast algorithm Does not require as much storage as depth buffer Disadvantages More complex algorithm Requires all polygons sent to GPU before drawing