1 /* Copyright (C) 2017 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
19 * Water settings (speed, height) and texture management
22 #ifndef INCLUDED_WATERMANAGER
23 #define INCLUDED_WATERMANAGER
25 #include "graphics/Texture.h"
27 #include "maths/Matrix3D.h"
28 #include "maths/Vector2D.h"
29 #include "ps/Shapes.h"
30 #include "renderer/VertexBufferManager.h"
39 * Class WaterManager: Maintain rendering-related water settings and textures
40 * Anything that affects gameplay should go in CcmpWaterManager.cpp and passed to this (possibly as copy).
46 CTexturePtr m_WaterTexture
[60];
47 CTexturePtr m_NormalMap
[60];
49 float* m_WindStrength
; // How strong the waves are at point X. % of waviness.
50 float* m_DistanceHeightmap
; // How far from the shore a point is. Manhattan
51 CVector3D
* m_BlurredNormalMap
; // Cache a slightly blurred map of the normals of the terrain.
53 // Waves vertex buffers
54 std::vector
< WaveObject
* > m_ShoreWaves
; // TODO: once we get C++11, remove pointer
55 // Waves indices buffer. Only one since All Wave Objects have the same.
56 CVertexBuffer::VBChunk
* m_ShoreWaves_VBIndices
;
61 CTexturePtr m_WaveTex
;
62 CTexturePtr m_FoamTex
;
65 GLuint m_FancyTextureNormal
;
66 GLuint m_FancyTextureOther
;
67 GLuint m_FancyTextureDepth
;
68 GLuint m_ReflFboDepthTexture
;
69 GLuint m_RefrFboDepthTexture
;
71 // used to know what to update when updating parts of the terrain only.
77 int m_WaterCurrentTex
;
80 // If disabled, force the use of the fixed function for rendering.
82 // Those variables register the current quality level. If there is a change, I have to recompile the shader.
83 // Use real depth or use the fake precomputed one.
84 bool m_WaterRealDepth
;
85 // Use fancy shore effects and show trails behind ships
86 bool m_WaterFancyEffects
;
87 // Use refractions instead of simply making the water more or less transparent.
88 bool m_WaterRefraction
;
89 // Use complete reflections instead of showing merely the sky.
90 bool m_WaterReflection
;
91 // Show shadows on the water.
94 bool m_NeedsReloading
;
95 // requires also recreating the super fancy information.
96 bool m_NeedInfoUpdate
;
100 double m_WaterTexTimer
;
101 float m_RepeatPeriod
;
103 // Reflection and refraction textures for fancy water
104 GLuint m_ReflectionTexture
;
105 GLuint m_RefractionTexture
;
106 size_t m_RefTextureSize
;
108 // framebuffer objects
109 GLuint m_RefractionFbo
;
110 GLuint m_ReflectionFbo
;
111 GLuint m_FancyEffectsFBO
;
113 // Model-view-projection matrices for reflected & refracted cameras
114 // (used to let the vertex shader do projective texturing)
115 CMatrix3D m_ReflectionMatrix
;
116 CMatrix3D m_RefractionMatrix
;
119 std::wstring m_WaterType
; // Which texture to use.
120 CColor m_WaterColor
; // Color of the water without refractions. This is what you're seeing when the water's deep or murkiness high.
121 CColor m_WaterTint
; // Tint of refraction in the water.
122 float m_Waviness
; // How big the waves are.
123 float m_Murkiness
; // How murky the water is.
124 float m_WindAngle
; // In which direction the water waves go.
131 * LoadWaterTextures: Load water textures from within the
132 * progressive load framework.
134 * @return 0 if loading has completed, a value from 1 to 100 (in percent of completion)
135 * if more textures need to be loaded and a negative error value on failure.
137 int LoadWaterTextures();
140 * Resize: Updates the fancy water textures so that water will render correctly
146 * ReloadWaterNormalTextures: Reload the normal textures so that changing
147 * water type in Atlas will actually do the right thing.
149 void ReloadWaterNormalTextures();
152 * UnloadWaterTextures: Free any loaded water textures and reset the internal state
153 * so that another call to LoadWaterTextures will begin progressive loading.
155 void UnloadWaterTextures();
158 * RecomputeWaterData: calculates all derived data from the waterheight
160 void RecomputeWaterData();
163 * RecomputeWindStrength: calculates the intensity of waves
165 void RecomputeWindStrength();
168 * RecomputeDistanceHeightmap: recalculates (or calculates) the distance heightmap.
170 void RecomputeDistanceHeightmap();
173 * RecomputeBlurredNormalMap: calculates the blurred normal map of the terrain. Slow.
175 void RecomputeBlurredNormalMap();
178 * CreateWaveMeshes: Creates the waves objects (and meshes).
180 void CreateWaveMeshes();
183 * Updates the map size. Will trigger a complete recalculation of fancy water information the next turn.
185 void SetMapSize(size_t size
);
188 * Updates the settings to the one from the renderer, and sets m_NeedsReloading.
190 void UpdateQuality();
193 * Returns true if fancy water shaders will be used (i.e. the hardware is capable
194 * and it hasn't been configured off)
196 bool WillRenderFancyWater();
198 void RenderWaves(const CFrustum
& frustrum
);
202 #endif // INCLUDED_WATERMANAGER