]> git.tdb.fi Git - libs/gl.git/blob - demos/forestpond/source/water.h
Remove the separate clamping step from forest pond fluid simulation
[libs/gl.git] / demos / forestpond / source / water.h
1 #ifndef WATER_H_
2 #define WATER_H_
3
4 #include <random>
5 #include <msp/gl/objectinstance.h>
6 #include <msp/gl/texture2d.h>
7
8 class Water: public Msp::GL::ObjectInstance
9 {
10 public:
11         struct Region
12         {
13                 const Msp::GL::Mesh &terrain;
14                 float left;
15                 float bottom;
16                 float right;
17                 float top;
18         };
19
20 private:
21         struct State
22         {
23                 Msp::GL::Texture2D surface;
24                 Msp::GL::Texture2D velocity;
25         };
26
27         unsigned width;
28         unsigned height;
29         State state[2];
30         State *current;
31         State *next;
32         float time = 0.0f;
33         float stepsize = 0.001f;
34         std::minstd_rand rng;
35         Msp::GL::Texture2D bottom;
36         Msp::GL::Texture2D normals;
37         Msp::GL::Texture2D variance_x;
38         Msp::GL::Texture2D variance_y;
39         const Msp::GL::Sampler &sampler;
40         const Msp::GL::Program &sim_integrate;
41         const Msp::GL::Program &sim_velocity;
42         const Msp::GL::Program &normals_shader;
43         const Msp::GL::Program &variance_x_shader;
44         const Msp::GL::Program &variance_y_shader;
45         Msp::GL::ProgramData sim_shdata;
46         Msp::GL::ProgramData shdata;
47         bool simulated = false;
48
49 public:
50         Water(const Msp::GL::Object &, Msp::DataFile::Collection &, const Region &);
51
52 public:
53         void setup_frame(Msp::GL::Renderer &) override;
54         void finish_frame() override;
55
56         void setup_render(Msp::GL::Renderer &, Msp::GL::Tag) const override;
57 };
58
59 #endif