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

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

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

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

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

Graphics Pipeline & Rasterization. CS-C3100 Fall 2017 Lehtinen

Fondamenti di Grafica 3D The Rasterization Pipeline.

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Pipeline Operations. CS 4620 Lecture 10

Triangle Rasterization

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

CS4620/5620: Lecture 14 Pipeline

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

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

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

Pipeline Operations. CS 4620 Lecture 14

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

Visibility: Z Buffering

Graphics and Interaction Rendering pipeline & object modelling

CS 488. More Shading and Illumination. Luc RENAMBOT

Rasterization Overview

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

Chapter 8: Implementation- Clipping and Rasterization

Ray tracing. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/19/07 1

Topic #1: Rasterization (Scan Conversion)

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

Game Architecture. 2/19/16: Rasterization

CS 130 Exam I. Fall 2015

CHAPTER 1 Graphics Systems and Models 3

MIT EECS 6.837, Teller and Durand 1

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

Rasterizing triangles

CS 130 Final. Fall 2015

- Rasterization. Geometry. Scan Conversion. Rasterization

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Clipping and Scan Conversion

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

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

3D Rasterization II COS 426

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

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Einführung in Visual Computing

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

Graphics Hardware and Display Devices

Hidden Surfaces II. Week 9, Mon Mar 15

Computer Graphics 7 - Rasterisation

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

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

Introduction to Visualization and Computer Graphics

Institutionen för systemteknik

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

CEng 477 Introduction to Computer Graphics Fall 2007

Hidden surface removal. Computer Graphics

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

Shadows in the graphics pipeline

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

Graphics Pipeline. CS535 Fall Daniel G. Aliaga Department of Computer Science Purdue University

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

Computer Graphics 7: Viewing in 3-D

CS Rasterization. Junqiao Zhao 赵君峤

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

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

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

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

QUESTION BANK 10CS65 : COMPUTER GRAPHICS AND VISUALIZATION

Computer Graphics and GPGPU Programming

The Viewing Pipeline Coordinate Systems

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

Computer Graphics. - Rasterization - Philipp Slusallek

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

COMPUTER GRAPHICS COURSE. Rendering Pipelines

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

Deferred Rendering Due: Wednesday November 15 at 10pm

Image-Based Modeling and Rendering. Image-Based Modeling and Rendering. Final projects IBMR. What we have learnt so far. What IBMR is about

CS451Real-time Rendering Pipeline

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

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

Fall CSCI 420: Computer Graphics. 7.1 Rasterization. Hao Li.

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

Realtime 3D Computer Graphics Virtual Reality

Computer Graphics Geometry and Transform

Topics. From vertices to fragments

Advanced Ray Tracing

Computer Graphics. Bing-Yu Chen National Taiwan University

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

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

Computer Graphics Shadow Algorithms

CS 112 The Rendering Pipeline. Slide 1

Intro to Ray-Tracing & Ray-Surface Acceleration

CSE528 Computer Graphics: Theory, Algorithms, and Applications

For each question, indicate whether the statement is true or false by circling T or F, respectively.

COMP371 COMPUTER GRAPHICS

Course Title: Computer Graphics Course no: CSC209

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

8. Hidden Surface Elimination

Transcription:

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

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 2

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 3

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

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

Viewing Transformation Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Maps world space to eye space Viewing position is transformed to origin & direction is oriented along some axis (usually z) z o y x WORLD SPACE FAR -n NEAR o P Image adapted from: Seth Teller u v EYE EYE SPACE Scan Conversion (Rasterization) Visibility / Display MIT EECS 6.837, Cutler and Durand 6

Clipping Modeling Transformations Illumination (Shading) Transform to Normalized Device Coordinates (NDC) Portions of the object outside the view volume (view frustum) are removed Viewing Transformation (Perspective / Orthographic) Clipping z FAR o NEAR x y EYE z x y Projection (to Screen Space) EYE SPACE Image adapted from: Seth Teller NDC Scan Conversion (Rasterization) Visibility / Display MIT EECS 6.837, Cutler and Durand 7

Projection Modeling Transformations The objects are projected to the 2D image place (screen space) Illumination (Shading) x y x y Viewing Transformation (Perspective / Orthographic) z z o Clipping Projection (to Screen Space) Scan Conversion (Rasterization) NDC Image adapted from: Seth Teller SCREEN SPACE Visibility / Display MIT EECS 6.837, Cutler and Durand 8

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

Visibility / Display Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display 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. MIT EECS 6.837, Cutler and Durand 10

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

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 12

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 13

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

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 15

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 16

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 17

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 18

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 19

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

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

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

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

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

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 25

Questions? MIT EECS 6.837, Cutler and Durand 26

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

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 28

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 29

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 30

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 31

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 32

Can we do better? For every triangle ComputeProjection Compute bbox, clip bbox to screen limits Setup line eq compute a i dx, b i dy for the 3 lines Initialize line eq, values for bbox corner L i =a i x0+b i y+c i 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 33

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

Full Clipping "clip" geometry to view frustum (eye x, eye y, eye z ) z axis image plane MIT EECS 6.837, Cutler and Durand 35

One-plane clipping "clip" geometry to near plane (eye x, eye y, eye z ) z axis image plane MIT EECS 6.837, Cutler and Durand 36

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

Adding Gouraud shading Interpolate colors of the 3 vertices Linear interpolation, e.g. for R channel: R=a R x+b R y+c R 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 38

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 39

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 40

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 41

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 42

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

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

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

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

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

Painter s algorithm Old solution for hidden-surface removal But Good because ordering is useful for other operations (transparency, antialiasing) 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 48

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 49

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 50

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 51

Works for hard cases! A C B MIT EECS 6.837, Cutler and Durand 52

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

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

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 1 0 0 0 x y 0 1 0 0 y = z 0 0 1 0 z z / d 0 0 1/d MIT EECS 6.837, Cutler and Durand 55 0 1

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 1 0 0 0 x y 0 1 0 0 y = 1 0 0 0 1 z z / d 0 0 1/d MIT EECS 6.837, Cutler and Durand 56 0 1

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 57

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 far near x MIT EECS 6.837, Cutler and Durand 58

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 59

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

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

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