Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/WaterManager.cpp
Show First 20 Lines • Show All 411 Lines • ▼ Show 20 Lines | void WaterManager::UnloadWaterTextures() | ||||
pglDeleteFramebuffersEXT(1, &m_RefractionFbo); | pglDeleteFramebuffersEXT(1, &m_RefractionFbo); | ||||
pglDeleteFramebuffersEXT(1, &m_ReflectionFbo); | pglDeleteFramebuffersEXT(1, &m_ReflectionFbo); | ||||
} | } | ||||
/////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////// | ||||
// Calculate our binary heightmap from the terrain heightmap. | // Calculate our binary heightmap from the terrain heightmap. | ||||
void WaterManager::RecomputeDistanceHeightmap() | void WaterManager::RecomputeDistanceHeightmap() | ||||
{ | { | ||||
CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); | ||||
if (!terrain || !terrain->GetHeightMap()) | if (!terrain || !terrain->GetHeightMap()) | ||||
return; | return; | ||||
size_t SideSize = m_MapSize*2; | size_t SideSize = m_MapSize*2; | ||||
if (m_DistanceHeightmap == NULL) | if (m_DistanceHeightmap == NULL) | ||||
m_DistanceHeightmap = new float[SideSize*SideSize]; | m_DistanceHeightmap = new float[SideSize*SideSize]; | ||||
// Create a manhattan-distance heightmap. | // Create a manhattan-distance heightmap. | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | for (size_t x = 0; x < SideSize; ++x) | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// This requires m_DistanceHeightmap to be defined properly. | // This requires m_DistanceHeightmap to be defined properly. | ||||
void WaterManager::CreateWaveMeshes() | void WaterManager::CreateWaveMeshes() | ||||
{ | { | ||||
size_t SideSize = m_MapSize*2; | size_t SideSize = m_MapSize*2; | ||||
CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); | ||||
if (!terrain || !terrain->GetHeightMap()) | if (!terrain || !terrain->GetHeightMap()) | ||||
return; | return; | ||||
for (WaveObject* const& obj : m_ShoreWaves) | for (WaveObject* const& obj : m_ShoreWaves) | ||||
{ | { | ||||
if (obj->m_VBvertices) | if (obj->m_VBvertices) | ||||
g_VBMan.Release(obj->m_VBvertices); | g_VBMan.Release(obj->m_VBvertices); | ||||
delete obj; | delete obj; | ||||
▲ Show 20 Lines • Show All 447 Lines • ▼ Show 20 Lines | #else | ||||
glDepthFunc(GL_LEQUAL); | glDepthFunc(GL_LEQUAL); | ||||
#endif | #endif | ||||
} | } | ||||
/////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////// | ||||
// Calculate The blurred normal map to get an idea of where water ought to go. | // Calculate The blurred normal map to get an idea of where water ought to go. | ||||
void WaterManager::RecomputeBlurredNormalMap() | void WaterManager::RecomputeBlurredNormalMap() | ||||
{ | { | ||||
CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); | ||||
if (!terrain || !terrain->GetHeightMap()) | if (!terrain || !terrain->GetHeightMap()) | ||||
return; | return; | ||||
// used to cache terrain normals since otherwise we'd recalculate them a lot (I'm blurring the "normal" map). | // used to cache terrain normals since otherwise we'd recalculate them a lot (I'm blurring the "normal" map). | ||||
// this might be updated to actually cache in the terrain manager but that's not for now. | // this might be updated to actually cache in the terrain manager but that's not for now. | ||||
if (m_BlurredNormalMap == NULL) | if (m_BlurredNormalMap == NULL) | ||||
m_BlurredNormalMap = new CVector3D[m_MapSize*m_MapSize]; | m_BlurredNormalMap = new CVector3D[m_MapSize*m_MapSize]; | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
/////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////// | ||||
// Calculate the strength of the wind at a given point on the map. | // Calculate the strength of the wind at a given point on the map. | ||||
// This is too slow and should support limited recomputation. | // This is too slow and should support limited recomputation. | ||||
void WaterManager::RecomputeWindStrength() | void WaterManager::RecomputeWindStrength() | ||||
{ | { | ||||
if (m_WindStrength == NULL) | if (m_WindStrength == NULL) | ||||
m_WindStrength = new float[m_MapSize*m_MapSize]; | m_WindStrength = new float[m_MapSize*m_MapSize]; | ||||
CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); | ||||
if (!terrain || !terrain->GetHeightMap()) | if (!terrain || !terrain->GetHeightMap()) | ||||
return; | return; | ||||
float waterLevel = m_WaterHeight; | float waterLevel = m_WaterHeight; | ||||
CVector2D windDir = CVector2D(cos(m_WindAngle),sin(m_WindAngle)); | CVector2D windDir = CVector2D(cos(m_WindAngle),sin(m_WindAngle)); | ||||
CVector2D perp = CVector2D(-windDir.Y, windDir.X); | CVector2D perp = CVector2D(-windDir.Y, windDir.X); | ||||
▲ Show 20 Lines • Show All 119 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator