Project 4: Antialias (Algo)

You can find the handout for this project here. Please skim the handout before your Algo Section!

You may look through the questions below before your section, but we will work through each question together, so make sure to attend section and participate to get full credit!

Please read the project handout before going to algo section and working on these questions!

Background

To prevent aliasing from textures in our scenes, we need to know how much of an object's texture is covered by a single pixel. In other words: if we look through the quadrilateral region of the view plane that corresponds to one pixel, and a textured object is visible, what region of that object's texture map will we see?

That region is itself a quadrilateral in texture space (bottom right of Figure 1), and the overall goal of this algo is to compute the lengths of its sides.

Explanation for using the chain rule for differentiation.
Figure 1: Using the chain rule for differentiation to figure what region of a texture map is covered by a single pixel.

The pixel on the view plane has a (finite) width and height . We can figure out how these map into texture space with a bit of calculus: differentiating through the computations that tell us what point on the object's texture is visible at a point on the image plane, we can use the chain rule for differentiation to figure out how the edge vectors of that pixel-sized rectangle map to the edge vectors of the corresponding quadrilateral in texture space. To first order, taking a step of length in the direction on the view plane moves us across texture space by the vector

and the length of this vector,

is the length of one side of the quadrilateral. We then have to do the same for to get the other side length, using the vector

These are the two red vectors in the bottom right part of Figure 1.

Notice that and are finite quantities (the actual width and height of a pixel), whereas , , etc. are derivatives (rates of change). Multiplying a derivative by a finite step gives (approximately) the finite change that results from that step. To compute the side lengths, we first need to figure out the values of and . Then, we need to figure out the partial derivatives.

In this algo, we'll work through how to compute , , and one of the relevant partial derivatives:

Note that the in and the in are in different coordinate spaces. The first describes a ray, so it lives in world space; the second is a derivative of the texture coordinates, which are defined on the object, so it lives in object space. Before multiplying them (otherwise, it doesn't make sense to), you need to put into object space by multiplying it by the object's inverse CTM, as in the equation above. The lecture slides have the notation for this.

The other partial derivatives can be computed using the same procedure, swapping for and for , as appropriate. Problem 1 walks through the computation of and . Problem 2 walks through (how the intersection point moves as we shift across the pixel). Problem 3 walks through (how texture coordinates move as we shift across the surface). Problem 4 leaves the last link, , for you to assemble yourself.

The Pixel Size: and

Setup: recall that in your raytracer, you have a camera coordinate frame with three basis vectors , , and . You constructed a view plane of width and height that was depth away from the camera along the axis. A point on the view plane can be addressed with coordinates , i.e. any point on the view plane can be expressed as:

The ray direction that passes through this point on the view plane can then be written as:

Illustration of the quantities involved in computing the direction of a ray from the camera.
Figure 2: Illustration of the quantities involved in computing the direction of a ray from the camera through a point on the view plane.

Note that and are finite quantities (actual lengths on the view plane), not derivatives.

Width and Height of a Single Pixel

Compute the width and height of a single pixel on the view plane. Assume that the output image to be rendered has a horizontal resolution of pixels and a vertical resolution of pixels.

Supersampling

Now, let's suppose that you are doing supersampling, i.e. sending more than one ray through each pixel. In this case, we want to figure out how much texture is visible beneath the subregion of the pixel that is covered by each sample. Suppose you are rendering with ray samples per pixel, distributed evenly along each axis.

What are the values of and that correspond to the size of the sub-pixel region covered by one sample?

Hint:

You may assume that is a perfect square, for simplicity.

: The Ray Derivative

Setup: define a ray from the camera into the scene as , where is the normalized ray direction, is the ray origin, and is the distance to the closest intersection. All of the quantities in this problem (, , , , and so on) are in world space.

Note that the lecture slides introduced a version of this derivation that assumed ray directions were unnormalized. In this algo question, you are working through an alternate derivation where ray directions are normalized. Either one can be correct, and you are welcome to implement either in your code, as long as the derivation you use matches what your raytracer does with primary ray directions (i.e. does it normalize them or not?)

Differentiation with Respect to

Differentiate with respect to . Which two terms does the product rule give you?

Expand

First, we need . Since , this is the derivative of a normalized vector.

Expand it with the quotient rule; you may use the fact that Write in terms of and .

Hint:

Simplify until every square root cancels. Your final answer should only involve (no square roots) raised to a power.

Differentiation of the Unnormalized Ray Direction

Now find , i.e. how the unnormalized ray direction changes as changes.

Hint:

You may find the definition of given at the beginning of Problem 1 helpful...

Solving for

Separately, we need . As mentioned in lecture, we can assume that since we're dealing with differential quantities, the differential local neighborhood of an intersection with any surface looks like a plane. Thus, it's fine to say that the intersection point lies on a plane with unit normal at a perpendicular distance , so . Differentiate both sides with respect to , substitute your expression for from 2.1, and solve for .

Note:

Since we're assuming the intersected surface is locally planar, and planes have constant normal vectors, you can assume that the normal does not vary as a function of .

: The Texture Coordinate Derivative

Recall that points on a sphere can be described with spherical coordinates and , and that these relate to the sphere's texture coordinates by:

Texture coordinates are defined on the object itself, so in this problem is a point in object space (not world space as in Problem 2).

Object Space Coordinates

Using and , rewrite and directly in terms of the object-space coordinates .

Building Block Derivatives

We ultimately want and : six partial derivatives in total (with respect to , , and ). Before applying the chain rule, work out these three building-block derivatives: , , and .

Hint:

behaves like for differentiation purposes; treat (the sphere's radius) as a constant.

Putting it All Together

Using the chain rule and your answers to 3.1 and 3.2, compute all six partial derivatives:

Hint:

Think about which of each of and actually depends on. Several of these six should come out to zero.

Those are the texture coordinate derivatives for a sphere. You will need to find the derivatives for your other three primitive objects, which should be easier now that you have done this.

Also note that these are derivatives with respect to the object-space point . To combine them with from Problem 2, which is in world space, you need to multiply by the object's inverse CTM first.

The Last Component:

You now have both links of the chain that don't depend on the texture itself: from Problem 2 (in world space), and (all six partials, i.e. ) from Problem 3 (in object space). You also know how to connect them: multiply by the object's inverse CTM.

The remaining link, , is the derivative of the shading value with respect to texture coordinates. We hope you now have the tools to derive this last piece on your own.

Submission

Algo Sections are graded on attendance and participation, so make sure the TAs know you're there!