1 #ifndef BUMPMAPPEDPHONGSHADER_HXX
 2 #define BUMPMAPPEDPHONGSHADER_HXX
 3 
 4 #include "PhongShader.hxx"
 5 #include "BumpMapping.hxx"
 6 
 7 class BumpMappedPhongShader : public PhongShader
 8 {
 9     private:
10         char* filename;
11         BumpMapping* bumpmap;       
12        
13     public:
14         /**
15          * parameter as normal for PhongShader
16          * plus additional, the filename of the height map
17          */
18         BumpMappedPhongShader(Scene *scene, Vec3f color, float ka, float kd, float ks, float ke, char* filename)
19         : PhongShader(scene, color, ka, kd, ks, ke), filename(filename)
20         {
21             assert( filename != NULL );
22             bumpmap = new BumpMapping(filename);            
23         };
24         
25         /**
26          * tidy up
27          */
28         ~BumpMappedPhongShader()
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 the PhongShader is extended by a method addNormal, which takes the old normal vector at the hitpoint
37          * and adds the perturbation computed by the help of the BumpMap.
38          * Afterwards the usual PhongShader procedure is used.
39          */
40         virtual Vec3f Shade(Ray &ray)
41         {           
42             Vec3f normal = bumpmap->GetNormal(ray);
43         
44             PhongShader::addNormal( normal );
45             Vec3f result = PhongShader::Shade(ray);
46             PhongShader::resetNormal();
47         
48             return result;
49         };
50 };
51 
52 #endif


syntax highlighted by Code2HTML, v. 0.9.1