          _______________BRDF__________Raytracing__________OpenGL__________RenderMan

Project Overview: Raytracing
Computed two types of intersection for a raytracer, a "Ray-Block" and a "Ray-Ellipsoid".

Software: Implemented in C++ in MS Visual Studio

Raytrace Ray-Block Intersection and AABB:

I created an AABB by first checking to see whether the ray is inside the box, if the ray is indeed inside the axis aligned box, I needed to find the maximum f the minimal points. I computed s for each x y z plane and it's inverse for a total of 6 versions of s. Then I compared each two points on each plane, (ie the x plane with normal (-1,0,0) and the other x plane with the normal (1,0,0)). Then, I found the maximum of the minimum values (I had 3 in total one for x y and z). I also need to check to see if this new potential 's' is greater then the current hit distance, if it is greater, then this potential is farther then the current distance, meaning it's behinds us in the scene from the view/eye so we don't need to draw it. Once we have a new 's', I changed the normal to the normal of the chosen s, I update "hit-info" then return.

Code Snippet:  To find the max of the mins, I used the formula:
s = ( N * ( Max - ray.origin ) ) / ( N * R );    diffuse:
Unit(LightPos - hit.point) * N
specular:
if (incidence > 0.0 )
r * (light->material->specular * specular ) * pow((incidence),e);
shadow: perturbed the point, in order to allot for floating point error. To accomplish the shadow effect, needed to check if there was another intersection between the ray and object. If there was, checked the distance of this intersection with the current distance, if less, then it occurs in the front, so just color the point "black". reflectiveness: perturbed the used recursion, by shooting a ray in the direction that I gave it, and would shade the point. In order to reflect rays and check if there is an intersection and color at the point in the current ray's direction, I multiplied it by an absorption factor pho, which is the reflectiveness of the material at this point.

### Raytracing Ray-Ellipsoid Intersect:

In order to compute the intersection of more complicated quadratic surfaces as is the case of an ellipsoid, we can instead use affine transformation to transform from an ellipsoid system into a sphere's (which is easier to compute). A sphere is an ellipsoid with all three radii with equal length, so if we specify the ellipsoid's center position, orientation matrix, ie the x y z axes basis, we can apply the transformation matrix M to transform a sphere to an ellipsoid and M-1 will transform the ellipsoid back to the sphere.
So with this matrix M we can multiply the point and ray such as:
Q' = M * Q
P' = M * P
N' = M-1 * N
In order to perform the intersection in the toytracer, I created an ellipsoid class that also extends the Primitive class. In the scene descriptor file I defined the ellipsoid's center position, and a matrix of it's orientation: ellipse (0, 0, .7) ( .5, 0, 0, 0; 0, 1, 0, 0; 0, 0, .5, 0 ).
To compute the ellipsoid's Intersect function, I recycled the transform.cpp's intersect code in order to transform between the two systems, called sphere.Intersect() I forwarded all the relevant parameters (normal, point, ray, and attributes of how to color the point, i.e. shader, material, environment map et. al.).

Code Snippet  Here are the results of various ellipsoids after changing the orientation in the scene descriptor file:   