AireEngine
A 3D Open-World Game Engine
Loading...
Searching...
No Matches
water.h
1#pragma once
2#include <vector>
3#include <glm/glm.hpp>
4#include <glad/glad.h>
5
6#include "../rendering/texture.h"
7#include "../rendering/shaderProgram.h"
8#include "../rendering/vao.h"
9#include "../rendering/buffer.h"
10#include "../rendering/camera.h"
11#include "../rendering/window.h"
12#include "../res-management/terrain.h"
13#include "../res-management/texManager.h"
14
15#include "../utils/bbox.h"
16#include "../utils/clock.h"
17
18namespace Aire {
20 public:
25 WaterSurface(TextureManager* texManager, const Terrain* terrain, const Box2D& region, float height);
26
29
35 void render(
36 const Window& window,
37 const Clock& clock,
38 Camera& camera,
39 Terrain& terrain,
40 ShaderProgram& terrainProg, //< TODO change the interface of terrain so that there is no need to pass this argument
41 Texture* skyboxTex
42 );
43
48 inline void toggleDepthSlowdown(bool turnOn, float slowdownDepth=-1.0f);
49
53 inline void toggleSoftEdges(bool turnOn, float shoreFadeDepth=-1.0f);
54
55 glm::vec3 deepWaterColor;
57 glm::vec3 depthExtinction;
59 glm::vec2 windDir;
60 float windSpeed;
61 float height;
66 float uvTiling;
68
69 private:
70 void prepareTextures(
71 const Window& window,
72 Camera& camera,
73 Terrain& terrain,
74 ShaderProgram& terrainProg
75 );
76
77 ShaderProgram waterProg;
79
80 TexturePtr dudvMap;
81 TexturePtr normalMap;
82 Texture2D refractionTex;
83 Texture2D refractionDepthTex;
84 Texture2D reflectionTex;
85 GLuint reflectionDepthBuffer;
86 GLuint refractionFB;
87 GLuint reflectionFB;
88
89 float slowdownDepth;
90 float shoreFadeDepth;
91 };
92
93 void Aire::WaterSurface::toggleDepthSlowdown(bool turnOn, float slowdownDepth) {
94 this->slowdownDepth = turnOn ? slowdownDepth : -1.0f;
95 }
96 inline void WaterSurface::toggleSoftEdges(bool turnOn, float shoreFadeDepth) {
97 this->shoreFadeDepth = turnOn ? shoreFadeDepth : -1.0f;
98 }
99}
Definition camera.h:9
Simple clock class.
Definition clock.h:6
A linked OpenGL program.
Definition shaderProgram.h:16
A class that represents a terrain object.
Definition terrain.h:28
A 2D texture class.
Definition texture.h:70
Texture base class.
Definition texture.h:20
Texture manager. Handles texture creation, storage, and deletion.
Definition texManager.h:20
Definition vao.h:8
Definition water.h:19
void toggleDepthSlowdown(bool turnOn, float slowdownDepth=-1.0f)
Definition water.h:93
~WaterSurface()
Free all resources associated with the water surface.
Definition water.cpp:160
glm::vec2 windDir
2D wind direction to control the waves on the surface
Definition water.h:59
float waterClarity
Parameter to control how transparent the water is.
Definition water.h:65
float windSpeed
A wind speed parameter to control the speed of the waves.
Definition water.h:60
glm::vec3 depthExtinction
Definition water.h:57
void toggleSoftEdges(bool turnOn, float shoreFadeDepth=-1.0f)
Definition water.h:96
glm::vec3 shallowWaterColor
Colour in shallow water.
Definition water.h:56
float height
Height of the water surface.
Definition water.h:61
float horizontalExtinction
Colour extinction (from shallow to deep water colour) along the eye vector.
Definition water.h:64
void render(const Window &window, const Clock &clock, Camera &camera, Terrain &terrain, ShaderProgram &terrainProg, Texture *skyboxTex)
Definition water.cpp:172
float heightDeepWater
Definition water.h:62
WaterSurface(TextureManager *texManager, const Terrain *terrain, const Box2D &region, float height)
Definition water.cpp:61
glm::vec3 deepWaterColor
Colour in deep water.
Definition water.h:55
float uvTiling
Definition water.h:66
Definition window.h:13
Utility struct for a 2D bounding-box.
Definition bbox.h:6