shader() example

This shader implements the gazing ball reflection mapping discussed in class.
void
shader(float *color)
{
   int iu,iv;

   vec_set(color,0,0,0);
   
   iu = (surfaceNormal[0]+1) * theTexture->cols * 0.5;
   iv = (surfaceNormal[1]+1) * theTexture->rows * 0.5;

   if((iu >= 0) && (iu < theTexture->cols) && 
      (iv >= 0) && (iv < theTexture->rows))
   {
      unsigned long val = theTexture->pixel[iv][iu];
      vec_set(color,((val>>24)&0xff)/255.0,
	      ((val>>16)&0xff)/255.0,
	      ((val>>8)&0xff)/255.0);
   }
   else
      vec_set(color,0,0,0);
}

The following .cfg file could be used with this shader:
#
# 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   numLights = 0
#
# Shader variables go here
#
string whichShader = reflection
string textureName = cafe.ppm

hanrahan@cs.stanford.edu
beers@graphics.stanford.edu

Copyright © 1997 Pat Hanrahan and Andrew C. Beers