shader() example
This uses a
noise
function to make a teapot with a noisy grayscale texture. The
implemention of this noise function is in
/usr/class/cs248/assignments/assignment4/mnoise.c. You are free to
use it. Modify the parameters to the FBm() function to get
interesting looking textures. (In case it needs to be said -- handing in
this function with these parameters for either the wood or marble texture will
get you impressively
few points.) |
|
void
shader(float *color)
{
/* See the file mnoise.h for the definition of this function.
In an actual shader, you'd make the last three arguments to this
function parameters settable from the configuration file. */
float noise = FBm(rawSurfacePosition[0],rawSurfacePosition[1],
rawSurfacePosition[2],1,2,2);
vec_set(color,diffuseColor[0]*noise,
diffuseColor[1]*noise,diffuseColor[2]*noise);
CLAMP_COLOR(color);
}
The following configuration file can 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 = 60
int numLights = 2
vec eyePosition = 0 0 20
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 = 1 1 1
hanrahan@cs.stanford.edu
beers@graphics.stanford.edu
Copyright © 1997 Pat Hanrahan and Andrew C. Beers