Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/DecalRData.cpp
Show All 18 Lines | |||||
#include "DecalRData.h" | #include "DecalRData.h" | ||||
#include "graphics/Decal.h" | #include "graphics/Decal.h" | ||||
#include "graphics/Model.h" | #include "graphics/Model.h" | ||||
#include "graphics/ShaderManager.h" | #include "graphics/ShaderManager.h" | ||||
#include "graphics/Terrain.h" | #include "graphics/Terrain.h" | ||||
#include "graphics/TextureManager.h" | #include "graphics/TextureManager.h" | ||||
#include "graphics/Water.h" | |||||
#include "lib/allocators/DynamicArena.h" | #include "lib/allocators/DynamicArena.h" | ||||
#include "lib/allocators/STLAllocators.h" | #include "lib/allocators/STLAllocators.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/CStrInternStatic.h" | #include "ps/CStrInternStatic.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/TerrainRenderer.h" | #include "renderer/TerrainRenderer.h" | ||||
#include "simulation2/components/ICmpWaterManager.h" | |||||
#include "simulation2/Simulation2.h" | |||||
#include <algorithm> | #include <algorithm> | ||||
// TODO: Currently each decal is a separate CDecalRData. We might want to use | // TODO: Currently each decal is a separate CDecalRData. We might want to use | ||||
// lots of decals for special effects like shadows, footprints, etc, in which | // lots of decals for special effects like shadows, footprints, etc, in which | ||||
// case we should probably redesign this to batch them all together for more | // case we should probably redesign this to batch them all together for more | ||||
// efficient rendering. | // efficient rendering. | ||||
Show All 19 Lines | bool operator()(const SDecalBatch& lhs, const SDecalBatch& rhs) const | ||||
if (lhs.indices->m_Owner != rhs.indices->m_Owner) | if (lhs.indices->m_Owner != rhs.indices->m_Owner) | ||||
return lhs.indices->m_Owner < rhs.indices->m_Owner; | return lhs.indices->m_Owner < rhs.indices->m_Owner; | ||||
return lhs.decal < rhs.decal; | return lhs.decal < rhs.decal; | ||||
} | } | ||||
}; | }; | ||||
} // anonymous namespace | } // anonymous namespace | ||||
CDecalRData::CDecalRData(CModelDecal* decal, CSimulation2* simulation) | CDecalRData::CDecalRData(CModelDecal* decal) | ||||
: m_Decal(decal), m_Simulation(simulation) | : m_Decal(decal) | ||||
{ | { | ||||
BuildVertexData(); | BuildVertexData(); | ||||
} | } | ||||
CDecalRData::~CDecalRData() = default; | CDecalRData::~CDecalRData() = default; | ||||
void CDecalRData::Update(CSimulation2* simulation) | void CDecalRData::Update() | ||||
{ | { | ||||
m_Simulation = simulation; | |||||
if (m_UpdateFlags != 0) | if (m_UpdateFlags != 0) | ||||
{ | { | ||||
BuildVertexData(); | BuildVertexData(); | ||||
m_UpdateFlags = 0; | m_UpdateFlags = 0; | ||||
} | } | ||||
} | } | ||||
void CDecalRData::RenderDecals( | void CDecalRData::RenderDecals( | ||||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | void CDecalRData::BuildVertexData() | ||||
if (i1 <= i0 && j1 <= j0) | if (i1 <= i0 && j1 <= j0) | ||||
{ | { | ||||
// We have nothing to render. | // We have nothing to render. | ||||
m_VBDecals.Reset(); | m_VBDecals.Reset(); | ||||
m_VBDecalsIndices.Reset(); | m_VBDecalsIndices.Reset(); | ||||
return; | return; | ||||
} | } | ||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*m_Simulation, SYSTEM_ENTITY); | |||||
std::vector<SDecalVertex> vertices((i1 - i0 + 1) * (j1 - j0 + 1)); | std::vector<SDecalVertex> vertices((i1 - i0 + 1) * (j1 - j0 + 1)); | ||||
for (ssize_t j = j0, idx = 0; j <= j1; ++j) | for (ssize_t j = j0, idx = 0; j <= j1; ++j) | ||||
{ | { | ||||
for (ssize_t i = i0; i <= i1; ++i, ++idx) | for (ssize_t i = i0; i <= i1; ++i, ++idx) | ||||
{ | { | ||||
SDecalVertex& vertex = vertices[idx]; | SDecalVertex& vertex = vertices[idx]; | ||||
m_Decal->m_Terrain->CalcPosition(i, j, vertex.m_Position); | m_Decal->m_Terrain->CalcPosition(i, j, vertex.m_Position); | ||||
if (decal.m_Floating && cmpWaterManager) | if (decal.m_Floating && m_Decal->m_Water) | ||||
{ | { | ||||
vertex.m_Position.Y = std::max( | vertex.m_Position.Y = std::max( | ||||
vertex.m_Position.Y, | vertex.m_Position.Y, | ||||
cmpWaterManager->GetExactWaterLevel(vertex.m_Position.X, vertex.m_Position.Z)); | m_Decal->m_Water->GetExactWaterHeight(vertex.m_Position.X, vertex.m_Position.Z)); | ||||
} | } | ||||
m_Decal->m_Terrain->CalcNormal(i, j, vertex.m_Normal); | m_Decal->m_Terrain->CalcNormal(i, j, vertex.m_Normal); | ||||
// Map from world space back into decal texture space. | // Map from world space back into decal texture space. | ||||
CVector3D inv = m_Decal->GetInvTransform().Transform(vertex.m_Position); | CVector3D inv = m_Decal->GetInvTransform().Transform(vertex.m_Position); | ||||
vertex.m_UV.X = 0.5f + (inv.X - decal.m_OffsetX) / decal.m_SizeX; | vertex.m_UV.X = 0.5f + (inv.X - decal.m_OffsetX) / decal.m_SizeX; | ||||
// Flip V to match our texture convention. | // Flip V to match our texture convention. | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator