The following code creates a simple shader that assumes the light is at the location of the camera. Under this condition, the shadeSample.fShadingNormal.fZ field of the shading normal is the dot product between the light vector and the normal vector. When both the light and the object are white, the shadeSample.fShadingNormal.fZ component intensifies the color. This implementation requires that the drawing port generate a valid shading normal.
class TLightAtTheEyeShader : public TShader { public: void ComputeShade( TShadingSample* shadeSample, const TSceneBundle& ) { shadeSample.fResultantColor>SetColor( TRGBColor( shadeSample.fShadingNormal.fZ, shadeSample.fShadingNormal.fZ, shadeSample.fShadingNormal.fZ ) ); } Boolean NeedNormal(){ return TRUE; } };
class TSimpleReflectShader : public TShader { public: void ComputeShade( TShadingSample& shadeSample, const TSceneBundle& ) { double y = (1. + shadeSample.fShadingNormal.fY )/2.; for( long i = 0; i < totalMapEntries1; i++ ) { if( y >= mapRange[i] && y < mapRange[i+1] ) { double val = ( y mapRange[i] ) / ( mapRange[i+1] mapRange[i] ); val = mapValue[i] * ( 1. val ) + mapValue[i+1] * val; break; } } shadeSample.fResultantColor>SetColor( TRGBColor( val, val, val ) ); } private: static double mapValue[7]; static double mapRange[7]; }; TSimpleReflectShader::mapValue = { 0., .2, 1., .3, .1, 1., 0. }; TSimpleReflectShader::mapRange = { 0., .3, .5, .65, .8, .85, 1. };