SUMMARY. CS380: Introduction to Computer Graphics Varying Variables Chapter 13. Min H. Kim KAIST School of Computing 18/04/26.

Similar documents
CS 130 Final. Fall 2015

Overview. By end of the week:

SUMMARY. CS380: Introduction to Computer Graphics Projection Chapter 10. Min H. Kim KAIST School of Computing 18/04/12. Smooth Interpolation

CS 130 Exam I. Fall 2015

CS 4204 Computer Graphics

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

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03.

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

Triangle Rasterization

- Rasterization. Geometry. Scan Conversion. Rasterization

Computer Graphics Seminar

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

Drawing Fast The Graphics Pipeline

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

CS 4620 Program 3: Pipeline

CSE328 Fundamentals of Computer Graphics

CS 130 Exam I. Fall 2015

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

CS4620/5620: Lecture 14 Pipeline

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

Shading Triangles. Lecture 37. Robb T. Koether. Hampden-Sydney College. Mon, Nov 30, 2015

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

Viewing and Projection

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

COMP3421. Vector geometry, Clipping

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

window World space (Object space)

6.837 Introduction to Computer Graphics Final Exam Tuesday, December 20, :05-12pm Two hand-written sheet of notes (4 pages) allowed 1 SSD [ /17]

Barycentric Coordinates and Parameterization

Rasterization. COMP 575/770 Spring 2013

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

3.1 Viewing and Projection

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Lecture 4. Viewing, Projection and Viewport Transformations

3D Viewing Episode 2

SUMMARY. CS380: Introduction to Computer Graphics Ray tracing Chapter 20. Min H. Kim KAIST School of Computing 18/05/29. Modeling

Computer Graphics with OpenGL ES (J. Han) Chapter VII Rasterizer

Pipeline Operations. CS 4620 Lecture 14

Viewing and Modeling

Robust Stencil Shadow Volumes. CEDEC 2001 Tokyo, Japan

3D Viewing Episode 2

Advanced Lighting Techniques Due: Monday November 2 at 10pm

Graphics Pipeline 2D Geometric Transformations

1 Affine and Projective Coordinate Notation

Ray-Triangle and Ray-Quadrilateral Intersections in Homogeneous Coordinates

INTRODUCTION TO COMPUTER GRAPHICS. It looks like a matrix Sort of. Viewing III. Projection in Practice. Bin Sheng 10/11/ / 52

The Graphics Pipeline and OpenGL I: Transformations!

E.Order of Operations

Clipping. CSC 7443: Scientific Information Visualization

3D Geometry and Camera Calibration

Homework #1. Displays, Image Processing, Affine Transformations, Hierarchical Modeling

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

COMP3421. Introduction to 3D Graphics

Last week. Machiraju/Zhang/Möller

Institutionen för systemteknik

CS451Real-time Rendering Pipeline

Practical Shadow Mapping

CS 464 Review. Review of Computer Graphics for Final Exam

INTRODUCTION TO COMPUTER GRAPHICS. cs123. It looks like a matrix Sort of. Viewing III. Projection in Practice 1 / 52

COMP 175 COMPUTER GRAPHICS. Ray Casting. COMP 175: Computer Graphics April 26, Erik Anderson 09 Ray Casting

3D Viewing. CS 4620 Lecture 8

GEOMETRIC TRANSFORMATIONS AND VIEWING

Viewing and Projection

Rendering Objects. Need to transform all geometry then

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

CS 4620 Midterm, March 21, 2017

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

CS 325 Computer Graphics

CS464 Oct 3 rd Assignment 3 Due 10/6/2017 Due 10/8/2017 Implementation Outline

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

Rasterization Overview

Texture Mapping. Texture (images) lecture 16. Texture mapping Aliasing (and anti-aliasing) Adding texture improves realism.

lecture 16 Texture mapping Aliasing (and anti-aliasing)

object (say a cube) will be made up of triangles, each with three vertices, each with known object coordinates.

09 - Designing Surfaces. CSCI-GA Computer Graphics - Fall 16 - Daniele Panozzo

Today. Parity. General Polygons? Non-Zero Winding Rule. Winding Numbers. CS559 Lecture 11 Polygons, Transformations

Perspective Projection and Texture Mapping

Homework #1. Displays, Image Processing, Affine Transformations, Hierarchical Modeling

CS 4620 Midterm, October 23, 2018 SOLUTION

MA 323 Geometric Modelling Course Notes: Day 21 Three Dimensional Bezier Curves, Projections and Rational Bezier Curves

N-Views (1) Homographies and Projection

Drawing Fast The Graphics Pipeline

The Graphics Pipeline and OpenGL I: Transformations!

Geometry. Prof. George Wolberg Dept. of Computer Science City College of New York

CS770/870 Fall 2015 Advanced GLSL

Lecture 2. Shaders, GLSL and GPGPU

Ray Tracing Basics I. Computer Graphics as Virtual Photography. camera (captures light) real scene. photo. Photographic print. Photography: processing

Basics of Computational Geometry

Drawing Fast The Graphics Pipeline

CSC 305 The Graphics Pipeline-1

Introduction to Homogeneous coordinates

Lecture 3 Sections 2.2, 4.4. Mon, Aug 31, 2009

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

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

Last week. Machiraju/Zhang/Möller/Fuhrmann

Viewing and Projection

Homogeneous Coordinates and Transformations of the Plane

Homework #2 and #3 Due Friday, October 12 th and Friday, October 19 th

Rasterization. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 16

Transcription:

CS380: Introduction to Computer Graphics Varying Variables Chapter 3 Min H. Kim KAIST School of Computing Rasterization SUMMARY 2

Path from vertex to pixel 3 Clipping coordinates Eye coordinates (projected) à clip coordinates à normalized device coordinates (NDCs) (reminder) Dividing clip coordinates (x c, y c,z c,w c ) by the w c (w c = ) component (the fourth component in the homogeneous coordinates) yields normalized device coordinates (NDCs). x n y n z n w n w n = x c y c z c w c s x 0 c x 0 0 s y c y 0 = f + n 0 0 2 fn f n f n 0 0 0 x e y e z e 4 2

Viewport matrix We need a transform that maps the lower left corner to [ 0.5, 0.5] t and upper right corner to [W 0.5, H 0.5] t The appropriate scale and shift can be done using the viewport matrix: x w y w z w W / 2 0 0 (W ) / 2 = 0 H / 2 0 (H ) / 2 0 0 / 2 / 2 0 0 0 x n y n z n 5 Texture Viewport The abstract domain for textures is not the canonical square, but instead is the unit square. In this case the coordinate transformation matrix is: x w y w = W 0 0 / 2 0 H 0 / 2 0 0 0 x t y t 6 3

Chapter 3 and Appendix B VARYING VARIABLES 7 Interpolation of varying variables In between the vertex and fragment shader, we need to interpolate the values of the varying variables. What is the desired interpolant, and how should we compute it. This is surprisingly subtle. 8 4

Texture mapping 9 Wrong representation of texture When texture coordinates (x t, y t ) are linearly interpolated in window coordinates, an incorrect image results. 0 5

Correct representation of texture How can we interpolate texture coordinates (x t, y t ) properly like this? Motivation: texture coordinates Let us map a square checkerboard image onto a quad We break up the quad and the image each into two triangles. We will associate [x t, y t ] t texture coordinates for each vertex. We desire that in the interior of a triangle, [x t, y t ] t should be determined as the unique interpolant functions over the triangle that are affine in (x o, y o,z o ) 2 6

Motivation: texture coordinates Even steps on the geometry should be even steps in the texture. If we use this interpolation and fetch the texture values, we should get an expected foreshortening effect. 3 Linear interpolation Suppose we simply used linear interpolation on the x t and y t functions on texture. Then, as we move by some fixed 2D vector displacement on the screen, the texture coordinates will be updated by some fixed 2D vector displacement in texture coordinates. In this case, all of the squares of the texture will map to equal size parallelograms. We will get an odd seam where the two triangles meet. 4 7

Affine functions in 2D We say a function v( ) is an affine function in the variables x and y if it is of the form: v(x, y)= ax +by +c for some constants a,b and c This can also be written as: x v = a b c y 5 Affine functions in 2D Also called linear but note the additive constant term. An affine function can be evaluated by plugging in x, y or by incremental evaluation along a line in x, y space. We already saw for example that z n is an affine function of x n, y n and so was a 3D edge function : z n = ax n + by n + c 6 8

Affine/linear interpolation in 2D v i If we are given, the values of v for three (non-collinear) points in the (x, y) 2D plane, say the vertices of a triangle, This determines an affine function v entire plane. x over the x2 v i x3 7 Affine/linear interpolation in 2D In this case, we say that v is the linear interpolant of the values at the three vertices. The process of evaluating the linear interpolant of three vertices is called linear interpolation. v i Given the one can use some simple matrix operations to solve for the constants [a,b,c]. x x2 v i x3 8 9

How do you interpolate values defined at vertices across the entire triangle? D Interpolation How do you interpolate values defined at vertices across the entire triangle? Solve a simpler problem first: x x 2 0

D Interpolation How do you interpolate values defined at vertices across the entire triangle? Solve a simpler problem first: 0 x t x 2 Want to define a value for every t [0,] 0 t D Interpolation How do we come up with this equation? Look at the picture! t

D Interpolation t The further t is from the red point, the more blue we want. D Interpolation t The further t is from the red point, the more blue we want. The further t is from the blue point, the more red we want. 2

D Interpolation t The further t is from the red point, the more blue we want. The further t is from the blue point, the more red we want. Percent blue = (length of blue segment)/(total length) D Interpolation t The further t is from the red point, the more blue we want. The further t is from the blue point, the more red we want. Percent blue = (length of blue segment)/(total length) Percent red = (length of red segment)/(total length) 3

D Interpolation t The further t is from the red point, the more blue we want. The further t is from the blue point, the more red we want. Percent blue = (length of blue segment)/(total length) Percent red = (length of red segment)/(total length) Value at t = (% blue)(value at blue) + (% red)(value at red) D Interpolation x 0 t The further t is from the red point, the more blue we want. The further t is from the blue point, the more red we want. Percent blue = t Percent red = -t Value at t = tx + (-t)x 2 x 2 4

2D Interpolation Now what about triangles? 2D Interpolation Now what about triangles? Just consider the geometry: x x 2 p What s the interpolated value at the point p? x 3 5

2D Interpolation x Last time (in D) we used ratios of lengths. x 2 p t x 3 2D Interpolation Now what about triangles? Just consider the geometry: What about ratios of areas (2D)? p 6

2D Interpolation Now what about triangles? Just consider the geometry: p If we color the areas carefully, the red area (for example) covers more of the triangle as p approaches the red point. 2D Interpolation Just like before: percent red = area of red triangle total area percent green = area of green triangle total area percent blue = area of blue triangle total area p 7

2D Interpolation p Just like before: percent red Value at p: = area of red triangle total area percent green = area of green triangle total area percent blue = area of blue triangle total area (% red)(value at red) + (% green)(value at green) + (% blue)(value at blue) 2D Interpolation Σ λ = i i Why? Look at the picture! x Just like before: percent red = percent green = A A A 2 A = λ = λ 2 barycentric coordinates percent blue = A 3 A = λ 3 x 2 A 3 A p A 2 Value at p: (A x + A x + A x )/A 2 2 3 3 x 3 barycentric interpolation a.k.a. convex combination a.k.a. affine linear extension Now convert this to a bunch of ugly symbols if you want... just don t think about it that way! 8

Affine functions in 3D We say a function v is affine in variable x, y and z if it is of the form: v(x, y,z)= ax +by +cz +d Such a function can be uniquely determined by its values at the four vertices of a tetrahedron sitting in 3D. 37 Triangles in 3D Given a triangle in 3D, suppose we specify the value of a function at its three vertices. There may be many functions that are affine in (x, y,z) that agree with these three values. But all of these functions will agree when restricted to the plane of the triangle in 2D. As such, we can refer to this restricted function over the triangle as the linear interplant of the vertex values. 38 9

Interpolating colors of an object When we associate colors with vertices, it is natural to interpret our desired color field to be the unique interpolating function over the triangle that is affine in the object coordinates, (x o, y o,z o ), not in screen coordinates! During texture mapping, it is natural to interpret each of the texture coordinates, (x t, y t ), as the unique interpolating functions over the triangle that affine in (x o, y o,z o ). 39 Interpolating colors of an object As a rather self referential example, we can even think of each of the three object coordinates of a point on some triangle in 3D as affine functions in (x o, y o,z o ). For example, v(x o, y o,z o )= x o (when a = and b = c = d =0) For this reason, the default semantics of OpenGL is to interpolate all varying variables as functions over triangles that are affine in (x o, y o,z o ). 40 20

Interpolating colors of an object As we will see, this is equivalent to a function being affine over eye coordinates, (x e, y e,z e ), but it is not equivalent to a function being affine over normalized device coordinates, (x n, y n,z n ), or window coordinates. 4 Going down If we have a function v that is affine in (x, y,z) when restricted to a triangle in 3D, Then we can use the fact that the triangle is flat to write v as a function that is affine in only two variables. Idea: write z as an affine function of (x, y) plug this into the affine expression for v. z = ex + fy + g v = ax +by +c(ex + fy + g)+d v = hx +iy + j 42 2

Going sideways Suppose we have some matrix expression of the form: x' x y' y z' w' = M for some 4-by-4 matrix M (where M does not even have to be an affine matrix). Then, just looking at the four rows independently, we see that x', y',z', and w' are all affine functions of (x, y,z). z 43 More sideways If we have a function v which is affine in (x, y,z), then, given the relation of the previous equation, we can see that v is also affine (x', y',z',w'). To see this, note that: v = a b c d v = a b c d x y z x' M y' z' w' x' y' z' w' = M x y z 44 22

More sideways v = e f g h x' y' z' w' So the property of affine-ness is in agreement between object or eye or clip coordinates, and also between normalized and window coordinates. 45 Not sideways The only time we have to be careful is when division is done. For example, given the relation: x' y' z' w' = M x y z vs. x'w' y'w' z'w' w' It will generally not be the case that a function v, which was affine in (x, y,z) will be affine in (x', y',z') or (x', y',z',w'). Our varying variables are not affine in NDC or windows coordinates. = M x y z 46 23

How to evaluate the varying variables Recall x n y n z n = PM Inverting our matrices, this implies that at each point on the triangle, we have the relation: x o y o z o x o y o z o = M P x n y n z n 47 How to evaluate the varying variables Now suppose that v is an affine function of (x o, y o,z o ). We also make use of the obvious fact that the constant function is also affine in (x o, y o,z o ) Thus for some (a,b,c,d), we have x o v a b c d = y o 0 0 0 z o 48 24

How to evaluate the varying variables And therefore: v v = = a b c d 0 0 0 e f g h i j k l x n M y P n w n z n x n w n y n w n z n For some appropriate values e l x o y o z o = M P x n w n y n w n z n 49 How to evaluate the varying variables Now divide both sides by and we get v Conclusion: = v e f g h i j k l and normalized device coordinates. x n y n z n are affine functions of 50 25

How to evaluate the varying variables going sideways we deduce that are affine functions of window coordinates (x. w, y w,z w ) v going down we can conclude: and are both affine function of (x w, y w ). Meaning that we can calculate their values at each pixel, just given their values at the vertices and linear interpolation. The above derivation can now be thrown away. v and 5 VV in OpenGL Now we can see how OpenGL can perform the correct rational linear interpolation to calculate v at each pixel. The vertex shader is run on each vertex, calculating clip coordinates and varying variables for each vertex. Clipping is run on each triangle; this may create new vertices. Linear interpolation in clip coordinates space is run to determine the clip coordinates and varying variable values for each such new vertex. 52 26

VV in OpenGL For each vertex, and for each varying variable v, OpenGL creates an internal variable v. Additionally, for each vertex OpenGL creates one internal variable. w Min H. Kim (KAIST) Foundations of 3D Computer n Graphics, S. Gortler, MIT Press, 202 53 VV in OpenGL For each vertex, division is done to obtain the normalized device coordinates. x n = x c w c, y n = y c w c,z n = z c w c, 54 27

VV in OpenGL For each vertex, the normalized device coordinates are transformed to window coordinates. The [x w, y w ] t coordinates are used to position the triangle on the screen. 55 For every interior pixel of the triangle, linear interpolation is used to obtain the interpolated values of v z. w, (for all v) and z w At each pixel, the interpolated value is used for z-buffering. 56 28

VV in OpenGL At each pixel, and for all varying variables, division is done on the interpolated internal variables to obtain the correct answer: v = v w / n 57 VV in OpenGL The varying variables v is passed into the fragment shader. 58 29