Modeling of worlds A complicated object be decomposed into simple objects and represented by hierarchical model A world scene usually contain many objects.

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.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
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
Lecture Fall 2001 Visibility Back-Face Culling Painter’s Algorithm.
Hidden Surface Removal CSE 581. Visibility Assumption: All polygons are opaque What polygons are visible with respect to your view frustum?  Outside:
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
Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a.
Part I: Basics of Computer Graphics
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.
Computer Graphics 14: Surface Detection Methods
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.
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.
CSC418 Computer Graphics n BSP tree n Z-Buffer n A-buffer n Scanline.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
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.
10/26/04© University of Wisconsin, CS559 Fall 2004 Last Time Drawing lines Polygon fill rules Midterm Oct 28.
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.
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.
Visible-Surface Detection Methods
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
Binary Space Partitioning Trees Ray Casting Depth Buffering
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.
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.
CS559: Computer Graphics Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008.
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.
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.
Lecture 30: Visible Surface Detection
Computer Graphics Implementation II
(c) 2002 University of Wisconsin, CS559
Solid Area Scan Conversion or Visible Surface Detection
Hidden Surface Removal
© 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
Last Time Clipping Homework 4, due Nov 2 in class
CSCE 441: Computer Graphics Hidden Surface Removal (Cont.)
Sweep Fill Details For row = min to row=max
(c) 2002 University of Wisconsin, CS559
Hidden Surface Removal
Implementation II Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

Modeling of worlds A complicated object be decomposed into simple objects and represented by hierarchical model A world scene usually contain many objects If position each objects are relatively fixed, then the world can be rendered by drawing each object. Eg. the buildings in a city CP411 Hidden face removing1

Dynamic world with many objects What if the objects are moving and their relative positions are changing? E.g. solar system, animations How do we remember and get the current position of each object? CP411 Hidden face removing2

Method one Remember the current position of all vertices of the object. E.g. when cube is moving remember the current coordinates of each object Pro: Con: Works when an object has a few vertices Bad when an object contains many object CP411 Hidden face removing3

Method two Use the model coordinate system, ie. the (Ux, Uy, Uz, O) or MC, the MC->WC transformation matrix to remember the position. When the an object is moving to a new position, apply the same transformation matrix to MC to get the new MC. Then new MC represents the new MC->WC transformation matrix and the object can be rendered with CTM * MC Pro : Con: CP411 Hidden face removing4

MC normalization The vectors in MC are unit vectors and orthogonal with each other. After a large number of transformations, the MC begins to deform due to error accumulation How to fix? CP411 Hidden face removing5

6 The drawing does not look right! What happens? A face drawn earlier is overwritten by other faces drawn later, even though it is closer to the viewer than the others How can we solve the problem?

CP411 Hidden face removing7 Visibility and Hidden surface removing 1.Visibility and visibility issues 2.Back-face method (to be implemented) 3.Depth sort method (to be implemented) 4.Depth-buffer method (implemented in OpenGL, to be used) 5.A-buffer method 6.Scan line method 7.Area-division method 8.BSP-tree method

CP411 Hidden face removing8 1. Visibility Given a set of polygons, determine which is visible at each pixel? –Also called hidden surface removal Many approaches were invented. Two major classes: –Object-space method: computations that operate on primitives –Image-space method: computations at the pixel level

CP411 Hidden face removing9 Space and Depth All the spaces in the viewing pipeline maintain depth, so we can work in any space –World, View and Canonical Screen spaces might be used –Depth can be updated on a per-pixel basis as we scan convert polygons or lines

CP411 Hidden face removing10 Issues with visibility Efficiency –it is slow to overwrite pixels, or scan convert things that cannot be seen Accuracy –answer should be right, and behave well when the viewpoint moves Complexity –object precision visibility may generate many small pieces of polygon –Must have technology that handles large, complex rendering databases In many complex worlds, few things are visible How much of the real world can you see at any moment?

CP411 Hidden face removing11 2. Back Face method Back faces are the surfaces facing at opposite directions from the viewpoint. A surface is a back face if the viewpoint is on the inside of the surface, ie, Ae x + Be y + Ce z + D < 0. The test will even be simpler after the viewing transformation Ax + By + Cz + D = 0 (e x, e y, e z )

CP411 Hidden face removing 12 Eye position Reference point How to detect if a face is a back face A face is a back face if Using this condition for back face detection in A3 will give a better performance. Credits to Alasdair and Derek

CP411 Hidden face removing13

CP411 Hidden face removing14 Back face detection algorithm with OpenGL If an object is opaque, back faces are obstructed by the object itself and thus are not visible from the viewer. In default mode, OpenGL draws both front face and back face as filled polygons. This is the reason why the preceding drawing of the cube did not look right. OpenGL can be set to display front faces as filled polygons and back faces as wire frames. glPolygonMode( GL_FRONT, GL_FILL); glPolygonMode( GL_BACK, GL_LINE); A more thorough solution is not to display the back faces at all. glCullFace(GL_BACK); glEnable(GL_CULL_FACE);

CP411 Hidden face removing15 2. Depth Sorting ( Painters) Method Algorithm: –Choose an order for the polygons based on some choice (e.g. depth to a point on the polygon) –Render the polygons in that order, deepest one first An example of a list-priority algorithm –Sort polygons on depth of some point –Render from back to front (modifying order on the fly) –Rendering: For surface S with greatest depth If no overlap in depth with other polygons, scan convert Else, for overlaps in depth, test for overlaps in the image plane –If none, scan convert and go to next polygon If S, S’ overlap in depth and in image plane, swap order and try again If S, S’ have been swapped already, split and reinsert

CP411 Hidden face removing16 The depth of a point The depth of a point is the z value of in view coordinate system The z value d of P (the depth of P) is equal to the length of project of P eye P on P eye P ref Peye Pref vz vx vy P d

CP411 Hidden face removing17 How to calculate the Z-value The z-value of P is equal to

CP411 Hidden face removing18

CP411 Hidden face removing19 The depth of a polygon can be defined to be the depth of its center Overlap of polygons is a problem with painter’s algorithm Testing for overlaps: Start drawing when first condition is met: –x-extents or y-extents do not overlap –S is behind the plane of S’ –S’ is in front of the plane of S –S and S’ do not intersect in the image plane S S’ S or z x S S’ z x S S

CP411 Hidden face removing20 Advantages: –Filter anti-aliasing works fine Composite in back to front order with a sequence of over operations –No depth quantization error Depth comparisons carried out in high-precision view space Disadvantages: –Over-rendering –Potentially very large number of splits -  (n 2 ) fragments from n polygons

CP411 Hidden face removing21 This renders nearer polygons over further Difficulty: –works for some important geometries (2.5D - e.g. VLSI) –doesn’t work in this form for most geometries - need at least better ways of determining ordering zszs xsxs Fails Which point for choosing ordering?

CP411 Hidden face removing22 3. The depth-buffer (Z buffer) algorithm When a new surface is drawn, a pixel value will be updated only if the part of the surface corresponding to the pixel is closer to the viewer than the surface currently displayed by the pixel. Suppose that the cyan face in the middle is drawn first. The pixel corresponding to the line of sight shown is set to cyan. Next, when the green face is drawn, the pixel will not be updated. Finally when the red triangle is drawn, the pixel is set to red. One pixel of the screen

CP411 Hidden face removing23 For each pixel on screen, have at least two buffers –Color buffer stores the current color of each pixel The thing to ultimately display –Z-Buffer stores at each pixel the depth (distance) of the nearest thing seen so far Frame Buffer Video Controller Monitor Display Processor Depth Buffer Depth Buffer Frame Buffer

CP411 Hidden face removing24 Initialize this buffer to a value corresponding to the furthest point As a polygon is filled in, compute the depth value of each pixel that is to be filled –if depth < z-buffer depth, fill in pixel color and new depth –else disregard

CP411 Hidden face removing25 The depth-buffer algorithm For each pixel at (x, y) of the screen //Initialization color( x, y) = background_color; depth( x, y) =  ; Draw each surface one by one For each pixel that covered by the projection of the surface (suppose the pixel is at (x, y) ) z = the depth of the surface corresponding to the pixel; if (z < depth( x, y) ) { color( x, y) = the color of the surface; depth( x, y) = z; }

CP411 Hidden face removing26 OpenGL Depth Buffer Functions OpenGL defines a depth buffer as its visibility algorithm –To set up the depth buffer testing (in main() ) glutInitDisplayMode(GLUT_DEPTH); –The enable depth testing: glEnable(GL_DEPTH_TEST); –To clear the depth buffer glClear(GL_DEPTH_BUFFER_BIT); –To clear color and depth: –glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); –The comparison function can be specified: glDepthFunc(…); For efficiency, we shall enable back-face culling as well.

CP411 Hidden face removing27 glutSolidSphere( 1.0, 20, 20);

CP411 Hidden face removing28 glutSolidTeapot( 1.5);

CP411 Hidden face removing29 Advantages: –Simple and now ubiquitous in hardware A z-buffer is part of what makes a graphics card “3D” –Computing the required depth values is simple Disadvantages: –Over-renders - worthless for very large collections of polygons –Depth quantization errors can be annoying –Can’t easily do transparency or filtering for anti-aliasing (Requires keeping information about partially covered polygons)

CP411 Hidden face removing30 4. A-buffer Handles transparent surfaces and filter anti-aliasing At each pixel, maintain a pointer to a list of polygons sorted by depth, and a sub-pixel coverage mask for each polygon –Matrix of bits saying which parts of the pixel are covered Algorithm: When drawing a pixel: –if polygon is opaque and covers pixel, insert into list, removing all polygons farther away –if polygon is transparent or only partially covers pixel, insert into list, but don’t remove farther polygons

CP411 Hidden face removing31 Algorithm: Rendering pass –At each pixel, traverse buffer using polygon colors and coverage masks to composite: Advantage: –Can do more than Z-buffer –Coverage mask idea can be used in other visibility algorithms Disadvantages: –Not in hardware, and slow in software –Still at heart a z-buffer: Over-rendering and depth quantization problems But, used in high quality rendering tools over =

CP411 Hidden face removing32 5. Scan Line Algorithm (Image Precision) Assume polygons do not intersect one another –Except maybe at edges or vertices Observation: across any given scan line, the visible polygon can change only at an edge Algorithm: –fill all polygons simultaneously –at each scan line, have all edges that cross scan line in AEL (Active Edge List) –keep record of current depth at current pixel - use to decide which is in front in filling span

CP411 Hidden face removing33 zszs xsxs zszs xsxs zszs xsxs Spans Where polygons overlap, draw front polygon

CP411 Hidden face removing34 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 (edge table) –Non-intersection criteria may be hard to meet

Final exam questions What is the back-face method for hidden surface removal? What is the painter’s method for hidden surface removal? What is the difference between depth-sort method and depth-buffer method? CP411 Hidden face removing35

CP411 Hidden face removing36

CP411 Hidden face removing37 6. Area Subdivision Exploits area coherence: Small areas of an image are likely to be covered by only one polygon Three easy cases for determining what’s in front in a given region: 1.a polygon is completely in front of everything else in that region 2.no surfaces project to the region 3.only one surface is completely inside the region, overlaps the region, or surrounds the region

CP411 Hidden face removing38 Warnock’s Area Subdivision Start with whole image If one of the easy cases is satisfied (previous slide), draw what’s in front Otherwise, subdivide the region and recurse If region is single pixel, choose surface with smallest depth

CP411 Hidden face removing39 Warnock’s Algorithm Regions labeled with case used to classify them: 1)One polygon in front 2)Empty 3)One polygon inside, surrounding or intersecting Small regions not labeled Note it’s a rendering algorithm and a HSR algorithm at the same time –Assuming you can draw squares

CP411 Hidden face removing40 Warnock’s Area Subdivision Method Advantages: –No over-rendering –Anti-aliases well - just recurs deeper to get sub-pixel information Disadvantage: –Tests are quite complex and slow

CP411 Hidden face removing41 7. BSP-Trees (Object Precision) Construct a binary space partition tree –Tree gives a rendering order –A list-priority algorithm 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 Trees Having a pre-built BSP tree will allow us to get a correct depth order of polygons in our scene for any point in space. We will build a data structure based on the polygons in the scene, that can be queried with any point input to return an ordering of those polygons.

Structure of a BSP Tree Each internal node has a +half space, a -half space, and a list of objects contained entirely within that plane (if any exist). Each leaf has a list of zero or one objects inside it, and no sub-trees The size of a BSP tree is the total number of objects stored in the leaves & nodes of the tree. This can be larger than the number of objects in our scene because of splitting.

The Big Picture Assume that no objects in our space overlap Use planes to recursively split our object space, keeping a tree structure of these recursive splits.

Choose a Splitting Line Choose a splitting plane, dividing our objects into three sets – those on each side of the plane, and those fully contained on the plane.

Choose More Splitting Lines What do we do when an object (like object 1) is divided by a splitting plane? It is divided into two objects, one on each side of the plane.

Split Recursively Until Done When we reach a convex space containing exactly zero or one objects, that is a leaf node.

Continue

Finished Once the tree is constructed, every root-to- leaf path describes a single convex subspace.

Querying the Tree If an eye point is in the positive/negative half-space of a plane, then everything in the negative/positive half-space is farther away -- so draw it first, using this algorithm recursively Then draw objects on the splitting plane, and recurse into the positive/negative half-space.

What Order Is Generated From This Eye Point? Q5, Q4, Q4’, Q3, Q1’, Q2, Q1

Summary 1.Back-face method 2.Depth sort method 3.Depth-buffer method 4.A-buffer method 5.Scan line method 6.Area-division method 7.BSP-tree method CP411 Hidden face removing53