src/WoodShader.h

Go to the documentation of this file.
00001 #ifndef WOODSHADER_H
00002 #define WOODSHADER_H
00003 
00004 
00005 #include "ProceduralShader.h"
00006 #include "Primitive.h"
00007 
00008 
00015 class WoodShader : public ProceduralShader
00016 {
00017 public:
00022     WoodShader(Scene *             scene,
00023                const RGBAColor &   color = RGBAColor(0.47, 0.23, 0.07))
00024         : ProceduralShader(scene, 0.99f, 0.35f, 5),  /* some magic numbers which makes nice wood effects */
00025           mMarkPerlin(0.05f, 6.0f, 8),
00026           mColor(color)
00027     {
00028     }
00029 
00033     RGBAColor shade(const Ray & ray) const
00034     {
00035         assert(false); //shader is not really ready yet
00036 
00037 //        const RGBAColor marks(222.0/255.0, 184.0/255.0, 135/255.0);
00038 //        const RGBAColor marks(0,0,0,1);
00039         const RGBAColor marks( 0.30,0.16,0.16);
00040         TexCoordinate uv = ray.hit()->texCoord(ray);
00041         uv.setY(std::min(std::max(uv.y(), 0.0f), 1.0f));
00042         
00043         Vec3f hit = ray.hitPoint(-EPSILON);
00044         //FIXME transformation thingy
00045 
00046 //        float noise = mPerlin.perlinNoise3D(hit.x(), hit.y(), hit.z()) * 20;
00047         float noise = mPerlin.perlinNoise3D(uv.x(), uv.y(), 10);
00048         float grain = noise - floor(noise);
00049         
00050         float bumps = mMarkPerlin.perlinNoise3D(hit.x() * 50, hit.y() * 50, hit.z()*20 );
00051         
00052         LOG(grain);
00053 //  LOG(bumps);
00054         // bumps = std::max(0.0f,std::min(1.0f,bumps));
00055         //LOG(bumps);
00056         //bumps = bumps / 2.0f;
00057         //  return mColor * bumps;
00058         //  if(bumps < 0.5f)
00059         // {
00060         //    bumps = 0;
00061         //}
00062         //  else
00063         //    bumps =1;
00064         lerp(mColor, marks, grain);
00065         return lerp(mColor, marks, grain);
00066         return mColor * std::min(1.0f, grain);
00067 
00068         return lerp(mColor * grain, marks, bumps)/4.0f;
00069 
00070 /*
00071         float noise = mPerlin.perlinNoise(uv.x()*1000, (uv.y()+0.66f)*1000)-0.2f;   // *magic*
00072         
00073         RGBAColor res = mColor;
00074         if (noise > 0.0)
00075             res += RGBAColor(noise * 5);
00076         
00077             return res;*/
00078   }
00079 
00080 private:
00081     PerlinNoise mMarkPerlin;  
00082     RGBAColor mColor; 
00083   
00084 };
00085 
00086 #endif
00087 

Generated on Fri Feb 1 00:01:42 2008 for Grayfall by  doxygen 1.5.1