shader() example
This shader will illuminate a surface with a directional light. It assumes
that the lightNDir parameters have been set for each
light.
void
shader(float *color)
{
int i;
vec_set(color,0,0,0);
for(i=0 ; i<numLights ; i++)
{
float tmp[3];
float dot = -vec_dot(lights[i].direction,surfaceNormal);
vec_scale2(dot,lights[i].color,tmp);
vec_comp_mult(tmp,diffuseColor,tmp);
vec_add(tmp,color,color);
}
CLAMP_COLOR(color);
}
The following configuration 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 zNear = 10
float fieldOfView = 90
vec eyePosition = 0 0 20
int numLights = 2
vec light0Pos = 0 20 40
color light0Color = 1 0 0
vec light1Pos = 0 -20 40
color light1Color = 0 1 0
#
# Shader variables go here
#
color diffuseColor = 0.5 0.5 0.5
string whichShader = directional
hanrahan@cs.stanford.edu
beers@graphics.stanford.edu
Copyright © 1997 Pat Hanrahan and Andrew C. Beers