SuzanneIsland: An island of Real-time rendering effects!
water_effect.h
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 #include <iostream>
6 
7 #include <GL/glew.h>
8 #include <GLFW/glfw3.h>
9 #include <glm/glm.hpp>
10 #include <glm/gtc/type_ptr.hpp>
11 
12 #include "../shader.h"
13 #include "../texture.hpp"
14 
25 {
26 
27 private:
28 
29  // smaller texture sizes will lead to blurrier reflection / refraction
30  int reflectionResolutionX;
31  int reflectionResolutionY;
32  int refractionResolutionX;
33  int refractionResolutionY;
34 
35  GLuint fboReflection, reflectionColorTexture, reflectionDepthBuffer;
36  GLuint fboRefraction, refractionColorTexture, refractionDepthTexture;
37 
38  Shader *waterShader = nullptr;
39  Texture *waterDistortionDuDvMap = nullptr;
40  float waveAmplitude, waveSpeed, waveTimeBasedShift;
41 
42  int windowWidth, windowHeight;
43 
44 
45 public:
48  WaterEffect(int windowWidth, int windowHeight, float reflectionResolutionFactor, float refractionResolutionFactor,
49  const std::string& waterDistortionDuDvMapPath, float waveAmplitude, float waveSpeed);
50  ~WaterEffect();
51 
52  inline void bindReflectionFrameBuffer() { bindFrameBuffer(fboReflection, reflectionResolutionX, reflectionResolutionY); }
53  inline void bindRefractionFrameBuffer() { bindFrameBuffer(fboRefraction, refractionResolutionX, refractionResolutionY); }
54 
55  void bindFrameBuffer(GLuint frameBuffer, int width, int height);
56  void bindDefaultFrameBuffer();
57 
58  Shader *setupWaterShader();
59 
60  void updateWaves(float deltaT);
61 
62 
63 private:
64 
66  GLuint createFrameBuffer();
67 
69  GLuint createColorTextureAttachment(int width, int height);
70 
73  GLuint createDepthTextureAttachment(int width, int height);
74 
78  GLuint createDepthRenderbufferAttachment(int width, int height);
79 
80 };
81 
WaterEffect This is used to create a real-time reflecting and refracting horizontal water surface wit...
Definition: water_effect.h:24
Texture class.
Definition: texture.hpp:13
Shader class.
Definition: shader.h:15
WaterEffect(int windowWidth, int windowHeight, float reflectionResolutionFactor, float refractionResolutionFactor, const std::string &waterDistortionDuDvMapPath, float waveAmplitude, float waveSpeed)
reflectionResolutionFactor and refractionResolutionFactor will be used to determine size of reflectio...
Definition: water_effect.cpp:3