CS Computer Graphics: Hidden Surface Removal

Similar documents
Painter s HSR Algorithm

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

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

Pipeline Operations. CS 4620 Lecture 10

Recall: Indexing into Cube Map

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

Hidden surface removal. Computer Graphics

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

Hidden Surface Removal

Computer Graphics. Bing-Yu Chen National Taiwan University

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

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

Pipeline Operations. CS 4620 Lecture 14

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

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

CS4620/5620: Lecture 14 Pipeline

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

CS 543: Computer Graphics. Projection

3D Rasterization II COS 426

Rasterization Overview

CEng 477 Introduction to Computer Graphics Fall 2007

Motivation. Culling Don t draw what you can t see! What can t we see? Low-level Culling

CS 543: Computer Graphics. Rasterization

Models and Architectures. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Models and Architectures

CS Computer Graphics: Raster Graphics, Part 3

CS451Real-time Rendering Pipeline

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

Lecture 4. Viewing, Projection and Viewport Transformations

Computer Graphics (CS 543) Lecture 10: Soft Shadows (Maps and Volumes), Normal and Bump Mapping

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

The Traditional Graphics Pipeline

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

The Traditional Graphics Pipeline

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

The Traditional Graphics Pipeline

Introduction to Computer Graphics with WebGL

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

CSE4030 Introduction to Computer Graphics

Topic #1: Rasterization (Scan Conversion)

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

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

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

8. Hidden Surface Elimination

Projection and viewing. Computer Graphics CSE 167 Lecture 4

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

9. Illumination and Shading

CS 543: Computer Graphics Lecture 04 Part III: 3D Modeling: Polygonal Meshes. Emmanuel Agu

Werner Purgathofer

9. Visible-Surface Detection Methods

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

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

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

Visibility: Z Buffering

Illumination and Reflection in OpenGL CS 460/560. Computer Graphics. Shadows. Photo-Realism: Ray Tracing. Binghamton University.

3D Object Representation

Deferred Rendering Due: Wednesday November 15 at 10pm

CS 4731/543: Computer Graphics Lecture 3 (Part III): 3D Modeling: Polygonal Meshes. Emmanuel Agu

Computer Graphics 1. Chapter 7 (June 17th, 2010, 2-4pm): Shading and rendering. LMU München Medieninformatik Andreas Butz Computergraphik 1 SS2010

Hidden Surface Elimination Raytracing. Pre-lecture business. Outline for today. Review Quiz. Image-Space vs. Object-Space

Fondamenti di Grafica 3D The Rasterization Pipeline.

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

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

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

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

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

CS 4620 Program 3: Pipeline

Volume Shadows Tutorial Nuclear / the Lab

Computer Graphics. Shadows

CS 591B Lecture 9: The OpenGL Rendering Pipeline

CS 130 Exam I. Fall 2015

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

Computer Graphics. Lecture 9 Environment mapping, Mirroring

Computer Graphics and Visualization. Graphics Systems and Models

CHAPTER 1 Graphics Systems and Models 3

Illumination & Shading I

CSC 8470 Computer Graphics. What is Computer Graphics?

Shadows in the graphics pipeline

CS488. Visible-Surface Determination. Luc RENAMBOT

Graphics for VEs. Ruth Aylett

Computer Graphics (CS 543) Lecture 9 (Part 2): Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Graphics and Interaction Rendering pipeline & object modelling

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

CS 112 The Rendering Pipeline. Slide 1

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

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Visibility and Occlusion Culling

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Computer Graphics 10 - Shadows

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

Sign up for crits! Announcments

Lecture 8 Ray tracing Part 1: Basic concept Yong-Jin Liu.

Friday, 11 January 13. Object Representation

Transcription:

CS 543 - Computer Graphics: Hidden Surface Removal by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-)

Hidden Surface Removal Drawing polygonal faces on screen consumes CPU cycles We cannot see every surface in scene To save time, draw only surfaces we see Surfaces we cannot see, and their elimination methods Occluded surfaces: hidden surface removal (visibility) Back faces: back face culling Faces outside view volume: viewing frustum culling Object-space techniques Applied before vertices are mapped to pixels Image-space techniques Applied after vertices have been rasterized R.W. Lindeman - WPI Dept. of Computer Science 2

Visibility Hidden Surface Removal A correct rendering requires correct visibility calculations When multiple opaque polygons cover the same screen space, only the closest one is visible (remove the other hidden surfaces) Wrong visibility Correct visibility R.W. Lindeman - WPI Dept. of Computer Science 3

Visibility Hidden Surface Removal (cont.) http://www.worldofescher.com/ R.W. Lindeman - WPI Dept. of Computer Science 4

Visibility Hidden Surface Removal (cont.) R.W. Lindeman - WPI Dept. of Computer Science 5

Visibility Hidden Surface Removal (cont.) Goal Determine which objects are visible to the eye Determine what colors to use to paint the pixels Active area of research Lots of algorithms have been proposed in the past (and is still a hot topic) R.W. Lindeman - WPI Dept. of Computer Science 6

Visibility Hidden Surface Removal (cont.) Where is visibility performed in the graphics pipeline? v1, m1 modeling and viewing Per-vertex lighting projection v2, m2 v3, m3 Rasterization texturing Shading visibility viewport mapping Display interpolate vertex colors clipping Note: Map (x,y) values to screen (draw) and use z value for depth testing R.W. Lindeman - WPI Dept. of Computer Science 7

OpenGL: Image-Space Approach Determine which of the n objects is visible to each pixel on the image plane for( each pixel in the image) { determine the object closest to the pixel draw the pixel using the object's color } R.W. Lindeman - WPI Dept. of Computer Science 8

Image Space Approach Z-buffer Method used in most of graphics hardware (and thus OpenGL) Z-buffer (or depth buffer) algorithm Requires lots of memory Recall After projection transformation, in viewport transformation x,y used to draw screen image, mapped to viewport z component is mapped to pseudo-depth with range [0,1] Objects/polygons are made up of vertices Hence, we know depth z at polygon vertices Point on object seen through pixel may be between vertices Need to interpolate to find z R.W. Lindeman - WPI Dept. of Computer Science 9

Image Space Approach Z-buffer (cont.) Basic Z-buffer idea Rasterize every input polygon For every pixel in the polygon interior, calculate its corresponding z value (by interpolation) Track depth values of closest polygon (smallest z) so far Paint the pixel with the color of the polygon whose z value is the closest to the eye R.W. Lindeman - WPI Dept. of Computer Science 10

Z (Depth) Buffer Algorithm How do we choose the polygon that has the closet Z for a given pixel? Example: eye at Z = 0, farther objects have increasingly positive values, between 0 and 1 1. Initialize (clear) every pixel in the Z buffer to 2. Track polygon Zs 3. As we rasterize polygons, check to see if polygon s Z through this pixel is less than current minimum Z through this pixel 4. Run the following loop: R.W. Lindeman - WPI Dept. of Computer Science 11

Z (Depth) Buffer Algorithm (cont.) foreach polygon in scene { foreach pixel (x,y) inside the polygon projection { if( z_polygon_pixel( x, y ) < z_buffer( x, y )) { z_buffer( x, y ) = z_polygon_pixel( x, y ); color_buffer( x, y ) = polygon color at ( x, y ) } } } Note: We know the depths at the vertices. Interpolate for interior z_polygon_pixel(x, y) depths R.W. Lindeman - WPI Dept. of Computer Science 12

Z-Buffer Example Correct Final image Top View Z = 0.5 Z = 0.3 R.W. Lindeman - WPI Dept. of Computer Science 13 eye

Z-Buffer Example (cont.) Step 1: Initialize the depth buffer eye Z = 0.5 Z = 0.3 R.W. Lindeman - WPI Dept. of Computer Science 14

Z-Buffer Example (cont.) Step 2: Draw the blue polygon, assuming the program draws blue polygon first (the order does not affect the final result anyway) 0.5 0.5 0.5 0.5 eye Z = 0.5 Z = 0.3 R.W. Lindeman - WPI Dept. of Computer Science 15

Z-Buffer Example (cont.) Step 3: Draw the yellow polygon Z-buffer drawback: wastes resources by rendering a face, and then drawing over it 0.5 0.5 0.3 0.3 0.5 0.3 0.3 0.3 0.3 eye Z = 0.5 Z = 0.3 R.W. Lindeman - WPI Dept. of Computer Science 16

Combined Z-buffer and Gouraud Shading // for each scan line for( int y = y bot ; y <= y top ; y++ ) { foreach polygon { find x left and x right find depth left, depth right and depth inc find color left, color right and color inc for( int x = x left, c = color left, d = depth left ; x < x right ; x++, c += color inc, d += depth inc ) { if( d < d[x][y] ) { put c into the pixel at (x, y) // update closest depth y top d[x][y] = d; color 4 } } } y s } y bot x left color 3 color 1 color 2 x right R.W. Lindeman - WPI Dept. of Computer Science 17

Z-Buffer Depth Compression Recall that we chose parameters a and b to map z from range [near, far] to pseudodepth range[0,1] This mapping is almost linear close to the eye, but is nonlinear further from the eye, approaches asymptote Also, limited number of bits Thus, two z values close to far plane may map to same pseudodepth: Errors!! Actual z 1 N apz b! Pz F + N + a =! F! N FN b!! 2 = F! N -1 F -Pz R.W. Lindeman - WPI Dept. of Computer Science 18

OpenGL Hidden-Surface Removal (HSR) Commands Primarily three commands to do HSR Instruct OpenGL to create a depth buffer glutinitdisplaymode(glut_depth GLUT_RGB) Enable depth testing glenable(gl_depth_test) Initialize the depth buffer every time we draw a new picture glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT) R.W. Lindeman - WPI Dept. of Computer Science 19

Back Face Culling Back faces: faces of an opaque object which are "pointing away" from the viewer Back face culling Remove back faces (supported by OpenGL) Back face How can we detect back faces? R.W. Lindeman - WPI Dept. of Computer Science 20

Back Face Culling (cont.) If we find a back face, do not draw Save rendering resources! There must be other forward face(s) closer to eye F is face of object we want to test if back face P is a point on F Form view vector, V as (eye P) N is normal to face F N N V Back face test: F is back face if N.V < 0 R.W. Lindeman - WPI Dept. of Computer Science 21

Back Face Culling: Draw Front Faces of a Mesh void Mesh::drawFrontFaces( void ) { for( int f = 0; f < numfaces; f++ ) { if( isbackface( f,... ) continue; glbegin( GL_POLYGON ); int in = face[f].vert[v].normindex; int iv = face[v].vert[v].vertindex; glnormal3f( norm[in].x, norm[in].y, norm[in].z); glvertex3f( pt[iv].x, pt[iv].y, pt[iv].z ); glend( ); } } Refer to: Case 7.3, p. 375 in Hill R.W. Lindeman - WPI Dept. of Computer Science 22

View-Frustum Culling Remove objects that are outside the viewing frustum Done by 3D clipping algorithm (e.g., Liang-Barsky) R.W. Lindeman - WPI Dept. of Computer Science 23

Ray Tracing Ray tracing is another example of image space method Ray tracing Cast a ray from eye through each pixel to the world Answers the question: What does eye see in direction looking through a given pixel? R.W. Lindeman - WPI Dept. of Computer Science 24

Painter's Algorithm A depth-sorting method Surfaces are sorted in the order of decreasing depth Surfaces are drawn in the sorted order, and overwrite the pixels in the frame buffer Subtle difference from depth buffer approach Entire face drawn Two problems It can be nontrivial to sort the surfaces There can be no solution for the sorting order R.W. Lindeman - WPI Dept. of Computer Science 25

Painter's Algorithm (cont.) R.W. Lindeman - WPI Dept. of Computer Science 26