Lecture 2 - The Big Picture (literally)

Reminders

Real-Time Interactive Comp. Graphics Applications

Goal: My program draws something to the screen, and my program can possibly animate it. The user should be able to interact with the program.

This is a big goal! So we'll break it up. Our first goal is rasterization, making a rasterizer (project 1). This will be about drawing a single static picture. The code outline is:

Starting the Rasterizer

We are given an obj file, full of indexed face sets (see Lecture 1 - Syllabus and Starting Graphics). Recall that:

Don't worry about the details. Just note that our projection will be setting all z's to 0 (which is orthographic projection). This implies we are just looking down the z axis.

World space is a place where our artists can build their worlds. Notice though that:

So the big thing you have to do here is: make a transformation from our 3D space of R3 to 2D limited-width version of R2,window.

Note

Since our pixel space will have to, eventually, cut off items in our world space. In a similar way, us as programmers can cut off items themselves in the world space.

Conflicts in Seeing the Items

Notice that, if we see two items, we need to consider the order that we render objects. We won't solve this yet, but keep it in mind.

Rasterizer Overview (How to Build)

Thus, for our P1 rasterizer, we need to:

  1. Read in our obj file to get vertices in world coordinates.
  2. Convert the world to pixel coordinates (will set boundaries in the world based on window size)
  3. Do a depth test to only write the 's in the front
  4. We only have the vertices colored in! So color the bounding triangle (ie: rasterize the triangle) and decide which pixels to color in.

The big question is 4. How do we decide the pixel to color in?

Line Rasterization

One of the early algorithms was line rasterization. Notice that there's 3 lines per triangle. You've seen the equation as y=mx+b. But this is a crappy line equation. A better one to use is the parametric line equation:

x=(1t)x0+tx1y=(1t)y0+ty1

Note that usually t[0,1], which is good. We can subdivide our line into some number of chunks n, and then consider t{0,1/n,2/n,...,n/n}.

If t>1 or t<0, you get the points that are on the direction of the line, but just outside of the edge in question (either past or front of the line).

Consider the barycentric coordinates:

v=αva+βvb+γvc

where γ=1αβ.

This seems confusing, but look at this worksheet:

IMG_3064.jpeg
The idea here is that if α,β,γ=13, we get the center of the triangle. If two are 1/2 and the other is 0, we get the midpoint of one of the edges. Here, if α,β,γ are randomly generated, we can get a bunch of random points in the triangle.

But what if we go backwards? Given a pixel coordinate, can we solve for α,β,γ? If so, we can tell if we're in the triangle (none are negative).

Therefore: the idea here is:

We can use these as well to color the pixels based on the colors of our triangle's vertices, and then use αva+βvb+γvc for each color to color the new pixel with that color.

More on Barycentric Coordinate Intuition

The way to think about this is that the areas of the triangles opposite to the point in question are the proporitions of α,β,γ:

So then:

α=Area of subArea of whole =AaAβ=AbAγ=AcA

Recall from Linear Analysis I that, if you have two edges e1,e2 that make up two of the 's edges, we can get the area of one triangle bounded by the two points (and the origin) via:

12||e1×e2||

Know that the determinant is needed here:

|e1xe2xe1ye2y|=e1xe2ye2xe1y

So the process is:

Ab=|xvcxvaxvcxyvcyvayvcyxvaxvcx |

So: