Graphics Pipeline & Rasterization. CS-C3100 Fall 2017 Lehtinen

Similar documents
Fondamenti di Grafica 3D The Rasterization Pipeline.

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

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

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

Last time? Rasterization. Scan Conversion (Rasterization) High-level concepts for Visibility / Display. Today

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

Rasterization Overview

CS451Real-time Rendering Pipeline

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

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

Last Time. Correct Transparent Shadow. Does Ray Tracing Simulate Physics? Does Ray Tracing Simulate Physics? Refraction and the Lifeguard Problem

Pipeline Operations. CS 4620 Lecture 14

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

Computer Graphics Shadow Algorithms

Pipeline Operations. CS 4620 Lecture 10

For Intuition about Scene Lighting. Today. Limitations of Planar Shadows. Cast Shadows on Planar Surfaces. Shadow/View Duality.

Last Time. Why are Shadows Important? Today. Graphics Pipeline. Clipping. Rasterization. Why are Shadows Important?

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

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

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

Shadow Rendering EDA101 Advanced Shading and Rendering

Real-Time Shadows. MIT EECS 6.837, Durand and Cutler

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

Real-Time Shadows. Last Time? Today. Why are Shadows Important? Shadows as a Depth Cue. For Intuition about Scene Lighting

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

CSE328 Fundamentals of Computer Graphics

Last Time. Reading for Today: Graphics Pipeline. Clipping. Rasterization

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

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

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

Triangle Rasterization

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Topic #1: Rasterization (Scan Conversion)

Real-Time Shadows. Last Time? Textures can Alias. Schedule. Questions? Quiz 1: Tuesday October 26 th, in class (1 week from today!

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

Visibility: Z Buffering

Shadows in the graphics pipeline

Real-Time Shadows. Last Time? Schedule. Questions? Today. Why are Shadows Important?

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

RASTERISED RENDERING

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

Game Architecture. 2/19/16: Rasterization

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

CHAPTER 1 Graphics Systems and Models 3

Real-Time Shadows. Computer Graphics. MIT EECS Durand 1

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

Projection and viewing. Computer Graphics CSE 167 Lecture 4

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Visibility and Occlusion Culling

Enhancing Traditional Rasterization Graphics with Ray Tracing. October 2015

Overview. A real-time shadow approach for an Augmented Reality application using shadow volumes. Augmented Reality.

3D Viewing. CS 4620 Lecture 8

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

Practical Shadow Mapping

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

The Graphics Pipeline. Interactive Computer Graphics. The Graphics Pipeline. The Graphics Pipeline. The Graphics Pipeline: Clipping

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Computer Graphics. Shadows

Speeding up your game

Last Time: Acceleration Data Structures for Ray Tracing. Schedule. Today. Shadows & Light Sources. Shadows

Ray Tracing. Computer Graphics CMU /15-662, Fall 2016

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

Models and Architectures

Topics and things to know about them:

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

Hidden surface removal. Computer Graphics

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

Robust Stencil Shadow Volumes. CEDEC 2001 Tokyo, Japan

CS4620/5620: Lecture 14 Pipeline

Culling. Computer Graphics CSE 167 Lecture 12

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

Specialized Acceleration Structures for Ray-Tracing. Warren Hunt

Lecture 4. Viewing, Projection and Viewport Transformations

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

Rendering Algorithms: Real-time indirect illumination. Spring 2010 Matthias Zwicker

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

Werner Purgathofer

Spring 2009 Prof. Hyesoon Kim

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

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

Spring 2011 Prof. Hyesoon Kim

3D Viewing. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 9

Announcements. Submitting Programs Upload source and executable(s) (Windows or Mac) to digital dropbox on Blackboard

6.837 Introduction to Computer Graphics Assignment 5: OpenGL and Solid Textures Due Wednesday October 22, 2003 at 11:59pm

Introduction to Computer Graphics with WebGL

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

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

TSBK03 Screen-Space Ambient Occlusion

CSE 167: Introduction to Computer Graphics Lecture #10: View Frustum Culling

Lecture 17: Shadows. Projects. Why Shadows? Shadows. Using the Shadow Map. Shadow Maps. Proposals due today. I will mail out comments

Computergrafik. Matthias Zwicker. Herbst 2010

Reading. 18. Projections and Z-buffers. Required: Watt, Section , 6.3, 6.6 (esp. intro and subsections 1, 4, and 8 10), Further reading:

The Rasterization Pipeline

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

Transcription:

Graphics Pipeline & Rasterization 1

How Do We Render Interactively? Use graphics hardware, via OpenGL or DirectX OpenGL is multi-platform, DirectX is MS only OpenGL rendering Very basic! Our ray tracer 2

How Do We Render Interactively? Use graphics hardware, via OpenGL or DirectX OpenGL is multi-platform, DirectX is MS only OpenGL rendering Our ray tracer Most global effects available in ray tracing will be sacrificed for speed, but some can be approximated 3

All Is Not Lost Crytek Example: Screen space reflection is possible..... but MUCH more cumbersome than ray tracing 4

Uncharted 4 5

Quantum Break 6

Battlefield 1 by DICE (video) 7

Ray Casting vs. GPUs for Triangles Ray Casting For each pixel (ray) For each triangle Does ray hit triangle? Keep closest hit Scene primitives Pixel raster

Ray Casting vs. GPUs for Triangles Ray Casting For each pixel (ray) For each triangle Does ray hit triangle? Keep closest hit Last time we replaced this with a traversal of a Bounding Volume Hierarchy (BVH) Scene primitives Pixel raster

Ray Casting vs. GPUs for Triangles Ray Casting For each pixel (ray) For each triangle Does ray hit triangle? Keep closest hit GPU For each triangle For each pixel Does triangle cover pixel? Keep closest hit Scene primitives Pixel raster Scene primitives Pixel raster 10

Ray Casting vs. GPUs for Triangles Ray Casting For each pixel (ray) For each triangle Does ray hit triangle? Keep closest hit GPU For each triangle For each pixel Does triangle cover pixel? Keep closest hit Scene primitives Pixel raster It s just a different order of the loops! Scene primitives Pixel raster 11

GPUs do Rasterization The process of taking a triangle and figuring out which pixels it covers is called rasterization GPU For each triangle For each pixel Does triangle cover pixel? Keep closest hit Pixel raster Scene primitives 12

GPUs do Rasterization The process of taking a triangle and figuring out which pixels it covers is called rasterization We ve seen acceleration structures for ray tracing; rasterization is not stupid either We re not actually going to test all pixels for each triangle GPU For each triangle For each pixel Does triangle cover pixel? Keep closest hit Pixel raster Scene primitives 13

Rasterization ( Scan Conversion ) Given a triangle s vertices & extra info for shading, figure out which pixels to "turn on" to render the primitive Compute illumination values to "fill in" the pixels within the primitive At each pixel, keep track of the closest primitive (z-buffer) Only overwrite if triangle being drawn is closer than the previous triangle in that pixel glbegin(gl_triangles) glnormal3f(...) glvertex3f(...) glvertex3f(...) glvertex3f(...) glend(); 14

What are the Main Differences? Ray Casting For each pixel (ray) For each triangle Does ray hit triangle? Keep closest hit Ray-centric GPU For each triangle For each pixel Does triangle cover pixel Keep closest hit Triangle-centric What needs to be stored in memory in each case? 15

What are the Main Differences? Ray Casting For each pixel (ray) For each triangle Does ray hit triangle? Keep closest hit GPU For each triangle For each pixel Does triangle cover pixel Keep closest hit Ray-centric In this basic form, ray tracing needs the entire scene description in memory at once Then, can sample the image completely freely The rasterizer only needs one triangle at a time, plus the entire image and associated depth information for all pixels Triangle-centric 16

Rasterization Advantages Modern scenes are more complicated than images A 1920x1080 frame at 64-bit color and 32-bit depth per pixel is 24MB (not that much) Of course, if we have more than one sample per pixel this gets larger, but e.g. 4x supersampling is still a relatively comfortable ~100MB 4K gets to hundreds of megabytes! Our scenes are routinely larger than this in bytes This wasn t always true... 17

Rasterization Advantages Weiler, Atherton 1977 18

Rasterization Advantages Modern scenes are more complicated than images A 1920x1080 frame (1080p) at 64-bit color and 32-bit depth per pixel is 24MB (not that much) Of course, if we have more than one sample per pixel (later) this gets larger, but e.g. 4x supersampling is still a relatively comfortable ~100MB Our scenes are routinely larger than this This wasn t always true A rasterization-based renderer can stream over the triangles, no need to keep entire dataset around Allows parallelism and optimization of memory systems 19

Rasterization Limitations Restricted to scan-convertible primitives Pretty much: triangles Faceting, shading artifacts This has largely gone away with programmable per-pixel shading, though No unified handling of shadows, reflection, transparency Potential problem of overdraw (high depth complexity) Each pixel touched many times scan conversion flat shading ray tracing scan conversion gouraud shading 20

Ray Casting / Tracing Advantages Generality: can render anything that can be intersected with a ray Easily allows recursion (shadows, reflections, etc.) Disadvantages Harder to implement in hardware (less computation coherence, must fit entire scene in memory, worse memory behavior) Not such a big point any more given general purpose GPUs Was traditionally too slow for interactive applications These are not as true any more as they used to be 21

Questions? Battlefield 4 by DICE (Stockholm) 22

Modern Graphics Pipeline Input Geometric model Triangle vertices, vertex normals, texture coordinates Lighting/material model (shader) Light source positions, colors, intensities, etc. Texture maps, specular/diffuse coefficients, etc. Viewpoint + projection plane You know this, you ve done it! Output Color (+depth) per pixel Colbert & Krivanek 23

Modern Graphics Pipeline Project vertices to 2D (image) Rasterize triangle: find which pixels should be lit Compute per-pixel color Test visibility (Z-buffer), update frame buffer color 24

Modern Graphics Pipeline Project vertices to 2D (image) Rasterize triangle: find which pixels should be lit For each pixel, test 3 edge equations if all pass, draw pixel Compute per-pixel color Test visibility (Z-buffer), update frame buffer color 25

Modern Graphics Pipeline Perform projection of vertices Rasterize triangle: find which pixels should be lit Compute per-pixel color Test visibility, update frame buffer color Store minimum distance to camera for each pixel in Z-buffer ~same as tmin in ray casting! if new_z < zbuffer[x,y] zbuffer[x,y]=new_z framebuffer[x,y]=new_color frame buffer Z buffer 26

Modern Graphics Pipeline For each triangle transform into eye space (perform projection) setup 3 edge equations for each pixel x,y if passes all edge equations compute z if z<zbuffer[x,y] zbuffer[x,y]=z framebuffer[x,y]=shade() Why quotes? We are leaving out programmable stages and parallelism 27

Questions? 28

Modern Graphics Pipeline Project vertices to 2D (image) Rasterize triangle: find which pixels should be lit Compute per-pixel color Test visibility (Z-buffer), update frame buffer 29

Projection Project vertices to 2D (image) Rasterize triangle: find which pixels should be lit Compute per-pixel color Test visibility (Z-buffer), update frame buffer 30

Orthographic vs. Perspective Orthographic Perspective 31

Perspective in 2D Camera at origin, looking along z, 90 degree f.o.v., image plane at z=1 x=-z x=z p=(x,z) z x p =(x/z,1) (0,0) z=1 z=0 32

Perspective in 2D x=-z The projected point in homogeneous coordinates (we just added w=1): x/z p = 1 1 x=z p=(x,z) z x p =(x/z,1) (0,0) z=1 z=0 33

Perspective in 2D x=-z x/z p = 1 1 x=z x z z p=(x,z) Projectively equivalent z x p =(x/z,1) (0,0) z=1 z=0 34

Perspective in 2D We ll just copy z to w, and get the projected point after homogenization! x=-z p x 1 0 0 x z = 0 1 0 z z 0 1 0 1 x=z p=(x,z) z x p =(x/z,1) (0,0) z=1 z=0 35

Extension to 3D Trivial: Just add another dimension y and treat it like x z is the special one, it turns into w Different fields of view and non-square image aspect ratios can be accomplished by simple scaling of the x and y axes. x y z w = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 x y z 1 36

Caveat These projections matrices work perfectly in the sense that you get the proper 2D projections of 3D points. However, since we are flattening the scene onto the z=1 plane, we ve lost all information about the distance to camera. We need the distance for Z buffering, i.e., figuring out what is in front of what! 37

The View Frustum in 2D (In 3D this is a truncated pyramid.) z=far p q z x (0,0) z=1 z=near z=0 38

The View Frustum in 2D We can transform the frustum by a modified projection in a way that makes it a square (cube in 3D) after division by w. z x z /w x /w 39

The View Frustum in 2D We can transform the frustum by a modified projection in a way that makes it a square (cube in 3D) after division by w. z x z /w x /w The final image is obtained by merely dropping the z coordinate after projection (orthogonal projection) 40

The View Frustum in 2D We can transform the frustum by a modified projection in a way that makes it a square (cube in 3D) after division by w. z x z /w x /w The x coordinate does not change w.r.t. the usual flattening projection, i.e., x /w stays the same 41

The Canonical View Volume z = 1 Point of the exercise: This gives screen coordinates and depth values for Z-buffering with unified math Caveat: OpenGL and DirectX define Z differently [0,1] vs. [-1,1] x = -1 x = 1 z = -1 42

OpenGL Form of the Projection x y z = far+near 0 0 w far near 1 0 0 0 0 1 0 0 0 0 1 0 2 far near far near x y z 1 Homogeneous coordinates within canonical view volume Input point in view coordinates Details/more intuition in handout in MyCourses Understanding Projections and Homogenous Coordinates 43

Recap: Projection Perform rotation/translation/other transforms to put viewpoint at origin and view direction along z axis Combine with projection matrix (perspective or orthographic) Homogenization achieves foreshortening Corollary: The entire transform from object space to canonical view volume [-1,1] 3 is a single matrix 44

45

Questions? 46

Modern Graphics Pipeline Project vertices to 2D (image) We now have screen coordinates Rasterize triangle: find which pixels should be lit Compute per-pixel color Test visibility (Z-buffer), update frame buffer 47

2D Scan Conversion Primitives are continuous geometric objects; screen is discrete (pixels) 48

2D Scan Conversion Primitives are continuous geometric objects; screen is discrete (pixels) Rasterization computes a discrete approximation in terms of pixels (how?) 49

Edge Functions The triangle s 3D edges project to line segments in the image (thanks to planar perspective!) Lines map to lines, not curves 50

Edge Functions The triangle s 3D edges project to line segments in the image (thanks to planar perspective) The interior of the triangle is the set of points that is inside all three halfspaces defined by these lines

Edge Functions The triangle s 3D edges project to line segments in the image (thanks to planar perspective) The interior of the triangle is the set of points that is inside all three halfspaces defined by these lines E i (x, y) = a i x + b i y + c i (x, y) within triangle E i (x, y) 0, i =1, 2, 352

Edge Function 1 E 1 (x, y) < 0 E 1 (x, y) > 0 E i (x, y) = a i x + b i y + c i (x, y) within triangle E i (x, y) 0, i =1, 2, 353

Edge Function 2 E 2 (x, y) < 0 E i (x, y) = a i x + b i y + c i (x, y) within triangle E 2 (x, y) > 0 E i (x, y) 0, i =1, 2, 354

Edge Function 3 E 3 (x, y) > 0 E i (x, y) = a i x + b i y + c i (x, y) within triangle E 3 (x, y) < 0 E i (x, y) 0, i =1, 2, 355

Brute Force Rasterizer Compute E1-E3 from projected vertices Called triangle setup, yields ai, bi, ci for i=1,2,3 For each pixel (x, y) Evaluate edge functions at pixel center If all non-negative, pixel is in! Problem? 56

Brute Force Rasterizer Compute E1-E3 from projected vertices ( setup ) For each pixel (x, y) Evaluate edge functions at pixel center If all non-negative, pixel is in! If the triangle is small, lots of useless computation if we really test all pixels 57

Easy Optimization Improvement: Scan over only the pixels that overlap the screen bounding box of the triangle How do we get such a bounding box? Xmin, Xmax, Ymin, Ymax of the projected triangle vertices 58

Rasterization Pseudocode Note: No visibility For every triangle Compute projection for vertices, compute the E i Compute bbox, clip bbox to screen limits For all pixels in bbox Evaluate edge functions E i If all > 0 Framebuffer[x,y ] = trianglecolor Bounding box clipping is easy, just clamp the coordinates to the screen rectangle 59

Questions? 60

Can We Do Better? For every triangle Compute projection for vertices, compute the E i Compute bbox, clip bbox to screen limits For all pixels in bbox Evaluate edge functions a i x + b i y + c i If all > 0 Framebuffer[x,y ] = trianglecolor 61

Can We Do Better? For every triangle Compute projection for vertices, compute the E i Compute bbox, clip bbox to screen limits For all pixels in bbox Evaluate edge functions a i x + b i y + c i If all > 0 Framebuffer[x,y ] = trianglecolor These are linear functions of the pixel coordinates (x,y), i.e., they only change by a constant amount when we step from x to x+1 (resp. y to y+1) 62

Incremental Edge Functions For every triangle ComputeProjection Compute bbox, clip bbox to screen limits For all scanlines y in bbox Evaluate all E i s at (x0,y): E i = a i x0 + b i y + c i For all pixels x in bbox If all E i >0 Framebuffer[x,y ] = trianglecolor Increment line equations: E i += a i We save ~two multiplications and two additions per pixel when the triangle is large 63

Incremental Edge Functions For every triangle ComputeProjection Compute bbox, clip bbox to screen limits For all scanlines y in bbox Evaluate all E i s at (x0,y): E i = a i x0 + b i y + c i For all pixels x in bbox If all E i >0 Framebuffer[x,y ] = trianglecolor Increment line equations: E i += a i We save ~two multiplications and two additions per pixel when the triangle is large Can also zig-zag to avoid reinitialization per scanline, just initialize once at x0, y0 64

Questions? For a really HC piece of rasterizer engineering, see the hierarchical Hilbert curve rasterizer by McCool, Wales and Moule. (Hierarchical? We ll look at that next..) 65

Can We Do Even Better? We compute the line equation for many useless pixels What could we do? 66

Indeed, We Can Be Smarter? 67

Indeed, We Can Be Smarter Hierarchical rasterization! Conservatively test blocks of pixels before going to per-pixel level (can skip large blocks at once) Usually two levels Conservative tests of axis-aligned blocks vs. edge functions are not very hard, thanks to linearity. See Akenine- Möller and Aila, Journal of Graphics Tools 10(3), 2005. 68

Indeed, We Can Be Smarter Hierarchical rasterization! Conservatively test blocks of pixels before going to per-pixel level (can skip large blocks at once) Usually two levels Can also test if an entire block is inside the triangle; then, can skip edge functions tests for all pixels for even further speedups. (Must still test Z, because they might still be occluded.) 69

Further References 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. Marc Olano Trey Greer, Triangle Scan Conversion using 2D Homogeneous Coordinates, Graphics Hardware 97 http://www.cs.unc.edu/~olano/papers/2dh-tri/2dh-tri.pdf Karras, Laine: Software rasterisation on GPUs (wut?) 70

Oldskool Rasterization Compute the boundary pixels using line rasterization 71

Oldskool Rasterization Compute the boundary pixels using line rasterization Fill the spans 72

Oldskool Rasterization Compute the boundary pixels using line rasterization Fill the spans MUCH MORE annoying to implement than edge functions 73

Questions? 74

What if the p z is > eye z? (eye x, eye y, eye z ) z axis + image plane 75

What if the p z is < eye z? Stuff from behind the camera gets projected to the front unless we do something (eye x, eye y, eye z ) z axis + image plane 76

What if the p z = eye z? When w = 0, point projects to infinity (homogenization is division by w ) (eye x, eye y, eye z ) z axis +??? image plane 77

A Solution: Clipping "clip" geometry to view frustum, discard outside parts (eye x, eye y, eye z ) z axis + z=near z=far image plane 78

Clipping Eliminate portions of objects outside the viewing frustum View Frustum boundaries of the image plane projected in 3D a near & far left clipping plane User may define additional clipping planes near right top far bottom 79

z=far Why Clip? Avoid degeneracies Don t draw stuff behind the eye Avoid division by 0 and overflow z=near 80

Related Idea View Frustum Culling Use bounding volumes/hierarchies to test whether any part of an object is within the view frustum Need frustum vs. bounding volume intersection test Crucial to do hierarchically when scene has lots of objects! Early rejection (different from clipping) See e.g. Optimized view frustum culling algorithms for bounding boxes, Ulf Assarsson and Tomas Möller, journal of graphics tools, 2000. 81

Questions? 82

Extra: Homogeneous Rasterization Idea: avoid projection (and division by zero) by performing rasterization in 3D Or equivalently, use 2D homogenous coordinates (w =z after the projection matrix, remember) Motivation: clipping is annoying Marc Olano, Trey Greer: Triangle scan conversion using 2D homogeneous coordinates, Proc. ACM SIGGRAPH/Eurographics Workshop on Graphics Hardware 1997 83

Homogeneous Rasterization 2D rasterization

Homogeneous Rasterization Replace 2D edge equation by 3D plane equation Plane going through 3D edge and viewpoint Still a halfspace, just 3D (in xyw coordinates) w x x y y 2D rasterization 3D (homogenous) rasterization 85

Homogeneous Rasterization Replace 2D edge equation by 3D plane equation Treat pixels as 3D points (x, y, 1) on image plane, test for containment in 3 halfspaces just like edge functions 2D rasterization 3D (homogenous) rasterization 86

Homogeneous Rasterization Given 3D triangle setup plane equations (plane through viewpoint & triangle edge) For each pixel x,y compute plane equations for (x,y,1) if all pass, draw pixel plane equation 2D pixel (x, y, 1) 3D triangle plane equation 87

Homogeneous Rasterization Works for triangles behind eye Still linear, can evaluate incrementally/hierarchically like 2D 2D pixel (x, y, 1) 3D triangle 88

Homogeneous Rasterization Recap Rasterizes with plane tests instead of edge tests Removes the need for clipping! 2D pixel (x, y, 1) 3D triangle 89

Questions? 90

Modern Graphics Pipeline Perform projection of vertices Rasterize triangle: find which pixels should be lit Compute per-pixel color Test visibility, update frame buffer 91

Pixel Shaders Modern graphics hardware enables the execution of rather complex programs, shaders, to compute the color of every single pixel Translucence Backlighting Procedural texture, Anisotropic brdf iridescence 92

That s All For Today! Next time: Screen-space interpolation, visibility, shading 93 Uncharted 2 by Naughty Dog / Sony