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),
00025 mMarkPerlin(0.05f, 6.0f, 8),
00026 mColor(color)
00027 {
00028 }
00029
00033 RGBAColor shade(const Ray & ray) const
00034 {
00035 assert(false);
00036
00037
00038
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
00045
00046
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
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
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
00072
00073
00074
00075
00076
00077
00078 }
00079
00080 private:
00081 PerlinNoise mMarkPerlin;
00082 RGBAColor mColor;
00083
00084 };
00085
00086 #endif
00087