General Hidden Surface Removal Algorithms. Binghamton University. EngiNet. Thomas J. Watson. School of Engineering and Applied Science CS 460/560

Similar documents
Introduction to 3D Graphics with OpenGL. Z-Buffer Hidden Surface Removal. Binghamton University. EngiNet. Thomas J. Watson

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

Photorealism CS 460/560. Shadows Ray Tracing Texture Mapping Radiosity. Computer Graphics. Binghamton University. EngiNet. Thomas J.

Visible Surface Detection Methods

Pipeline Operations. CS 4620 Lecture 10

8. Hidden Surface Elimination

Photorealism. Photorealism: Ray Tracing. Ray Tracing

9. Illumination and Shading

CS 488. More Shading and Illumination. Luc RENAMBOT

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

CS 130 Exam I. Fall 2015

CS5620 Intro to Computer Graphics

Scan Converting Text. Attributes of Output Primitives. CS 460/560 Computer Graphics. Binghamton University. EngiNet. Thomas J.

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

Text in OpenGL and Windows. Computer Graphics Attributes. Computer Graphics. Binghamton University. EngiNet. Thomas J. Watson

Graphics for VEs. Ruth Aylett

Graphics for VEs. Ruth Aylett

CS 130 Exam I. Fall 2015

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

Photorealism. Ray Tracing Texture Mapping Radiosity

Werner Purgathofer

Binghamton University. EngiNet. Thomas J. Watson. School of Engineering and Applied Science. Computer Graphics. State University of New York.

CMSC 435 Introductory Computer Graphics Pipeline. Announcements

Illumination Models & Shading

Hidden surface removal. Computer Graphics

Visualisatie BMT. Rendering. Arjan Kok

Rasterization. MIT EECS Frédo Durand and Barb Cutler. MIT EECS 6.837, Cutler and Durand 1

Homework #2. Shading, Ray Tracing, and Texture Mapping

4.5 VISIBLE SURFACE DETECTION METHODES

8. Hidden Surface Elimination

Computer Graphics. Bing-Yu Chen National Taiwan University

CMSC427: Computer Graphics Lecture Notes Last update: November 21, 2014

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

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

CEng 477 Introduction to Computer Graphics Fall 2007

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

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

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

The Traditional Graphics Pipeline

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

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

Computer Vision Systems. Viewing Systems Projections Illuminations Rendering Culling and Clipping Implementations

9. Visible-Surface Detection Methods

Computer Graphics II

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

Institutionen för systemteknik

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

Painter s HSR Algorithm

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

Shading Techniques Denbigh Starkey

Hidden Surface Removal

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

Incremental Form. Idea. More efficient if we look at d k, the value of the decision variable at x = k

Polygon Filling. Can write frame buffer one word at time rather than one bit. 2/3/2000 CS 4/57101 Lecture 6 1

Computer Graphics: 8-Hidden Surface Removal

Computer Graphics. Shadows

CS 325 Computer Graphics

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

CS4620/5620: Lecture 14 Pipeline

Topic #1: Rasterization (Scan Conversion)

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Illumination and Shading

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

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

Scan Conversion. Drawing Lines Drawing Circles

Rendering. Basic Math Review. Rasterizing Lines and Polygons Hidden Surface Remove Multi-pass Rendering with Accumulation Buffers.

Pipeline Operations. CS 4620 Lecture 14

Hidden-Surface Removal.

CS475m - Computer Graphics. Lecture 1 : Rasterization Basics

CS 464 Review. Review of Computer Graphics for Final Exam

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

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Clipping. Concepts, Algorithms for line clipping. 1 of 16. Andries van Dam. Clipping - 10/12/17

surface: reflectance transparency, opacity, translucency orientation illumination: location intensity wavelength point-source, diffuse source

Rasterizing triangles

Rasterization and Graphics Hardware. Not just about fancy 3D! Rendering/Rasterization. The simplest case: Points. When do we care?

CEng 477 Introduction to Computer Graphics Fall

w Foley, Section16.1 Reading

Dithering and Rendering. CS116B Chris Pollett Apr 18, 2004.

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

Introduction to Visualization and Computer Graphics

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

Shading. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller/Fuhrmann

CPSC 314 LIGHTING AND SHADING

Computer Graphics 7 - Rasterisation

Lighting/Shading III. Week 7, Wed Mar 3

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

Local Illumination. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Final projects. Rasterization. The Graphics Pipeline. Illumination (Shading) (Lighting) Viewing Transformation. Rest of semester. This week, with TAs

Computer Science 426 Midterm 3/11/04, 1:30PM-2:50PM

Midterm Exam Fundamentals of Computer Graphics (COMP 557) Thurs. Feb. 19, 2015 Professor Michael Langer

Visible-Surface Detection 1. 2IV60 Computer graphics set 11: Hidden Surfaces. Visible-Surface Detection 3. Visible-Surface Detection 2

Principles of Computer Graphics. Lecture 3 1

Visibility: Z Buffering

Hidden Surfaces II. Week 9, Mon Mar 15

Transcription:

Binghamton University EngiNet State University of New York EngiNet Thomas J. Watson School of Engineering and Applied Science WARNING All rights reserved. No Part of this video lecture series may be reproduced in any form or by any electronic or mechanical means, including the use of information storage and retrieval systems, without written approval from the copyright owner. 2007 The Research Foundation of the State University of New York CS 460/560 Computer Graphics Professor Richard Eckert April 25, 2007 General Hidden Surface Removal Algorithms Z-Buffer Depth Sort 1

Hidden Surface Removal Determination of surfaces not visible to the viewer Many different techniques Back face culling, for single objects only Z-Buffer Depth Sort Z-Buffer Hidden Surface Removal Algorithm Basic Idea: At a given pixel we want to plot color of closest surface that projects to that pixel We re looking for minimum zv Use a buffer (array) parallel to the frame buffer Store minimum values of zv One for every pixel Called the Z-Buffer Z-Buffer Technique Applied to a Polygon Mesh Initialize Z-Buffer and Frame Buffer Look at each polygon Look at each point (xs,ys) projected to by the polygon Compute zv of the point on the polygon If zv is closer than value stored at [x,y] in Z-Buffer Replace value in Z-Buffer with zv Update corresponding element in frame buffer with color of the polygon Z-Buffer Algorithm Applied to Convex Polygons Data Structures: For each polygon Polygon color Polygon vertex coordinates: xs, ys, and zv Note mixed coordinates Edge table (xmin, ymin, zmin, xmax, ymax, zmax) Active edge list (AEL) with active edges intersected by current scanline sorted on xs (See scanline polygon fill notes) Other Data Structures Frame Buffer FBuf[x][y] Will store the color of each pixel (x,y) Z-Buffer ZBuf[x][y] Will store the zv distance of point on closest polygon that projects to pixel (x,y) on screen Initialize each element of FBuf[][] to background color Initialize each element of ZBuf[][] to infinity (largest possible value) 2

The Algorithm For each polygon For each scanline y spanning the polygon Get left & right active edges from AEL Get x,z coordinates of endpoints from edge table Compute scanline/edge intersection pts (xl,zl,xr,zr ) (Use x-y & z-y interpolation) For (x=xl toxr) Compute z by z-x interpol. If (z < ZBuf [x,y]) ZBuf [x,y] = z FBuf [x,y] = polygon color Double Interpolation We know (from Edge Table): lower/upper vertices of left active edge: (x0,y0,z0) and (x1,y1,z1) lower/upper vertices of right active edge: (x2,y2,z2) and (x3,y3,z3) We also know y of current scanline x-y Interpolation: Find x coords of intersection pts (xl,xr) Left Edge: xl-x0 y -y0 ------- = ------- x1-x0 y1-y0 Solving for xl: xl = (x1-x0)*(y-y0)/(y1-y0) + x0 Similarly for xron right edge: xr = (x3-x2)*(y-y2)/(y3-y2) + x2 z-y Interpolation Find z coordinates of intersection points of scan line (y) with left and right edges Done the same way as x-y interpolation x coordinates replaced by z coordinates Results: zl = (z1-z0)*(y-y0)/(y1-y0) + z0 zr = (z3-z2)*(y-y2)/(y3-y2) + z2 z-x Interpolation Find z value on polygon at pixel x on current scanline (y) Interpolate between the left and right edge intersection points: z-zl x-xl -------- = -------- zr-zl xr-xl Solving for z: z = (zr-zl)*(x-xl)/(xr-xl) + zl Speeding up the Algorithm Do interpolations incrementally Get new values from old values by adding correct increments xl,xr,zl,zr (in the outer loop) z (in the inner loop) Avoids multiplications and divisions inside algorithm loops 3

Z-Buffer Performance Outer loop repeats for each polygon Complex scenes have more polygons So complex scenes should be slower But:-- More polygons usually means smaller polygons So inner loops (y and x) are faster For most real scenes, performance is approximately independent of scene complexity Disadvantage of Z-Buffer Memory requirements Z-Buffer is at least as big as the frame buffer For best results, need floating point or doubles for z values Example 1000 X 1000 resolution screen Assume 8 bytes to store a double 8 Megabytes required for Z-Buffer But memory has become cheap Z-Buffer used very commonly now Often implemented in hardware Depth Sort Hidden Surface Removal (Newell, Newell, & Sanchez) Depth Sort Hidden Surface Removal Algorithm Basic Idea Order polygons according to how far away they are from the observer Then paint them into the picture, farthest first, closest last (Painter s Algorithm) So: Farthest surfaces are entered into frame buffer first, nearest last Means far surfaces are painted over by near surfaces Details of Depth Sort 1. Remove back faces (preprocessing) 2. Decompose remaining polygons into triangles (preprocessing) Depth determination easiest for triangles 3. Sort triangles in depth order 4. Apply Painter s algorithm to display sorted triangles farthest first, closest last 3. Sorting in Depth Order For each triangle: Create a linked list containing pointers to all triangles in front of it And a counter of all triangles in back of it 4

4. Applying Painter s Algorithm Repeat: Index through triangles & draw any whose counter is 0 (those that have no triangles behind them farthest away) Decrement counter of all triangles in list of drawn triangle (# in back has been reduced by 1) Mark counter of drawn triangle as finished -- Don t want to draw it again Example Details of Depth Sort Initialize all triangle counters to 0 For i = 1 to n-1 For j = i+1 to n If triangles i and j OVERLAP If triangle j is IN FRONT of triangle i Add triangle j to i s list ctr[j]++ Else Add triangle i to j s list ctr[i]++ [If no overlap, all ctrs=0, so all triangles painted] Determination of OVERLAP 1. Mini-max test: look at enclosing rectangles If rectangles don t overlap, triangles don t Easy test for no overlap: xmax1<xmin2 or xmax2<xmin1 or ymax1<ymin2 or ymax2<ymin1 But if rectangles overlap, triangles may not 5

So check for intersections between edge pairs x = x1 + (x2-x1)t y = y1 + (y2-y1)t x = x3 + (x4-x3)s y = y3 + (y4-y3)s Solve for s,t 0<=s<=1 and 0<=t<=1 ==> they intersect which means triangles overlap But one triangle could be contained in the other Test for containment D & A must be on SAME SIDE of BC Same for E and F Repeat for AB C with D, E, F And for AC B with D, E, F SAME SIDE Test Point (x,y) Line (x1,y1) to (x2,y2) If Point lies on Line: (y-y1)/(x-x1) = (y2-y1)/(x2-x1) Define f(x,y)=(x-x1)(y2-y1)-(y-y1)(x2-x1) f(x,y) = 0 ==> Point lies on line f(x,y) < 0 ==> Point lies on one side f(x,y) > 0 ==> Point lies on other side Determination of IN FRONT 1. Mini-max test If all vertex zv s of triangle i < all vertex zv s of triangle j: then triangle i is in front of triangle j zv(i),max < zv(j),min If Mini-max Test is Inconclusive Find a point with same x,y on projection of overlapping triangles Triangle with smaller z is in front Here triangle i is in front of triangle j Special Problem Cases Interpenetrating triangles Cyclicly overlapping triangles Decompose triangles into smaller ones 6

Disadvantage of Depth Sort Performance depends on number of polygons More polygons, slower Not good for complex scenes Illumination, Reflection, Shading The Phong Model Illumination, Reflection, Shading Need to display surfaces in natural colors Colors observed if we really saw the scene How do they get those colors? Observed Colors Depend on: Light sources in scene Material properties of object surfaces How light interacts with those surfaces Reflection, Transmission, Absorption Need an Illumination/Reflection model Light Sources Approximate with two types: 1. Ambient (non-directional, diffuse, background light) Take as a constant Non-directional Grossly approximates multiply -reflected light Global reflection 2. Light Sources Approximate with a series of point sources Directional Interaction of Light with Surfaces Absorption Transmission Reflection Diffuse Nondirectional Dull, chalky surfaces No highlights Specular Directional Mirror-like surfaces Highlights Material Properties Incident light is reflected to different degrees Depends on physical (material) properties of reflecting surface This gives intrinsic color to materials Approximate by giving 3 diffuse reflection coefficients Fractions of red, green blue reflected kr, kg, kb (0 <= k <= 1) 0 means no reflection in that color band 1 means 100% reflection in that band 7

Phong Illumination/Reflection Model Assume all illumination comes from: Ambient Light Point sources Diffuse reflection of Ambient light Reflection from Point sources: Some is reflected diffusely Some is reflected specularly Reflection of Ambient Light I = k d *I a I = intensity of ambient light reflected k d = ambient reflection coefficient Actually 3 values of k d : kr, kg, kb (So this is really three equations) I a = Intensity of ambient light in scene Ia, kr, kg, kb are adjustable parameters FinalPhong Model Result (Single Light Source) Three color intensity equations: I(r,g,b) = Ambient + Point Diffuse + Point Specular I(r,g,b) =kd(r,g,b)*ia (ambient) + Ip*kd(r,g,b)*(N. L) (diffuse from point source) + Ip*ks*(R. V) n (specular from pt. Source) It can be shown that R = 2*(N. L)N - L where N and L are unit vectors Note that specular term has no color dependency (First approximation) If viewer moves, specular term must be recomputed 8