diff --git a/Runtime/Graphics/CBooRenderer.cpp b/Runtime/Graphics/CBooRenderer.cpp index feff9ee16..4301da320 100644 --- a/Runtime/Graphics/CBooRenderer.cpp +++ b/Runtime/Graphics/CBooRenderer.cpp @@ -302,6 +302,17 @@ void CBooRenderer::AddStaticGeometry(const std::vector* g } } +void CBooRenderer::EnablePVS(const CPVSVisSet* set, u32 modelCount) +{ + xc8_pvs.emplace(*set); + xe0_pvsModelCount = modelCount; +} + +void CBooRenderer::DisablePVS() +{ + xc8_pvs = std::experimental::nullopt; +} + void CBooRenderer::RemoveStaticGeometry(const std::vector* geometry) { auto search = FindStaticGeometry(geometry); @@ -309,17 +320,91 @@ void CBooRenderer::RemoveStaticGeometry(const std::vector x1c_areaListItems.erase(search); } -void CBooRenderer::DrawUnsortedGeometry(const std::vector&, int, unsigned int, unsigned int) +void CBooRenderer::DrawUnsortedGeometry(const std::vector&, int mask, int targetMask) { + //SetupRendererStates(true); + + CAreaListItem* lastOctreeItem = nullptr; + + for (CAreaListItem& item : x1c_areaListItems) + { + if (item.x18_unk != 0xff) + continue; + + if (item.x4_octTree) + lastOctreeItem = &item; + + CPVSVisSet* pvs = nullptr; + if (xc8_pvs) + pvs = &*xc8_pvs; + if (xe0_pvsModelCount != item.x10_models.size()) + pvs = nullptr; + + int idx = 0; + for (auto it = item.x10_models.begin() ; it != item.x10_models.end() ; ++it, ++idx) + { + CBooModel* model = *it; + if (pvs) + { + bool vis = pvs->GetVisible(idx); + switch (xc4_pvsMode) + { + case EPVSMode::PVS: + { + if (!vis) + { + model->x40_25_modelVisible = false; + continue; + } + } + case EPVSMode::PVSAndMask: + { + if (!vis && (model->x41_mask & mask) != targetMask) + { + model->x40_25_modelVisible = false; + continue; + } + } + default: break; + } + } + + if ((model->x41_mask & mask) != targetMask) + { + model->x40_25_modelVisible = false; + continue; + } + + if (!x44_frustumPlanes.aabbFrustumTest(model->x20_aabb)) + { + model->x40_25_modelVisible = false; + continue; + } + + if (x318_25_drawWireframe) + { + model->x40_25_modelVisible = false; + //HandleUnsortedModelWireframe(); + continue; + } + + model->x40_25_modelVisible = true; + //HandleUnsortedModel(); + } + + } + + //SetupCGraphicsStates(); } -void CBooRenderer::DrawSortedGeometry(const std::vector&, int, unsigned int, unsigned int) +void CBooRenderer::DrawSortedGeometry(const std::vector&, int mask, int targetMask) { - //SetupRendererStates(); + //SetupRendererStates(true); } -void CBooRenderer::DrawStaticGeometry(const std::vector&, int, unsigned int, unsigned int) +void CBooRenderer::DrawStaticGeometry(const std::vector& lights, int mask, int targetMask) { + DrawUnsortedGeometry(lights, mask, targetMask); } void CBooRenderer::PostRenderFogs() diff --git a/Runtime/Graphics/CBooRenderer.hpp b/Runtime/Graphics/CBooRenderer.hpp index cdf2bcdfa..094cac799 100644 --- a/Runtime/Graphics/CBooRenderer.hpp +++ b/Runtime/Graphics/CBooRenderer.hpp @@ -7,6 +7,7 @@ #include "CDrawablePlaneObject.hpp" #include "Shaders/CThermalColdFilter.hpp" #include "CRandom16.hpp" +#include "CPVSVisSet.hpp" namespace urde { @@ -71,6 +72,15 @@ class CBooRenderer : public IRenderer zeus::CPlane xb0_ = {0.f, 1.f, 0.f, 0.f}; + enum class EPVSMode + { + Mask, + PVS, + PVSAndMask + } xc4_pvsMode = EPVSMode::Mask; + std::experimental::optional xc8_pvs; + u32 xe0_pvsModelCount = 0; + //boo::ITextureS* xe4_blackTex = nullptr; bool xee_24_ : 1; @@ -96,7 +106,7 @@ class CBooRenderer : public IRenderer struct { bool x318_24_refectionDirty : 1; - bool x318_25_ : 1; + bool x318_25_drawWireframe : 1; bool x318_26_ : 1; bool x318_27_ : 1; bool x318_28_ : 1; @@ -121,10 +131,12 @@ public: std::list::iterator FindStaticGeometry(const std::vector*); void AddStaticGeometry(const std::vector*, const CAreaOctTree*, int); + void EnablePVS(const CPVSVisSet*, u32); + void DisablePVS(); void RemoveStaticGeometry(const std::vector*); - void DrawUnsortedGeometry(const std::vector&, int, unsigned int, unsigned int); - void DrawSortedGeometry(const std::vector&, int, unsigned int, unsigned int); - void DrawStaticGeometry(const std::vector&, int, unsigned int, unsigned int); + void DrawUnsortedGeometry(const std::vector&, int mask, int targetMask); + void DrawSortedGeometry(const std::vector&, int mask, int targetMask); + void DrawStaticGeometry(const std::vector&, int mask, int targetMask); void PostRenderFogs(); void AddParticleGen(const CParticleGen&); void AddPlaneObject(const void*, const zeus::CAABox&, const zeus::CPlane&, int); diff --git a/Runtime/Graphics/CMakeLists.txt b/Runtime/Graphics/CMakeLists.txt index 532a3c36a..9fcaee9c9 100644 --- a/Runtime/Graphics/CMakeLists.txt +++ b/Runtime/Graphics/CMakeLists.txt @@ -20,6 +20,10 @@ set(GRAPHICS_SOURCES CMoviePlayer.hpp CMoviePlayer.cpp CFrustumPlanes.hpp CFrustumPlanes.cpp CGraphicsPalette.hpp CGraphicsPalette.cpp + CPVSVisSet.hpp CPVSVisSet.cpp + CPVSVisOctree.hpp CPVSVisOctree.cpp + CPVSBounds.hpp CPVSBounds.cpp + CPVSAreaSet.hpp CPVSAreaSet.cpp CGraphics.hpp CGraphics.cpp Shaders/TShader.hpp Shaders/TShaderDecl.hpp Shaders/CLineRendererShaders.hpp Shaders/CLineRendererShaders.cpp Shaders/CLineRendererShadersGLSL.cpp diff --git a/Runtime/Graphics/CModel.hpp b/Runtime/Graphics/CModel.hpp index b1f39f24f..56ac55d3f 100644 --- a/Runtime/Graphics/CModel.hpp +++ b/Runtime/Graphics/CModel.hpp @@ -84,7 +84,8 @@ private: CBooSurface* x38_firstUnsortedSurface = nullptr; CBooSurface* x3c_firstSortedSurface = nullptr; bool x40_24_texturesLoaded : 1; - bool x40_25_ : 1; + bool x40_25_modelVisible : 1; + u8 x41_mask = 0; struct UVAnimationBuffer { diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp index 53ef1e28a..6695e1349 100644 --- a/Runtime/Graphics/CModelBoo.cpp +++ b/Runtime/Graphics/CModelBoo.cpp @@ -18,7 +18,7 @@ CBooModel::CBooModel(std::vector* surfaces, SShader& shader, : x0_surfaces(surfaces), x4_matSet(&shader.m_matSet), m_pipelines(&shader.m_shaders), m_vtxFmt(vtxFmt), x8_vbo(vbo), xc_ibo(ibo), m_weightVecCount(weightVecCount), m_skinBankCount(skinBankCount), x1c_textures(&shader.x0_textures), x20_aabb(aabb), - x40_24_texturesLoaded(false), x40_25_(0) + x40_24_texturesLoaded(false), x40_25_modelVisible(0) { for (CBooSurface& surf : *x0_surfaces) surf.m_parent = this; diff --git a/Runtime/Graphics/CPVSAreaSet.cpp b/Runtime/Graphics/CPVSAreaSet.cpp new file mode 100644 index 000000000..aa9b86046 --- /dev/null +++ b/Runtime/Graphics/CPVSAreaSet.cpp @@ -0,0 +1,10 @@ +#include "CPVSAreaSet.hpp" + +namespace urde +{ + +CPVSAreaSet::CPVSAreaSet(CInputStream& in) +{ +} + +} diff --git a/Runtime/Graphics/CPVSAreaSet.hpp b/Runtime/Graphics/CPVSAreaSet.hpp new file mode 100644 index 000000000..6fb8dc042 --- /dev/null +++ b/Runtime/Graphics/CPVSAreaSet.hpp @@ -0,0 +1,22 @@ +#ifndef __URDE_CPVSAREASET_HPP__ +#define __URDE_CPVSAREASET_HPP__ + +#include "RetroTypes.hpp" + +namespace urde +{ + +class CPVSAreaSet +{ + struct CPVSAreaHolder + { + CPVSAreaHolder(CInputStream& in); + }; + std::vector xunk; +public: + CPVSAreaSet(CInputStream& in); +}; + +} + +#endif // __URDE_CPVSAREASET_HPP__ diff --git a/Runtime/Graphics/CPVSBounds.cpp b/Runtime/Graphics/CPVSBounds.cpp new file mode 100644 index 000000000..ad0a5d8fb --- /dev/null +++ b/Runtime/Graphics/CPVSBounds.cpp @@ -0,0 +1,18 @@ +#include "CPVSBounds.hpp" + +namespace urde +{ + +CPVSBounds::CPVSBounds(CInputStream& in) +{ +} + +u32 CPVSBounds::GetBoundsFileSize() +{ +} + +bool CPVSBounds::PointInBounds(const zeus::CVector3f&) const +{ +} + +} diff --git a/Runtime/Graphics/CPVSBounds.hpp b/Runtime/Graphics/CPVSBounds.hpp new file mode 100644 index 000000000..59f9b9847 --- /dev/null +++ b/Runtime/Graphics/CPVSBounds.hpp @@ -0,0 +1,20 @@ +#ifndef __URDE_CPVSBOUNDS_HPP__ +#define __URDE_CPVSBOUNDS_HPP__ + +#include "RetroTypes.hpp" +#include "zeus/CVector3f.hpp" + +namespace urde +{ + +class CPVSBounds +{ +public: + CPVSBounds(CInputStream& in); + u32 GetBoundsFileSize(); + bool PointInBounds(const zeus::CVector3f&) const; +}; + +} + +#endif // __URDE_CPVSBOUNDS_HPP__ diff --git a/Runtime/Graphics/CPVSVisOctree.cpp b/Runtime/Graphics/CPVSVisOctree.cpp new file mode 100644 index 000000000..a9c74393c --- /dev/null +++ b/Runtime/Graphics/CPVSVisOctree.cpp @@ -0,0 +1,25 @@ +#include "CPVSVisOctree.hpp" + +namespace urde +{ + +CPVSVisOctree::CPVSVisOctree(CInputStream& in) +{ +} + +u32 CPVSVisOctree::GetNumChildren(const unsigned char*) const +{ + return 0; +} + +u32 CPVSVisOctree::GetChildIndex(const unsigned char*, const zeus::CVector3f&) const +{ + return 0; +} + +u32 CPVSVisOctree::SetTestPoint(const zeus::CVector3f&) const +{ + return 0; +} + +} diff --git a/Runtime/Graphics/CPVSVisOctree.hpp b/Runtime/Graphics/CPVSVisOctree.hpp new file mode 100644 index 000000000..4d75f2581 --- /dev/null +++ b/Runtime/Graphics/CPVSVisOctree.hpp @@ -0,0 +1,21 @@ +#ifndef __URDE_CPVSVISOCTREE_HPP__ +#define __URDE_CPVSVISOCTREE_HPP__ + +#include "RetroTypes.hpp" +#include "zeus/CVector3f.hpp" + +namespace urde +{ + +class CPVSVisOctree +{ +public: + CPVSVisOctree(CInputStream& in); + u32 GetNumChildren(const unsigned char*) const; + u32 GetChildIndex(const unsigned char*, const zeus::CVector3f&) const; + u32 SetTestPoint(const zeus::CVector3f&) const; +}; + +} + +#endif // __URDE_CPVSVISOCTREE_HPP__ diff --git a/Runtime/Graphics/CPVSVisSet.cpp b/Runtime/Graphics/CPVSVisSet.cpp new file mode 100644 index 000000000..327bc0b24 --- /dev/null +++ b/Runtime/Graphics/CPVSVisSet.cpp @@ -0,0 +1,23 @@ +#include "CPVSVisSet.hpp" + +namespace urde +{ + +void CPVSVisSet::Reset(bool) +{ +} + +bool CPVSVisSet::GetVisible(int) +{ + return false; +} + +void CPVSVisSet::SetVisible(int,bool) +{ +} + +void CPVSVisSet::SetFromMemory(const unsigned char*) +{ +} + +} diff --git a/Runtime/Graphics/CPVSVisSet.hpp b/Runtime/Graphics/CPVSVisSet.hpp new file mode 100644 index 000000000..892a9c4cd --- /dev/null +++ b/Runtime/Graphics/CPVSVisSet.hpp @@ -0,0 +1,27 @@ +#ifndef __URDE_CPVSVISSET_HPP__ +#define __URDE_CPVSVISSET_HPP__ + +#include "RetroTypes.hpp" +#include + +namespace urde +{ + +class CPVSVisSet +{ + int x0_bitCount; + int x4_setCount = 0; + std::vector x8_bitset; +public: + CPVSVisSet(int count) : x0_bitCount(count) {} + CPVSVisSet(int a, std::vector&& bitset) + : x0_bitCount(1), x4_setCount(a), x8_bitset(std::move(bitset)) {} + void Reset(bool); + bool GetVisible(int); + void SetVisible(int,bool); + void SetFromMemory(const unsigned char*); +}; + +} + +#endif // __URDE_CPVSVISSET_HPP__ diff --git a/Runtime/Graphics/IRenderer.hpp b/Runtime/Graphics/IRenderer.hpp index 8d088181d..8dcad859c 100644 --- a/Runtime/Graphics/IRenderer.hpp +++ b/Runtime/Graphics/IRenderer.hpp @@ -17,6 +17,7 @@ class CAreaOctTree; class CParticleGen; class CModel; class CSkinnedModel; +class CPVSVisSet; class IRenderer { @@ -41,10 +42,12 @@ public: virtual ~IRenderer() = default; virtual void AddStaticGeometry(const std::vector*, const CAreaOctTree*, int)=0; + virtual void EnablePVS(const CPVSVisSet*, u32)=0; + virtual void DisablePVS()=0; virtual void RemoveStaticGeometry(const std::vector*)=0; - virtual void DrawUnsortedGeometry(const std::vector&, int, unsigned int, unsigned int)=0; - virtual void DrawSortedGeometry(const std::vector&, int, unsigned int, unsigned int)=0; - virtual void DrawStaticGeometry(const std::vector&, int, unsigned int, unsigned int)=0; + virtual void DrawUnsortedGeometry(const std::vector&, int, int)=0; + virtual void DrawSortedGeometry(const std::vector&, int, int)=0; + virtual void DrawStaticGeometry(const std::vector&, int, int)=0; virtual void PostRenderFogs()=0; virtual void AddParticleGen(const CParticleGen&)=0; virtual void AddPlaneObject(const void*, const zeus::CAABox&, const zeus::CPlane&, int)=0;