This shader implements the gazing ball reflection mapping discussed in class and shown above.
void
shader(float *color)
{
int iu,iv;
/* Compute texture coordinates given the surface normal */
iu = 0.5 * (surfaceNormal[0] + 1) * theTexture->width;
iv = 0.5 * (surfaceNormal[1] + 1) * theTexture->height;
/* Get color from texture */
if ((iu >= 0) && (iu < theTexture->width) &&
(iv >= 0) && (iv < theTexture->height)) {
Pixel pixel = ImagePixel(theTexture, iu, iv);
vec_set(color, pixel.r / 255.0, pixel.g / 255.0, pixel.b / 255.0);
}
else
vec_set(color, 0, 0, 0);
}
# # This stuff has nothing to do with the shader, only scene layout # string patchObject = models/patches/teapot.obj int loDice = 10 int hiDice = 20 int zNear = 10 float fieldOfView = 90 vec eyePosition = 0 0 10 int numLights = 1 # # Shader variables go here # string whichShader = reflection string textureName = images/cafe.ppm