MIT EECS Frédo Durand and Barb Cutler

Slides:



Advertisements
Similar presentations
Real-Time Rendering 靜宜大學資工研究所 蔡奇偉副教授 2010©.
Advertisements

CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Graphics Pipeline.
3D Graphics Rendering and Terrain Modeling
Graphics Graphics Korea University cgvr.korea.ac.kr 1 Hidden Surface Removal 고려대학교 컴퓨터 그래픽스 연구실.
Part I: Basics of Computer Graphics
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
CS 4731: Computer Graphics Lecture 18: Hidden Surface Removal Emmanuel Agu.
Computer Graphics Hardware Acceleration for Embedded Level Systems Brian Murray
CS6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003 Object-Order vs. Screen-Order Rendering April 24, 2003.
Clipping & Scan Conversion
IN4151 Introduction 3D graphics 1 Introduction 3D Computer Graphics part 1 Projective display Viewing pipeline Graphics hardware Image-based rendering.
Global Illumination May 7, Global Effects translucent surface shadow multiple reflection.
Game Engine Design ITCS 4010/5010 Spring 2006 Kalpathi Subramanian Department of Computer Science UNC Charlotte.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
Part I: Basics of Computer Graphics Rendering Polygonal Objects (Read Chapter 1 of Advanced Animation and Rendering Techniques) Chapter
CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Other Rendering Techniques Types of rendering – Wireframe techniques – Scan-line conversion – Reyes.
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
Polygon Scan Conversion and Z-Buffering
Computer Graphics Panos Trahanias ΗΥ358 Spring 2009.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
MIT EECS 6.837, Durand and Cutler Graphics Pipeline: Projective Transformations.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 14 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 14 Going-through.
CSC418 Computer Graphics n BSP tree n Z-Buffer n A-buffer n Scanline.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
COMPUTER GRAPHICS CSCI 375. What do I need to know?  Familiarity with  Trigonometry  Analytic geometry  Linear algebra  Data structures  OOP.
Shadows. Shadows is important in scenes, consolidating spatial relationships “Geometric shadows”: the shape of an area in shadow Early days, just pasted.
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,
Programming 3D Applications CE Displaying Computer Graphics Week 3 Lecture 5 Bob Hobbs Faculty of Computing, Engineering and Technology Staffordshire.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
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.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
Binary Space Partitioning Trees Ray Casting Depth Buffering
Hidden Surface Removal
CS559: Computer Graphics Lecture 9: Rasterization Li Zhang Spring 2008.
Implementation II.
Computer Graphics Zhen Jiang West Chester University.
MIT EECS 6.837, Cutler and Durand 1 Rasterization MIT EECS Frédo Durand and Barb Cutler.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Visible Surface Determination (VSD) To render or not to render, that is the question… 1 of.
MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Projective Transformations.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Graphic pipeline  Scan-conversion algorithm (high level)  Pixels.
1 Angel: Interactive Computer Graphics5E © Addison- Wesley 2009 Image Formation Fundamental imaging notions Fundamental imaging notions Physical basis.
Rendering Pipeline Fall, D Polygon Rendering Many applications use rendering of 3D polygons with direct illumination.
CS559: Computer Graphics Final Review Li Zhang Spring 2010.
Computer Graphics I, Fall 2010 Implementation II.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Line Clipping & Line Rasterization.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Models and Architectures 靜宜大學 資訊工程系 蔡奇偉 副教授 2012.
MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Clipping & Line Rasterization.
Visible Surface Detection
Rendering Pipeline Fall, 2015.
- Introduction - Graphics Pipeline
Computer Graphics Implementation II
Week 2 - Friday CS361.
3D Graphics Rendering PPT By Ricardo Veguilla.
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Lecture 13 Clipping & Scan Conversion
CS5500 Computer Graphics May 29, 2006
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
Presentation transcript:

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

MIT EECS 6.837, Cutler and Durand Final projects Rest of semester Weekly meetings with TAs Office hours on appointment This week, with TAs Refine timeline Define high-level architecture Project should be a whole, but subparts should be identified with regular merging of code MIT EECS 6.837, Cutler and Durand

The Graphics Pipeline Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display MIT EECS 6.837, Cutler and Durand

Modeling Transformations 3D models defined in their own coordinate system (object space) Modeling transforms orient the models within a common coordinate frame (world space) Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Object space World space Visibility / Display MIT EECS 6.837, Cutler and Durand

Illumination (Shading) (Lighting) Modeling Transformations Vertices lit (shaded) according to material properties, surface properties (normal) and light sources Local lighting model (Diffuse, Ambient, Phong, etc.) Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display MIT EECS 6.837, Cutler and Durand

Viewing Transformation Modeling Transformations Maps world space to eye space Viewing position is transformed to origin & direction is oriented along some axis (usually z) Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Eye space Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display World space MIT EECS 6.837, Cutler and Durand

Clipping Transform to Normalized Device Coordinates (NDC) Modeling Transformations Transform to Normalized Device Coordinates (NDC) Portions of the object outside the view volume (view frustum) are removed Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Eye space NDC Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display MIT EECS 6.837, Cutler and Durand

Projection Modeling Transformations The objects are projected to the 2D image place (screen space) Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping NDC Screen Space Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display MIT EECS 6.837, Cutler and Durand

Scan Conversion (Rasterization) Modeling Transformations Rasterizes objects into pixels Interpolate values as we go (color, depth, etc.) Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display MIT EECS 6.837, Cutler and Durand

Visibility / Display Modeling Transformations Each pixel remembers the closest object (depth buffer) Almost every step in the graphics pipeline involves a change of coordinate system. Transformations are central to understanding 3D computer graphics. Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Today Polygon scan conversion smart back to brute force Visibility MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand 2D Scan Conversion Geometric primitive 2D: point, line, polygon, circle... 3D: point, line, polyhedron, sphere... Primitives are continuous; screen is discrete MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand 2D Scan Conversion Solution: compute discrete approximation Scan Conversion: algorithms for efficient generation of the samples comprising this approximation MIT EECS 6.837, Cutler and Durand

Brute force solution for triangles ? MIT EECS 6.837, Cutler and Durand

Brute force solution for triangles For each pixel Compute line equations at pixel center “clip” against the triangle Problem? MIT EECS 6.837, Cutler and Durand

Brute force solution for triangles For each pixel Compute line equations at pixel center “clip” against the triangle Problem? If the triangle is small, a lot of useless computation MIT EECS 6.837, Cutler and Durand

Brute force solution for triangles Improvement: Compute only for the screen bounding box of the triangle How do we get such a bounding box? MIT EECS 6.837, Cutler and Durand

Brute force solution for triangles Improvement: Compute only for the screen bounding box of the triangle Xmin, Xmax, Ymin, Ymax of the triangle vertices MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Can we do better? Kind of! We compute the line equation for many useless pixels What could we do? MIT EECS 6.837, Cutler and Durand

Use line rasterization Compute the boundary pixels Shirley page 55 MIT EECS 6.837, Cutler and Durand

Scan-line Rasterization Compute the boundary pixels Fill the spans Shirley page 55 MIT EECS 6.837, Cutler and Durand

Scan-line Rasterization Requires some initial setup to prepare Shirley page 55 MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Clipping problem How do we clip parts outside window? MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Clipping problem How do we clip parts outside window? Create two triangles or more. Quite annoying. MIT EECS 6.837, Cutler and Durand

Old style graphics hardware Triangles were big Bresenham+interpolation is worth it Annoying clipping step + a couple of other things have changed Not that good to parallelize beyond triangle granularity MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Questions? MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Today Polygon scan conversion smart back to brute force Visibility MIT EECS 6.837, Cutler and Durand

For modern graphics cards Triangles are usually very small Setup cost are becoming more troublesome Clipping is annoying Brute force is tractable MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Modern rasterization For every triangle ComputeProjection Compute bbox, clip bbox to screen limits For all pixels in bbox Compute line equations If all line equations>0 //pixel [x,y] in triangle Framebuffer[x,y]=triangleColor MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Modern rasterization For every triangle ComputeProjection Compute bbox, clip bbox to screen limits For all pixels in bbox Compute line equations If all line equations>0 //pixel [x,y] in triangle Framebuffer[x,y]=triangleColor Note that Bbox clipping is trivial MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Can we do better? For every triangle ComputeProjection Compute bbox, clip bbox to screen limits For all pixels in bbox Compute line equations If all line equations>0 //pixel [x,y] in triangle Framebuffer[x,y]=triangleColor MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Can we do better? For every triangle ComputeProjection Compute bbox, clip bbox to screen limits For all pixels in bbox Compute line equations ax+by+c If all line equations>0 //pixel [x,y] in triangle Framebuffer[x,y]=triangleColor We don’t need to recompute line equation from scratch MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Can we do better? For every triangle ComputeProjection Compute bbox, clip bbox to screen limits Setup line eq compute aidx, bidy for the 3 lines Initialize line eq, values for bbox corner Li=aix0+biy+ci For all scanline y in bbox For 3 lines, update Li For all x in bbox Increment line equations: Li+=adx If all Li>0 //pixel [x,y] in triangle Framebuffer[x,y]=triangleColor We save one multiplication per pixel MIT EECS 6.837, Cutler and Durand

The Graphics Pipeline Modern hardware mostly avoids clipping Modeling Transformations Modern hardware mostly avoids clipping Only with respect to plane z=0 Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display MIT EECS 6.837, Cutler and Durand

"clip" geometry to view frustum Full Clipping "clip" geometry to view frustum z axis (eyex, eyey, eyez) image plane MIT EECS 6.837, Cutler and Durand

"clip" geometry to near plane One-plane clipping "clip" geometry to near plane z axis (eyex, eyey, eyez) image plane MIT EECS 6.837, Cutler and Durand

Adding Gouraud shading Interpolate colors of the 3 vertices Linear interpolation MIT EECS 6.837, Cutler and Durand

Adding Gouraud shading Interpolate colors of the 3 vertices Linear interpolation, e.g. for R channel: R=aRx+bRy+cR Such that R[x0,y0]=R0; R[x1, y1]=R1; R[x2,y2]=R2 Same as a plane equation in (x,y,R) MIT EECS 6.837, Cutler and Durand

Adding Gouraud shading Interpolate colors For every triangle ComputeProjection Compute bbox, clip bbox to screen limits Setup line eq Setup color equation For all pixels in bbox Increment line equations Increment color equation If all Li>0 //pixel [x,y] in triangle Framebuffer[x,y]=interpolatedColor MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand In the modern hardware Edge eq. in homogeneous coordinates [x, y, w] Tiles to add a mid-level granularity early rejection of tiles Memory access coherence MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Ref Henry Fuchs, Jack Goldfeather, Jeff Hultquist, Susan Spach, John Austin, Frederick Brooks, Jr., John Eyles and John Poulton, “Fast Spheres, Shadows, Textures, Transparencies, and Image Enhancements in Pixel-Planes”, Proceedings of SIGGRAPH ‘85 (San Francisco, CA, July 22–26, 1985). In Computer Graphics, v19n3 (July 1985), ACM SIGGRAPH, New York, NY, 1985. Juan Pineda, “A Parallel Algorithm for Polygon Rasterization”, Proceedings of SIGGRAPH ‘88 (Atlanta, GA, August 1–5, 1988). In Computer Graphics, v22n4 (August 1988), ACM SIGGRAPH, New York, NY, 1988. Figure 7: Image from the spinning teapot performance test. Triangle Scan Conversion using 2D Homogeneous Coordinates, Marc Olano Trey Greer http://www.cs.unc.edu/~olano/papers/2dh-tri/2dh-tri.pdf MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Take-home message The appropriate algorithm depends on Balance between various resources (CPU, memory, bandwidth) The input (size of triangles, etc.) Smart algorithms often have initial preprocess Assess whether it is worth it To save time, identify redundant computation Put outside the loop and interpolate if needed MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Questions? MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Today Polygon scan conversion smart back to brute force Visibility MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Visibility How do we know which parts are visible/in front? MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Ray Casting Maintain intersection with closest object MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Painter’s algorithm Draw back-to-front How do we sort objects? Can we always sort objects? 5 7 3 4 6 2 1 MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Painter’s algorithm A Draw back-to-front How do we sort objects? Can we always sort objects? No, there can be cycles Requires to split polygons B MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Painter’s algorithm Old solution for hidden-surface removal Good because ordering is useful for other operations (transparency, antialiasing) But Ordering is tough Cycles Must be done by CPU Hardly used now But some sort of partial ordering is sometimes useful Usuall front-to-back To make sure foreground is rendered first MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand visibility In ray casting, use intersection with closest t Now we have swapped the loops (pixel, object) How do we do? MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Z buffer In addition to frame buffer (R, G, B) Store distance to camera (z-buffer) Pixel is updated only if new z is closer than z-buffer value MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Z-buffer pseudo code For every triangle Compute Projection, color at vertices Setup line equations Compute bbox, clip bbox to screen limits For all pixels in bbox Increment line equations Compute curentZ Increment currentColor If all line equations>0 //pixel [x,y] in triangle If currentZ<zBuffer[x,y] //pixel is visible Framebuffer[x,y]=currentColor zBuffer[x,y]=currentZ MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Works for hard cases! MIT EECS 6.837, Cutler and Durand

What exactly do we store Floating point distance Can we interpolate z in screen space? i.e. does z vary linearly in screen space? MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Z interpolation X’=x/z Hyperbolic variation Z cannot be linearly interpolated MIT EECS 6.837, Cutler and Durand

Simple Perspective Projection Project all points along the z axis to the z = d plane, eyepoint at the origin homogenize x * d / z y * d / z d 1 x y z z / d 1 1 1 1/d x y z 1 = = MIT EECS 6.837, Cutler and Durand

Yet another Perspective Projection Change the z component Compute d/z Can be linearly interpolated homogenize x * d / z y * d / z d/z 1 x y 1 z / d 1 1 1/d 1 x y z 1 = = MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Advantages of 1/z Can be interpolated linearly in screen space Puts more precision for close objects Useful when using integers more precision where perceptible MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Integer z-buffer Use 1/z to have more precision in the foreground Set a near and far plane 1/z values linearly encoded between 1/near and 1/far Careful, test direction is reversed MIT EECS 6.837, Cutler and Durand

Integer Z-buffer pseudo code For every triangle Compute Projection, color at vertices Setup line equations, depth equation Compute bbox, clip bbox to screen limits For all pixels in bbox Increment line equations Increment curent_1ovZ Increment currentColor If all line equations>0 //pixel [x,y] in triangle If current_1ovZ>1ovzBuffer[x,y]//pixel is visible Framebuffer[x,y]=currentColor 1ovzBuffer[x,y]=current1ovZ MIT EECS 6.837, Cutler and Durand

Gouraud interpolation Gouraud: interpolate color linearly in screen space Is it correct? [R0, G0, B0] [R1, G1, B1] MIT EECS 6.837, Cutler and Durand

Gouraud interpolation Gouraud: interpolate color linearly in screen space Not correct. We should use hyperbolic interpolation But quite costly (division) [R0, G0, B0] [R1, G1, B1] MIT EECS 6.837, Cutler and Durand

MIT EECS 6.837, Cutler and Durand Next time Clipping Segment intersection & scanline algorithms MIT EECS 6.837, Cutler and Durand