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.

Slides:



Advertisements
Similar presentations
Visible-Surface Detection(identification)
Advertisements

Hidden Surface Removal - 12 a (Visible Surface determination)
Computer Graphics Inf4/MSc Computer Graphics Lecture 9 Visible Surface Determination.
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.
Lecture Fall 2001 Visibility Back-Face Culling Painter’s Algorithm.
CAP4730: Computational Structures in Computer Graphics Visible Surface Determination.
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
Part I: Basics of Computer Graphics
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Course Website: Computer Graphics 15: More Surface Detection Methods.
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.
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.
1 Clipping and Hidden Surfaces CS-184: Computer Graphics Prof. James O’Brien.
Visible-surface Detection Computer Graphics Seminar MUM
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.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
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.
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
Polygon Scan Conversion and Z-Buffering
10/29/02 (c) 2002 University of Wisconsin, CS559 Today Hidden Surface Removal Exact Visibility.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
CSC418 Computer Graphics n BSP tree n Z-Buffer n A-buffer n Scanline.
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.
Visible-Surface Detection Methods
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
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.
1 3D Hidden Surface Removal 김 성 남. 2 Contents Goal Motivation Approaches - back face detection - depth buffer - A-buffer - Scan line - Depth.
College of Computer and Information Science, Northeastern UniversityJanuary 6, CS4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 22 –
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.
Computer Graphics I, Fall 2010 Implementation II.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
Hidden Surface Removal. Visible Surface Invisible Primitives  Why might a polygon be invisible?  Polygon outside the field of view  Polygon is backfacing.
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.
COMPUTER GRAPHICS CS 482 – FALL 2015 NOVEMBER 10, 2015 VISIBILITY CULLING HIDDEN SURFACES ANTIALIASING HALFTONING.
Visible-Surface Detection Methods. To identify those parts of a scene that are visible from a chosen viewing position. Surfaces which are obscured by.
Lecture 30: Visible Surface Detection
Visible Surface Detection
Computer Graphics Implementation II
Solid Area Scan Conversion or Visible Surface Detection
Hidden Surfaces Dr. Scott Schaefer.
CSCE 441: Computer Graphics Hidden Surface Removal
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Implementation II Ed Angel Professor Emeritus of Computer Science
Lecture 32: Visible Surface Detection
Hidden Surface Removal
Introduction to Computer Graphics with WebGL
Hidden Surface Removal
Lecture 31: Visible Surface Detection
Implementation II Ed Angel Professor Emeritus of Computer Science
Visible-Surface Determination
Presentation transcript:

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. Other names: Visible-surface detection Hidden-surface elimination Display all visible surfaces, do not display any occluded surfaces. We can categorize into Object-space methods Image-space methods

3 Hidden Surface Elimination Object space algorithms: determine which objects are in front of others Resize doesn’t require recalculation Works for static scenes May be difficult to determine Image space algorithms: determine which object is visible at each pixel Resize requires recalculation Works for dynamic scenes

4 Don’t draw surfaces facing away from viewpoint: Assumes objects are solid polyhedra Usually combined with additional methods Compute polygon normal n: Assume counter-clockwise vertex order For a triangle (a, b, c): n = (b – a)  (c – a) Compute vector from viewpoint to any point p on polygon v: Facing away (don’t draw) if n and v are pointed in opposite directions  dot product n · v > 0 Back-Face Culling a b c n x y z

5 Back-Face Culling Example v = (-1, 0, -1) n 2 = (-3, 1, -2) n 1 · v = (2, 1, 2) · (-1, 0, -1) = -2 – 2 = -4, so n 1 ·v < 0 so n 1 front facing polygon n 1 = (2, 1, 2) n 2 · v = (-3, 1, -2) · (-1, 0, -1) = = 5 so n 2 · v > 0 so n 2 back facing polygon

6 Back Face Culling If the viewpoint is on the +z axis looking at the origin, we only need check the sign of the z component of the object’s normal vector if n z < 0, it is back facing if n z > 0 it is front facing What if n z = 0? the polygon is parallel to the view direction, so we don’t see it

7 Painter’s Algorithm(depth sorting algm) Object-space algorithm Draw surfaces from back (farthest away) to front (closest) : Sort surfaces/polygons by their depth (z value) Draw objects in order (farthest to closest) Closer objects paint over the top of farther away objects

8 List Priority Algorithms A visibility ordering is placed on the objects Objects are rendered back to front based on that ordering Problems: overlapping polygons x z

9 Depth Sort Algorithm An extension to the painter’s algorithm Performs a similar algorithm but attempts to resolve overlapping polygons Algorithm: Sort objects by their minimum z value (farthest from the viewer) Resolve any ambiguities caused by overlapping polygons, splitting polygons if necessary Scan convert polygons in ascending order of their z values (back to front)

10 Depth-Sort Algorithm Depth-Sort test for overlapping polygons: Let P be the most distant polygon in the sorted list. Before scan converting P, we must make sure it does not overlap another polygon and obscure it For each polygon Q that P might obscure, we make the following tests. As soon as one succeeds, there is no overlap, so we quit: 1.Are their x extents non-overlapping? 2.Are their y extents non-overlapping? 3.Is P entirely on the other side of Q’s plane from the viewpoint? 4.Is Q entirely on the same side of P’s plane as the viewpoint? 5.Are their projections onto the (x, y) plane non- overlapping?

11 Test 3 succeeds: Test 3 fails, test 4 succeeds: z Q P Depth-Sort Algorithm z Q P x x

12 Depth-Sort Algorithm If all 5 tests fail, assume that P obscures Q, reverse their roles, and repeat steps 3 and 4 If these tests also fail, one of the polygons must be split into multiple polygons and the tests run again.

13 Binary Space Partition (BSP) Tree Recursively subdivide space to determine depth order: Think of scene as clusters of objects Find plane that separates two clusters An object on same side of the plane as the viewpoint can obscure, but cannot be obscured by, an object on the other side. Recursively subdivide clusters by finding appropriate planes Store subdivision (space-partioning) planes in a binary tree Node: stores a polygon and a space partioning plane Left child: subtree of objects on negative side of plane Right child: subtree of objects on positive side of plane

14 Binary Space Partition (BSP) Tree Very efficient for static scenes New viewpoints calculated quickly Invented by Henry Fuchs and others. Fuchs is a professor at UNC. Used in first-person shooters. Used in Doom.

15 BSP Trees: Basic Idea – + In the plane (= 0) Behind the plane (– side) eye t2t2 t1t1 In front of the plane (+ side)

16 BSP Trees: Basic Idea (cont.) Assume (for now) the polygons do not cross the plane. Let f (p) be the implicit equation of a plane evaluated at p. if f t1 (eye) < 0 draw t 1 draw t 2 else draw t 2 draw t 1 – + In the plane Behind the plane eye t2t2 t1t1

17 BSP Algorithm BSP Tree: partitions space into positive and negative sides Node: polygon and a space partioning plane Left (right) child: subtree of objects on negative (positive) side of plane Use a modified in-order traversal to draw the scene: Start at root Compute which side of node’s plane eye is on Recursively scan convert polygons on opposite side from eye Scan convert node’s polygon Recursively scan convert polygons on same side as eye Root polygon + – 4 + – eye

18 BSP Algorithm (cont.) Root polygon + – 4 + – eye draw(tree, eye){ if tree.empty() return; if tree.f plane (eye) < 0 draw(tree.plus, eye); rasterize(tree.triangle); draw(tree.minus, eye) else draw(tree.minus, eye); rasterize(tree.triangle); draw(tree.plus, eye); } 1 32 –+ 4 + Resulting drawing order: 2, 4, 1, 3

19 BSP Tree Algorithm 1.Select a polygon and make it the root 2.Partition space into two half-spaces determined by the normal of the root polygon 3.If a polygon is intersected by the plane, split the polygon into two polygons, one in each half space 4.Select one polygon in the root’s front and one in the root’s back and assign them as children of the root 5.Recursively subdivide space depending on each of the children generated from step 4. 6.Stop when a sub-space contains a single polygon

20 BSP Tree example Initial Scene:

21 BSP Tree example Select polygon 3 as the root a 4b 5 3 4a 4b front back

22 BSP Tree example Select polygons 2 and 4b as the next nodes b 4a 3 4b 2 1a 5 1b 1a front back

23 BSP Tree example Select polygon 1b as the next node a 4b 2 1a 5 1b 1a 1b 4a front back

24 BSP Tree Once the tree is built, you can scan convert The viewpoint will be in one of the subspaces To scan convert properly: Recursively scan convert all polygons in the root’s subspace that doesn’t contain the viewpoint Then scan convert the root Then recursively scan convert the subspace that contains the viewpoint

25 BSP Tree example Suppose the viewpoint is as shown: Since the eye is in front of 3, scan convert the polygons in back of 3 first 3 4b 2 1a 5 1b 4a front back a 4b 1b 1a eye

26 BSP Tree example The eye is behind 4b, so scan convert the polygons in front of 4b first (there are none) Then scan convert 4b, then scan convert the polygons in back of 4b (5) a 4b 1b 1a 3 4b 2 1a 5 1b 4a front back eye

27 BSP Tree example Next scan convert 3 Then scan convert the polygons in front of 3 3 4b 2 1a 5 1b 4a front back a 4b 1b 1a eye

28 BSP Tree example The eyepoint is behind 2, so scan convert the polygons in front of 2 first 3 4b 2 1a 5 1b 4a front back a 4b 1b 1a eye

29 BSP Tree example The eyepoint is behind 1b, so scan convert the polygons in front of 1b first (none) Then scan convert 1b, then the polygons behind 1b (4a) 3 4b 2 1a 5 1b 4a front back a 4b 1b 1a eye

30 BSP Tree example Then scan convert 2 Then scan convert the polygons behind 2 (1a) 3 4b 2 1a 5 1b 4a front back a 4b 1b 1a eye

31 BSP Tree example So, the final ordering is: 4b, 5, 3, 1b, 4a, 2, 1a 3 4b 2 1a 5 1b 4a front back a 4b 1b 1a eye

32 Cutting Triangles Must maintain same vertex ordering to keep the same normal! t 1 =(a, b, A) t 2 = (b, B, A) t 3 = (A, B, c) b a A B c t1t1 t2t2 t3t3 Plane a b B c A If triangle intersects plane  Split

33 Cutting Triangles (cont.) Assume we’ve c isolated on one side of plane and that f plane (c) > 0, then: Add t 1 and t 2 to negative subtree: minus.add(t 1 ) minus.add(t 2 ) Add t 3 to positive subtree: plus.add(t 3 ) t 1 =(a, b, A) t 2 = (b, B, A) t 3 = (A, B, c) –+ b a A B c t1t1 t2t2 t3t3 Plane

34 Cutting Triangles (cont.) How do we find A and B? A: intersection of line between a and c with the plane f plane Use parametric form of line: p(t) = a + t(c – a) Plug p into the plane equation for the triangle: f plane (p) = (n · p) + D = n · (a + t(c – a)) + D Solve for t and plug back into p(t) to get A Repeat for B a b B c A We use same formula in ray tracing!!

35 Z-Buffering Image precision algorithm: Determine which object is visible at each pixel Order of polygons not critical Works for dynamic scenes Takes more memory Basic idea: Rasterize (scan-convert) each polygon Keep track of a z value at each pixel Interpolate z value of polygon vertices during rasterization Replace pixel with new color if z value is smaller (i.e., if object is closer to eye)

36 Scan Line Algorithms Image precision Similar to the ideas behind polygon scan conversion, except now we are dealing with multiple polygons Need to determine, for each pixel, which object is visible at that pixel The approach we will present is the “Watkins Algorithm”

37 Watkins Algorithm Similar to the edge table idea used in polygon scan conversion Create an Edge Table (ET) Entries in the edge table have the following format: X is the x coordinate of the endpoint with the smaller y coordinate Y max is the y coordinate of the endpoint with the greatest Y value dx is the x increment used in going from one scan line to the next ID is the polygon to which this edge belongs XY max dxIDnext

38 Watkins Algorithm - cont Edges are sorted by smallest Y value and placed in buckets accordingly We also need a Polygon Table (PT) that contains information about the polygons Entries in the polygon table have the following format: ID is the id of this polygon Plane Coefs are the coefficients of the plane in which this polygon lies Shading info is the color or shading info to be used in the scan conversion of the polygon In/Out flag - a boolean flag to be used in scan conversion IDPlane CoefsShading InfoIn/Out Flag

39 Watkins Algorithm - cont In addition to the ET and PT, we keep an Active Edge Table (AET), similar to the one used in single polygon scan conversion Process scan line by scan line, left to right Initially all polygon In/Out flags are FALSE When a scan line intersects and edge, that polygon’s In/Out flag is set to TRUE.

40 Watkins Algorithm - cont If two or more In/Out flags are TRUE, use the plane equations for the polygons to determine which intersected polygon is in front Y = the current scan line X = the intersection point between the scan line and the edges Z is computed using the plane equations If we have non-penetrating polygons, shade with one polygon’s color until the next edge intersection, then update accordingly.

41 Watkins Algorithm - cont What about penetrating polygons? Break them into sub-polygons and scan convert the sub-polygons Y1Y1 Y2Y2 Y3Y3

42 An area-subdivision technique Idea: Divide an area into four equal sub-areas At each stage, the projection of each polygon will do one of four things: 1.Completely surround a particular area 2.Intersect the area 3.Be completely contained in the area 4.Be disjoint to the area Warnock’s Algorithm

43 Warnock’s Algorithm Disjoint polygons do not influence an area. Parts of an intersecting polygon that lie outside the area do not influence that area At each step, we determine the areas we can color and color them, then subdivide the areas that are ambiguous.

44 Warnock’s Algorithm At each stage of the algorithm, examine the areas: 1.If no polygons lie within an area, the area is filled with the background color 2.If only one polygon is in part of the area, the area is first filled with the background color and then the polygon is scan converted within the area. 3.If one polygon surrounds the area and it is in front of any other polygons, the entire area is filled with the color of the surrounding polygon. 4.Otherwise, subdivide the area and repeat the above 4 tests.

45 Warnock’s Algorithm Initial scene

46 Warnock’s Algorithm First subdivision

47 Warnock’s Algorithm Second subdivision

48 Warnock’s Algorithm Third subdivision

49 Warnock’s Algorithm Fourth subdivision

50 Warnock’s Algorithm Subdivision continues until: All areas meet one of the four criteria An area is pixel size in this case, the polygon with the closest point at that pixel determines the pixel color

51 Visible Surface Ray Tracing From the center of projection, send a ray through each pixel The color of the pixel is determined by the first object intersected by the ray Eye Image plane