Project 3: Intersect (Algo)
Cameras
When implementing ray tracing, you will often need to transform points between different coordinate spaces, e.g. between the world and camera spaces.
Remember that a camera's view matrix describes a transformation which takes points from world space to camera space.
Suppose you are given the position, look vector, and up vector of a virtual camera. How would you use this information to compute the camera's view matrix? If you prefer, you may describe what should be computed instead of writing mathematical equations.
Generating Rays
Pixels In Space
Recall that the view plane describes an imaginary 2D plane, perpendicular to the camera's look vector, which is some distance away from the camera. Here's a diagram:
Now, suppose you are given the following information about a specific pixel in an image:
: image width, in pixels : image height, in pixels : our pixel's row index : our pixel's column index : depth of the view plane from the camera position : height view angle : width view angle
Please calculate the 3D point on the view plane, (x, y, z)
, in camera space, which corresponds with this pixel.
For the purpose of this algo, we use
to express the depth of the view plane from camera position. However, this value is arbitrary—in your implementation, feel free to set it to . Why do you think that is the case? (Not an algo question) As always, please assume that the pixel
(0, 0)
corresponds to the top left pixel of the image.
Rays
We would like to shoot a ray from our camera, located at
Please write an expression for this ray in the form
Implicit Shape Primitives
In lecture, we derived implicit equations for spheres and cylinders to perform intersection tests. In this question, you will attempt to do the same with a cone.
Begin by writing out the implicit equations for a cone with the following parameters:
- Radius = 0.5 at the flat base.
- Height = 1
- Origin is halfway along the height of the cone.
You will have to write two implicit equations, one for the conical top and one for the flat base. Each should be of the form
Next, you will solve these implicit equations for their intersection points with some arbitrary ray
Please find the values of
Example of Boundary Checking:
solves for the flat base, but it is not a valid solution.
Your final answer might be pretty long. Feel free to use sub-expressions!
Transforming Object Normals
In the first part of the ray project, you will need to compute the lighting equation using the world space normal at the intersection point. From the previous question you may notice we have only computed the object space postion and normal. Thus we are going to have to transform the intersection data from object space to world space.
For positions, you already know how to do this (think back to lab 4!). However, transforming normals is not as simple as multiplying by the model matrix.
Write down the equation for the world space normal vector,
: the normal vector in object-space. : the object's model matrix
Submission
Submit your answers to these questions to the "Project 3: Intersect (Algo)" assignment on Gradescope.