Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.

Similar documents
Visibility: Z Buffering

Hidden Surfaces II. Week 9, Mon Mar 15

University of British Columbia CPSC 314 Computer Graphics Jan-Apr Tamara Munzner. Hidden Surfaces.

CEng 477 Introduction to Computer Graphics Fall 2007

CSE528 Computer Graphics: Theory, Algorithms, and Applications

CSE328 Fundamentals of Computer Graphics: Concepts, Theory, Algorithms, and Applications

Hidden Surfaces / Depth Test

Hidden surface removal. Computer Graphics

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

Visible-Surface Detection Methods. Chapter? Intro. to Computer Graphics Spring 2008, Y. G. Shin

Identifying those parts of a scene that are visible from a chosen viewing position, and only process (scan convert) those parts

Computer Graphics. Bing-Yu Chen National Taiwan University

Visible Surface Detection. (Chapt. 15 in FVD, Chapt. 13 in Hearn & Baker)

Page 1. Area-Subdivision Algorithms z-buffer Algorithm List Priority Algorithms BSP (Binary Space Partitioning Tree) Scan-line Algorithms

OpenGL refresher. Advanced Computer Graphics 2012

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

Drawing the Visible Objects

CS4620/5620: Lecture 14 Pipeline

Painter s Algorithm: Problems

CSE 167: Introduction to Computer Graphics Lecture #9: Visibility. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

Computer Graphics. Bing-Yu Chen National Taiwan University

Two basic types: image-precision and object-precision. Image-precision For each pixel, determine which object is visable Requires np operations

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

CSE 167: Introduction to Computer Graphics Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

Exercise 1 Introduction to OpenGL

CS Computer Graphics: Hidden Surface Removal

Computer Graphics II

VISIBILITY & CULLING. Don t draw what you can t see. Thomas Larsson, Afshin Ameri DVA338, Spring 2018, MDH

9. Visible-Surface Detection Methods

Computer Graphics. Rendering. by Brian Wyvill University of Calgary. cpsc/enel P 1

Pipeline Operations. CS 4620 Lecture 10

Introduction to Computer Graphics with OpenGL/GLUT

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Lecture 4 of 41. Lab 1a: OpenGL Basics

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Triangle Rasterization

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

Topic #1: Rasterization (Scan Conversion)

Basic Graphics Programming

CSE 167: Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Lecture 2 2D transformations Introduction to OpenGL

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

8. Hidden Surface Elimination

Intro to OpenGL III. Don Fussell Computer Science Department The University of Texas at Austin

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Lecture 4. Viewing, Projection and Viewport Transformations

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

Rasterization Overview

Projection and viewing. Computer Graphics CSE 167 Lecture 4

Pipeline Operations. CS 4620 Lecture 14

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

More Visible Surface Detection. CS116B Chris Pollett Mar. 16, 2005.

CS 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18

University of British Columbia CPSC 314 Computer Graphics May-June Tamara Munzner Sampling, Virtual Trackball, Hidden Surfaces

CSE 167: Introduction to Computer Graphics Lecture #5: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

CS559: Computer Graphics. Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

Spatial Data Structures

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

Spatial Data Structures

Intro to OpenGL II. Don Fussell Computer Science Department The University of Texas at Austin

Visibility and Occlusion Culling

Clipping. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Interaction. CSCI 480 Computer Graphics Lecture 3

CHAPTER 1 Graphics Systems and Models 3

2 Transformations and Homogeneous Coordinates

Hidden Surface Removal

VR-programming tools (procedural) More VRML later in this course! (declarative)

Determination (Penentuan Permukaan Tampak)

Spatial Data Structures and Speed-Up Techniques. Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

Binary Space Partition Trees. Overview. Binary Space Partitioning Trees (Fuchs, Kedem and Naylor `80)

Computer Graphics. Shadows

Graphics and Interaction Rendering pipeline & object modelling

Basic Graphics Programming

Interaction. CSCI 420 Computer Graphics Lecture 3

Hidden Surface Elimination: BSP trees

Computer Graphics: 8-Hidden Surface Removal

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Announcements. Written Assignment2 is out, due March 8 Graded Programming Assignment2 next Tuesday

Interaction Computer Graphics I Lecture 3

Lecture 2. Determinants. Ax = 0. a 11 x 1 + a 12 x a 1n x n = 0 a 21 x 1 + a 22 x a 2n x n = 0

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

Computer graphic -- Programming with OpenGL I

An Interactive Introduction to OpenGL Programming

Lectures OpenGL Introduction

CS452/552; EE465/505. Clipping & Scan Conversion

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

INFOGR Computer Graphics. J. Bikker - April-July Lecture 11: Visibility. Welcome!

Today. CS-184: Computer Graphics. Lecture #10: Clipping and Hidden Surfaces. Clipping. Hidden Surface Removal

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

Precept 2 Aleksey Boyko February 18, 2011

Lecture 3 Advanced Computer Graphics (CS & SE )

Transcription:

Utah School of Computing Spring 13 Class of Algorithms Lecture Set Visible Surface Determination CS56 Computer Graphics From Rich Riesenfeld Spring 13 Object (Model) Space Algorithms Work in the model data space Image Space Algorithms Work in the projected space Most common VSD domain Utah School of Computing Back Face Culling: Object Space v Back Face Culling: Object Space n n n v n n n v Utah School of Computing 3 Utah School of Computing 4 Back Face Culling Test Back Face Culling: Image Space For Object Space look at sign of For Image Space look at sign of v n n n n n Utah School of Computing 5 n Utah School of Computing 6

Utah School of Computing Spring 13 Back Face Culling: Image Space Back Face Culling n n Completes the job for convex polyhedral objects Nonconvex objects need additional processing beyond back face culling Utah School of Computing 7 Utah School of Computing Back Face Culling: Examples Back Face Culling: Examples Utah School of Computing Utah School of Computing Back Face Culling: Examples Back-Face Culling On the surface of a closed manifold, polygons whose normals point away from the camera are always occluded: Utah School of Computing 11 Note: backface culling alone doesn t solve the hidden-surface problem!

Utah School of Computing Spring 13 Back-Face Culling Silhouettes Not rendering backfacing polygons improves performance By how much? Reduces by about half the number of polygons to be considered for each pixel For Object Space vn For Image Space n Utah School of Computing Occlusion Painter s Algortihm For most interesting scenes, some polygons will overlap: How do painter s solve this? 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: Painter s Algortihm How do painter s solve this? Sort the polygons in depth order Draw the polygons back-to-front QED Draw blue, then green, then orange Will this work in the general case?

Utah School of Computing Spring 13 Painter s Algorithm: Problems 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: Now known as analytic visibility algorithms Analytic Visibility Algorithms 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 ) So, for about a decade (late 6s to late 7s) there was intense interest in finding efficient algorithms for hidden surface removal We ll talk about two: Binary Space-Partition (BSP) Trees Warnock s Algorithm Binary Space Partition Trees (17) BSP Trees: Objects BSP tree: organie 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 Notice: nodes are always convex

Utah School of Computing Spring 13 BSP Trees: Objects BSP Trees: Objects BSP Trees: Objects BSP Trees: Objects if (T is a leaf node) renderobject(t) { renderbsp(far); renderbsp(near); }

Utah School of Computing Spring 13

Utah School of Computing Spring 13

Utah School of Computing Spring 13 3D Polygons: BSP Tree Construction Split along the plane containing any polygon Classify all polygons into positive or negative half-space of the plane If a polygon intersects plane, split it into two Recurse down the negative half-space Recurse down the positive half-space

Utah School of Computing Spring 13 Polygons: BSP Tree Traversal Query: given a viewpoint, produce an ordered list of (possibly split) polygons from back to front: BSPnode::Draw(Vec3 viewpt) Classify viewpt: in + or - half-space of node->plane? /* Call that the near half-space */ farchild->draw(viewpt); render node->polygon; /* always on node->plane */ nearchild->draw(viewpt); Intuitively: at each partition, draw the stuff on the farther side, then the polygon on the partition, then the stuff on the nearer side Discussion: BSP Tree Cons 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: Ouch Worst case: can create up to O(n 3 ) objects! Nice demo: BSP Demo http://www.symbolcraft.com/graphics/bsp/ Summary: BSP Trees Pros: Simple, elegant scheme Only writes to framebuffer (i.e., painters algorithm) Once very popular for video games (but getting less so) Widely used in ray-tacing Cons: Computationally intense preprocess stage restricts algorithm to static scenes Worst-case time to construct tree: O(n 3 ) Splitting increases polygon count Again, O(n 3 ) worst case Warnock s Algorithm (16) PIXAR uses a similar scheme 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 Then recursively: Clip objects to viewport If number of objects incident to viewport is ero or one, visibility is trivial Otherwise, subdivide into smaller viewports, distribute primitives among them, and recurse What is the terminating condition? How to determine the correct visible surface in this case? Warnock s Algorithm

Utah School of Computing Spring 13 Warnock s Algorithm Warnock s Algorithm What is the terminating condition? One polygon per cell How to determine the correct visible surface in this case? What is the terminating condition? One polygon per cell How to determine the correct visible surface in this case? Cell = single pixel Warnock s Algorithm The Z-Buffer Algorithm Pros: Very elegant scheme Extends to any primitive type Cons: Hard to embed hierarchical schemes in hardware Complex scenes usually have small polygons and high depth complexity Thus most screen regions come down to the single-pixel case Both BSP trees and Warnock s algorithm were proposed when memory was expensive Example: first 512x512 framebuffer > $5,! Ed Catmull (mid-7s) proposed a radical new approach called -buffering. The big idea: resolve visibility independently at each pixel The Z-Buffer Algorithm The Z-Buffer Algorithm We know how to rasterie polygons into an image discretied into pixels: What happens if multiple primitives occupy the same pixel on the screen? Which is allowed to paint the pixel?

Utah School of Computing Spring 13 The Z-Buffer Algorithm Idea: retain depth (Z in eye coordinates) through projection transform Use canonical viewing volumes Can transform canonical perspective volume into canonical parallel volume with: 1 M 1 1 1 1 min 1 min min n n n f 1 nf -Buffer (Depth Buffer) Conceptually: Sort ( x, y) Sort ( x, y) (max xx xy (min xx xy ) ) Utah School of Computing 62 The Z-Buffer Algorithm Interpolating Z Augment framebuffer with Z-buffer or depth buffer which stores Z value at each pixel At frame beginning initialie all pixel depths to When rasteriing, 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 there Edge equations: Z is just another planar parameter: = (-D - Ax By) / C If walking across scanline by (x) new = (A/C)(x) Look familiar? 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? -2-4 -6 - --12--16-1--22 -Buffer - - - - - - - - - - - - - - - - Spring Utah School of Computing 66

Utah School of Computing Spring 13-2 -4-6 - -Buffer (dup) --12--16-1--22 - - - - - - - - - - - - - - - -Buffer: Render -2-4 -6 - --12--16-1--22 - Spring Utah School of Computing 67 Spring Utah School of Computing 6 - - - - - - - - - - - - - - - - -Buffer: Render -2-4 -6 - --12--16-1--22 - - - - - - - - - - - - - - - - Utah School of Computing 6 -Buffer: Render -2-4 -6 - --12--16-1--22 Utah School of Computing 7 -Buffer: Render -2-4 -6 - --12--16-1--22 -Buffer: Render -2-4 -6 - --12--16-1--22 Utah School of Computing 71 Utah School of Computing 72

Utah School of Computing Spring 13 -Buffer: Render -2-4 -6 - --12--16-1--22 -Buffer: Render -2-4 -6 - --12--16-1--22 Utah School of Computing 73 Utah School of Computing 74 -Buffer: Render -2-4 -6 - --12--16-1--22 -Buffer: Render -2-4 -6 - --12--16-1--22 Utah School of Computing 75 Utah School of Computing 76 1 -Buffer: Render -2-4 -6 - --12--16-1--22 1 Utah School of Computing 77 -Buffer: Render -2-4 -6 - --12--16-1--22 1 Utah School of Computing 7

Utah School of Computing Spring 13 -Buffer: Render -2-4 -6 - --12--16-1--22 -Buffer: Render -2-4 -6 - --12--16-1--22 1 Utah School of Computing 7 1 Utah School of Computing -Buffer: Render -2-4 -6 - --12--16-1--22 -Buffer: Render -2-4 -6 - --12--16-1--22 1 Utah School of Computing 1 1 Utah School of Computing 2 -Buffer: Render -2-4 -6 - --12--16-1--22 -Buffer: Render -2-4 -6 - --12--16-1--22 1 Utah School of Computing 3 1 Utah School of Computing 4

Utah School of Computing Spring 13 -Buffer: Render -2-4 -6 - --12--16-1--22 -Buffer: Render -2-4 -6 - --12--16-1--22 1 Utah School of Computing 5 1 Utah School of Computing 6 -Buffer: Render -2-4 -6 - --12--16-1--22 1 Utah School of Computing 7 -Buffer: Render -2-4 -6 - --12--16-1--22 1 Utah School of Computing -Buffer: Render -2-4 -6 - --12--16-1--22 1 Utah School of Computing -Buffer: Render -2-4 -6 - --12--16-1--22 1 Utah School of Computing

Utah School of Computing Spring 13 -Buffer: Render -2-4 -6 - --12--16-1--22 4 1 Utah School of Computing 1 -Buffer: Render -2-4 -6 - --12--16-1--22 4 6 1 Utah School of Computing 2 -Buffer: Render -2-4 -6 - --12--16-1--22 4 6 7 1 Utah School of Computing 3 -Buffer: Render -2-4 -6 - --12--16-1--22 4 6 7 1 Utah School of Computing 4 -Buffer: Render -2-4 -6 - --12--16-1--22 4 6 7 1 Utah School of Computing 5 -Buffer: Render -2-4 -6 - --12--16-1--22 4 6 7 11 1 Utah School of Computing 6

Utah School of Computing Spring 13 -Buffer: Rendering (done) -2-4 -6 - --12--16-1--22 4 6 7 11 1 Utah School of Computing 7 -Buffer: Result -2-4 -6 - --12--16-1--22 4 6 7 11 1 Utah School of Computing -Buffer: Pros -Buffer: Cons Simple algorithm Easy to implement in hardware Complexity is order N, for polygons No polygon processing order required Easily handles polygon interpenetration Memory intensive Hard to do antialiasing Hard to simulate translucent polygons Precision issues (scintillating, worse with perspective projection) Utah School of Computing Utah School of Computing -Buffer Algorithm Initialie buffer Set background intensity, color <r,g,b> Set depth to max (min) values -Buffer Algorithm As a polygon P is scan converted Calculate depth (x,y) at each pixel (x,y) being processed Compare (x,y) with -Buffer(x,y) Replace -Buffer(x,y) with (x,y) if closer to eye Utah School of Computing 1 Utah School of Computing 2

Utah School of Computing Spring 13 -Buffer Algorithm a-buffer Algorithm Convert all polygons Correct image gets generated when done OpenGL: depth-buffer = -Buffer Generates linked list for each pixel Memory of all contributions allows for proper handling of many advanced techniques Even more memory intensive Widely used for high quality rendering Utah School of Computing 3 Utah School of Computing 4 a-buffer Algorithm: Example Utah School of Computing 5-2 -4-6 - --12--16-1--22 a-buffer - - - - - - - - - - - - - - - - Utah School of Computing 6 12 3 4 5 6 7 12 16 1 22 12 3 4 5 6 7 12 16 1 22 Utah School of Computing 7 Utah School of Computing

Utah School of Computing Spring 13 12 3 4 5 6 7 12 16 1 22 12 3 4 5 6 7 12 16 1 22 Utah School of Computing Utah School of Computing 1 12 3 4 5 6 7 12 16 1 22 Utah School of Computing 111 12 3 4 5 6 7 12 16 1 22 Utah School of Computing 112 12 3 4 5 6 7 12 16 1 22 12 3 4 5 6 7 12 16 1 22 Utah School of Computing 113 Utah School of Computing 1

Utah School of Computing Spring 13 12 3 4 5 6 7 12 16 1 22 12 3 4 5 6 7 12 16 1 22 1 1 Utah School of Computing 1 Utah School of Computing 116 12 3 4 5 6 7 12 16 1 22 12 3 4 5 6 7 12 16 1 22 1 Utah School of Computing 1 Utah School of Computing 11 1 12 3 4 5 6 7 12 16 1 22 12 3 4 5 6 7 12 16 1 22 1 Utah School of Computing 11 1 Utah School of Computing 1

Utah School of Computing Spring 13 12 3 4 5 6 7 12 16 1 22 12 3 4 5 6 7 12 16 1 22 1 Utah School of Computing 121 1 Utah School of Computing 122 12 3 4 5 6 7 12 16 1 22 12 3 4 5 6 7 12 16 1 22 1 1 1 Utah School of Computing 123 1 Utah School of Computing 124 12 3 4 5 6 7 12 16 1 22 1 1 1 12 3 4 5 6 7 12 16 1 22 1 1 1 1 1 Utah School of Computing 125 1 Utah School of Computing 126

Utah School of Computing Spring 13 12 3 4 5 6 7 12 16 1 22 Utah School of Computing 127 1 1 1 1 1 12 3 4 5 6 7 12 16 1 22 Utah School of Computing 12 1 1 1 1 1 12 3 4 5 6 7 12 16 1 22 1 1 1 1 1 Utah School of Computing 12 12 3 4 5 6 7 12 16 1 22 4 Utah School of Computing 13 1 1 1 1 1 12 3 4 5 6 7 12 16 1 22 4 6 1 1 1 1 1 Utah School of Computing 131 12 3 4 5 6 7 12 16 1 22 4 6 1 7 1 1 1 1 Utah School of Computing 132

Utah School of Computing Spring 13 12 3 4 5 6 7 12 16 1 22 4 6 1 7 1 1 1 1 Utah School of Computing 133 12 3 4 5 6 7 12 16 1 22 4 6 1 7 1 1 1 1 Utah School of Computing 134 12 3 4 5 6 7 12 16 1 22 4 6 1 7 1 1 1 11 1 Utah School of Computing 135 ing (done) 12 3 4 5 6 7 12 16 1 22 4 6 1 7 1 1 1 11 1 Utah School of Computing 136 a-buffer: Result 12 3 4 5 6 7 12 16 1 22 4 6 1 7 1 1 1 11 1 Utah School of Computing 137 CPU Display List OpenGL Architecture Polynomial Evaluator Pixel Operations Per Vertex Operations & Primitive Assembly Rasteriation Texture Memory Per Fragment Operations Frame Buffer

Utah School of Computing Spring 13 Depth Buffering and Hidden Surface Removal Depth Buffering Using OpenGL Color Buffer 1 2 4 16 1 2 4 16 Display Depth Buffer Request a depth buffer glutinitdisplaymode( GLUT_RGB GLUT_DOUBLE GLUT_DEPTH ); Enable depth buffering glenable( GL_DEPTH_TEST ); Clear color and depth buffers glclear( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT ); Render scene Swap color buffers An Updated Program Template An Updated Program Template (cont.) void main( int argc, char** argv ) { glutinit( &argc, argv ); glutinitdisplaymode( GLUT_RGB GLUT_DOUBLE GLUT_DEPTH ); glutcreatewindow( Tetrahedron ); init(); glutidlefunc( idle ); glutdisplayfunc( display ); glutmainloop(); } void init( void ) { glclearcolor(.,., 1., 1. ); glenable( GL_DEPTH_TEST ); } void idle( void ) { glutpostredisplay(); } An Updated Program Template (cont.) void drawscene( void ) { GLfloat vertices[] = { }; GLfloat colors[] = { }; glclear( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT ); glbegin( GL_TRIANGLE_STRIP ); /* calls to glcolor*() and glvertex*() */ glend(); glutswapbuffers(); } Lecture Set The End Visible Surface Determination 4