1 #ifndef BUMPMAPPEDEYELIGHTSHADER_HXX
 2 #define BUMPMAPPEDEYELIGHTSHADER_HXX
 3 
 4 #include "BumpMapping.hxx"
 5 
 6 class BumpMappedEyeLightShader : public Shader
 7 {
 8     private:
 9         Vec3f color;
10         char* filename;
11         BumpMapping* bumpmap;
12        
13     public:
14         /**
15          * parameter as normal for EyeLightShader, thus only the scene and a color
16          * plus additional, the filename of the height map
17          */
18         BumpMappedEyeLightShader(Scene *scene, Vec3f color, char* filename)
19         : Shader(scene), color(color), filename(filename)
20         {
21             assert( filename != NULL );
22             bumpmap = new BumpMapping(filename);            
23         };
24 
25         /**
26          * tidy up
27          */
28         ~BumpMappedEyeLightShader()
29         {
30             if (bumpmap)
31                 delete bumpmap;
32         };
33 
34         /**
35          * As indicated in Blinn's Paper, the normal vector has to be adjusted. 
36          * Therefore we compute the part which has to be added (for more details, please have a look into BumpMapping.hxx)
37          * We then know: 
38                 new_normal = old_normal + added_part
39          * and can simply apply the shade procedure as normal for the eyelight shader onto this new vector.
40          */     
41         virtual Vec3f Shade(Ray &ray)
42         {
43             Vec3f normal = ray.hit->GetNormal(ray) + bumpmap->GetNormal(ray);
44             Normalize(normal);
45 
46             return color * fabs(Dot(ray.dir,normal));
47         };
48 };
49 
50 #endif


syntax highlighted by Code2HTML, v. 0.9.1