Homework 10

Extend your Phong-shaded sphere Applet, so that it can be used to apply the following procedural textures to your test sphere:
  1. A pattern of fuzzy dots.
  2. A pattern of tunably sharper dots.
  3. A bump pattern.

The first part can be done by some variation of f(x,y,z) = sin(x)*sin(y)*sin(z). You'll want to play with both frequency and amplitude to get reasonable results (ie: vary the domain and range, respectively, of the calls to the three sine functions). For example, you'll probably want to "normalize" the range of f() so that it ends up with values between 0 and 1 (so that you can use 0 as black and 1 as white).

You can always normalize from a known range [a..b] into the range [0..1] via the function N(a,b,t) = (t-a)/(b-a). For example, N(-1,1,t) will shift t from the range [-1..1] to [0..1].

The second part can be done by applying a high gain filter to the normalized N(-1,1,f(x,y,z)). Such a filter pushes low values downward toward zero, and high values upward toward one. A simple (but not tunable) version of such a filter can be implemented by the cubic "s-curve" function 3*(t^2) - 2*(t^3). I'd like you to create a similar, but tunable, function gain(g,t), which produces a higher gain as you increase its g argument. Then apply this to create
F(x,y,z) = gain(g,N(-1,1,f(x,y,z)))
using various values of g to modulate sharpness.
The last part is done by varying the surface normal (prior to doing the Phong lighting model) in shadePixel(). This is trickier, since you need to vary the surface normal by the vector-valued derivative of your function. You can approximate this derivative by sampling values near the surface point, as follows:
dF(x,y,z) = [F(x+µ,y,z)-F(x,y,z) , F(x,y+µ,z)-F(x,y,z) , F(x,y,z+µ)-F(x,y,z)]
for some very small value of µ. To make the appearance of a bumpy surface, you add dF(x,y,z) to the surface normal vector, and then renormalize the result, prior to shading.