Hidden Surface Removal

Similar documents
Scan-Line Fill. Scan-Line Algorithm. Sort by scan line Fill each span vertex order generated by vertex list

INTRODUCTION TO RENDERING TECHNIQUES

A Short Introduction to Computer Graphics

Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

B2.53-R3: COMPUTER GRAPHICS. NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions.

Lezione 4: Grafica 3D*(II)

Computer Graphics. Introduction. Computer graphics. What is computer graphics? Yung-Yu Chuang

3D Scanner using Line Laser. 1. Introduction. 2. Theory

Activity Set 4. Trainer Guide

Realtime 3D Computer Graphics Virtual Reality

Silverlight for Windows Embedded Graphics and Rendering Pipeline 1

Shortest Path Algorithms

Adobe Illustrator CS5 Part 1: Introduction to Illustrator

Triangulation by Ear Clipping

H.Calculating Normal Vectors

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

Lesson 26: Reflection & Mirror Diagrams

MGL Avionics. MapMaker 2. User guide

Interaction. Triangles (Clarification) Choice of Programming Language. Display Lists. The CPU-GPU bus. CSCI 480 Computer Graphics Lecture 3

3D Drawing. Single Point Perspective with Diminishing Spaces

Transformations in the pipeline

x x y y Then, my slope is =. Notice, if we use the slope formula, we ll get the same thing: m =

Consolidated Visualization of Enormous 3D Scan Point Clouds with Scanopy

Reflection and Refraction

3D Drawing. Single Point Perspective with Diminishing Spaces

Fixplot Instruction Manual. (data plotting program)

Solving Systems of Linear Equations Graphing

CS 4204 Computer Graphics

Geometry of Vectors. 1 Cartesian Coordinates. Carlo Tomasi

Cabri Geometry Application User Guide

SolidWorks Implementation Guides. Sketching Concepts

AR-media Player v2.3. INSTALLATION & USER GUIDE (February, 2013) (Windows XP/Vista/7)

Lecture Notes, CEng 477

Photo VR: A System of Rendering High Quality Images for Virtual Environments Using Sphere-like Polyhedral Environment Maps

Digital Photography Composition. Kent Messamore 9/8/2013

Lecture 12: Cameras and Geometry. CAP 5415 Fall 2010

Lesson 10: Video-Out Interface

Tutorial for Tracker and Supporting Software By David Chandler

Rapid Android Development

Image Synthesis. Transparency. computer graphics & visualization

Visualization of 2D Domains

Twelve. Figure 12.1: 3D Curved MPR Viewer Window

3D Viewing. Chapter 7. Projections. 3D clipping. OpenGL viewing functions and clipping planes

Freehand Sketching. Sections

13.4 THE CROSS PRODUCT

Computer Graphics Hardware An Overview

Using Image J to Measure the Brightness of Stars (Written by Do H. Kim)

Bicycle Math. presented to the Math, Computer Science, & Physics Seminar Bard College Annandale-on-Hudson, New York. Timothy E.

Multivariate data visualization using shadow

Making natural looking Volumetric Clouds In Blender 2.48a

Vector Math Computer Graphics Scott D. Anderson

The Theory and Practice of Using a Sine Bar, version 2

Optimizing AAA Games for Mobile Platforms

Introduction to Computer Graphics

5. Tutorial. Starting FlashCut CNC

The GED math test gives you a page of math formulas that

New Features in TerraPhoto. Arttu Soininen Software developer Terrasolid Ltd

Let s explore the content and skills assessed by Heart of Algebra questions.

Algebra Geometry Glossary. 90 angle

The Dennis Technique for SketchUp Models in Photoshop

Largest Fixed-Aspect, Axis-Aligned Rectangle

Charlesworth School Year Group Maths Targets

MassArt Studio Foundation: Visual Language Digital Media Cookbook, Fall 2013

3D Interactive Information Visualization: Guidelines from experience and analysis of applications

5.3 The Cross Product in R 3

Implementation of Canny Edge Detector of color images on CELL/B.E. Architecture.

Math Content by Strand 1

1. The volume of the object below is 186 cm 3. Calculate the Length of x. (a) 3.1 cm (b) 2.5 cm (c) 1.75 cm (d) 1.25 cm

Graphics Pipeline in a Nutshell

Data Storage 3.1. Foundations of Computer Science Cengage Learning

The purposes of this experiment are to test Faraday's Law qualitatively and to test Lenz's Law.

Presents. AccuDraw. Instructor Pam Roberts

Shader Model 3.0. Ashu Rege. NVIDIA Developer Technology Group

Using MATLAB to Measure the Diameter of an Object within an Image

Intersection of a Line and a Convex. Hull of Points Cloud

CS 4620 Practicum Programming Assignment 6 Animation

Grade 8 Mathematics Geometry: Lesson 2

Computer Graphics CS 543 Lecture 12 (Part 1) Curves. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Adding vectors We can do arithmetic with vectors. We ll start with vector addition and related operations. Suppose you have two vectors

Geometry Notes PERIMETER AND AREA

Blender 3D: Noob to Pro/Die Another Way

MULTI-LAYER VISUALIZATION OF MOBILE MAPPING DATA

An Extremely Inexpensive Multisampling Scheme

COMP175: Computer Graphics. Lecture 1 Introduction and Display Technologies

Graphic Design. Background: The part of an artwork that appears to be farthest from the viewer, or in the distance of the scene.

Linear Programming. March 14, 2014

Comp 410/510. Computer Graphics Spring Introduction to Graphics Systems

Direct and Reflected: Understanding the Truth with Y-S 3

Grade 1 Geometric Shapes Conceptual Lessons Unit Outline Type of Knowledge & SBAC Claim Prerequisite Knowledge:

Line and Polygon Clipping. Foley & Van Dam, Chapter 3

3D Viewer. user's manual _2

Year 9 mathematics test

Quick Reference ebook

4BA6 - Topic 4 Dr. Steven Collins. Chap. 5 3D Viewing and Projections

also describes the method used to collect the data for the faces. These techniques could be used to animate other flexible surfaces.

Understand the Sketcher workbench of CATIA V5.

Basic controls of Rhinoceros 3D software

N Q.3 Choose a level of accuracy appropriate to limitations on measurement when reporting quantities.

BALTIC OLYMPIAD IN INFORMATICS Stockholm, April 18-22, 2009 Page 1 of?? ENG rectangle. Rectangle

Transcription:

Hidden Surface Removal Hidden surface removal (HSR) determines which polygons are nearest to the viewer at a given pixel Key criterion: a point P occludes a point Q (and thus Q is hidden ) if P and Q lie on the same ray (line) from the camera or eye and P is between the camera location and Q Calculating this ray is tough with a frustum, but normalizing that frustum to a cube (which the projection matrix does) transforms the oblique rays to straightforward parallelism with the z axis Q P Q P!! Thus, at the earliest, HSR happens after the projection matrix is applied explaining the separation between the projection and viewport transformations!

Backface Culling An excellent preprocessing step to speed up hidden surface removal is backface culling or backface removal Backface culling checks the normal vector of every surface that we are rendering and throws away any surface whose vector points away from us (the viewer) This is easier (and faster) than it may seem (see below) This killer combination of speed and reduction is what makes backface culling work so well as an initial pass at hidden surface removal Here s the algorithm: Note how a polygon is front-facing if the angle! between its normal and the vector toward the camera/viewer is between 90 and 90 degrees. In other words, this means: cos!! 0 Recall from our study of vectors that cos! = (u v) / u v. So, given e is the vector toward the camera and n is the normal vector, cos!! 0 is the same as saying: e n! 0 e (camera/eye) n (normal) But, if we perform this calculation after transforming to normalized device coordinates (our 2! 2! 2 cube), e is merely < 0, 0, 1, 0"> in homogeneous coordinates Thus, backface culling is a matter of checking if the z component of n is greater than or equal to zero after NDC transformation!!

If everything we are only rendering a single, convex polyhedron, then backface culling is equivalent to HSR Backface culling is a straightforward switch in OpenGL turn it on or off using GL_CULL_FACE Backface Culling == HSR When Backface culling " HSR if a polyhedron is not convex, or if there is more than one polyhedron involved: HSR Algorithms A number of HSR algorithms have been defined over the years that s what we re describing today While there is no absolute best algorithm, there is a current prevailing winner due to the way it fits the cost/performance ratio of today s technology The algorithms trade off on the following: Memory required Accuracy vs. speed Effect of increasing scene complexity on performance Hardware capabilities/limitations

Depth Sorting By Newell, Newell, & Sancha, 1972 Paint each polygon in the scene in order, from the most distant to the nearest A painter s algorithm that naturally performs HSR by progressively painting over the farthest polygons Two primary steps: Sort the polygons in occlusion-compatible order that is, a sequence P1, P2, P3,, Pn such that for any polygon Pi, 1 # i # n, Pi hides (occludes) polygons Pi + 1 to Pn Scan convert (paint) each polygon from Pn down to P1 It s all in the sorting! Useful preprocess: decompose polygons into triangles to simplify depth comparisons (tesselation) because of polygons arranged like A polygon sort algorithm would be: Determine a maximum z for each polygon P Sort the polygons according to this maximum z For each polygon, make sure that all of the polygons that are behind it according to maximum z are indeed hidden we need to do this because sometimes maximum z doesn t imply occlusion: P P' maximum z Note how P s maximum z is greater than P' s but it is actually P that is occluding P' camera/viewer

Overlap Testing for Depth Sort The catch in this algorithm is indeed in the overlap testing component how do we do this accurately and quickly? There are 5 cases to test if any one of them succeeds, then we can leave the polygons in their current maximum z-based order Otherwise, maximum z did not correspond to occlusion, so we swap the polygons involved 1. Minimax depth test: Minimum z of one polygon is less than the maximum z of the other polygon 2. Minimax x y test: Polygons do not overlap in the x and y directions 3. Behind-plane test: All vertices of one polygon are behind the plane defined by the other polygon (derive plane equation to do this) 4. In-front-of-plane test: All vertices of one polygon are in front of the plane defined by the other polygon (plane equation again) 5. Full overlap test: Check for overlap in either the x or y directions and determine the respective z values at the overlapping area

Warnock Algorithm Takes advantage of area coherence: divide the display area into successively smaller rectangles until the entire rectangle can be filled with a single color Warnock Pseudocode algorithm dowarnock(x1, y1, x2, y2) { if rectangle is a pixel then { if no polygons map to this pixel then { set pixel to background color } else { set pixel to the color of the polygon closest to this pixel } end if } else { if no polygons overlap this rectangle then { set rectangle to background color } else if polygon(s) completely overlap this rectangle then { set rectangle to the color of the closest of these polygons } else { dowarnock(x1, y1, (x1 + x2) / 2, (y1 + y2) / 2) dowarnock(x1, (y1 + y2) / 2, (x1 + x2) / 2, y2) dowarnock((x1 + x2) / 2, y1, x2, (y1 + y2) / 2) dowarnock((x1 + x2) / 2, (y1 + y2) / 2, x2, y1 } end if } end if }

Scan-Line Algorithm a.k.a. scan coherence algorithm not to be confused with z-buffer on one scan line (we ll talk about z-buffer next) Display-oriented: instead of traversing the list of polygons, we go through the display s pixels and figure out which polygon is on the current pixel Most efficient algorithm prior to lower-cost memory and specialized graphics hardware Also benefits from sorted surfaces and tesselation Traverse the display device one scan line at a time, leftto-right, top-to-bottom Check polygon list to see which ones intersect the current pixel Once we are in a polygon, we know that we will stay in it until we hit another one of that polygon s edges (this is the core of scan coherence ) When in polygons > 1, perform a depth check, and paint the color of the polygon that wins that check no polygons: use background color 1 polygon: use that polygon!s color > 1 polygon: use depth test winner!s color

Incremental z Calculation Two observations/assumptions: Polygons are flat i.e., they lie on a plane As we traverse a polygon one scan line at a time, the z coordinate at that pixel changes at a constant rate (since the polygon is flat) Thus, we can have incremental calculation of the current z coordinate, which is faster than calculating it analytically from the current x and y coordinates (another use of the coherence concept) Calculate the slope of the polygon upon entry (based on the plane s equation Ax + By + Cz + D = 0 note how <A, B, C, D> is the normal vector, expressed in homogeneous coordinates) Calculate the initial value of z i at the entry point: zi = ( Axi Byi D) / C Since we are scanning along the x-axis, going from the entry point to the next is just +1 to the x coordinate: z i+1 = ( A(x i + 1) By i D) / C = ( Ax i By i D A) / C z i+1 = z i (A / C) A / C is constant per polygon so, calculating the next z is a single addition!

Z-Buffer Algorithm Very general and powerful technique works for all polygon and occlusion cases (including cyclical) The trick maintain a separate, parallel buffer for the depths (z coordinates) of the closest polygon at that pixel (thus, the synonymous depth buffer moniker) red blue red brown black white green red red black white green red brown black blue blue blue blue blue green white red red brown frame buffer display device 0.5 0.8 0.5 0.2 1.0 0.35 0.44 0.5 0.5 1.0 0.35 0.44 0.5 0.2 1.0 0.8 0.8 0.8 0.8 0.8 0.44 0.35 0.5 0.5 0.2 z or depth buffer Z-Buffer Pseudocode clear frame buffer viewport to background color clear depth buffer zbuffer to 1.0 for each polygon P for each pixel (x ndc, y ndc ) to which P projects if z ndc < zbuffer[x ndc, y ndc ] then endif endfor endfor zbuffer[x ndc, y ndc ] := z ndc viewport[x ndc, y ndc ] := color of P at (x ndc, y ndc ) Note how the initial value of the depth buffer is 1.0 because in NDC, that is the maximum z value We use the coordinates after the viewport transform (i.e., conversion of 1 1 to width and height)

Z-Buffer Implementation Notes Because z-buffer also calculates the z per polygon per scan line, we can use the same incremental z calculation optimization as the scan-line algorithm Note that z-buffer uses significantly more memory than the other algorithms it needs a buffer with the same width/height as the viewport! Actual memory used would be width! height! sizeof(real) These days, sizeof(real) is around 4 to 8 bytes bigger than a typical RGB pixel Thus, a z-buffer implementation immediately requires at least thrice the desired display resolution: 2 swappable buffers for animation, and a third buffer for depth See why it s easy to outgrow video memory now? OpenGL Uses Z-Buffer Preprocess polygons with backface culling, then use z- buffer (if enabled): glenable(gl_depth_test); // --- Activates depth buffer HSR. Depth buffer management corresponds to frame buffer management it is allocated at the same time: glutinitdisplaymode(...... GLUT_DEPTH); // --- Initializes depth buffer. and also reset along with the frame buffer glclear(...... GL_DEPTH_BUFFER_BIT); // --- Sets depth buffer to 1.0.

HSR Algorithm Comparison Sutherland, Sproull, and Schumaker, ACM Computing Surveys, March 1974 (yes, 1974) Number of Faces/Polygons Algorithm 100 2500 60000 Depth Sort 1 10 507 Scan-Line 5 21 100 Warnock 11 64 307 z-buffer 54 54 54 T I M E HSR Algorithm Conclusions Depth sort is quickest for a small number of polygons, but slows down significantly as polygon count increases Scan-line and Warnock performance also depends on polygon count, but they don t degrade as quickly z-buffer is virtually independent of the number of polygons; more polygons means smaller regions to test (since the frame buffer s size is fixed), so the total number of calculations tends to even out Final conclusion: the main drawback of z-buffer is memory use, but that s cheap today, so z-buffer wins