|
This is a ray tracer for a wide range of implicit functions. It also uses Phong shading and velvet shading. To use: click in the applet window to move one of the shapes (you have to do this first) press v to try the velvet shader press s to try various shapes press t to try a bump map and volume textures click in the center of the torus to see the little surprise I put in for my wife I can enter in any formula in the code, and the applet tries to raytrace it. To raytrace a unit sphere, for example, I would just write x*x+y*y+z*z-1. I first tried a ray-marching technique, but found it was too slow. So I used a binary search for the root to make it faster. The downside is that the search can find the wrong root unless you restrict the range it is searching in to have only one root. Once it has found a surface on a given row, it knows the root at the next pixel will be about the same distance away, so it gets more efficient. Velvet and fur have the interesting property that when you are looking directly into the fibers, it looks darker. So I compare the eye direction with the normal to get that effect. I also add some noise in the normals to make it look fuzzy. Notice how the shapes blob together. That's because I am multiplying the equation for each shape together and subtracting a small constant. The last shape you get by pressing 's' repeatedly is a sphere which has been set to intersect with the torus. The bump map is a perturbation of the direction the normals are facing. The volume textures are true modifications to the geometry of the object. It's just a sine curve in 1, 2, and 3 dimensions. |