ray trace movie
another ray trace movie
raytraced ball moving through space (the matlab conversion has badly decreased the quality somehow)

Programming Assignment 4

I made a simple raytracer in matlab.  It has the ability to render spheres and planes, where
the objects and lights are located anywhere in space, the center of projection is anywhere,
and the direction of view is anywhere.  Code I've written for the raytracer, some redundant,
is:
    Pwfi.m (creates the projection matrix, given cop and dov)
    intersect.m (finds the intersection of the ray e + t*v with the sphere defined by c, r)
    p_intersect.m (finds the intersection of the ray with the plane defined by a point and normal)
    raytrace_with_planes.m (send this function spheres, planes, lights, cop, dov, resolution)
    random_raytrace.m (provide an image of random spheres)
    make_ray_movie.m (provide multiple cop's and dov's for a movie)
    make_ray_movie_2.m (provide multiple centers for a given sphere for a movie)

How the raytracer works (pseudocode):
for every pixel
    compute a ray
    for every sphere
        if it intersects the ray closer than all previous spheres, reassign closest_sphere and min_t
    end
    for every plane
        if it intersects the ray closer than all previous spheres and planes, reassignments
    end
    if there was an intersection for this ray (since planes are infinite, this is almost always true)
        get normal and view information and the intersection point for that object
        for every light
            cast a ray from the point to the light and see if there is an intersecting object (for
                                                    every sphere, for every plane, like before)
            if the point is not in shadow for that light
                calculate lighting on that point from that light, and add it to the color of the pixel.
            end
        end
    end
end

Conclusion:
Getting the initial raytracer to work was very easy, but adding bits of matlab code for
shadows and plane rendering made it frustratingly slow to wait for output to see if it was
correct.  To avoid flooding color for the random raytraced images, I had to make a lot of
restrictions that basically make the random spheres very similar except for color.  For the
first raytrace movie above, I did a cubic interpolation between four of the light sources via
the method we've learned in class.  In the third movie, the sphere follows a rising spiral
within the rendering volume, but occasionally all of the sphere is not within the volume.  As
you can see this is not a problem.

    

     (an additional light)