CS 445 / 645 Introduction to Computer Graphics Lecture 21 Visibility Visibility.

Slides:



Advertisements
Similar presentations
Visible-Surface Detection(identification)
Advertisements

CSC418 Computer Graphics n Polygon normals n Back Faces n Visibility Algorithms.
Graphics Pipeline.
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.
David Luebke5/11/2015 CS 551 / 645: Introductory Computer Graphics David Luebke
Lecture Fall 2001 Visibility Back-Face Culling Painter’s Algorithm.
CS 551 / 645: Introductory Computer Graphics Visible Surface Determination.
CAP4730: Computational Structures in Computer Graphics Visible Surface Determination.
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.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 Hidden Surface Removal 고려대학교 컴퓨터 그래픽스 연구실.
CS 445 / 645: Introductory Computer Graphics
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.
1 CSCE 441: Computer Graphics Hidden Surface Removal (Cont.) Jinxiang Chai.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Visibility II Week 7,
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Hidden Surfaces II Week.
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.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Visibility Week 9, Fri 31 Oct 2003.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Visibility Week 7, Wed.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Visibility: Z Buffering Week 10, Mon 3 Nov 2003.
10/11/2001CS 638, Fall 2001 Today Kd-trees BSP Trees.
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
Shadows Computer Graphics. Shadows Shadows Extended light sources produce penumbras In real-time, we only use point light sources –Extended light sources.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Clipping II, Hidden Surfaces.
10/29/02 (c) 2002 University of Wisconsin, CS559 Today Hidden Surface Removal Exact Visibility.
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.
Real-Time Rendering SPEEDING UP RENDERING Lecture 04 Marina Gavrilova.
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.
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.
Binary Space Partitioning Trees Ray Casting Depth Buffering
Hidden Surface Removal
Implementation II.
1 Visiblity: Culling and Clipping Computer Graphics COMP 770 (236) Spring 2009 January 21 & 26: 2009.
David Luebke11/26/2015 CS 551 / 645: Introductory Computer Graphics David Luebke
Computer Graphics Zhen Jiang West Chester University.
David Luebke 1 12/8/2015 Visibility CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Visible Surface Determination (VSD) To render or not to render, that is the question… 1 of.
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.
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.
Hidden Surfaces University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner.
Hidden Surfaces / Depth Test University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016 Tamara Munzner.
Lecture 30: Visible Surface Detection
Visible Surface Detection
Visibility Week 9, Fri 31 Oct 2003
CSC418 Computer Graphics Back Faces Visibility Algorithms.
Hidden Surfaces Dr. Scott Schaefer.
CSCE 441: Computer Graphics Hidden Surface Removal
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Visibility: Z Buffering Week 10, Mon 3 Nov 2003
Hidden Surfaces II Week 9, Mon Mar 15
Hidden Surface Removal
Presentation transcript:

CS 445 / 645 Introduction to Computer Graphics Lecture 21 Visibility Visibility

Recap: Rendering Pipeline Modeling transformationsModeling transformations Viewing transformationsViewing transformations Projection transformationsProjection transformations ClippingClipping Scan conversionScan conversion We now know everything about how to draw a polygon on the screen, except visible surface determination Modeling transformationsModeling transformations Viewing transformationsViewing transformations Projection transformationsProjection transformations ClippingClipping Scan conversionScan conversion We now know everything about how to draw a polygon on the screen, except visible surface determination

Invisible Primitives Why might a polygon be invisible? Polygon outside the field of viewPolygon outside the field of view Polygon is backfacingPolygon is backfacing Polygon is occluded by object(s) nearer the viewpointPolygon is occluded by object(s) nearer the viewpoint For efficiency reasons, we want to avoid spending work on polygons outside field of view or backfacing For efficiency and correctness reasons, we need to know when polygons are occluded Why might a polygon be invisible? Polygon outside the field of viewPolygon outside the field of view Polygon is backfacingPolygon is backfacing Polygon is occluded by object(s) nearer the viewpointPolygon is occluded by object(s) nearer the viewpoint For efficiency reasons, we want to avoid spending work on polygons outside field of view or backfacing For efficiency and correctness reasons, we need to know when polygons are occluded

View Frustum Clipping Remove polygons entirely outside frustum Note that this includes polygons “behind” eye (actually behind near plane)Note that this includes polygons “behind” eye (actually behind near plane) Pass through polygons entirely inside frustum Modify remaining polygons to include only portions intersecting view frustum Remove polygons entirely outside frustum Note that this includes polygons “behind” eye (actually behind near plane)Note that this includes polygons “behind” eye (actually behind near plane) Pass through polygons entirely inside frustum Modify remaining polygons to include only portions intersecting view frustum

Back-Face Culling Most objects in scene are typically “solid” More rigorously: closed, orientable manifolds Must not cut through itselfMust not cut through itself Must have two distinct sidesMust have two distinct sides – A sphere is orientable since it has two sides, 'inside' and 'outside'. – A Mobius strip or a Klein bottle is not orientable Cannot “walk” from one side to the otherCannot “walk” from one side to the other –A sphere is a closed manifold whereas a plane is not Most objects in scene are typically “solid” More rigorously: closed, orientable manifolds Must not cut through itselfMust not cut through itself Must have two distinct sidesMust have two distinct sides – A sphere is orientable since it has two sides, 'inside' and 'outside'. – A Mobius strip or a Klein bottle is not orientable Cannot “walk” from one side to the otherCannot “walk” from one side to the other –A sphere is a closed manifold whereas a plane is not

Back-Face Culling Most objects in scene are typically “solid” More rigorously: closed, orientable manifolds Local neighborhood of all points isomorphic to discLocal neighborhood of all points isomorphic to disc Boundary partitions space into interior & exteriorBoundary partitions space into interior & exterior Most objects in scene are typically “solid” More rigorously: closed, orientable manifolds Local neighborhood of all points isomorphic to discLocal neighborhood of all points isomorphic to disc Boundary partitions space into interior & exteriorBoundary partitions space into interior & exterior Yes No

Manifold Examples of manifold objects: SphereSphere TorusTorus Well-formed CAD partWell-formed CAD part Examples of manifold objects: SphereSphere TorusTorus Well-formed CAD partWell-formed CAD part

Back-Face Culling Examples of non-manifold objects: A single polygonA single polygon A terrain or height fieldA terrain or height field polyhedron w/ missing facepolyhedron w/ missing face Anything with cracks or holes in boundaryAnything with cracks or holes in boundary one-polygon thick lampshadeone-polygon thick lampshade Examples of non-manifold objects: A single polygonA single polygon A terrain or height fieldA terrain or height field polyhedron w/ missing facepolyhedron w/ missing face Anything with cracks or holes in boundaryAnything with cracks or holes in boundary one-polygon thick lampshadeone-polygon thick lampshade

Back-Face Culling On the surface of a closed manifold, polygons whose normals point away from the camera are always occluded: Note: backface culling alone doesn’t solve the hidden-surface problem!

Back-Face Culling Not rendering backfacing polygons improves performance By how much?By how much? –Reduces by about half the number of polygons to be considered for each pixel  Every front-facing polygon must have a corresponding rear-facing one Not rendering backfacing polygons improves performance By how much?By how much? –Reduces by about half the number of polygons to be considered for each pixel  Every front-facing polygon must have a corresponding rear-facing one

Occlusion For most interesting scenes, some polygons will overlap: To render the correct image, we need to determine which polygons occlude which For most interesting scenes, some polygons will overlap: To render the correct image, we need to determine which polygons occlude which

Painter’s Algorithm Simple approach: render the polygons from back to front, “painting over” previous polygons: Draw blue, then green, then orangeDraw blue, then green, then orange Will this work in the general case? Simple approach: render the polygons from back to front, “painting over” previous polygons: Draw blue, then green, then orangeDraw blue, then green, then orange Will this work in the general case?

Painter’s Algorithm: Problems Intersecting polygons present a problem Even non-intersecting polygons can form a cycle with no valid visibility order: Intersecting polygons present a problem Even non-intersecting polygons can form a cycle with no valid visibility order:

Analytic Visibility Algorithms Early visibility algorithms computed the set of visible polygon fragments directly, then rendered the fragments to a display:

Analytic Visibility Algorithms What is the minimum worst-case cost of computing the fragments for a scene composed of n polygons? Answer: O(n 2 ) What’s your opinion of O(n 2 )? What is the minimum worst-case cost of computing the fragments for a scene composed of n polygons? Answer: O(n 2 ) What’s your opinion of O(n 2 )?

Analytic Visibility Algorithms So, for about a decade (late 60s to late 70s) there was intense interest in finding efficient algorithms for hidden surface removal We’ll talk about two: Binary Space-Partition (BSP) TreesBinary Space-Partition (BSP) Trees Warnock’s AlgorithmWarnock’s Algorithm So, for about a decade (late 60s to late 70s) there was intense interest in finding efficient algorithms for hidden surface removal We’ll talk about two: Binary Space-Partition (BSP) TreesBinary Space-Partition (BSP) Trees Warnock’s AlgorithmWarnock’s Algorithm

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

BSP Trees: Objects

Rendering BSP Trees renderBSP(BSPtree *T) BSPtree *near, *far; if (eye on left side of T->plane) near = T->left; far = T->right; else near = T->right; far = T->left; renderBSP(far); if (T is a leaf node) renderObject(T) renderBSP(near); renderBSP(near); renderBSP(BSPtree *T) BSPtree *near, *far; if (eye on left side of T->plane) near = T->left; far = T->right; else near = T->right; far = T->left; renderBSP(far); if (T is a leaf node) renderObject(T) renderBSP(near); renderBSP(near);

Rendering BSP Trees

Polygons: BSP Tree Construction Split along the plane defined by any polygon from scene Classify all polygons into positive or negative half-space of the plane If a polygon intersects plane, split polygon into two and classify them bothIf a polygon intersects plane, split polygon into two and classify them both Recurse down the negative half-space Recurse down the positive half-space Split along the plane defined by any polygon from scene Classify all polygons into positive or negative half-space of the plane If a polygon intersects plane, split polygon into two and classify them bothIf a polygon intersects plane, split polygon into two and classify them both Recurse down the negative half-space Recurse down the positive half-space

No bunnies were harmed in my example But what if a splitting plane passes through an object? Split the object; give half to each nodeSplit the object; give half to each node No bunnies were harmed in my example But what if a splitting plane passes through an object? Split the object; give half to each nodeSplit the object; give half to each node Discussion: BSP Tree Cons Ouch

BSP Demo Nice demo: Nice demo:

Summary: BSP Trees Pros: Simple, elegant schemeSimple, elegant scheme Only writes to framebuffer (no reads to see if current polygon is in front of previously rendered polygon, i.e., painters algorithm)Only writes to framebuffer (no reads to see if current polygon is in front of previously rendered polygon, i.e., painters algorithm) –Thus very popular for video games (but getting less so) Cons: Computationally intense preprocess stage restricts algorithm to static scenesComputationally intense preprocess stage restricts algorithm to static scenes Slow time to construct treeSlow time to construct tree Splitting increases polygon countSplitting increases polygon countPros: Simple, elegant schemeSimple, elegant scheme Only writes to framebuffer (no reads to see if current polygon is in front of previously rendered polygon, i.e., painters algorithm)Only writes to framebuffer (no reads to see if current polygon is in front of previously rendered polygon, i.e., painters algorithm) –Thus very popular for video games (but getting less so) Cons: Computationally intense preprocess stage restricts algorithm to static scenesComputationally intense preprocess stage restricts algorithm to static scenes Slow time to construct treeSlow time to construct tree Splitting increases polygon countSplitting increases polygon count

Octrees Frequently used in modern video games A BSP tree subdivides space into a series of half-spaces using single planesA BSP tree subdivides space into a series of half-spaces using single planes An octree subdivides space into eight voxels using three axis-aligned planesAn octree subdivides space into eight voxels using three axis-aligned planes –A voxel is labeled as having polygons inside it or not Frequently used in modern video games A BSP tree subdivides space into a series of half-spaces using single planesA BSP tree subdivides space into a series of half-spaces using single planes An octree subdivides space into eight voxels using three axis-aligned planesAn octree subdivides space into eight voxels using three axis-aligned planes –A voxel is labeled as having polygons inside it or not

Octrees A voxel may have geometry inside it or subdivideA voxel may have geometry inside it or subdivide –Can have as many as eight children Thus we partition 3-D space into 3-D cellsThus we partition 3-D space into 3-D cells Checking visibility with polygons is now faster due to only checking particular cellsChecking visibility with polygons is now faster due to only checking particular cells Quadtrees are a 2-D variantQuadtrees are a 2-D variant A voxel may have geometry inside it or subdivideA voxel may have geometry inside it or subdivide –Can have as many as eight children Thus we partition 3-D space into 3-D cellsThus we partition 3-D space into 3-D cells Checking visibility with polygons is now faster due to only checking particular cellsChecking visibility with polygons is now faster due to only checking particular cells Quadtrees are a 2-D variantQuadtrees are a 2-D variant

Warnock’s Algorithm (1969) Elegant scheme based on a powerful general approach common in graphics: if the situation is too complex, subdivide Start with a root viewport and a list of all primitives (polygons)Start with a root viewport and a list of all primitives (polygons) Then recursively:Then recursively: –Clip objects to viewport –If number of objects incident to viewport is zero or one, visibility is trivial –Otherwise, subdivide into smaller viewports, distribute primitives among them, and recurse Elegant scheme based on a powerful general approach common in graphics: if the situation is too complex, subdivide Start with a root viewport and a list of all primitives (polygons)Start with a root viewport and a list of all primitives (polygons) Then recursively:Then recursively: –Clip objects to viewport –If number of objects incident to viewport is zero or one, visibility is trivial –Otherwise, subdivide into smaller viewports, distribute primitives among them, and recurse

Warnock’s Algorithm What is the terminating condition? How to determine the correct visible surface in this case? What is the terminating condition? How to determine the correct visible surface in this case?

Warnock’s Algorithm Pros: Very elegant schemeVery elegant scheme Extends to any primitive typeExtends to any primitive typeCons: Hard to embed hierarchical schemes in hardwareHard to embed hierarchical schemes in hardware Complex scenes usually have small polygons and high depth complexityComplex scenes usually have small polygons and high depth complexity –Thus most screen regions come down to the single-pixel case Pros: Very elegant schemeVery elegant scheme Extends to any primitive typeExtends to any primitive typeCons: Hard to embed hierarchical schemes in hardwareHard to embed hierarchical schemes in hardware Complex scenes usually have small polygons and high depth complexityComplex scenes usually have small polygons and high depth complexity –Thus most screen regions come down to the single-pixel case

The Z-Buffer Algorithm Both BSP trees and Warnock’s algorithm were proposed when memory was expensive Example: first 512x512 framebuffer > $50,000!Example: first 512x512 framebuffer > $50,000! Ed Catmull (mid-70s) proposed a radical new approach called z-buffering. The big idea: resolve visibility independently at each pixel Both BSP trees and Warnock’s algorithm were proposed when memory was expensive Example: first 512x512 framebuffer > $50,000!Example: first 512x512 framebuffer > $50,000! Ed Catmull (mid-70s) proposed a radical new approach called z-buffering. The big idea: resolve visibility independently at each pixel

The Z-Buffer Algorithm We know how to rasterize polygons into an image discretized into pixels:

The Z-Buffer Algorithm What happens if multiple primitives occupy the same pixel on the screen? Which is allowed to paint the pixel?

The Z-Buffer Algorithm Idea: retain depth (Z in eye coordinates) through projection transform Use canonical viewing volumesUse canonical viewing volumes Each vertex has z coordinate (relative to eye point) intactEach vertex has z coordinate (relative to eye point) intact Idea: retain depth (Z in eye coordinates) through projection transform Use canonical viewing volumesUse canonical viewing volumes Each vertex has z coordinate (relative to eye point) intactEach vertex has z coordinate (relative to eye point) intact

The Z-Buffer Algorithm Augment framebuffer with Z-buffer or depth buffer which stores Z value at each pixel At frame beginning, initialize all pixel depths to At frame beginning, initialize all pixel depths to  When rasterizing, interpolate depth (Z) across polygon and store in pixel of Z-bufferWhen rasterizing, interpolate depth (Z) across polygon and store in pixel of Z-buffer Suppress writing to a pixel if its Z value is more distant than the Z value already stored thereSuppress writing to a pixel if its Z value is more distant than the Z value already stored there Augment framebuffer with Z-buffer or depth buffer which stores Z value at each pixel At frame beginning, initialize all pixel depths to At frame beginning, initialize all pixel depths to  When rasterizing, interpolate depth (Z) across polygon and store in pixel of Z-bufferWhen rasterizing, interpolate depth (Z) across polygon and store in pixel of Z-buffer Suppress writing to a pixel if its Z value is more distant than the Z value already stored thereSuppress writing to a pixel if its Z value is more distant than the Z value already stored there

Interpolating Z Edge equations: Z is just another planar parameter: z = (-D - Ax – By) / C If walking across scanline by (  x) If walking across scanline by (  x) z new = z old – (A/C)(  x) Look familiar?Look familiar? Total cost:Total cost: –1 more parameter to increment in inner loop –3x3 matrix multiply for setup Edge walking: just interpolate Z along edges and across spans Edge equations: Z is just another planar parameter: z = (-D - Ax – By) / C If walking across scanline by (  x) If walking across scanline by (  x) z new = z old – (A/C)(  x) Look familiar?Look familiar? Total cost:Total cost: –1 more parameter to increment in inner loop –3x3 matrix multiply for setup Edge walking: just interpolate Z along edges and across spans

The Z-Buffer Algorithm How much memory does the Z-buffer use? Does the image rendered depend on the drawing order? Does the time to render the image depend on the drawing order? How does Z-buffer load scale with visible polygons? With framebuffer resolution? How much memory does the Z-buffer use? Does the image rendered depend on the drawing order? Does the time to render the image depend on the drawing order? How does Z-buffer load scale with visible polygons? With framebuffer resolution?

Z-Buffer Pros Simple!!! Easy to implement in hardware Polygons can be processed in arbitrary order Easily handles polygon interpenetration Enables deferred shading Rasterize shading parameters (e.g., surface normal) and only shade final visible fragmentsRasterize shading parameters (e.g., surface normal) and only shade final visible fragmentsSimple!!! Easy to implement in hardware Polygons can be processed in arbitrary order Easily handles polygon interpenetration Enables deferred shading Rasterize shading parameters (e.g., surface normal) and only shade final visible fragmentsRasterize shading parameters (e.g., surface normal) and only shade final visible fragments

Z-Buffer Cons Lots of memory (e.g. 1280x1024x32 bits) With 16 bits cannot discern millimeter differences in objects at 1 km distanceWith 16 bits cannot discern millimeter differences in objects at 1 km distance Read-Modify-Write in inner loop requires fast memory Hard to do analytic antialiasing We don’t know which polygon to map pixel back toWe don’t know which polygon to map pixel back to Shared edges are handled inconsistently Ordering dependentOrdering dependent Hard to simulate translucent polygons We throw away color of polygons behind closest oneWe throw away color of polygons behind closest one Lots of memory (e.g. 1280x1024x32 bits) With 16 bits cannot discern millimeter differences in objects at 1 km distanceWith 16 bits cannot discern millimeter differences in objects at 1 km distance Read-Modify-Write in inner loop requires fast memory Hard to do analytic antialiasing We don’t know which polygon to map pixel back toWe don’t know which polygon to map pixel back to Shared edges are handled inconsistently Ordering dependentOrdering dependent Hard to simulate translucent polygons We throw away color of polygons behind closest oneWe throw away color of polygons behind closest one