1 #ifndef PROCEDURALWATER_HXX
2 #define PROCEDURALWATER_HXX
3
4 #include "Procedural.hxx"
5 #include "Noise.hxx"
6
7 // Creates a water surface. This is the bumpmapping of the paper function, if you like...
8 // To do it this way is product of many (far more complex) tests, which all led to bad results.
9 // However, the net tells us how to render sea waves and such stuff, but nobody tells how to create
10 // waves on pools or ponds...
11 class ProceduralWater : public Procedural
12 {
13 private:
14 Noise *noise;
15 float Intensity;
16 Vec3f WaveDirection;
17
18 public:
19 ProceduralWater(float Intensity, Vec3f WaveDirection)
20 : Procedural(false, true, false, true), Intensity(Intensity), WaveDirection(WaveDirection)
21 {
22 noise = new Noise(Vec3f(64));
23 };
24
25 virtual ~ProceduralWater()
26 {
27 delete noise;
28 };
29
30 virtual Vec3f GetColor (Vec3f coordinate)
31 {
32 return Vec3f(0);
33 };
34
35 virtual void BumpMap(Vec3f &normal, Vec3f coordinate)
36 {
37 float turbulence = noise->Turbulence(coordinate, 0.01f);
38 normal += Intensity * (turbulence - 0.5) * WaveDirection;
39 Normalize(normal);
40 };
41 };
42
43 #endif
syntax highlighted by Code2HTML, v. 0.9.1