2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CFluidPlaneDoor.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/World/CFluidPlaneCPU.hpp"
|
2017-08-14 03:55:06 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2017-08-14 03:55:06 +00:00
|
|
|
|
|
|
|
CFluidPlaneDoor::CFluidPlaneDoor(CAssetId patternTex1, CAssetId patternTex2, CAssetId colorTex, float tileSize,
|
|
|
|
u32 tileSubdivisions, EFluidType fluidType, float alpha,
|
|
|
|
const CFluidUVMotion& uvMotion)
|
2018-12-08 05:30:43 +00:00
|
|
|
: CFluidPlane(patternTex1, patternTex2, colorTex, alpha, fluidType, 0.5f, uvMotion)
|
|
|
|
, xa0_tileSize(tileSize)
|
|
|
|
, xa4_tileSubdivisions(tileSubdivisions & ~0x1)
|
|
|
|
, xa8_rippleResolution(xa0_tileSize / float(xa4_tileSubdivisions)) {}
|
|
|
|
|
|
|
|
CFluidPlaneShader::RenderSetupInfo CFluidPlaneDoor::RenderSetup(const CStateManager& mgr, float alpha,
|
|
|
|
const zeus::CTransform& xf, const zeus::CAABox& aabb,
|
2020-04-06 06:15:37 +00:00
|
|
|
bool noNormals) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CFluidPlaneShader::RenderSetupInfo out;
|
|
|
|
|
2020-04-12 13:20:22 +00:00
|
|
|
const float uvT = mgr.GetFluidPlaneManager()->GetUVT();
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::SetModelMatrix(xf);
|
|
|
|
|
2020-04-12 13:20:22 +00:00
|
|
|
const auto fluidUVs = x4c_uvMotion.CalculateFluidTextureOffset(uvT);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
out.texMtxs[0][0][0] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale();
|
|
|
|
out.texMtxs[0][1][1] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale();
|
|
|
|
out.texMtxs[0][3][0] = fluidUVs[1][0];
|
|
|
|
out.texMtxs[0][3][1] = fluidUVs[1][1];
|
|
|
|
|
|
|
|
out.texMtxs[1][0][0] = x4c_uvMotion.GetFluidLayers()[2].GetUVScale();
|
|
|
|
out.texMtxs[1][1][1] = x4c_uvMotion.GetFluidLayers()[2].GetUVScale();
|
|
|
|
out.texMtxs[1][3][0] = fluidUVs[2][0];
|
|
|
|
out.texMtxs[1][3][1] = fluidUVs[2][1];
|
|
|
|
|
|
|
|
out.texMtxs[2][0][0] = x4c_uvMotion.GetFluidLayers()[0].GetUVScale();
|
|
|
|
out.texMtxs[2][1][1] = x4c_uvMotion.GetFluidLayers()[0].GetUVScale();
|
|
|
|
out.texMtxs[2][3][0] = fluidUVs[0][0];
|
|
|
|
out.texMtxs[2][3][1] = fluidUVs[0][1];
|
|
|
|
|
|
|
|
out.kColors[0] = zeus::CColor(1.f, alpha);
|
|
|
|
|
|
|
|
if (!m_shader) {
|
|
|
|
auto gridDimX = u32((xa0_tileSize + aabb.max.x() - aabb.min.x() - 0.01f) / xa0_tileSize);
|
|
|
|
auto gridDimY = u32((xa0_tileSize + aabb.max.y() - aabb.min.y() - 0.01f) / xa0_tileSize);
|
|
|
|
u32 gridCellCount = (gridDimX + 1) * (gridDimY + 1);
|
|
|
|
u32 maxVerts = gridCellCount * ((std::max(2, xa4_tileSubdivisions) * 4 + 2) * 4);
|
|
|
|
m_shader.emplace(x10_texPattern1, x20_texPattern2, x30_texColor, maxVerts);
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
2017-08-14 03:55:06 +00:00
|
|
|
}
|
|
|
|
|
2018-06-04 01:56:21 +00:00
|
|
|
/* Used to be part of locked cache
|
|
|
|
* These are too big for stack allocation */
|
2018-06-07 04:43:26 +00:00
|
|
|
static CFluidPlaneRender::SHFieldSample lc_heights[46][46] = {};
|
2018-06-04 01:56:21 +00:00
|
|
|
static u8 lc_flags[9][9] = {};
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CFluidPlaneDoor::Render(const CStateManager& mgr, float alpha, const zeus::CAABox& aabb,
|
|
|
|
const zeus::CTransform& xf, const zeus::CTransform& areaXf, bool noNormals,
|
|
|
|
const zeus::CFrustum& frustum,
|
2019-06-12 02:05:17 +00:00
|
|
|
const std::optional<CRippleManager>& rippleManager, TUniqueId waterId,
|
2018-12-08 05:30:43 +00:00
|
|
|
const bool* gridFlags, u32 gridDimX, u32 gridDimY,
|
2020-04-06 06:15:37 +00:00
|
|
|
const zeus::CVector3f& areaCenter) {
|
2019-07-21 08:42:52 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP("CFluidPlaneDoor::Render", zeus::skCyan);
|
2018-12-08 05:30:43 +00:00
|
|
|
CFluidPlaneShader::RenderSetupInfo setupInfo = RenderSetup(mgr, alpha, xf, aabb, noNormals);
|
2019-06-21 06:02:56 +00:00
|
|
|
|
2019-07-21 08:42:52 +00:00
|
|
|
//if (!m_shader->isReady())
|
|
|
|
// return;
|
2019-06-21 06:02:56 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CFluidPlaneRender::numSubdivisionsInTile = xa4_tileSubdivisions;
|
|
|
|
CFluidPlaneRender::numTilesInHField = 42 / xa4_tileSubdivisions;
|
|
|
|
CFluidPlaneRender::numSubdivisionsInHField = CFluidPlaneRender::numTilesInHField * xa4_tileSubdivisions;
|
|
|
|
zeus::CVector2f centerPlane(aabb.center().x(), aabb.center().y());
|
|
|
|
float patchSize = xa8_rippleResolution * CFluidPlaneRender::numSubdivisionsInHField;
|
|
|
|
float ooSubdivSize = 1.f / xa8_rippleResolution;
|
|
|
|
|
|
|
|
m_verts.clear();
|
|
|
|
m_pVerts.clear();
|
|
|
|
m_shader->prepareDraw(setupInfo);
|
|
|
|
|
|
|
|
for (float curX = aabb.min.x(); curX < aabb.max.x(); curX += patchSize) {
|
|
|
|
float remSubdivsX = (aabb.max.x() - curX) * ooSubdivSize;
|
|
|
|
for (float curY = aabb.min.y(); curY < aabb.max.y(); curY += patchSize) {
|
|
|
|
float remSubdivsY = (aabb.max.y() - curY) * ooSubdivSize;
|
|
|
|
int remSubdivsXi = std::min(CFluidPlaneRender::numSubdivisionsInHField, int(remSubdivsX));
|
|
|
|
int remSubdivsYi = std::min(CFluidPlaneRender::numSubdivisionsInHField, int(remSubdivsY));
|
|
|
|
zeus::CAABox aabb2(aabb.min, zeus::CVector3f(xa8_rippleResolution * remSubdivsXi + curX,
|
|
|
|
xa8_rippleResolution * remSubdivsYi + curY, aabb.max.z()));
|
|
|
|
if (frustum.aabbFrustumTest(aabb2.getTransformedAABox(xf))) {
|
|
|
|
CFluidPlaneRender::SPatchInfo patchInfo(zeus::CVector3f(curX, curY, aabb.min.z()), aabb2.max, xf.origin,
|
|
|
|
xa8_rippleResolution, xa0_tileSize, 0.f,
|
|
|
|
CFluidPlaneRender::numSubdivisionsInHField,
|
|
|
|
CFluidPlaneRender::NormalMode::None, 0, 0, 0, 0, 0, 0, 0, nullptr);
|
|
|
|
|
|
|
|
RenderPatch(patchInfo, lc_heights, lc_flags, true, true, m_verts, m_pVerts);
|
|
|
|
}
|
2017-08-14 03:55:06 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-08-14 03:55:06 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
m_shader->loadVerts(m_verts, m_pVerts);
|
|
|
|
m_shader->doneDrawing();
|
2017-08-14 03:55:06 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|