Tuesday, October 18, 2011

Assignment #4 - Texture and Anti-Aliasing

This assignment included texture, anti-aliasing, viewing the scene from different angles, and making a movie out of raytraced frames.

The first step for me was getting the plane textured with the checkerboard pattern.


I didn't get it quite correct, at first, as you can see above.  My rectangles are defined by their center point, a height and width, and two vectors which allow for orientation and texturing.  In the image above, the origin of the rectangle (plane) is right below the red ball, and you can see that the pattern is ok in the upper right and lower left quadrants, but not ok in the other two.  I fixed it, as you can see below.


After getting the checkerboard texture working, I worked on adding an OrientedSphere class, which I would use to both texture the sphere and rotate it in the animated scene.  The first image with the earth texture on the sphere looks all wrong.


Here I'm trying to visualize the spherical coordinates I generated in the process of texturing the sphere.


Here I'm visualizing the projections of the vector pointing from the center of the sphere to the hit point onto the oriented sphere's "forward", "up", and "right" vectors.


Below I thought I was on the trail of something, but I still wasn't getting near the cause of the problem.


Aha!  I was treating the earth image RGB data as RGBA data, and once I fixed it, I got the map textured onto the sphere.


Since I'm eventually going to be viewing from different angles, I'd like to not have a "dark side of the moon" in my scene.  And since I had designed my raytracer for this eventuality, supporting multiple colored point lights wasn't very difficult.  Below, I've added a blue-ish green light.


Now a third light, a pink-ish one.


In the following two images, I've highlighted a problem I'm having with the earth texture on the sphere.  I rotated the offending sphere until you can see the longitudinal line across which the texture image seems to be mirrored


In the image below, I rotated the sphere 180 degrees so you can see the other line of longitudinal reflection.  I still have a bug in the way I generate the texture coordinates for the sphere, I guess.  For now, I'm leaving it behind to move on to the rest of the assignment.


I implemented a simple anti-aliasing approach which just divides each pixel up into an n x n grid and puts a ray through the center of each sub-pixel grid cell.  This approach could be extended pretty easily to do jittered samples, but as a base line, I thought I'd see what the simplest method got me.  Below is an image rendered with 16 rays per pixel.  The places where the image is obviously much better include on the green sphere in the reflected checkerboard  pattern, and the texture in the other sphere.


Below is an image rendered with 121 rays per pixel.  In my opinion, the 16 rays per pixel version is almost as good, and it rendered much more quickly.


Here's a close up with 1 ray per pixel.


Below is the same close-up with 25 rays per pixel.



The final step this week was to allow viewing from different angles.  I decided to allow moving and rotating the raytracing camera using the keyboard to make capturing a short clip a little easier.  Below is a short video clip, assembled by using the keys to move through the scene and rotate the globe, while capturing the image at each step.  I then converted the ppm images to png and made an mpg video out of them using ffmpeg.




You can check out this assignment by doing an "svn update" in my repository.  Check out the README.txt for the available command-line options when running.

No comments:

Post a Comment