-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcWater.h
178 lines (129 loc) · 5.46 KB
/
cWater.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
///////////////////////////////////////////////////////
//*-------------------------------------------------*//
//| Part of Project One (https://www.maus-games.at) |//
//*-------------------------------------------------*//
//| Copyright (c) 2010 Martin Mauersics |//
//| Released under the zlib License |//
//*-------------------------------------------------*//
///////////////////////////////////////////////////////
#pragma once
#ifndef _P1_GUARD_WATER_H_
#define _P1_GUARD_WATER_H_
// TODO 5: reduce reflection-framebuffer without reflection enabled
// TODO 3: water-surface clipping for refraction (what did I mean here?)
// TODO 5: flying should create strong/fast water ripples
// TODO 3: specular contribution should be reduced by shadow (object shadow and environment darkening)
// TODO 3: remove sqrt/coreUnpackNormalMap in rainy shader (pre-processing like in outdoor)
// TODO 3: do not load default water shader and texture if not required (maybe create water-interface, NormalWater, Clean, Fresh)
// TODO 3: rain resolution is not affected by environment-scale-factor (check dynamically, textures might shift)
// TODO 2: rain-water animation becomes slower on skipped frames because calculations are in the update routine
// ****************************************************************
// water definitions
#define WATER_HEIGHT (-20.0f) // default water-surface z-position
#define WATER_SIZE (200.0f) // absolute size of the water-surface
#define WATER_SKY_SIZE (3.0f) // texture size of the sky-plane
#define WATER_SCALE_FACTOR (SCALE_FACTOR) // frame buffer resolution factor (reflection and depth)
#define RAIN_DROPS (20u) //
#define RAIN_DROP_SPEED (1.15f) //
#define RAIN_DROP_WIDTH (0.2f) //
#define RAIN_SCALE_FACTOR (SCALE_FACTOR) // frame buffer resolution factor
// ****************************************************************
// water-surface class
class cWater : public coreObject3D
{
protected:
coreFlow m_fAnimation; // water animation value
coreFloat m_fFlyOffset; // current fly offset
coreFrameBuffer m_Reflection; // reflection frame buffer (reduced resolution)
coreFrameBuffer m_Refraction; // refraction frame buffer
coreFrameBuffer m_Depth; // depth frame buffer (reduced resolution)
coreFullscreen m_Sky; // sky-plane as reflection background
coreProgramPtr m_apSkyProgram[2]; //
public:
explicit cWater(const coreHashString& sSkyTexture)noexcept;
virtual ~cWater()override;
DISABLE_COPY(cWater)
// render and move the water-surface
void Render(coreFrameBuffer* pBackground);
void Move()final;
// update water reflection and depth
void UpdateReflection();
void UpdateDepth(cOutdoor* pOutdoor, const coreList<coreBatchList*>& apObjectList);
// set object properties
inline void SetFlyOffset(const coreFloat fFlyOffset) {m_fFlyOffset = fFlyOffset;}
// get object properties
inline const coreFloat& GetFlyOffset ()const {return m_fFlyOffset;}
inline coreFrameBuffer* GetReflection() {return &m_Reflection;}
inline coreFrameBuffer* GetRefraction() {return &m_Refraction;}
inline coreFrameBuffer* GetDepth () {return &m_Depth;}
virtual void Reshape();
private:
// own routines for derived classes
virtual void __RenderOwn() {}
virtual void __MoveOwn () {}
virtual void __UpdateOwn() {}
// hide default render functions
inline void Render(const coreProgramPtr& pProgram)final {UNREACHABLE}
inline void Render()final {UNREACHABLE}
};
// ****************************************************************
// underwater-surface class
class cUnderWater final : public cWater
{
public:
cUnderWater()noexcept;
DISABLE_COPY(cUnderWater)
};
// ****************************************************************
// ice-surface class
class cIceWater final : public cWater
{
private:
coreObject3D m_Ice; //
public:
explicit cIceWater(const coreHashString& sSkyTexture)noexcept;
DISABLE_COPY(cIceWater)
private:
//
void __RenderOwn()final;
void __MoveOwn ()final;
};
// ****************************************************************
// rain-surface class
class cRainWater final : public cWater
{
private:
coreFrameBuffer m_WaveMap; //
coreFullscreen m_WaveInjection; //
coreObject3D m_aDrop[RAIN_DROPS]; //
coreBatchList m_DropList; //
coreUintW m_iCurDrop; //
coreFlow m_fFallDelay; //
public:
explicit cRainWater(const coreHashString& sSkyTexture)noexcept;
~cRainWater()final;
DISABLE_COPY(cRainWater)
void Reshape()final;
private:
//
void __UpdateOwn()final;
};
// ****************************************************************
// lava-surface class
class cLava final : public coreObject3D
{
private:
coreFlow m_fAnimation; // lava animation value
coreFloat m_fFlyOffset; // current fly offset
public:
cLava()noexcept;
DISABLE_COPY(cLava)
// render and move the lava-surface
void Render()final;
void Move ()final;
// set object properties
inline void SetFlyOffset(const coreFloat fFlyOffset) {m_fFlyOffset = fFlyOffset;}
// get object properties
inline const coreFloat& GetFlyOffset()const {return m_fFlyOffset;}
};
#endif // _P1_GUARD_WATER_H_