In this lecture we went through the process of ray tracing to
a sphere,
implementing Phong shading for that sphere, and
then adding various types of procedural texture to the sphere.
By the end we had something that looked like an orange.
Or maybe a planet floating in the depths of outer space that
happens to look remarkably like an orange.
I have broken down what we did in class into eight progressive
steps, which you can access by downloading and unzipping
shader3.zip.
Your homework, due before class on Thursday Feb 28,
will be to implement the function ray_sphere().
In order for you to be able to see things working,
I have implemented a totally fake version of ray_sphere():
float ray_sphere(vec3 V,vec3 W,vec4 S) {
float rr = min(1., 49. * dot(W.xy,W.xy));
return rr >= 1. ? -1. : 3.5 - sqrt(1.-rr)/2.;
}
It happens to look like the particular sphere we used as an
example in class, but it's a total fake kludge.
You need to replace this with a real implementation of
ray_sphere(), which implements the math from
last week's lecture on how to trace a ray to a sphere.
For extra credit you can try implementing multiple spheres,
using the same array technique that we used to implement
multiple light sources.
You could also see if you can vary the shape of the sphere.
For example, try elongating it to an ellipse.
Or you could create a really interesting animation.
|