1 Clipping and Hidden Surfaces CS-184: Computer Graphics Prof. James O’Brien.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

Visible-Surface Detection(identification)
Collisions and Intersections When objects move, test for collision. When projecting surfaces, check for intersections. (Many slides adapted from Amitabh.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
10/10/02 (c) 2002 University of Wisconsin, CS 559 Last Time Finished viewing: Now you know how to: –Define a region of space that you wish to view – the.
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.
CAP4730: Computational Structures in Computer Graphics Visible Surface Determination.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
3/2/04© University of Wisconsin, CS559 Spring 2004 Last Time General Perspective –Methods for specifying the view volume As a set of clip planes As a field.
Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)
Korea Univ. Graphics Lab. 3D Game Engine Design Chapter 12. Spatial Sorting Chung Ji Hye
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Clipping II, Hidden Surfaces.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
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.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Visibility culling – Clipping. The visibility problem What polygons are visible? There are few visible polygons. –Avoid redundant processing Three classes.
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.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Clipping.
Spatial Data Structure: Quadtree, Octree,and BSP tree Mengxia Zhu Fall 2007.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
10/11/2001CS 638, Fall 2001 Today Kd-trees BSP Trees.
2/26/04© University of Wisconsin, CS559 Spring 2004 Last Time General Orthographic Viewing –Specifying cameras in world coordinates –Building world  view.
Hidden Surface Removal
Clipping Apart from clipping to the view volume, clipping is a basic operation in many other algorithms –Breaking space up into chunks –2D drawing and.
10/29/02 (c) 2002 University of Wisconsin, CS559 Today Hidden Surface Removal Exact Visibility.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
02/26/02 (c) 2002 University of Wisconsin, CS 559 Last Time Canonical view pipeline Orthographic projection –There was an error in the matrix for taking.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
The Visibility Problem In many environments, most of the primitives (triangles) are not visible most of the time –Architectural walkthroughs, Urban environments.
CSC418 Computer Graphics n BSP tree n Z-Buffer n A-buffer n Scanline.
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
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.
CSE Real Time Rendering Week 9. Post Geometry Shaders Courtesy: E. Angel and D. Shreiner – Interactive Computer Graphics 6E © Addison-Wesley 2012.
03/14/02 (c) 2002 University of Wisconsin, CS559 Last Time Some more visibility (Hidden Surface Removal) algorithms –A-buffer –Scanline –Depth sorting.
CS-378: Game Technology Lecture #2.2: Clipping and Hidden Surfaces Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney,
3/23/04© University of Wisconsin, CS559 Spring 2004 Last Time Antialiasing –Area-weighted sampling Visibility –Painters algorithm –Depth buffer (Z-buffer)
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.
Implementation II.
1 Visiblity: Culling and Clipping Computer Graphics COMP 770 (236) Spring 2009 January 21 & 26: 2009.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
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.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
CS559: Computer Graphics Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008.
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
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.
Computer Graphics Implementation II
(c) 2002 University of Wisconsin, CS559
© University of Wisconsin, CS559 Fall 2004
Hidden Surfaces Dr. Scott Schaefer.
© University of Wisconsin, CS559 Spring 2004
CSCE 441: Computer Graphics Hidden Surface Removal
Implementation II Ed Angel Professor Emeritus of Computer Science
© University of Wisconsin, CS559 Fall 2004
(c) 2002 University of Wisconsin, CS559
Sweep Fill Details For row = min to row=max
Hidden Surface Removal
Implementation II Ed Angel Professor Emeritus of Computer Science
COMPUTER GRAPHICS Clipping
Presentation transcript:

1 Clipping and Hidden Surfaces CS-184: Computer Graphics Prof. James O’Brien

2 Clipping Don’t want to draw stuff that is not in screen area – Waste of time – Bogus memory access – Looks ugly Clipping removes unwanted stuff Can also clip for other reasons – Cut away views

3 Basic Line Clipping

4 Cohen-Sutherland Line Clip Clip line against each edge of clip region in turn – If both endpoints outside, discard line and stop – If both endpoints in, continue to next edge (or finish) – If one in, one out, chop line at crossing pt and continue Works in both 2D and 3D for convex clipping regions

5 Cohen-Sutherland Line Clip

6 Trivial reject and accept (speed things up…) Trivial KeepNOT Trivial RejectTrivial Reject

7 Cohen-Sutherland Line Clip Out codes

8 Liang-Barsky Clipping Parametric clipping - view line in parametric form and reason about the parameter values More efficient, as not computing the coordinate values at irrelevant vertices Works for rectilinear clip regions in 2D or 3D Clipping conditions on parameter: Line is inside clip region for values of t such that (for 2D):

9 Liang-Barsky Clipping Infinite line intersects clip region edges at: where Note: Left edge is 1, right edge is 2, top edge is 3, bottom is 4

10 Liang-Barsky Clipping When p k <0, as t increases line goes from outside to inside - entering When p k >0, line goes from inside to outside – leaving When p k =0, line is parallel to an edge (clipping is easy) If there is a segment of the line inside the clip region, sequence of infinite line intersections must go: enter, enter, leave, leave

11 Liang-Barsky Clipping Enter Leave Enter Leave Enter Leave

12 Liang-Barsky Clipping Compute entering t values, which are q k /p k for each p k <0 Compute leaving t values, which are q k /p k for each p k >0 Parameter value for small t end of line is:t small = max(0, entering t’s) parameter value for large t end of line is: t large =min(1, leaving t’s) if t small <t large, there is a line segment - compute endpoints by substituting t values Improvement (and actual Liang-Barsky): – compute t’s for each edge in turn (some rejects occur earlier like this)

13 Sutherland-Hodgman Polygon Clip Clip the polygon against each edge of the clip region in turn – Clip polygon each time to line containing edge – Only works for convex clip regions (Why?)

14 Sutherland-Hodgman Polygon Clip To clip a polygon to a line/plane: – Consider the polygon as a list of vertices – One side of the line/plane is considered inside the clip region, the other side is outside – We are going to rewrite the polygon one vertex at a time – the rewritten polygon will be the polygon clipped to the line/plane – Check start vertex: if “inside”, emit it, otherwise ignore it – Continue processing vertices as follows…

15 Sutherland-Hodgman Polygon Clip InsideOutside s p Output p InsideOutside s p Output i InsideOutside s p No output InsideOutside s p Output i and p i i

16 General Clipping (Weiler Algorithm)

17 General Clipping (Weiler Algorithm) Rearranging pointers makes it possible to enumerate all components of the intersection

18 Inside-Outside Testing

19 Inside/Outside in Screen Space

20 Finding Intersection Points

21 Backface Culling

22 Z-Buffer ( a.k.a. Depth Buffer ) Use additional buffer to store a Z value at each pixel When filling pixel write Z value to buffer also Don’t fill if new Z value is larger than old Quantization and aliasing problems sometimes occur Very commonly used Standard feature in hardware Interpolating Z values over polygons

23 Z-Buffer and Transparency Must render in order back to front Partially transparent Opaque 1st 2nd 3rd Front Good Partially transparent Opaque 2nd 3rd 1st Not Good Talk about compositing later…

24 A-Buffer Store list of polygons at each pixel (fragments) Draw opaque stuff first,only keep closest frag Second pass for transparent stuff Allows antialiasing… Not good for hardware implementation

25 Scan Line Algorithm Assume polygons don’t intersect each other As scanning keep list of active edges Decide who’s on top when crossing edges

26 Scan Line Algorithm Advantages: – Simple – Potentially fewer quantization errors (more bits available for depth) – Don’t over-render (each pixel only drawn once) – Filter anti-aliasing can be made to work (have information about all polygons at each pixel) Disadvantages: – Invisible polygons clog AEL, ET – Non-intersection criteria may be hard to meet

27 Painters Algorithm Sort based on depth and draw back to front How dow we sort quickly? What about intersecting polygons?

28 BSP-Trees (Object Precision) Construct a binary space partition tree – Depth-first traversal gives a rendering order (varient) Tree splits 3D world with planes – The world is broken into convex cells – Each cell is the intersection of all the half-spaces of splitting planes on tree path to the cell Also used to model the shape of objects, and in other visibility algorithms – BSP visibility in games does not necessarily refer to this algorithm

29 BSP-Tree Example A C B A B C

30 Building BSP-Trees Choose polygon (arbitrary) Split its cell using plane on which polygon lies – May have to chop polygons in two (Clipping!) Continue until each cell contains only one polygon fragment Splitting planes could be chosen in other ways, but there is no efficient optimal algorithm for building BSP trees – Optimal means minimum number of polygon fragments in a balanced tree

31 Building Example We will build a BSP tree, in 2D, for a 3 room building –Ignoring doors Splitting edge order is shown –“Back” side of edge is side with the number

b4b a, 4a, 62, 3b, 4b, a 3a Building Example

33 Building Example 1 23b4b 5a 6 1 3a, 4a, a 3a 3b, 5b 2 4b, 5a -+ 5b

34 Building Example 1 23b4b 5a a 3a 2 4b, 5a - + 5b 4a, 6 3a + 5b 3b +

35 Building Example (Done) 1 23b4b 5a a 3a b 3a + 3b + 4a 6 + 5b 4b 5a +

36 BSP-Tree Rendering Observation: Things on the opposite side of a splitting plane from the viewpoint cannot obscure things on the same side as the viewpoint Rendering algorithm is recursive descent of the BSP Tree At each node (for back to front rendering): – Recurse down the side of the sub-tree that does not contain the viewpoint ● Test viewpoint against the split plane to decide which tree – Draw the polygon in the splitting plane ● Paint over whatever has already been drawn – Recurse down the side of the tree containing the viewpoint

37 BSP-Tree Rendering Example A C B A B C st2nd3rd4th

38 BSP-Tree Rendering Advantages: – One tree works for any viewing point – Filter anti-aliasing and transparency work ● Have back to front ordering for compositing – Can also render front to back, and avoid drawing back polygons that cannot contribute to the view ● User two trees – an extra one that subdivides the window Disadvantages: – Can be many small pieces of polygon

39 Cells and Portals Assume the world can be broken into cells – Simple shapes – Rooms in a building, for instance Define portals to be the transparent boundaries between cells – Doorways between rooms, windows, etc In a world like this, can determine exactly which parts of which rooms are visible – Then render visible rooms plus contents An Exact Visibility Algorithm -- sometimes

40 Cell and Portal Visibility Start in the cell containing the viewer, with the full viewing frustum Render the walls of that room and its contents Recursively clip the viewing frustum to each portal out of the cell, and call the algorithm on the cell beyond the portal

41 Cell-Portal Example View

42 Cell-Portal Example View

43 Cell-Portal Example View

44

45 Acknowledgments Some of these slide contents were based on original materials from – Prof. David Forsyth of U.C. Berkeley – Prof. Stephen Chenney of U.W. Madison