00001 #ifndef CLOUDSHADER_H 00002 #define CLOUDSHADER_H 00003 00004 00005 #include "ProceduralShader.h" 00006 #include "Primitive.h" 00007 00008 00015 class CloudShader : public ProceduralShader 00016 { 00017 public: 00022 CloudShader(Scene * scene, 00023 const RGBAColor & color) 00024 : ProceduralShader(scene, 0.65f, 0.015f, 8), /* some magic numbers which makes nice cloud effects */ 00025 mColor(color) 00026 { 00027 } 00028 00032 RGBAColor shade(const Ray & ray) const 00033 { 00034 TexCoordinate uv = ray.hit()->texCoord(ray); 00035 uv.setY(std::min(std::max(uv.y(), 0.0f), 1.0f)); 00036 float noise = mPerlin.perlinNoise(uv.x()*1000, (uv.y()+0.66f)*1000)-0.2f; // *magic* 00037 00038 RGBAColor res = mColor; 00039 if (noise > 0.0) 00040 res += RGBAColor(noise * 5); 00041 00042 // athmospheric scattering 00043 res += RGBAColor(powf(1.0 - uv.y(), 12)*0.85f); 00044 00045 return res; 00046 } 00047 00048 private: 00049 RGBAColor mColor; 00050 }; 00051 00052 #endif 00053