2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-05-13 16:31:21 +00:00

Migrate to DolphinCGraphics impl & cleanup old code

aurora now uses the original model buffers, but
byteswapped. Migrates over to the updated impl.
This commit is contained in:
Luke Street 2025-04-14 17:26:25 -06:00
parent bae47ea4c4
commit 5c21e48920
229 changed files with 3029 additions and 23239 deletions

View File

@ -328,7 +328,7 @@ set(ZLIB_LIBRARIES ZLIB::ZLIB CACHE STRING "zlib libraries" FORCE)
include(ExternalProject) include(ExternalProject)
ExternalProject_Add(bintoc ExternalProject_Add(bintoc
SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/bintoc" SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/bintoc"
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE} -DVCPKG_TARGET_TRIPLET:STRING=${VCPKG_TARGET_TRIPLET}
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config Release --target install) INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config Release --target install)
include(${CMAKE_CURRENT_LIST_DIR}/bintoc/bintocHelpers.cmake) include(${CMAKE_CURRENT_LIST_DIR}/bintoc/bintocHelpers.cmake)

View File

@ -1049,8 +1049,7 @@ void CAutoMapper::ProcessControllerInput(const CFinalInput& input, CStateManager
x308_textpane_instructions2->TextSupport().SetText(u""); x308_textpane_instructions2->TextSupport().SetText(u"");
} else { } else {
x2fc_textpane_hint->TextSupport().SetText(u""); x2fc_textpane_hint->TextSupport().SetText(u"");
std::u16string str = std::u16string str = fmt::format(u"&image=SI,0.6,1.0,{};", g_tweakPlayerRes->x24_lStick[x2e4_lStickPos]);
fmt::format(u"&image=SI,0.6,1.0,{};", g_tweakPlayerRes->x24_lStick[x2e4_lStickPos]);
str += g_MainStringTable->GetString(46 + (!g_Main->IsUSA() || g_Main->IsTrilogy())); // Rotate str += g_MainStringTable->GetString(46 + (!g_Main->IsUSA() || g_Main->IsTrilogy())); // Rotate
x300_textpane_instructions->TextSupport().SetText(str); x300_textpane_instructions->TextSupport().SetText(str);
str = fmt::format(u"&image=SI,0.6,1.0,{};", g_tweakPlayerRes->x4c_cStick[x2e8_rStickPos]); str = fmt::format(u"&image=SI,0.6,1.0,{};", g_tweakPlayerRes->x4c_cStick[x2e8_rStickPos]);
@ -1083,8 +1082,7 @@ void CAutoMapper::ProcessControllerInput(const CFinalInput& input, CStateManager
} }
} }
if (input.PZ() || input.PSpecialKey(ESpecialKey::Tab) || input.PB() || if (input.PZ() || input.PSpecialKey(ESpecialKey::Tab) || input.PB() || input.PSpecialKey(ESpecialKey::Esc)) {
input.PSpecialKey(ESpecialKey::Esc)) {
if (x328_ == 0) { if (x328_ == 0) {
if (CanLeaveMapScreenInternal(mgr)) { if (CanLeaveMapScreenInternal(mgr)) {
LeaveMapScreen(mgr); LeaveMapScreen(mgr);
@ -1295,8 +1293,9 @@ void CAutoMapper::Update(float dt, CStateManager& mgr) {
void CAutoMapper::Draw(const CStateManager& mgr, const zeus::CTransform& xf, float alpha) { void CAutoMapper::Draw(const CStateManager& mgr, const zeus::CTransform& xf, float alpha) {
SCOPED_GRAPHICS_DEBUG_GROUP("CAutoMapper::Draw", zeus::skPurple); SCOPED_GRAPHICS_DEBUG_GROUP("CAutoMapper::Draw", zeus::skPurple);
alpha *= g_GameState->GameOptions().GetHUDAlpha() / 255.f; alpha *= g_GameState->GameOptions().GetHUDAlpha() / 255.f;
// Blend mode alpha g_Renderer->SetBlendMode_AlphaBlended();
// Backface cull CGraphics::SetCullMode(ERglCullMode::Front);
float alphaInterp; float alphaInterp;
if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) { if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) {
alphaInterp = 1.f; alphaInterp = 1.f;
@ -1496,9 +1495,10 @@ void CAutoMapper::Draw(const CStateManager& mgr, const zeus::CTransform& xf, flo
} }
} }
// No zread, no zwrite g_Renderer->SetDepthReadWrite(false, false);
// Ambient color white g_Renderer->SetAmbientColor(zeus::skWhite);
// Disable all lights CGraphics::DisableAllLights();
if (m_frmeInitialized) { if (m_frmeInitialized) {
float frmeAlpha = 0.f; float frmeAlpha = 0.f;
if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) { if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) {

View File

@ -8,6 +8,7 @@
#include "Runtime/GameGlobalObjects.hpp" #include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/World/CWorld.hpp" #include "Runtime/World/CWorld.hpp"
#include "Runtime/CBasics.hpp" #include "Runtime/CBasics.hpp"
#include "Runtime/Graphics/CGX.hpp"
namespace metaforce { namespace metaforce {
constexpr std::array<zeus::CVector3f, 3> MinesPostTransforms{{ constexpr std::array<zeus::CVector3f, 3> MinesPostTransforms{{
@ -101,49 +102,10 @@ void CMapArea::PostConstruct() {
tmp += 12; tmp += 12;
} }
std::vector<u32> index;
m_surfaces.reserve(x30_surfaceCount); m_surfaces.reserve(x30_surfaceCount);
for (u32 i = 0, j = 0; i < x30_surfaceCount; ++i, j += 32) { for (u32 i = 0, j = 0; i < x30_surfaceCount; ++i, j += 32) {
m_surfaces.emplace_back(x40_surfaceStart + j).PostConstruct(x44_buf.get(), index); m_surfaces.emplace_back(x40_surfaceStart + j).PostConstruct(x44_buf.get());
} }
// CGraphics::CommitResources([this, &index](boo::IGraphicsDataFactory::Context& ctx) {
// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, m_verts.data(), 16, m_verts.size());
// m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, index.data(), 4, index.size());
//
// /* Only the map universe specifies Always; it draws a maximum of 1016 instances */
// size_t instCount = (xc_visibilityMode == EVisMode::Always) ? 1024 : 1;
//
// for (u32 i = 0; i < x30_surfaceCount; ++i) {
// CMapAreaSurface& surf = m_surfaces[i];
// surf.m_instances.reserve(instCount);
// for (u32 inst = 0; inst < instCount; ++inst) {
// CMapAreaSurface::Instance& instance = surf.m_instances.emplace_back(ctx, m_vbo, m_ibo);
//
// athena::io::MemoryReader r(surf.x1c_outlineOffset, INT_MAX);
// u32 outlineCount = r.ReadLong();
//
// std::vector<CLineRenderer>& linePrims = instance.m_linePrims;
// linePrims.reserve(outlineCount * 2);
// for (u32 j = 0; j < 2; ++j) {
// r.seek(4, athena::SeekOrigin::Begin);
// for (u32 k = 0; k < outlineCount; ++k) {
// const u32 count = r.ReadLong();
// r.seek(count);
// r.seekAlign4();
// linePrims.emplace_back(ctx, CLineRenderer::EPrimitiveMode::LineStrip, count, nullptr, false, false, true);
// }
// }
// }
// }
//
// for (u32 i = 0; i < x28_mappableObjCount; ++i) {
// CMappableObject& mapObj = m_mappableObjects[i];
// if (CMappableObject::IsDoorType(mapObj.GetType()))
// mapObj.CreateDoorSurface(ctx);
// }
// return true;
// } BooTrace);
} }
bool CMapArea::GetIsVisibleToAutoMapper(bool worldVis, bool areaVis) const { bool CMapArea::GetIsVisibleToAutoMapper(bool worldVis, bool areaVis) const {
@ -183,129 +145,87 @@ CMapArea::CMapAreaSurface::CMapAreaSurface(const void* surfBuf) {
CMemoryInStream r(surfBuf, 32, CMemoryInStream::EOwnerShip::NotOwned); CMemoryInStream r(surfBuf, 32, CMemoryInStream::EOwnerShip::NotOwned);
x0_normal = r.Get<zeus::CVector3f>(); x0_normal = r.Get<zeus::CVector3f>();
xc_centroid = r.Get<zeus::CVector3f>(); xc_centroid = r.Get<zeus::CVector3f>();
x18_surfOffset = reinterpret_cast<const u8*>(uintptr_t(r.ReadLong())); x18_surfOffset = reinterpret_cast<const u32*>(static_cast<uintptr_t>(r.ReadLong()));
x1c_outlineOffset = reinterpret_cast<const u8*>(uintptr_t(r.ReadLong())); x1c_outlineOffset = reinterpret_cast<const u32*>(static_cast<uintptr_t>(r.ReadLong()));
} }
void CMapArea::CMapAreaSurface::PostConstruct(const u8* buf, std::vector<u32>& index) { void CMapArea::CMapAreaSurface::PostConstruct(const void* buf) {
x18_surfOffset = buf + reinterpret_cast<uintptr_t>(x18_surfOffset); x18_surfOffset =
x1c_outlineOffset = buf + reinterpret_cast<uintptr_t>(x1c_outlineOffset); reinterpret_cast<const u32*>(static_cast<const u8*>(buf) + reinterpret_cast<uintptr_t>(x18_surfOffset));
x1c_outlineOffset =
m_primStart = index.size(); reinterpret_cast<const u32*>(static_cast<const u8*>(buf) + reinterpret_cast<uintptr_t>(x1c_outlineOffset));
bool start = true;
{
CMemoryInStream r(x18_surfOffset, INT_MAX, CMemoryInStream::EOwnerShip::NotOwned);
u32 primCount = r.ReadLong();
for (u32 i = 0; i < primCount; ++i) {
GXPrimitive prim = GXPrimitive(r.ReadLong());
u32 count = r.ReadLong();
switch (prim) {
case GX_TRIANGLES: {
for (u32 v = 0; v < count; v += 3) {
if (!start) {
index.push_back(index.back());
index.push_back(r.ReadUint8());
index.push_back(index.back());
} else {
index.push_back(r.ReadUint8());
start = false;
}
index.push_back(r.ReadUint8());
index.push_back(r.ReadUint8());
index.push_back(index.back());
}
break;
}
case GX_TRIANGLESTRIP: {
if (!start) {
index.push_back(index.back());
index.push_back(r.ReadUint8());
index.push_back(index.back());
} else {
index.push_back(r.ReadUint8());
start = false;
}
for (u32 v = 1; v < count; ++v)
index.push_back(r.ReadUint8());
if (count & 1)
index.push_back(index.back());
break;
}
case GX_TRIANGLEFAN: {
u8 firstVert = r.ReadUint8();
if (!start) {
index.push_back(index.back());
index.push_back(r.ReadUint8());
} else {
index.push_back(r.ReadUint8());
index.push_back(index.back());
start = false;
}
for (u32 v = 1; v < count; ++v) {
index.push_back(firstVert);
index.push_back(r.ReadUint8());
}
break;
}
default:
break;
}
u32 pos = r.GetReadPosition();
while (r.GetReadPosition() != ROUND_UP_4(pos)) {
r.ReadUint8();
}
}
}
m_primCount = index.size() - m_primStart;
} }
void CMapArea::CMapAreaSurface::Draw(const zeus::CVector3f* verts, const zeus::CColor& surfColor, void CMapArea::CMapAreaSurface::Draw(TConstVectorRef verts, const CColor& surfColor, const CColor& lineColor,
const zeus::CColor& lineColor, float lineWidth, size_t instIdx) { float lineWidth) const {
if (instIdx >= m_instances.size()) { bool hasSurfAlpha = surfColor.a() > 0.0f;
return; bool hasLineAlpha = lineColor.a() > 0.0f;
u32 numSurfaces = CBasics::SwapBytes(*x18_surfOffset);
u32 numOutlines = CBasics::SwapBytes(*x1c_outlineOffset);
if (!verts.empty()) {
CGX::SetArray(GX_VA_POS, verts);
} }
if (hasSurfAlpha) {
CGX::SetTevKColor(GX_KCOLOR0, surfColor);
const u32* surface = &x18_surfOffset[1];
for (u32 i = 0; i < numSurfaces; ++i) {
GXPrimitive primType = static_cast<GXPrimitive>(CBasics::SwapBytes(*surface++));
u32 numVertices = CBasics::SwapBytes(*surface++);
const u8* data = reinterpret_cast<const u8*>(surface);
surface += ((numVertices + 3) & ~3) / 4;
Instance& instance = m_instances[instIdx]; CGX::Begin(primType, GX_VTXFMT0, numVertices);
for (u32 v = 0; v < numVertices; ++v) {
GXPosition1x8(data[v]);
}
CGX::End();
}
}
if (hasLineAlpha) {
bool thickLine = lineWidth > 1.f;
for (u32 j = 0; j < (thickLine ? 1 : 0) + 1; ++j) {
const u32* outline = &x1c_outlineOffset[1];
if (surfColor.a()) { if (thickLine) {
instance.m_surfacePrims.draw(surfColor, m_primStart, m_primCount); CGraphics::SetLineWidth(lineWidth - j, ERglTexOffset::One);
} }
CColor clr = lineColor;
if (thickLine) {
clr.a() *= 0.5f;
}
CGX::SetTevKColor(GX_KCOLOR0, clr);
if (lineColor.a()) { for (u32 i = 0; i < numOutlines; ++i) {
bool draw2 = lineWidth > 1.f; u32 numVertices = CBasics::SwapBytes(*outline++);
u32 outlineCount = *reinterpret_cast<const u32*>(x1c_outlineOffset); const u8* data = reinterpret_cast<const u8*>(outline);
#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ outline += ((numVertices + 3) & ~3) / 4;
outlineCount = CBasics::SwapBytes(outlineCount);
#endif
std::vector<CLineRenderer>& linePrims = instance.m_linePrims; CGX::Begin(GX_LINESTRIP, GX_VTXFMT0, numVertices);
zeus::CColor color = lineColor; for (u32 v = 0; v < numVertices; ++v) {
if (draw2) GXPosition1x8(data[v]);
color.a() *= 0.5f; }
float width = lineWidth; CGX::End();
}
}
}
}
auto primIt = linePrims.begin(); void CMapArea::CMapAreaSurface::SetupGXMaterial() {
for (u32 j = 0; j <= u32(draw2); ++j) { const GXVtxDescList list[2] = {
CMemoryInStream r(x1c_outlineOffset, INT_MAX, CMemoryInStream::EOwnerShip::NotOwned); {GX_VA_POS, GX_INDEX8},
r.ReadLong(); {GX_VA_NULL, GX_NONE},
for (u32 i = 0; i < outlineCount; ++i) { };
CLineRenderer& prim = *primIt++; CGX::SetVtxDescv(list);
prim.Reset(); CGX::SetNumChans(1);
u32 count = r.ReadLong(); CGX::SetNumTexGens(0);
for (u32 v = 0; v < count; ++v) { CGX::SetNumTevStages(1);
u8 idx = r.ReadUint8(); CGX::SetChanCtrl(CGX::EChannelId::Channel0, false, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE);
prim.AddVertex(verts[idx], color, width); CGX::SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_KONST);
} CGX::SetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_KONST);
CGX::SetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, true, GX_TEVPREV);
u32 pos = r.GetReadPosition(); CGX::SetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, true, GX_TEVPREV);
while (r.GetReadPosition() != ROUND_UP_4(pos)) { CGX::SetTevKColorSel(GX_TEVSTAGE0, GX_TEV_KCSEL_K0);
r.ReadUint8(); CGX::SetTevKAlphaSel(GX_TEVSTAGE0, GX_TEV_KASEL_K0_A);
}
prim.Render();
}
width -= 1.f;
}
}
} }
CFactoryFnReturn FMapAreaFactory(const SObjectTag& objTag, CInputStream& in, const CVParamTransfer&, CFactoryFnReturn FMapAreaFactory(const SObjectTag& objTag, CInputStream& in, const CVParamTransfer&,

View File

@ -3,46 +3,38 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "Runtime/Graphics/CCubeModel.hpp"
#include "Runtime/AutoMapper/CMappableObject.hpp" #include "Runtime/AutoMapper/CMappableObject.hpp"
#include "Runtime/CResFactory.hpp" #include "Runtime/CResFactory.hpp"
#include "Runtime/Graphics/CLineRenderer.hpp"
#include "Runtime/Graphics/Shaders/CMapSurfaceShader.hpp"
#include "Runtime/RetroTypes.hpp" #include "Runtime/RetroTypes.hpp"
#include <zeus/CAABox.hpp> #include <zeus/CAABox.hpp>
#include <zeus/CVector3f.hpp> #include <zeus/CVector3f.hpp>
namespace metaforce { namespace metaforce {
using CColor = zeus::CColor;
using CVector3f = zeus::CVector3f;
class IWorld; class IWorld;
class CMapArea { class CMapArea {
public: public:
class CMapAreaSurface { class CMapAreaSurface {
friend class CMapArea; friend class CMapArea;
zeus::CVector3f x0_normal; CVector3f x0_normal;
zeus::CVector3f xc_centroid; CVector3f xc_centroid;
const u8* x18_surfOffset; const u32* x18_surfOffset;
const u8* x1c_outlineOffset; const u32* x1c_outlineOffset;
u32 m_primStart;
u32 m_primCount;
struct Instance {
CMapSurfaceShader m_surfacePrims;
std::vector<CLineRenderer> m_linePrims;
Instance(std::vector<zeus::CVector3f> vbo,
std::vector<u16> ibo)
: m_surfacePrims(vbo, ibo) {}
Instance(Instance&&) = default;
Instance& operator=(Instance&&) = default;
};
std::vector<Instance> m_instances;
public: public:
explicit CMapAreaSurface(const void* surfBuf); explicit CMapAreaSurface(const void* surfBuf);
CMapAreaSurface(CMapAreaSurface&&) = default;
void PostConstruct(const u8* buf, std::vector<u32>& index); void PostConstruct(const void* buf);
void Draw(const zeus::CVector3f* verts, const zeus::CColor& surfColor, const zeus::CColor& lineColor, void Draw(TConstVectorRef verts, const CColor& surfColor, const CColor& lineColor, float lineWidth) const;
float lineWidth, size_t instIdx = 0);
const zeus::CVector3f& GetNormal() const { return x0_normal; } static void SetupGXMaterial();
const zeus::CVector3f& GetCenterPosition() const { return xc_centroid; }
const CVector3f& GetNormal() const { return x0_normal; }
const CVector3f& GetCenterPosition() const { return xc_centroid; }
}; };
enum class EVisMode { Always, MapStationOrVisit, Visit, Never }; enum class EVisMode { Always, MapStationOrVisit, Visit, Never };
@ -59,12 +51,10 @@ private:
u8* x38_moStart; u8* x38_moStart;
std::vector<CMappableObject> m_mappableObjects; std::vector<CMappableObject> m_mappableObjects;
u8* x3c_vertexStart; u8* x3c_vertexStart;
std::vector<zeus::CVector3f> m_verts; std::vector<aurora::Vec3<float>> m_verts;
u8* x40_surfaceStart; u8* x40_surfaceStart;
std::vector<CMapAreaSurface> m_surfaces; std::vector<CMapAreaSurface> m_surfaces;
std::unique_ptr<u8[]> x44_buf; std::unique_ptr<u8[]> x44_buf;
// boo::ObjToken<boo::IGraphicsBufferS> m_vbo;
// boo::ObjToken<boo::IGraphicsBufferS> m_ibo;
public: public:
explicit CMapArea(CInputStream& in, u32 size); explicit CMapArea(CInputStream& in, u32 size);
@ -80,7 +70,7 @@ public:
u32 GetNumSurfaces() const { return m_surfaces.size(); } u32 GetNumSurfaces() const { return m_surfaces.size(); }
zeus::CTransform GetAreaPostTransform(const IWorld& world, TAreaId aid) const; zeus::CTransform GetAreaPostTransform(const IWorld& world, TAreaId aid) const;
static const zeus::CVector3f& GetAreaPostTranslate(const IWorld& world, TAreaId aid); static const zeus::CVector3f& GetAreaPostTranslate(const IWorld& world, TAreaId aid);
const zeus::CVector3f* GetVertices() const { return m_verts.data(); } TConstVectorRef GetVertices() const { return m_verts; }
}; };
CFactoryFnReturn FMapAreaFactory(const SObjectTag& objTag, CInputStream& in, const CVParamTransfer&, CObjectReference*); CFactoryFnReturn FMapAreaFactory(const SObjectTag& objTag, CInputStream& in, const CVParamTransfer&, CObjectReference*);

View File

@ -85,7 +85,6 @@ void CMapUniverse::Draw(const CMapUniverseDrawParms& parms, const zeus::CVector3
int lastWldIdx = -1; int lastWldIdx = -1;
int lastHexIdx = -1; int lastHexIdx = -1;
size_t instIdx = 0;
for (const CMapObjectSortInfo& info : sortInfos) { for (const CMapObjectSortInfo& info : sortInfos) {
const CMapWorldData& mwData = x10_worldDatas[info.GetWorldIndex()]; const CMapWorldData& mwData = x10_worldDatas[info.GetWorldIndex()];
zeus::CColor surfColor = info.GetSurfaceColor(); zeus::CColor surfColor = info.GetSurfaceColor();
@ -110,7 +109,7 @@ void CMapUniverse::Draw(const CMapUniverseDrawParms& parms, const zeus::CVector3
if (info.GetAreaIndex() != lastHexIdx || info.GetWorldIndex() != lastWldIdx) if (info.GetAreaIndex() != lastHexIdx || info.GetWorldIndex() != lastWldIdx)
CGraphics::SetModelMatrix(parms.GetPaneProjectionTransform() * mwData.GetMapAreaData(info.GetAreaIndex())); CGraphics::SetModelMatrix(parms.GetPaneProjectionTransform() * mwData.GetMapAreaData(info.GetAreaIndex()));
surf.Draw(x4_hexagonToken->GetVertices(), surfColor, outlineColor, 2.f, instIdx++); surf.Draw(x4_hexagonToken->GetVertices(), surfColor, outlineColor, 2.f);
} }
} }

View File

@ -8,6 +8,7 @@
#include "Runtime/GameGlobalObjects.hpp" #include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/AutoMapper/CMapWorldInfo.hpp" #include "Runtime/AutoMapper/CMapWorldInfo.hpp"
#include "Runtime/World/CWorld.hpp" #include "Runtime/World/CWorld.hpp"
#include "Runtime/Graphics/CCubeRenderer.hpp"
namespace metaforce { namespace metaforce {
namespace { namespace {
@ -460,8 +461,8 @@ bool CMapWorld::IsMapAreaValid(const IWorld& wld, int areaIdx, bool checkLoad) c
void CMapWorld::DrawAreas(const CMapWorldDrawParms& parms, int selArea, const std::vector<CMapAreaBFSInfo>& bfsInfos, void CMapWorld::DrawAreas(const CMapWorldDrawParms& parms, int selArea, const std::vector<CMapAreaBFSInfo>& bfsInfos,
bool inMapScreen) { bool inMapScreen) {
// Alpha blend g_Renderer->SetBlendMode_AlphaBlended();
// Line width 1 CGraphics::SetLineWidth(1.f, ERglTexOffset::One);
int surfCount = 0; int surfCount = 0;
int objCount = 0; int objCount = 0;
@ -556,7 +557,7 @@ void CMapWorld::DrawAreas(const CMapWorldDrawParms& parms, int selArea, const st
u32 si = 0; u32 si = 0;
for (; i < mapa->GetNumMappableObjects(); ++i, si += 6) { for (; i < mapa->GetNumMappableObjects(); ++i, si += 6) {
const CMappableObject& obj = mapa->GetMappableObject(i); const CMappableObject& obj = mapa->GetMappableObject(i);
if (!obj.IsVisibleToAutoMapper(mwInfo.IsWorldVisible(thisArea), mwInfo)) if (!obj.GetIsVisibleToAutoMapper(mwInfo.IsWorldVisible(thisArea), mwInfo))
continue; continue;
bool doorType = CMappableObject::IsDoorType(obj.GetType()); bool doorType = CMappableObject::IsDoorType(obj.GetType());
@ -582,9 +583,11 @@ void CMapWorld::DrawAreas(const CMapWorldDrawParms& parms, int selArea, const st
} }
} }
if (!sortInfos.empty()) {
std::sort(sortInfos.begin(), sortInfos.end(), [](const CMapObjectSortInfo& a, const CMapObjectSortInfo& b) { std::sort(sortInfos.begin(), sortInfos.end(), [](const CMapObjectSortInfo& a, const CMapObjectSortInfo& b) {
return a.GetZDistance() > b.GetZDistance(); return a.GetZDistance() > b.GetZDistance();
}); });
CMapArea::CMapAreaSurface::SetupGXMaterial();
u32 lastAreaIdx = UINT32_MAX; u32 lastAreaIdx = UINT32_MAX;
CMapObjectSortInfo::EObjectCode lastType = CMapObjectSortInfo::EObjectCode::Invalid; CMapObjectSortInfo::EObjectCode lastType = CMapObjectSortInfo::EObjectCode::Invalid;
@ -636,6 +639,7 @@ void CMapWorld::DrawAreas(const CMapWorldDrawParms& parms, int selArea, const st
lastType = info.GetObjectCode(); lastType = info.GetObjectCode();
} }
} }
}
} }
void CMapWorld::RecalculateWorldSphere(const CMapWorldInfo& mwInfo, const IWorld& wld) { void CMapWorld::RecalculateWorldSphere(const CMapWorldInfo& mwInfo, const IWorld& wld) {

View File

@ -1,19 +1,41 @@
#include "Runtime/AutoMapper/CMappableObject.hpp" #include "Runtime/AutoMapper/CMappableObject.hpp"
#include "Runtime/AutoMapper/CMapWorldInfo.hpp" #include "Runtime/AutoMapper/CMapWorldInfo.hpp"
#include "Runtime/AutoMapper/CMapArea.hpp"
#include "Runtime/CSimplePool.hpp" #include "Runtime/CSimplePool.hpp"
#include "Runtime/CToken.hpp" #include "Runtime/CToken.hpp"
#include "Runtime/Camera/CCameraFilter.hpp"
#include "Runtime/GameGlobalObjects.hpp" #include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Graphics/CGX.hpp"
#include "Runtime/Graphics/CTexture.hpp" #include "Runtime/Graphics/CTexture.hpp"
namespace metaforce { namespace metaforce {
std::array<zeus::CVector3f, 8> CMappableObject::skDoorVerts{}; using zeus::CColor;
using zeus::CVector3f;
using uchar = unsigned char;
std::array<u16, 24> CMappableObject::skDoorIndices{ struct SDrawData {
6, 4, 2, 0, 3, 1, 7, 5, 1, 0, 5, 4, 7, 6, 3, 2, 3, 2, 1, 0, 5, 4, 7, 6, float x0_x;
float x4_y;
float x8_z;
uchar xc_idxA;
uchar xd_idxB;
uchar xe_idxC;
uchar xf_idxD;
}; };
static const SDrawData sDrawData[6] = {
// clang-format off
{ 0.f, 0.f, -1.f, 6, 4, 2, 0},
{ 0.f, 0.f, 1.f, 3, 1, 7, 5},
{ 0.f, -1.f, 1.f, 1, 0, 5, 4},
{ 0.f, 1.f, 1.f, 7, 6, 3, 2},
{-1.f, 0.f, 0.f, 3, 2, 1, 0},
{ 1.f, 0.f, 0.f, 5, 4, 7, 6},
// clang-format on
};
static std::array<aurora::Vec3<float>, 8> skDoorVerts{};
CMappableObject::CMappableObject(const void* buf) { CMappableObject::CMappableObject(const void* buf) {
CMemoryInStream r(buf, 64); CMemoryInStream r(buf, 64);
x0_type = EMappableObjectType(r.ReadLong()); x0_type = EMappableObjectType(r.ReadLong());
@ -24,11 +46,11 @@ CMappableObject::CMappableObject(const void* buf) {
} }
zeus::CTransform CMappableObject::AdjustTransformForType() const { zeus::CTransform CMappableObject::AdjustTransformForType() const {
const float doorCenterX = g_tweakAutoMapper->GetDoorCenter().x(); const float doorCenterX = g_tweakAutoMapper->xa4_doorCenterA;
const float doorCenterZ = g_tweakAutoMapper->GetDoorCenter().z(); const float doorCenterZ = g_tweakAutoMapper->xac_doorCenterC;
if (x0_type == EMappableObjectType::BigDoor1) { if (x0_type == EMappableObjectType::BigDoor1) {
zeus::CTransform orientation; zeus::CTransform orientation;
orientation.origin = {-1.4f * doorCenterX, 0.0f, 0.0f}; orientation.origin = {0.0f, 0.0f, -1.4f * doorCenterX};
orientation.rotateLocalZ(zeus::degToRad(90.0f)); orientation.rotateLocalZ(zeus::degToRad(90.0f));
return (x10_transform * orientation) * zeus::CTransform::Scale(zeus::CVector3f{1.5f}); return (x10_transform * orientation) * zeus::CTransform::Scale(zeus::CVector3f{1.5f});
} else if (x0_type == EMappableObjectType::BigDoor2) { } else if (x0_type == EMappableObjectType::BigDoor2) {
@ -54,15 +76,15 @@ zeus::CTransform CMappableObject::AdjustTransformForType() const {
orientation.origin = {-0.49f * doorCenterX, 0.f, -1.f * doorCenterZ}; orientation.origin = {-0.49f * doorCenterX, 0.f, -1.f * doorCenterZ};
orientation.rotateLocalY(zeus::degToRad(90.f)); orientation.rotateLocalY(zeus::degToRad(90.f));
return x10_transform * orientation; return x10_transform * orientation;
} else if (x0_type >= EMappableObjectType::BlueDoor && x0_type <= EMappableObjectType::PlasmaDoorFloor2) { } else if (IsDoorType(x0_type)) {
return x10_transform; return x10_transform;
} }
return zeus::CTransform::Translate(x10_transform.origin); return zeus::CTransform::Translate(x10_transform.origin);
} }
std::pair<zeus::CColor, zeus::CColor> CMappableObject::GetDoorColors(int curAreaId, const CMapWorldInfo& mwInfo, std::pair<CColor, CColor> CMappableObject::GetDoorColors(int curAreaId, const CMapWorldInfo& mwInfo,
float alpha) const { float alpha) const {
zeus::CColor color = {1.f, 0.f, 1.f, 1.f}; CColor color;
if (x8_objId.AreaNum() == curAreaId) { if (x8_objId.AreaNum() == curAreaId) {
if (mwInfo.IsDoorVisited(x8_objId) && x0_type == EMappableObjectType::ShieldDoor) { if (mwInfo.IsDoorVisited(x8_objId) && x0_type == EMappableObjectType::ShieldDoor) {
color = g_tweakAutoMapper->GetDoorColor(0); color = g_tweakAutoMapper->GetDoorColor(0);
@ -102,7 +124,7 @@ std::pair<zeus::CColor, zeus::CColor> CMappableObject::GetDoorColors(int curArea
} }
color.a() *= alpha; color.a() *= alpha;
return {color, zeus::CColor(std::min(1.4f * color.r(), 1.f), std::min(1.4f * color.g(), 1.f), return {color, CColor(std::min(1.4f * color.r(), 1.f), std::min(1.4f * color.g(), 1.f),
std::min(1.4f * color.b(), 1.f), std::min(1.4f * color.a(), 1.f))}; std::min(1.4f * color.b(), 1.f), std::min(1.4f * color.a(), 1.f))};
} }
@ -110,48 +132,58 @@ void CMappableObject::PostConstruct(const void*) { x10_transform = AdjustTransfo
void CMappableObject::Draw(int curArea, const CMapWorldInfo& mwInfo, float alpha, bool needsVtxLoad) { void CMappableObject::Draw(int curArea, const CMapWorldInfo& mwInfo, float alpha, bool needsVtxLoad) {
SCOPED_GRAPHICS_DEBUG_GROUP("CMappableObject::Draw", zeus::skCyan); SCOPED_GRAPHICS_DEBUG_GROUP("CMappableObject::Draw", zeus::skCyan);
if (IsDoorType(x0_type)) { if (IsDoorType(x0_type) == true) {
std::pair<zeus::CColor, zeus::CColor> colors = GetDoorColors(curArea, mwInfo, alpha); std::pair<CColor, CColor> colors = GetDoorColors(curArea, mwInfo, alpha);
// TODO for (int i = 0; i < 6; ++i) {
// for (int s = 0; s < 6; ++s) { if (needsVtxLoad) {
// DoorSurface& ds = *m_doorSurface; CGX::SetArray(GX_VA_POS, skDoorVerts);
// ds.m_surface.draw(colors.first, s * 4, 4); }
// CLineRenderer& line = ds.m_outline; CGX::SetTevKColor(GX_KCOLOR0, colors.first);
// const u16* baseIdx = &skDoorIndices[s * 4]; CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4);
// line.Reset(); GXPosition1x8(sDrawData[i].xc_idxA);
// line.AddVertex(skDoorVerts[baseIdx[0]], colors.second, 1.f); GXPosition1x8(sDrawData[i].xd_idxB);
// line.AddVertex(skDoorVerts[baseIdx[1]], colors.second, 1.f); GXPosition1x8(sDrawData[i].xe_idxC);
// line.AddVertex(skDoorVerts[baseIdx[3]], colors.second, 1.f); GXPosition1x8(sDrawData[i].xf_idxD);
// line.AddVertex(skDoorVerts[baseIdx[2]], colors.second, 1.f); CGX::End();
// line.Render();
// } CGX::SetTevKColor(GX_KCOLOR0, colors.second);
} else { CGX::Begin(GX_LINESTRIP, GX_VTXFMT0, 5);
GXPosition1x8(sDrawData[i].xc_idxA);
GXPosition1x8(sDrawData[i].xd_idxB);
GXPosition1x8(sDrawData[i].xf_idxD);
GXPosition1x8(sDrawData[i].xe_idxC);
GXPosition1x8(sDrawData[i].xc_idxA);
CGX::End();
}
return;
}
CAssetId iconRes; CAssetId iconRes;
zeus::CColor iconColor = zeus::skWhite; CColor iconColor = CColor(0xffffffffu);
switch (x0_type) { switch (x0_type) {
case EMappableObjectType::DownArrowYellow: case EMappableObjectType::DownArrowYellow:
iconColor = CColor(0xffff96ffu);
iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon; iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon;
iconColor = zeus::CColor{1.f, 1.f, 0.588f, 1.f};
break; break;
case EMappableObjectType::UpArrowYellow: case EMappableObjectType::UpArrowYellow:
iconColor = CColor(0xffff96ffu);
iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon; iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon;
iconColor = zeus::CColor{1.f, 1.f, 0.588f, 1.f};
break; break;
case EMappableObjectType::DownArrowGreen: case EMappableObjectType::DownArrowGreen:
iconColor = CColor(0x64ff96ffu);
iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon; iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon;
iconColor = zeus::CColor{0.392f, 1.f, 0.588f, 1.f};
break; break;
case EMappableObjectType::UpArrowGreen: case EMappableObjectType::UpArrowGreen:
iconColor = CColor(0x64ff96ffu);
iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon; iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon;
iconColor = zeus::CColor{0.392f, 1.f, 0.588f, 1.f};
break; break;
case EMappableObjectType::DownArrowRed: case EMappableObjectType::DownArrowRed:
iconColor = CColor(0xff6496ffu);
iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon; iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon;
iconColor = zeus::CColor{1.f, 0.392f, 0.588f, 1.f};
break; break;
case EMappableObjectType::UpArrowRed: case EMappableObjectType::UpArrowRed:
iconColor = CColor(0xff6496ffu);
iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon; iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon;
iconColor = zeus::CColor{1.f, 0.392f, 0.588f, 1.f};
break; break;
case EMappableObjectType::SaveStation: case EMappableObjectType::SaveStation:
iconRes = g_tweakPlayerRes->x4_saveStationIcon; iconRes = g_tweakPlayerRes->x4_saveStationIcon;
@ -164,62 +196,75 @@ void CMappableObject::Draw(int curArea, const CMapWorldInfo& mwInfo, float alpha
break; break;
} }
iconColor.a() *= alpha; TLockedToken<CTexture> tex = g_SimplePool->GetObj(SObjectTag('TXTR', iconRes));
tex->Load(GX_TEXMAP0, EClampMode::Repeat);
CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvModulate);
CGraphics::StreamBegin(ERglPrimitive::TriangleStrip);
iconColor.a() = alpha;
CGraphics::StreamColor(iconColor);
CGraphics::StreamTexcoord(0.0f, 1.0f);
CGraphics::StreamVertex(-2.6f, 0.0f, 2.6f);
CGraphics::StreamTexcoord(0.0f, 0.0f);
CGraphics::StreamVertex(-2.6f, 0.0f, -2.6f);
CGraphics::StreamTexcoord(1.0f, 1.0f);
CGraphics::StreamVertex(2.6f, 0.0f, 2.6f);
CGraphics::StreamTexcoord(1.0f, 0.0f);
CGraphics::StreamVertex(2.6f, 0.0f, -2.6f);
CGraphics::StreamEnd();
TLockedToken<CTexture> tex = g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), iconRes}); // Metaforce addition: restore GX state
// if (!m_texQuadFilter || m_texQuadFilter->GetTex().GetObj() != tex.GetObj()) { CMapArea::CMapAreaSurface::SetupGXMaterial();
//m_texQuadFilter.emplace(EFilterType::Add, tex, CTexturedQuadFilter::ZTest::GEqual);
// }
// constexpr std::array<CTexturedQuadFilter::Vert, 4> verts{{
// {{-2.6f, 0.f, 2.6f}, {0.f, 1.f}},
// {{-2.6f, 0.f, -2.6f}, {0.f, 0.f}},
// {{2.6f, 0.f, 2.6f}, {1.f, 1.f}},
// {{2.6f, 0.f, -2.6f}, {1.f, 0.f}},
// }};
//m_texQuadFilter->drawVerts(iconColor, verts);
}
} }
void CMappableObject::DrawDoorSurface(int curArea, const CMapWorldInfo& mwInfo, float alpha, int surfIdx, void CMappableObject::DrawDoorSurface(int curArea, const CMapWorldInfo& mwInfo, float alpha, int surfIdx,
bool needsVtxLoad) { bool needsVtxLoad) {
std::pair<zeus::CColor, zeus::CColor> colors = GetDoorColors(curArea, mwInfo, alpha); std::pair<CColor, CColor> colors = GetDoorColors(curArea, mwInfo, alpha);
// DoorSurface& ds = *m_doorSurface; const SDrawData& drawData = sDrawData[surfIdx];
// ds.m_surface.draw(colors.first, surfIdx * 4, 4); if (needsVtxLoad) {
// CLineRenderer& line = ds.m_outline; CGX::SetArray(GX_VA_POS, skDoorVerts);
// const u16* baseIdx = &skDoorIndices[surfIdx * 4];
// line.Reset();
// line.AddVertex(skDoorVerts[baseIdx[0]], colors.second, 1.f);
// line.AddVertex(skDoorVerts[baseIdx[1]], colors.second, 1.f);
// line.AddVertex(skDoorVerts[baseIdx[3]], colors.second, 1.f);
// line.AddVertex(skDoorVerts[baseIdx[2]], colors.second, 1.f);
// line.Render();
}
zeus::CVector3f CMappableObject::BuildSurfaceCenterPoint(int surfIdx) const {
const zeus::CVector3f& doorCenter = g_tweakAutoMapper->GetDoorCenter();
switch (surfIdx) {
case 0:
return x10_transform * zeus::skZero3f;
case 1:
return x10_transform * zeus::CVector3f{0.f, 0.f, 2.f * doorCenter.x()};
case 2:
return x10_transform * zeus::CVector3f{0.f, -doorCenter.y(), 0.f};
case 3:
return x10_transform * zeus::CVector3f{0.f, doorCenter.y(), 0.f};
case 4:
return x10_transform * zeus::CVector3f{-doorCenter.x(), 0.f, 0.f};
case 5:
return x10_transform * zeus::CVector3f{doorCenter.x(), 0.f, 0.f};
default:
break;
} }
return {}; CGX::SetTevKColor(GX_KCOLOR0, colors.first);
CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4);
GXPosition1x8(drawData.xc_idxA);
GXPosition1x8(drawData.xd_idxB);
GXPosition1x8(drawData.xe_idxC);
GXPosition1x8(drawData.xf_idxD);
CGX::End();
CGX::SetTevKColor(GX_KCOLOR0, colors.second);
CGX::Begin(GX_LINESTRIP, GX_VTXFMT0, 5);
GXPosition1x8(drawData.xc_idxA);
GXPosition1x8(drawData.xd_idxB);
GXPosition1x8(drawData.xf_idxD);
GXPosition1x8(drawData.xe_idxC);
GXPosition1x8(drawData.xc_idxA);
CGX::End();
} }
bool CMappableObject::IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& mwInfo) const { CVector3f CMappableObject::BuildSurfaceCenterPoint(int surfaceIdx) const {
const float x = g_tweakAutoMapper->xac_doorCenterC;
const float y = g_tweakAutoMapper->xa8_doorCenterB;
const float z = g_tweakAutoMapper->xa4_doorCenterA;
switch (surfaceIdx) {
case 0:
return x10_transform * CVector3f{};
case 1:
return x10_transform * CVector3f(0.f, 0.f, 2.f * z);
case 2:
return x10_transform * CVector3f(0.f, -y, 0.f);
case 3:
return x10_transform * CVector3f(0.f, y, 0.f);
case 4:
return x10_transform * CVector3f(-x, 0.f, 0.f);
case 5:
return x10_transform * CVector3f(x, 0.f, 0.f);
default:
return CVector3f{};
}
}
bool CMappableObject::GetIsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& mwInfo) const {
bool areaVis = mwInfo.IsAreaVisible(x8_objId.AreaNum()); bool areaVis = mwInfo.IsAreaVisible(x8_objId.AreaNum());
switch (x4_visibilityMode) { switch (x4_visibilityMode) {
case EVisMode::Always: case EVisMode::Always:
@ -229,8 +274,9 @@ bool CMappableObject::IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo&
case EVisMode::MapStationOrVisit2: case EVisMode::MapStationOrVisit2:
return worldVis || areaVis; return worldVis || areaVis;
case EVisMode::Visit: case EVisMode::Visit:
if (IsDoorType(x0_type)) if (IsDoorType(x0_type)) {
return mwInfo.IsDoorVisited(x8_objId); return mwInfo.IsDoorVisited(x8_objId);
}
return areaVis; return areaVis;
case EVisMode::Never: case EVisMode::Never:
return false; return false;
@ -238,29 +284,16 @@ bool CMappableObject::IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo&
} }
void CMappableObject::ReadAutoMapperTweaks(const ITweakAutoMapper& tweaks) { void CMappableObject::ReadAutoMapperTweaks(const ITweakAutoMapper& tweaks) {
const zeus::CVector3f& center = tweaks.GetDoorCenter(); const float x = tweaks.xac_doorCenterC;
const zeus::simd_floats centerF(center.mSimd); const float y = tweaks.xa8_doorCenterB;
const float z = tweaks.xa4_doorCenterA;
// Wrap door verts around -Z to build surface skDoorVerts[0] = aurora::Vec3(-x, -y, 0.f);
auto& doorVerts = skDoorVerts; skDoorVerts[1] = aurora::Vec3(-x, -y, z * 2.f);
doorVerts[0].assign(-centerF[2], -centerF[1], 0.f); skDoorVerts[2] = aurora::Vec3(-x, y, 0.f);
doorVerts[1].assign(-centerF[2], -centerF[1], 2.f * centerF[0]); skDoorVerts[3] = aurora::Vec3(-x, y, z * 2.f);
doorVerts[2].assign(-centerF[2], centerF[1], 0.f); skDoorVerts[4] = aurora::Vec3(-x * .2f, -y, 0.f);
doorVerts[3].assign(-centerF[2], centerF[1], 2.f * centerF[0]); skDoorVerts[5] = aurora::Vec3(-x * .2f, -y, z * 2.f);
doorVerts[4].assign(.2f * -centerF[2], -centerF[1], 0.f); skDoorVerts[6] = aurora::Vec3(-x * .2f, y, 0.f);
doorVerts[5].assign(.2f * -centerF[2], -centerF[1], 2.f * centerF[0]); skDoorVerts[7] = aurora::Vec3(-x * .2f, y, z * 2.f);
doorVerts[6].assign(.2f * -centerF[2], centerF[1], 0.f);
doorVerts[7].assign(.2f * -centerF[2], centerF[1], 2.f * centerF[0]);
// CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) {
// g_doorVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, skDoorVerts.data(), 16, skDoorVerts.size());
// g_doorIbo = ctx.newStaticBuffer(boo::BufferUse::Index, DoorIndices.data(), 4, DoorIndices.size());
// return true;
// } BooTrace);
}
void CMappableObject::Shutdown() {
// g_doorVbo.reset();
// g_doorIbo.reset();
} }
} // namespace metaforce } // namespace metaforce

View File

@ -1,15 +1,10 @@
#pragma once #pragma once
#include <array>
#include <optional>
#include <utility> #include <utility>
#include "Runtime/GameGlobalObjects.hpp" #include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Graphics/CLineRenderer.hpp"
#include "Runtime/Graphics/Shaders/CMapSurfaceShader.hpp"
#include "Runtime/RetroTypes.hpp" #include "Runtime/RetroTypes.hpp"
#include <zeus/CAABox.hpp>
#include <zeus/CTransform.hpp> #include <zeus/CTransform.hpp>
namespace metaforce { namespace metaforce {
@ -49,24 +44,12 @@ public:
enum class EVisMode { Always, MapStationOrVisit, Visit, Never, MapStationOrVisit2 }; enum class EVisMode { Always, MapStationOrVisit, Visit, Never, MapStationOrVisit2 };
private: private:
static std::array<zeus::CVector3f, 8> skDoorVerts;
static std::array<u16, 24> skDoorIndices;
EMappableObjectType x0_type; EMappableObjectType x0_type;
EVisMode x4_visibilityMode; EVisMode x4_visibilityMode;
TEditorId x8_objId; TEditorId x8_objId;
u32 xc_; u32 xc_;
zeus::CTransform x10_transform; zeus::CTransform x10_transform;
// struct DoorSurface {
// CMapSurfaceShader m_surface;
// CLineRenderer m_outline;
// explicit DoorSurface()
// : m_surface(skDoorVerts, skDoorIndices)
// , m_outline(CLineRenderer::EPrimitiveMode::LineLoop, 5, {}, false, false, true) {}
// };
// std::optional<DoorSurface> m_doorSurface;
zeus::CTransform AdjustTransformForType() const; zeus::CTransform AdjustTransformForType() const;
std::pair<zeus::CColor, zeus::CColor> GetDoorColors(int idx, const CMapWorldInfo& mwInfo, float alpha) const; std::pair<zeus::CColor, zeus::CColor> GetDoorColors(int idx, const CMapWorldInfo& mwInfo, float alpha) const;
@ -81,15 +64,13 @@ public:
zeus::CVector3f BuildSurfaceCenterPoint(int surfIdx) const; zeus::CVector3f BuildSurfaceCenterPoint(int surfIdx) const;
bool IsDoorConnectedToArea(int idx, const CStateManager&) const; bool IsDoorConnectedToArea(int idx, const CStateManager&) const;
bool IsDoorConnectedToVisitedArea(const CStateManager&) const; bool IsDoorConnectedToVisitedArea(const CStateManager&) const;
bool IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& mwInfo) const; bool GetIsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& mwInfo) const;
bool GetIsSeen() const; bool GetIsSeen() const;
// void CreateDoorSurface() { m_doorSurface.emplace(); }
static void ReadAutoMapperTweaks(const ITweakAutoMapper&); static void ReadAutoMapperTweaks(const ITweakAutoMapper&);
static bool GetTweakIsMapVisibilityCheat(); static bool GetTweakIsMapVisibilityCheat();
static bool IsDoorType(EMappableObjectType type) { static bool IsDoorType(EMappableObjectType type) {
return type >= EMappableObjectType::BlueDoor && type <= EMappableObjectType::PlasmaDoorFloor2; return type >= EMappableObjectType::BlueDoor && type <= EMappableObjectType::PlasmaDoorFloor2;
} }
static void Shutdown();
}; };
} // namespace metaforce } // namespace metaforce

View File

@ -470,11 +470,13 @@ static void aurora_log_callback(AuroraLogLevel level, const char* module, const
break; break;
} }
const std::string_view view(message, len); const std::string_view view(message, len);
spdlog::log(severity, "[{}] {}", module, view);
if (level == LOG_FATAL) { if (level == LOG_FATAL) {
spdlog::default_logger()->flush();
auto msg = fmt::format("Metaforce encountered an internal error:\n\n{}", view); auto msg = fmt::format("Metaforce encountered an internal error:\n\n{}", view);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Metaforce", msg.c_str(), metaforce::g_window); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Metaforce", msg.c_str(), metaforce::g_window);
std::abort();
} }
spdlog::log(severity, "[{}] {}", module, view);
} }
static void aurora_imgui_init_callback(const AuroraWindowSize* size) { g_app->onImGuiInit(size->scale); } static void aurora_imgui_init_callback(const AuroraWindowSize* size) { g_app->onImGuiInit(size->scale); }

View File

@ -150,7 +150,7 @@ endfunction()
set(RUNTIME_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) set(RUNTIME_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
set(RUNTIME_LIBRARIES zeus nod NESEmulator libjpeg-turbo jbus kabufuda OptickCore set(RUNTIME_LIBRARIES zeus nod NESEmulator libjpeg-turbo jbus kabufuda OptickCore
imgui_support aurora::core aurora::gx aurora::vi spdlog::spdlog $<$<BOOL:${WIN32}>:nowide::nowide> imgui_support aurora::core aurora::gx aurora::vi aurora::mtx spdlog::spdlog $<$<BOOL:${WIN32}>:nowide::nowide>
${ZLIB_LIBRARIES} ${ZLIB_LIBRARIES}
) )

View File

@ -500,7 +500,7 @@ void CStateManager::DrawReflection(const zeus::CVector3f& reflectPoint) {
const zeus::CVector3f viewPos = playerPos - surfToPlayer.normalized() * 3.5f; const zeus::CVector3f viewPos = playerPos - surfToPlayer.normalized() * 3.5f;
const zeus::CTransform look = zeus::lookAt(viewPos, playerPos, {0.f, 0.f, -1.f}); const zeus::CTransform look = zeus::lookAt(viewPos, playerPos, {0.f, 0.f, -1.f});
const zeus::CTransform backupView = CGraphics::g_ViewMatrix; const zeus::CTransform backupView = CGraphics::mViewMatrix;
CGraphics::SetViewPointMatrix(look); CGraphics::SetViewPointMatrix(look);
const CGraphics::CProjectionState backupProj = CGraphics::GetProjectionState(); const CGraphics::CProjectionState backupProj = CGraphics::GetProjectionState();
const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this); const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this);
@ -649,38 +649,38 @@ void CStateManager::DrawAdditionalFilters() {
CCameraFilterPass::DrawFilter(EFilterType::Add, EFilterShape::Fullscreen, color, nullptr, 1.f); CCameraFilterPass::DrawFilter(EFilterType::Add, EFilterShape::Fullscreen, color, nullptr, 1.f);
} }
zeus::CFrustum CStateManager::SetupDrawFrustum(const SViewport& vp) const { zeus::CFrustum CStateManager::SetupDrawFrustum(const CViewport& vp) const {
zeus::CFrustum ret; zeus::CFrustum ret;
const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this); const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this);
const zeus::CTransform camXf = x870_cameraManager->GetCurrentCameraTransform(*this); const zeus::CTransform camXf = x870_cameraManager->GetCurrentCameraTransform(*this);
const int vpWidth = static_cast<int>(xf2c_viewportScale.x() * vp.x8_width); const int vpWidth = static_cast<int>(xf2c_viewportScale.x() * vp.mWidth);
const int vpHeight = static_cast<int>(xf2c_viewportScale.y() * vp.xc_height); const int vpHeight = static_cast<int>(xf2c_viewportScale.y() * vp.mHeight);
const int vpLeft = static_cast<int>((vp.x8_width - vpWidth) / 2 + vp.x0_left); const int vpLeft = (vp.mWidth - vpWidth) / 2 + vp.mLeft;
const int vpTop = static_cast<int>((vp.xc_height - vpHeight) / 2 + vp.x4_top); const int vpTop = (vp.mHeight - vpHeight) / 2 + vp.mTop;
g_Renderer->SetViewport(vpLeft, vpTop, vpWidth, vpHeight); g_Renderer->SetViewport(vpLeft, vpTop, vpWidth, vpHeight);
const float fov = std::atan(std::tan(zeus::degToRad(cam->GetFov()) * 0.5f) * xf2c_viewportScale.y()) * 2.f; const float fov = std::atan(std::tan(zeus::degToRad(cam->GetFov()) * 0.5f) * xf2c_viewportScale.y()) * 2.f;
const float width = xf2c_viewportScale.x() * vp.x8_width; const float width = xf2c_viewportScale.x() * vp.mWidth;
const float height = xf2c_viewportScale.y() * vp.xc_height; const float height = xf2c_viewportScale.y() * vp.mHeight;
zeus::CProjection proj; zeus::CProjection proj;
proj.setPersp(zeus::SProjPersp{fov, width / height, cam->GetNearClipDistance(), cam->GetFarClipDistance()}); proj.setPersp(zeus::SProjPersp{fov, width / height, cam->GetNearClipDistance(), cam->GetFarClipDistance()});
ret.updatePlanes(camXf, proj); ret.updatePlanes(camXf, proj);
return ret; return ret;
} }
zeus::CFrustum CStateManager::SetupViewForDraw(const SViewport& vp) const { zeus::CFrustum CStateManager::SetupViewForDraw(const CViewport& vp) const {
const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this); const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this);
const zeus::CTransform camXf = x870_cameraManager->GetCurrentCameraTransform(*this); const zeus::CTransform camXf = x870_cameraManager->GetCurrentCameraTransform(*this);
g_Renderer->SetWorldViewpoint(camXf); g_Renderer->SetWorldViewpoint(camXf);
CCubeModel::SetNewPlayerPositionAndTime(x84c_player->GetTranslation(), CStopwatch::GetGlobalTimerObj()); CCubeModel::SetNewPlayerPositionAndTime(x84c_player->GetTranslation(), CStopwatch::GetGlobalTimerObj());
const int vpWidth = static_cast<int>(xf2c_viewportScale.x() * vp.x8_width); const int vpWidth = static_cast<int>(xf2c_viewportScale.x() * vp.mWidth);
const int vpHeight = static_cast<int>(xf2c_viewportScale.y() * vp.xc_height); const int vpHeight = static_cast<int>(xf2c_viewportScale.y() * vp.mHeight);
const int vpLeft = static_cast<int>((vp.x8_width - vpWidth) / 2 + vp.x0_left); const int vpLeft = (vp.mWidth - vpWidth) / 2 + vp.mLeft;
const int vpTop = static_cast<int>((vp.xc_height - vpHeight) / 2 + vp.x4_top); const int vpTop = (vp.mHeight - vpHeight) / 2 + vp.mTop;
g_Renderer->SetViewport(vpLeft, vpTop, vpWidth, vpHeight); g_Renderer->SetViewport(vpLeft, vpTop, vpWidth, vpHeight);
CGraphics::SetDepthRange(DEPTH_WORLD, DEPTH_FAR); CGraphics::SetDepthRange(DEPTH_WORLD, DEPTH_FAR);
const float fov = std::atan(std::tan(zeus::degToRad(cam->GetFov()) * 0.5f) * xf2c_viewportScale.y()) * 2.f; const float fov = std::atan(std::tan(zeus::degToRad(cam->GetFov()) * 0.5f) * xf2c_viewportScale.y()) * 2.f;
const float width = xf2c_viewportScale.x() * vp.x8_width; const float width = xf2c_viewportScale.x() * vp.mWidth;
const float height = xf2c_viewportScale.y() * vp.xc_height; const float height = xf2c_viewportScale.y() * vp.mHeight;
g_Renderer->SetPerspective(zeus::radToDeg(fov), width, height, cam->GetNearClipDistance(), cam->GetFarClipDistance()); g_Renderer->SetPerspective(zeus::radToDeg(fov), width, height, cam->GetNearClipDistance(), cam->GetFarClipDistance());
zeus::CFrustum frustum; zeus::CFrustum frustum;
zeus::CProjection proj; zeus::CProjection proj;
@ -690,14 +690,13 @@ zeus::CFrustum CStateManager::SetupViewForDraw(const SViewport& vp) const {
g_Renderer->PrimColor(zeus::skWhite); g_Renderer->PrimColor(zeus::skWhite);
CGraphics::SetModelMatrix(zeus::CTransform()); CGraphics::SetModelMatrix(zeus::CTransform());
x87c_fluidPlaneManager->StartFrame(false); x87c_fluidPlaneManager->StartFrame(false);
g_Renderer->SetDebugOption(IRenderer::EDebugOption::PVSState, int(EPVSVisSetState::NodeFound)); g_Renderer->SetDebugOption(IRenderer::EDebugOption::PVSState, static_cast<int>(EPVSVisSetState::NodeFound));
return frustum; return frustum;
} }
void CStateManager::ResetViewAfterDraw(const SViewport& backupViewport, void CStateManager::ResetViewAfterDraw(const CViewport& backupViewport,
const zeus::CTransform& backupViewMatrix) const { const zeus::CTransform& backupViewMatrix) const {
g_Renderer->SetViewport(backupViewport.x0_left, backupViewport.x4_top, backupViewport.x8_width, g_Renderer->SetViewport(backupViewport.mLeft, backupViewport.mTop, backupViewport.mWidth, backupViewport.mHeight);
backupViewport.xc_height);
const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this); const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this);
zeus::CFrustum frustum; zeus::CFrustum frustum;
@ -712,15 +711,15 @@ void CStateManager::ResetViewAfterDraw(const SViewport& backupViewport,
void CStateManager::DrawWorld() { void CStateManager::DrawWorld() {
SCOPED_GRAPHICS_DEBUG_GROUP("CStateManager::DrawWorld", zeus::skBlue); SCOPED_GRAPHICS_DEBUG_GROUP("CStateManager::DrawWorld", zeus::skBlue);
const CTimeProvider timeProvider(xf14_curTimeMod900); const CTimeProvider timeProvider(xf14_curTimeMod900);
const SViewport backupViewport = CGraphics::g_Viewport; const CViewport backupViewport = CGraphics::mViewport;
/* Area camera is in (not necessarily player) */ /* Area camera is in (not necessarily player) */
const TAreaId visAreaId = GetVisAreaId(); const TAreaId visAreaId = GetVisAreaId();
x850_world->TouchSky(); x850_world->TouchSky();
const zeus::CFrustum frustum = SetupViewForDraw(CGraphics::g_Viewport); const zeus::CFrustum frustum = SetupViewForDraw(CGraphics::mViewport);
const zeus::CTransform backupViewMatrix = CGraphics::g_ViewMatrix; const zeus::CTransform backupViewMatrix = CGraphics::mViewMatrix;
int areaCount = 0; int areaCount = 0;
std::array<const CGameArea*, 10> areaArr; std::array<const CGameArea*, 10> areaArr;
@ -747,7 +746,7 @@ void CStateManager::DrawWorld() {
if (visAreaId == b->x4_selfIdx) { if (visAreaId == b->x4_selfIdx) {
return true; return true;
} }
return CGraphics::g_ViewPoint.dot(a->GetAABB().center()) > CGraphics::g_ViewPoint.dot(b->GetAABB().center()); return CGraphics::mViewPoint.dot(a->GetAABB().center()) > CGraphics::mViewPoint.dot(b->GetAABB().center());
}); });
int pvsCount = 0; int pvsCount = 0;
@ -789,7 +788,7 @@ void CStateManager::DrawWorld() {
g_Renderer->SetWorldFog(ERglFogMode::None, 0.f, 1.f, zeus::skBlack); g_Renderer->SetWorldFog(ERglFogMode::None, 0.f, 1.f, zeus::skBlack);
} }
x850_world->DrawSky(zeus::CTransform::Translate(CGraphics::g_ViewPoint)); x850_world->DrawSky(zeus::CTransform::Translate(CGraphics::mViewPoint));
if (areaCount != 0) { if (areaCount != 0) {
SetupFogForArea(*areaArr[areaCount - 1]); SetupFogForArea(*areaArr[areaCount - 1]);
@ -1074,7 +1073,7 @@ void CStateManager::PreRender() {
} }
SCOPED_GRAPHICS_DEBUG_GROUP("CStateManager::PreRender", zeus::skBlue); SCOPED_GRAPHICS_DEBUG_GROUP("CStateManager::PreRender", zeus::skBlue);
const zeus::CFrustum frustum = SetupDrawFrustum(CGraphics::g_Viewport); const zeus::CFrustum frustum = SetupDrawFrustum(CGraphics::mViewport);
x86c_stateManagerContainer->xf370_.clear(); x86c_stateManagerContainer->xf370_.clear();
x86c_stateManagerContainer->xf39c_renderLast.clear(); x86c_stateManagerContainer->xf39c_renderLast.clear();
xf7c_projectedShadow = nullptr; xf7c_projectedShadow = nullptr;
@ -1143,7 +1142,7 @@ bool CStateManager::GetVisSetForArea(TAreaId a, TAreaId b, CPVSVisSet& setOut) c
return false; return false;
} }
const zeus::CVector3f viewPoint = CGraphics::g_ViewMatrix.origin; const zeus::CVector3f viewPoint = CGraphics::mViewMatrix.origin;
zeus::CVector3f closestDockPoint = viewPoint; zeus::CVector3f closestDockPoint = viewPoint;
bool hasClosestDock = false; bool hasClosestDock = false;
if (a != b) { if (a != b) {

View File

@ -250,9 +250,9 @@ public:
void RenderCamerasAndAreaLights(); void RenderCamerasAndAreaLights();
void DrawE3DeathEffect(); void DrawE3DeathEffect();
void DrawAdditionalFilters(); void DrawAdditionalFilters();
zeus::CFrustum SetupDrawFrustum(const SViewport& vp) const; zeus::CFrustum SetupDrawFrustum(const CViewport& vp) const;
zeus::CFrustum SetupViewForDraw(const SViewport& vp) const; zeus::CFrustum SetupViewForDraw(const CViewport& vp) const;
void ResetViewAfterDraw(const SViewport& backupViewport, const zeus::CTransform& backupViewMatrix) const; void ResetViewAfterDraw(const CViewport& backupViewport, const zeus::CTransform& backupViewMatrix) const;
void DrawWorld(); void DrawWorld();
void SetupFogForArea3XRange(TAreaId area) const; void SetupFogForArea3XRange(TAreaId area) const;
void SetupFogForArea(TAreaId area) const; void SetupFogForArea(TAreaId area) const;

View File

@ -8,5 +8,6 @@ public:
CTimeProvider(const float& time); CTimeProvider(const float& time);
~CTimeProvider(); ~CTimeProvider();
float GetSecondsMod900() const { return x0_currentTime; }
}; };
} // namespace metaforce } // namespace metaforce

View File

@ -191,7 +191,7 @@ void CCameraFilterPass::DrawFullScreenTexturedQuadQuarters(const zeus::CColor& c
CGraphics::SetCullMode(ERglCullMode::None); CGraphics::SetCullMode(ERglCullMode::None);
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
g_Renderer->SetModelMatrix(zeus::CTransform::Scale((i & 1) != 0 ? 1.f : -1.f, 0.f, (i & 2) != 0 ? 1.f : -1.f)); g_Renderer->SetModelMatrix(zeus::CTransform::Scale((i & 1) != 0 ? 1.f : -1.f, 0.f, (i & 2) != 0 ? 1.f : -1.f));
CGraphics::StreamBegin(GX_TRIANGLESTRIP); CGraphics::StreamBegin(ERglPrimitive::TriangleStrip);
CGraphics::StreamColor(color); CGraphics::StreamColor(color);
CGraphics::StreamTexcoord(lod, lod); CGraphics::StreamTexcoord(lod, lod);
CGraphics::StreamVertex(lt.x(), 0.f, rb.y()); CGraphics::StreamVertex(lt.x(), 0.f, rb.y());
@ -217,7 +217,7 @@ void CCameraFilterPass::DrawFullScreenTexturedQuad(const zeus::CColor& color, CT
} }
CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvModulate); CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvModulate);
CGraphics::SetTevOp(ERglTevStage::Stage1, CTevCombiners::kEnvPassthru); CGraphics::SetTevOp(ERglTevStage::Stage1, CTevCombiners::kEnvPassthru);
CGraphics::StreamBegin(GX_TRIANGLESTRIP); CGraphics::StreamBegin(ERglPrimitive::TriangleStrip);
CGraphics::StreamColor(color); CGraphics::StreamColor(color);
CGraphics::StreamTexcoord(u, v); CGraphics::StreamTexcoord(u, v);
CGraphics::StreamVertex(lt.x() - 1.f, 0.f, 1.f + rb.y()); CGraphics::StreamVertex(lt.x() - 1.f, 0.f, 1.f + rb.y());
@ -255,7 +255,7 @@ void CCameraFilterPass::DrawRandomStatic(const zeus::CColor& color, float alpha,
m_randomStatic.UnLock(); m_randomStatic.UnLock();
m_randomStatic.Load(GX_TEXMAP0, EClampMode::Clamp); m_randomStatic.Load(GX_TEXMAP0, EClampMode::Clamp);
CGraphics::StreamBegin(GX_TRIANGLESTRIP); CGraphics::StreamBegin(ERglPrimitive::TriangleStrip);
CGraphics::StreamColor(color); CGraphics::StreamColor(color);
CGraphics::StreamTexcoord(0.f, 1.f); CGraphics::StreamTexcoord(0.f, 1.f);
CGraphics::StreamVertex(lb.x() - 1.f, 0.01f, rt.y() + 1.f); CGraphics::StreamVertex(lb.x() - 1.f, 0.01f, rt.y() + 1.f);

View File

@ -1,12 +1,7 @@
#pragma once #pragma once
#include <memory>
#include <optional>
#include "Runtime/CToken.hpp" #include "Runtime/CToken.hpp"
#include "Runtime/Graphics/CTexture.hpp" #include "Runtime/Graphics/CTexture.hpp"
#include "Runtime/Graphics/Shaders/CCameraBlurFilter.hpp"
#include "Runtime/Graphics/Shaders/CXRayBlurFilter.hpp"
#include "Runtime/RetroTypes.hpp" #include "Runtime/RetroTypes.hpp"
#include <zeus/CColor.hpp> #include <zeus/CColor.hpp>
@ -38,7 +33,6 @@ enum class EFilterShape {
}; };
class CCameraFilterPass { class CCameraFilterPass {
private:
EFilterType x0_curType = EFilterType::Passthru; EFilterType x0_curType = EFilterType::Passthru;
EFilterType x4_nextType = EFilterType::Passthru; EFilterType x4_nextType = EFilterType::Passthru;
EFilterShape x8_shape = EFilterShape::Fullscreen; EFilterShape x8_shape = EFilterShape::Fullscreen;

View File

@ -57,9 +57,7 @@ zeus::CVector3f CGameCamera::ConvertToScreenSpace(const zeus::CVector3f& v) cons
if (rVec.isZero()) if (rVec.isZero())
return {-1.f, -1.f, 1.f}; return {-1.f, -1.f, 1.f};
rVec = zeus::CVector3f(rVec.x(), rVec.z(), -rVec.y()); return GetPerspectiveMatrix().multiplyOneOverW(rVec);
zeus::CMatrix4f mtx = GetPerspectiveMatrix();
return mtx.multiplyOneOverW(rVec);
} }
zeus::CTransform CGameCamera::ValidateCameraTransform(const zeus::CTransform& newXf, zeus::CTransform CGameCamera::ValidateCameraTransform(const zeus::CTransform& newXf,

View File

@ -67,8 +67,8 @@ CAnimData::CAnimData(CAssetId id, const CCharacterInfo& character, int defaultAn
g_TransientInt32POINodes.resize(16); g_TransientInt32POINodes.resize(16);
xd8_modelData->CalculateDefault(); xd8_modelData->CalculateDefault();
for (const auto& item : *xd8_modelData->GetModel()->GetPositions()) { for (const auto& item : xd8_modelData->GetModel()->GetPositions()) {
x108_aabb.accumulateBounds(item); x108_aabb.accumulateBounds({item.x, item.y, item.z});
} }
x120_particleDB.CacheParticleDesc(xc_charInfo.GetParticleResData()); x120_particleDB.CacheParticleDesc(xc_charInfo.GetParticleResData());
@ -560,7 +560,7 @@ void CAnimData::SetupRender(CSkinnedModel& model, CVertexMorphEffect* morphEffec
} }
void CAnimData::DrawSkinnedModel(CSkinnedModel& model, const CModelFlags& flags) { void CAnimData::DrawSkinnedModel(CSkinnedModel& model, const CModelFlags& flags) {
CGX::SetChanCtrl(CGX::EChannelId::Channel0, CGraphics::g_LightActive); CGX::SetChanCtrl(CGX::EChannelId::Channel0, CGraphics::mLightActive);
model.Draw(flags); model.Draw(flags);
} }
@ -888,8 +888,8 @@ zeus::CAABox CAnimData::GetBoundingBox() const {
void CAnimData::SubstituteModelData(const TCachedToken<CSkinnedModel>& model) { void CAnimData::SubstituteModelData(const TCachedToken<CSkinnedModel>& model) {
xd8_modelData = model; xd8_modelData = model;
x108_aabb = {}; x108_aabb = {};
for (const auto& item : *xd8_modelData->GetModel()->GetPositions()) { for (const auto& item : xd8_modelData->GetModel()->GetPositions()) {
x108_aabb.accumulateBounds(item); x108_aabb.accumulateBounds({item.x, item.y, item.z});
} }
} }

View File

@ -286,7 +286,7 @@ void CModelData::RenderThermal(const zeus::CTransform& xf, const zeus::CColor& m
if (x10_animData) { if (x10_animData) {
CSkinnedModel& model = PickAnimatedModel(EWhichModel::ThermalHot); CSkinnedModel& model = PickAnimatedModel(EWhichModel::ThermalHot);
x10_animData->SetupRender(model, nullptr, nullptr); x10_animData->SetupRender(model, nullptr, {});
ThermalDraw(model, mulColor, addColor, flags); ThermalDraw(model, mulColor, addColor, flags);
} else { } else {
auto& model = PickStaticModel(EWhichModel::ThermalHot); auto& model = PickStaticModel(EWhichModel::ThermalHot);
@ -335,7 +335,7 @@ void CModelData::Render(EWhichModel which, const zeus::CTransform& xf, const CAc
} }
if (x10_animData) { if (x10_animData) {
x10_animData->Render(PickAnimatedModel(which), drawFlags, nullptr, nullptr); x10_animData->Render(PickAnimatedModel(which), drawFlags, nullptr, {});
} else { } else {
// TODO supposed to be optional_object? // TODO supposed to be optional_object?
if (x1c_normalModel) { if (x1c_normalModel) {
@ -357,10 +357,10 @@ void CModelData::FlatDraw(EWhichModel which, const zeus::CTransform& xf, bool un
g_Renderer->SetModelMatrix(xf * zeus::CTransform::Scale(x0_scale)); g_Renderer->SetModelMatrix(xf * zeus::CTransform::Scale(x0_scale));
CGraphics::DisableAllLights(); CGraphics::DisableAllLights();
if (!x10_animData) { if (!x10_animData) {
g_Renderer->DrawModelFlat(*PickStaticModel(which), flags, unsortedOnly, nullptr, nullptr); g_Renderer->DrawModelFlat(*PickStaticModel(which), flags, unsortedOnly, {}, {});
} else { } else {
auto model = PickAnimatedModel(which); auto model = PickAnimatedModel(which);
x10_animData->SetupRender(model, nullptr, nullptr); x10_animData->SetupRender(model, nullptr, {});
model.DoDrawCallback([=](TConstVectorRef positions, TConstVectorRef normals) { model.DoDrawCallback([=](TConstVectorRef positions, TConstVectorRef normals) {
auto m = model.GetModel(); auto m = model.GetModel();
g_Renderer->DrawModelFlat(*m, flags, unsortedOnly, positions, normals); g_Renderer->DrawModelFlat(*m, flags, unsortedOnly, positions, normals);
@ -371,12 +371,12 @@ void CModelData::FlatDraw(EWhichModel which, const zeus::CTransform& xf, bool un
void CModelData::MultiLightingDraw(EWhichModel which, const zeus::CTransform& xf, const CActorLights* lights, void CModelData::MultiLightingDraw(EWhichModel which, const zeus::CTransform& xf, const CActorLights* lights,
const zeus::CColor& alphaColor, const zeus::CColor& additiveColor) { const zeus::CColor& alphaColor, const zeus::CColor& additiveColor) {
CModel* model = nullptr; CModel* model = nullptr;
const auto callback = [&](auto positions, auto normals) { const auto callback = [&](TConstVectorRef positions, TConstVectorRef normals) {
CGraphics::DisableAllLights(); CGraphics::DisableAllLights();
constexpr CModelFlags flags1{5, 0, 3, zeus::CColor{1.f, 0.f}}; constexpr CModelFlags flags1{5, 0, 3, zeus::CColor{1.f, 0.f}};
const CModelFlags flags2{5, 0, 1, alphaColor}; const CModelFlags flags2{5, 0, 1, alphaColor};
const CModelFlags flags3{7, 0, 1, additiveColor}; const CModelFlags flags3{7, 0, 1, additiveColor};
if (positions == nullptr) { if (positions.empty()) {
model->Draw(flags1); model->Draw(flags1);
if (lights != nullptr) { if (lights != nullptr) {
lights->ActivateLights(); lights->ActivateLights();
@ -395,12 +395,12 @@ void CModelData::MultiLightingDraw(EWhichModel which, const zeus::CTransform& xf
CGraphics::SetModelMatrix(xf * zeus::CTransform::Scale(x0_scale)); CGraphics::SetModelMatrix(xf * zeus::CTransform::Scale(x0_scale));
if (x10_animData) { if (x10_animData) {
auto& skinnedModel = PickAnimatedModel(which); auto& skinnedModel = PickAnimatedModel(which);
x10_animData->SetupRender(skinnedModel, nullptr, nullptr); x10_animData->SetupRender(skinnedModel, nullptr, {});
model = skinnedModel.GetModel().GetObj(); model = skinnedModel.GetModel().GetObj();
skinnedModel.DoDrawCallback(callback); skinnedModel.DoDrawCallback(callback);
} else { } else {
model = PickStaticModel(which).GetObj(); model = PickStaticModel(which).GetObj();
callback(nullptr, nullptr); callback({}, {});
} }
} }
@ -415,7 +415,7 @@ void CModelData::MultiPassDraw(EWhichModel which, const zeus::CTransform& xf, co
} }
if (x10_animData) { if (x10_animData) {
auto& skinnedModel = PickAnimatedModel(which); auto& skinnedModel = PickAnimatedModel(which);
x10_animData->SetupRender(skinnedModel, nullptr, nullptr); x10_animData->SetupRender(skinnedModel, nullptr, {});
auto& model = *skinnedModel.GetModel(); auto& model = *skinnedModel.GetModel();
skinnedModel.DoDrawCallback([&](auto positions, auto normals) { skinnedModel.DoDrawCallback([&](auto positions, auto normals) {
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
@ -443,12 +443,12 @@ void CModelData::DisintegrateDraw(EWhichModel which, const zeus::CTransform& xf,
const auto aabb = GetBounds(scaledXf); const auto aabb = GetBounds(scaledXf);
if (x10_animData) { if (x10_animData) {
auto& model = PickAnimatedModel(which); auto& model = PickAnimatedModel(which);
x10_animData->SetupRender(model, nullptr, nullptr); x10_animData->SetupRender(model, nullptr, {});
model.DoDrawCallback([&](auto positions, auto normals) { model.DoDrawCallback([&](auto positions, auto normals) {
g_Renderer->DrawModelDisintegrate(*model.GetModel(), tex, addColor, positions, normals, t); g_Renderer->DrawModelDisintegrate(*model.GetModel(), tex, addColor, positions, normals, t);
}); });
} else { } else {
g_Renderer->DrawModelDisintegrate(*PickStaticModel(which), tex, addColor, nullptr, nullptr, t); g_Renderer->DrawModelDisintegrate(*PickStaticModel(which), tex, addColor, {}, {}, t);
} }
} }

View File

@ -52,7 +52,7 @@ void CSkinRules::BuildPoints(TConstVectorRef positions, TVectorRef out) {
size_t offset = 0; size_t offset = 0;
for (auto& bone : x0_bones) { for (auto& bone : x0_bones) {
u32 vertexCount = bone.GetVertexCount(); u32 vertexCount = bone.GetVertexCount();
bone.BuildPoints(positions->data() + offset, out, vertexCount); bone.BuildPoints(positions.data() + offset, out, vertexCount);
offset += vertexCount; offset += vertexCount;
} }
} }
@ -61,7 +61,7 @@ void CSkinRules::BuildNormals(TConstVectorRef normals, TVectorRef out) {
size_t offset = 0; size_t offset = 0;
for (auto& bone : x0_bones) { for (auto& bone : x0_bones) {
u32 vertexCount = bone.GetVertexCount(); u32 vertexCount = bone.GetVertexCount();
bone.BuildNormals(normals->data() + offset, out, vertexCount); bone.BuildNormals(normals.data() + offset, out, vertexCount);
offset += vertexCount; offset += vertexCount;
} }
} }
@ -85,15 +85,19 @@ static inline auto StreamInSkinWeighting(CInputStream& in) {
CVirtualBone::CVirtualBone(CInputStream& in) : x0_weights(StreamInSkinWeighting(in)), x1c_vertexCount(in.ReadLong()) {} CVirtualBone::CVirtualBone(CInputStream& in) : x0_weights(StreamInSkinWeighting(in)), x1c_vertexCount(in.ReadLong()) {}
void CVirtualBone::BuildPoints(const zeus::CVector3f* in, TVectorRef out, u32 count) const { void CVirtualBone::BuildPoints(const aurora::Vec3<float>* in, TVectorRef out, u32 count) const {
for (u32 i = 0; i < count; ++i) { for (u32 i = 0; i < count; ++i) {
out->emplace_back(x20_xf * in[i]); const auto& vec = in[i];
zeus::CVector3f zout = x20_xf * zeus::CVector3f{vec.x, vec.y, vec.z};
out->emplace_back(zout.x(), zout.y(), zout.z());
} }
} }
void CVirtualBone::BuildNormals(const zeus::CVector3f* in, TVectorRef out, u32 count) const { void CVirtualBone::BuildNormals(const aurora::Vec3<float>* in, TVectorRef out, u32 count) const {
for (u32 i = 0; i < count; ++i) { for (u32 i = 0; i < count; ++i) {
out->emplace_back(x50_rotation * in[i]); const auto& vec = in[i];
zeus::CVector3f zout = x50_rotation * zeus::CVector3f{vec.x, vec.y, vec.z};
out->emplace_back(zout.x(), zout.y(), zout.z());
} }
} }

View File

@ -31,8 +31,8 @@ class CVirtualBone {
public: public:
explicit CVirtualBone(CInputStream& in); explicit CVirtualBone(CInputStream& in);
void BuildPoints(const zeus::CVector3f* in, TVectorRef out, u32 count) const; void BuildPoints(const aurora::Vec3<float>* in, TVectorRef out, u32 count) const;
void BuildNormals(const zeus::CVector3f* in, TVectorRef out, u32 count) const; void BuildNormals(const aurora::Vec3<float>* in, TVectorRef out, u32 count) const;
void BuildAccumulatedTransform(const CPoseAsTransforms& pose, const zeus::CVector3f* points); void BuildAccumulatedTransform(const CPoseAsTransforms& pose, const zeus::CVector3f* points);
[[nodiscard]] const auto& GetWeights() const { return x0_weights; } [[nodiscard]] const auto& GetWeights() const { return x0_weights; }

View File

@ -185,17 +185,18 @@ void CCollisionActor::SetSphereRadius(float radius) {
x288_sphereRadius = radius; x288_sphereRadius = radius;
x284_spherePrimitive->SetSphereRadius(radius); x284_spherePrimitive->SetSphereRadius(radius);
} }
void CCollisionActor::DebugDraw() { void CCollisionActor::DebugDraw() {
zeus::CAABox aabox; // zeus::CAABox aabox;
if (x258_primitiveType == EPrimitiveType::OBBTreeGroup) // if (x258_primitiveType == EPrimitiveType::OBBTreeGroup)
aabox = x27c_obbTreeGroupPrimitive->CalculateAABox(x34_transform); // aabox = x27c_obbTreeGroupPrimitive->CalculateAABox(x34_transform);
else if (x258_primitiveType == EPrimitiveType::AABox) // else if (x258_primitiveType == EPrimitiveType::AABox)
aabox = x280_aaboxPrimitive->CalculateAABox(x34_transform); // aabox = x280_aaboxPrimitive->CalculateAABox(x34_transform);
else if (x258_primitiveType == EPrimitiveType::Sphere) // else if (x258_primitiveType == EPrimitiveType::Sphere)
aabox = x284_spherePrimitive->CalculateAABox(x34_transform); // aabox = x284_spherePrimitive->CalculateAABox(x34_transform);
m_aabox.setAABB(aabox); // m_aabox.setAABB(aabox);
zeus::CColor col = !GetActive() ? zeus::skRed : zeus::skGreen; // zeus::CColor col = !GetActive() ? zeus::skRed : zeus::skGreen;
col.a() = 0.5f; // col.a() = 0.5f;
m_aabox.draw(col); // m_aabox.draw(col);
} }
} // namespace metaforce } // namespace metaforce

View File

@ -3,7 +3,6 @@
#include <memory> #include <memory>
#include <string_view> #include <string_view>
#include "Runtime/Graphics/Shaders/CAABoxShader.hpp"
#include "Runtime/World/CDamageVulnerability.hpp" #include "Runtime/World/CDamageVulnerability.hpp"
#include "Runtime/World/CHealthInfo.hpp" #include "Runtime/World/CHealthInfo.hpp"
#include "Runtime/World/CPhysicsActor.hpp" #include "Runtime/World/CPhysicsActor.hpp"
@ -33,8 +32,6 @@ class CCollisionActor : public CPhysicsActor {
EWeaponCollisionResponseTypes x300_responseType = EWeaponCollisionResponseTypes::EnemyNormal; EWeaponCollisionResponseTypes x300_responseType = EWeaponCollisionResponseTypes::EnemyNormal;
zeus::CVector3f x304_extendedTouchBounds = zeus::skZero3f; zeus::CVector3f x304_extendedTouchBounds = zeus::skZero3f;
CAABoxShader m_aabox;
public: public:
DEFINE_ENTITY DEFINE_ENTITY
CCollisionActor(TUniqueId uid, TAreaId areaId, TUniqueId owner, const zeus::CVector3f& extent, CCollisionActor(TUniqueId uid, TAreaId areaId, TUniqueId owner, const zeus::CVector3f& extent,

View File

@ -1,303 +0,0 @@
#pragma once
#include <functional>
#include <list>
#include <optional>
#include <unordered_map>
#include <utility>
#include <vector>
#include "Runtime/CRandom16.hpp"
#include "Runtime/rstl.hpp"
#include "Runtime/Graphics/CDrawable.hpp"
#include "Runtime/Graphics/CDrawablePlaneObject.hpp"
#include "Runtime/Graphics/CPVSVisSet.hpp"
#include "Runtime/Graphics/CTexture.hpp"
#include "Runtime/Graphics/IRenderer.hpp"
#include "Runtime/Graphics/Shaders/CFogVolumeFilter.hpp"
#include "Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp"
#include "Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp"
#include "Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp"
#include "Runtime/Graphics/Shaders/CThermalColdFilter.hpp"
#include "Runtime/Graphics/Shaders/CThermalHotFilter.hpp"
#include "Runtime/World/CGameArea.hpp"
#include "CMetroidModelInstance.hpp"
#include <zeus/CAABox.hpp>
#include <zeus/CColor.hpp>
#include <zeus/CFrustum.hpp>
#include <zeus/CPlane.hpp>
#include <zeus/CRectangle.hpp>
#include <zeus/CTransform.hpp>
#include <zeus/CVector3f.hpp>
namespace metaforce {
class CBooModel;
class CMemorySys;
class CParticleGen;
class CTexture;
class IFactory;
class IObjectStore;
class Buckets;
enum class EWorldShadowMode { None, WorldOnActorShadow, BallOnWorldShadow, BallOnWorldIds, MAX };
class CBooRenderer final : public IRenderer {
friend class CBooModel;
friend class CGameArea;
friend class CModel;
friend class CMorphBallShadow;
friend class CWorldTransManager;
struct CAreaListItem {
const std::vector<CMetroidModelInstance>* x0_geometry;
const CAreaRenderOctTree* x4_octTree;
/* originally auto_ptrs of vectors */
std::unordered_map<CAssetId, TCachedToken<CTexture>> x8_textures;
std::vector<CBooModel*> x10_models;
int x18_areaIdx;
/* Per-area octree-word major, light bits minor */
std::vector<u32> x1c_lightOctreeWords;
const SShader* m_shaderSet;
CAreaListItem(const std::vector<CMetroidModelInstance>* geom, const CAreaRenderOctTree* octTree,
std::unordered_map<CAssetId, TCachedToken<CTexture>>&& textures, std::vector<CBooModel*>&& models,
int areaIdx, const SShader* shaderSet);
~CAreaListItem();
};
struct CFogVolumeListItem {
zeus::CTransform x0_transform;
zeus::CColor x30_color;
zeus::CAABox x34_aabb;
TLockedToken<CModel> x4c_model;
// bool x58_b; Optional for model token
const CSkinnedModel* x5c_skinnedModel = nullptr;
CFogVolumeListItem(const zeus::CTransform& xf, const zeus::CColor& color, const zeus::CAABox& aabb,
const TLockedToken<CModel>* model, const CSkinnedModel* sModel)
: x0_transform(xf), x30_color(color), x34_aabb(aabb), x5c_skinnedModel(sModel) {
if (model)
x4c_model = *model;
}
};
IFactory& x8_factory;
IObjectStore& xc_store;
TLockedToken<CTexture> m_staticEntropy;
// CFont x10_fnt;
u32 x18_ = 0;
std::list<CAreaListItem> x1c_areaListItems;
zeus::CFrustum x44_frustumPlanes;
TDrawableCallback xa8_drawableCallback;
void* xac_callbackContext;
zeus::CPlane xb0_viewPlane = {0.f, 1.f, 0.f, 0.f};
enum class EPVSMode { Mask, PVS, PVSAndMask } xc4_pvsMode = EPVSMode::Mask;
std::optional<CPVSVisSet> xc8_pvs;
u32 xe0_pvsAreaIdx = 0;
// boo::ITextureS* xe4_blackTex = nullptr;
bool xee_24_ : 1 = true;
aurora::gfx::TextureHandle m_clearTexture;
aurora::gfx::TextureHandle m_blackTexture;
aurora::gfx::TextureHandle m_whiteTexture;
std::unordered_map<zeus::CColor, aurora::gfx::TextureHandle> m_colorTextures;
aurora::gfx::TextureHandle x14c_reflectionTex;
// boo::ITextureS* x150_mirrorRamp = nullptr;
// aurora::gfx::TextureHandle x1b8_fogVolumeRamp;
aurora::gfx::TextureHandle x220_sphereRamp;
// TLockedToken<CTexture> m_thermoPaletteTex;
// aurora::gfx::TextureHandle x288_thermoPalette;
// TLockedToken<CTexture> m_ballFadeTex;
aurora::gfx::TextureHandle m_ballFade;
aurora::gfx::TextureHandle m_ballShadowId;
// boo::ObjToken<boo::IGraphicsBufferS> m_scanLinesEvenVBO;
// boo::ObjToken<boo::IGraphicsBufferS> m_scanLinesOddVBO;
int m_ballShadowIdW = 64;
int m_ballShadowIdH = 64;
CRandom16 x2a8_thermalRand;
std::list<CFogVolumeListItem> x2ac_fogVolumes;
// std::list<CFogVolumePlaneShader> m_fogVolumePlaneShaders;
// std::list<CFogVolumePlaneShader>::iterator m_nextFogVolumePlaneShader;
// std::list<CFogVolumeFilter> m_fogVolumeFilters;
// std::list<CFogVolumeFilter>::iterator m_nextFogVolumeFilter;
std::list<std::pair<zeus::CVector3f, float>> x2c4_spaceWarps;
u32 x2dc_reflectionAge = 2;
zeus::CColor x2e0_ = zeus::skWhite;
zeus::CVector3f x2e4_ = {0.f, 1.f, 0.f};
CSpaceWarpFilter m_spaceWarpFilter;
float x2f0_thermalVisorLevel;
zeus::CColor x2f4_thermColor;
float x2f8_thermColdScale = 0.f;
zeus::CColor x2fc_tevReg1Color = {1.f, 0.f, 1.f, 1.f};
std::optional<CThermalColdFilter> m_thermColdFilter;
std::optional<CThermalHotFilter> m_thermHotFilter;
std::vector<CLight> x300_dynamicLights;
u32 x310_phazonSuitMaskCountdown = 0;
// std::unique_ptr<CTexture> x314_phazonSuitMask;
CPhazonSuitFilter m_phazonSuitFilter;
bool x318_24_refectionDirty : 1 = false;
bool x318_25_drawWireframe : 1 = false;
bool x318_26_requestRGBA6 : 1 = false;
bool x318_27_currentRGBA6 : 1 = false;
bool x318_28_disableFog : 1 = false;
bool x318_29_thermalVisor : 1 = false;
bool x318_30_inAreaDraw : 1 = false;
bool x318_31_persistRGBA6 : 1 = false;
bool m_thermalHotPass : 1 = false;
// void GenerateFogVolumeRampTex();
// void GenerateSphereRampTex();
// void GenerateScanLinesVBO();
// void LoadThermoPalette();
// void LoadBallFade();
void ActivateLightsForModel(CAreaListItem* item, CBooModel& model);
void RenderBucketItems(CAreaListItem* item);
void HandleUnsortedModel(CAreaListItem* item, CBooModel& model, const CModelFlags& flags);
static void CalcDrawFogFan(const zeus::CPlane* planes, size_t numPlanes, const zeus::CVector3f* verts,
size_t numVerts, size_t iteration, size_t level, CFogVolumePlaneShader& fogVol);
static void DrawFogSlices(const zeus::CPlane* planes, size_t numPlanes, size_t iteration,
const zeus::CVector3f& center, float delta, CFogVolumePlaneShader& fogVol);
static void RenderFogVolumeModel(const zeus::CAABox& aabb, const CModel* model, const zeus::CTransform& modelMtx,
const zeus::CTransform& viewMtx, const CSkinnedModel* sModel, int pass);
void SetupRendererStates() const;
void ReallyDrawPhazonSuitIndirectEffect(const zeus::CColor& vertColor, /*const CTexture& maskTex,*/
const CTexture& indTex, const zeus::CColor& modColor, float scale, float offX,
float offY);
void ReallyDrawPhazonSuitEffect(const zeus::CColor& modColor /*, const CTexture& maskTex*/);
void DoPhazonSuitIndirectAlphaBlur(float blurRadius /*, float f2*/, const TLockedToken<CTexture>& indTex);
public:
CBooRenderer(IObjectStore& store, IFactory& resFac);
~CBooRenderer() override;
void AddWorldSurfaces(CBooModel& model);
std::list<CAreaListItem>::iterator FindStaticGeometry(const std::vector<CMetroidModelInstance>*);
void AddStaticGeometry(const std::vector<CMetroidModelInstance>* geometry, const CAreaRenderOctTree* octTree,
int areaIdx, const SShader* shaderSet) override;
void EnablePVS(const CPVSVisSet& set, u32 areaIdx) override;
void DisablePVS() override;
void UpdateAreaUniforms(int areaIdx, EWorldShadowMode shadowMode = EWorldShadowMode::None, bool activateLights = true,
int cubeFace = -1, const CModelFlags* ballShadowFlags = nullptr);
void RemoveStaticGeometry(const std::vector<CMetroidModelInstance>*) override;
void DrawAreaGeometry(int areaIdx, int mask, int targetMask) override;
void DrawUnsortedGeometry(int areaIdx, int mask, int targetMask, bool shadowRender = false) override;
void DrawSortedGeometry(int areaIdx, int mask, int targetMask) override;
void DrawStaticGeometry(int areaIdx, int mask, int targetMask) override;
void DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly) override;
void PostRenderFogs() override;
void SetModelMatrix(const zeus::CTransform& xf) override;
void AddParticleGen(CParticleGen& gen) override;
void AddParticleGen(CParticleGen& gen, const zeus::CVector3f& pos, const zeus::CAABox& bounds) override;
void AddPlaneObject(void* obj, const zeus::CAABox& aabb, const zeus::CPlane& plane, int type) override;
void AddDrawable(void* obj, const zeus::CVector3f& pos, const zeus::CAABox& aabb, int mode,
EDrawableSorting sorting) override;
void SetDrawableCallback(TDrawableCallback cb, void* ctx) override;
void SetWorldViewpoint(const zeus::CTransform& xf) override;
void SetPerspective(float fovy, float width, float height, float znear, float zfar) override;
void SetPerspective(float fovy, float aspect, float znear, float zfar) override;
std::pair<zeus::CVector2f, zeus::CVector2f> SetViewportOrtho(bool centered, float znear, float zfar) override;
void SetClippingPlanes(const zeus::CFrustum& frustum) override;
void SetViewport(int left, int bottom, int width, int height) override;
// void SetDepthReadWrite(bool, bool);
// void SetBlendMode_AdditiveAlpha();
// void SetBlendMode_AlphaBlended();
// void SetBlendMode_NoColorWrite();
// void SetBlendMode_ColorMultiply();
// void SetBlendMode_InvertDst();
// void SetBlendMode_InvertSrc();
// void SetBlendMode_Replace();
// void SetBlendMode_AdditiveDestColor();
void SetDebugOption(EDebugOption, int) override;
void BeginScene() override;
void EndScene() override;
// void BeginPrimitive(EPrimitiveType, int);
// void BeginLines(int);
// void BeginLineStrip(int);
// void BeginTriangles(int);
// void BeginTriangleStrip(int);
// void BeginTriangleFan(int);
// void PrimVertex(const zeus::CVector3f&);
// void PrimNormal(const zeus::CVector3f&);
// void PrimColor(float, float, float, float);
// void PrimColor(const zeus::CColor&);
// void EndPrimitive();
void SetAmbientColor(const zeus::CColor& color) override;
void DrawString(const char* string, int, int) override;
u32 GetFPS() override;
void CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) override;
void DrawSpaceWarp(const zeus::CVector3f& pt, float strength) override;
void DrawThermalModel(const CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol) override;
void DrawXRayOutline(const zeus::CAABox&) override;
void SetWireframeFlags(int flags) override;
void SetWorldFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color) override;
void RenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, const TLockedToken<CModel>* model,
const CSkinnedModel* sModel) override;
void SetThermal(bool thermal, float level, const zeus::CColor& color) override;
void SetThermalColdScale(float scale) override;
void DoThermalBlendCold() override;
void DoThermalBlendHot() override;
u32 GetStaticWorldDataSize() override;
void PrepareDynamicLights(const std::vector<CLight>& lights) override;
void SetGXRegister1Color(const zeus::CColor& color) override;
void SetWorldLightFadeLevel(float level) override;
void SetWorldLightMultiplyColor(const zeus::CColor& col) override;
void DrawPhazonSuitIndirectEffect(const zeus::CColor& nonIndirectMod, const TLockedToken<CTexture>& indTex,
const zeus::CColor& indirectMod, float blurRadius, float indScale, float indOffX,
float indOffY);
void AllocatePhazonSuitMaskTexture();
void ReallyRenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, const CModel* model,
const CSkinnedModel* sModel);
// const boo::ObjToken<boo::ITexture>& GetThermoPalette() const { return x288_thermoPalette; }
// const boo::ObjToken<boo::ITextureS>& GetFogRampTex() const { return x1b8_fogVolumeRamp; }
// const boo::ObjToken<boo::ITexture>& GetRandomStaticEntropyTex() const { return m_staticEntropy->GetBooTexture(); }
// const boo::ObjToken<boo::IGraphicsBufferS>& GetScanLinesEvenVBO() const { return m_scanLinesEvenVBO; }
// const boo::ObjToken<boo::IGraphicsBufferS>& GetScanLinesOddVBO() const { return m_scanLinesOddVBO; }
const aurora::gfx::TextureHandle& GetClearTexture() const { return m_clearTexture; }
const aurora::gfx::TextureHandle& GetBlackTexture() const { return m_blackTexture; }
const aurora::gfx::TextureHandle& GetWhiteTexture() const { return m_whiteTexture; }
aurora::gfx::TextureHandle GetColorTexture(const zeus::CColor& color);
static void BindMainDrawTarget() {
// CGraphics::g_BooMainCommandQueue->setRenderTarget(CGraphics::g_SpareTexture);
}
void BindReflectionDrawTarget() {
// CGraphics::g_BooMainCommandQueue->setRenderTarget(x14c_reflectionTex);
}
void BindBallShadowIdTarget() {
// CGraphics::g_BooMainCommandQueue->setRenderTarget(m_ballShadowId);
SetViewport(0, 0, m_ballShadowIdW, m_ballShadowIdH);
}
void ResolveBallShadowIdTarget() {
// CGraphics::g_BooMainCommandQueue->resolveBindTexture(
// m_ballShadowId, boo::SWindowRect(0, 0, m_ballShadowIdW, m_ballShadowIdH), false, 0, true, false);
}
void FindOverlappingWorldModels(std::vector<u32>& modelBits, const zeus::CAABox& aabb) const;
int DrawOverlappingWorldModelIDs(int alphaVal, const std::vector<u32>& modelBits, const zeus::CAABox& aabb);
void DrawOverlappingWorldModelShadows(int alphaVal, const std::vector<u32>& modelBits, const zeus::CAABox& aabb,
float alpha);
bool IsThermalVisorActive() const { return x318_29_thermalVisor; }
bool IsThermalVisorHotPass() const { return m_thermalHotPass; }
};
} // namespace metaforce

File diff suppressed because it is too large Load Diff

View File

@ -312,7 +312,7 @@ u32 CCubeMaterial::HandleColorChannels(u32 chanCount, u32 firstChan) {
CGX::SetChanAmbColor(CGX::EChannelId::Channel1, GX_BLACK); CGX::SetChanAmbColor(CGX::EChannelId::Channel1, GX_BLACK);
CGX::SetChanMatColor(CGX::EChannelId::Channel1, GX_WHITE); CGX::SetChanMatColor(CGX::EChannelId::Channel1, GX_WHITE);
auto chan0Lights = CGraphics::g_LightActive & ~CCubeModel::sChannel0DisableLightMask; auto chan0Lights = CGraphics::mLightActive & ~CCubeModel::sChannel0DisableLightMask;
CGX::SetChanCtrl(CGX::EChannelId::Channel0, firstChan, chan0Lights); CGX::SetChanCtrl(CGX::EChannelId::Channel0, firstChan, chan0Lights);
CGX::SetChanCtrl(CGX::EChannelId::Channel1, CCubeModel::sChannel1EnableLightMask); CGX::SetChanCtrl(CGX::EChannelId::Channel1, CCubeModel::sChannel1EnableLightMask);
if (chan0Lights.any()) { if (chan0Lights.any()) {
@ -334,8 +334,8 @@ u32 CCubeMaterial::HandleColorChannels(u32 chanCount, u32 firstChan) {
if (chanCount == 0) { if (chanCount == 0) {
CGX::SetChanCtrl(CGX::EChannelId::Channel0, {}); CGX::SetChanCtrl(CGX::EChannelId::Channel0, {});
} else { } else {
CGX::SetChanCtrl(CGX::EChannelId::Channel0, firstChan, CGraphics::g_LightActive); CGX::SetChanCtrl(CGX::EChannelId::Channel0, firstChan, CGraphics::mLightActive);
if (CGraphics::g_LightActive.any()) { if (CGraphics::mLightActive.any()) {
CGX::SetChanMatColor(CGX::EChannelId::Channel0, GX_WHITE); CGX::SetChanMatColor(CGX::EChannelId::Channel0, GX_WHITE);
} else { } else {
CGX::SetChanMatColor(CGX::EChannelId::Channel0, CGX::GetChanAmbColor(CGX::EChannelId::Channel0)); CGX::SetChanMatColor(CGX::EChannelId::Channel0, CGX::GetChanAmbColor(CGX::EChannelId::Channel0));
@ -363,26 +363,35 @@ void CCubeMaterial::HandleTev(u32 tevCur, const u32* materialDataCur, const u32*
CGX::SetTevKAlphaSel(stage, static_cast<GXTevKAlphaSel>(matFlags >> 0x10 & 0xFF)); CGX::SetTevKAlphaSel(stage, static_cast<GXTevKAlphaSel>(matFlags >> 0x10 & 0xFF));
} }
constexpr zeus::CTransform MvPostXf{ u32 CCubeMaterial::HandleAnimatedUV(const u32* uvAnim, GXTexMtx texMtx, GXPTTexMtx ptTexMtx) {
{zeus::CVector3f{0.5f, 0.f, 0.f}, {0.f, 0.f, 0.f}, {0.f, 0.5f, 0.f}}, static const Mtx postMtx = {
{0.5f, 0.5f, 1.f}, {0.5f, 0.0f, 0.0f, 0.5f},
}; {0.0f, 0.0f, 0.5f, 0.5f},
{0.0f, 0.0f, 0.0f, 1.0f},
u32 CCubeMaterial::HandleAnimatedUV(const u32* uvAnim, GXTexMtx texMtx, GXPTTexMtx pttTexMtx) { };
static Mtx translateMtx = {
{1.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 1.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 1.0f, 0.0f},
};
u32 type = SBig(*uvAnim); u32 type = SBig(*uvAnim);
const float* params = reinterpret_cast<const float*>(uvAnim + 1); const float* params = reinterpret_cast<const float*>(uvAnim + 1);
switch (type) { switch (type) {
case 0: { case 0: {
auto xf = CGraphics::g_ViewMatrix.inverse().multiplyIgnoreTranslation(CGraphics::g_GXModelMatrix); auto xf = CGraphics::GetViewMatrix().quickInverse().multiplyIgnoreTranslation(CGraphics::GetModelMatrix());
xf.origin.zeroOut(); xf.origin.zeroOut();
GXLoadTexMtxImm(&xf, texMtx, GX_MTX3x4); Mtx mtx;
GXLoadTexMtxImm(&MvPostXf, pttTexMtx, GX_MTX3x4); xf.toCStyleMatrix(mtx);
GXLoadTexMtxImm(mtx, texMtx, GX_MTX3x4);
GXLoadTexMtxImm(postMtx, ptTexMtx, GX_MTX3x4);
return 1; return 1;
} }
case 1: { case 1: {
auto xf = CGraphics::g_ViewMatrix.inverse() * CGraphics::g_GXModelMatrix; auto xf = CGraphics::GetViewMatrix().quickInverse() * CGraphics::GetModelMatrix();
GXLoadTexMtxImm(&xf, texMtx, GX_MTX3x4); Mtx mtx;
GXLoadTexMtxImm(&MvPostXf, pttTexMtx, GX_MTX3x4); xf.toCStyleMatrix(mtx);
GXLoadTexMtxImm(mtx, texMtx, GX_MTX3x4);
GXLoadTexMtxImm(postMtx, ptTexMtx, GX_MTX3x4);
return 1; return 1;
} }
case 2: { case 2: {
@ -391,74 +400,101 @@ u32 CCubeMaterial::HandleAnimatedUV(const u32* uvAnim, GXTexMtx texMtx, GXPTTexM
const float f3 = SBig(params[2]); const float f3 = SBig(params[2]);
const float f4 = SBig(params[3]); const float f4 = SBig(params[3]);
const float seconds = CGraphics::GetSecondsMod900(); const float seconds = CGraphics::GetSecondsMod900();
const auto xf = zeus::CTransform::Translate(seconds * f3 + f1, seconds * f4 + f2, 0.f); translateMtx[0][3] = f1 + seconds * f3;
GXLoadTexMtxImm(&xf, texMtx, GX_MTX3x4); translateMtx[1][3] = f2 + seconds * f4;
GXLoadTexMtxImm(translateMtx, texMtx, GX_MTX3x4);
return 5; return 5;
} }
case 3: { case 3: {
const float angle = CGraphics::GetSecondsMod900() * SBig(params[1]) + SBig(params[0]); const float f1 = SBig(params[0]);
const float acos = std::cos(angle); const float f2 = SBig(params[1]);
const float seconds = CGraphics::GetSecondsMod900();
const float angle = f1 + seconds * f2;
const float asin = std::sin(angle); const float asin = std::sin(angle);
zeus::CTransform xf; const float acos = std::cos(angle);
xf.basis[0][0] = acos; Mtx mtx = {
xf.basis[0][1] = asin; {acos, -asin, 0.f, (1.f - (acos - asin)) * 0.5f},
xf.basis[1][0] = -asin; {asin, acos, 0.f, (1.f - (asin + acos)) * 0.5f},
xf.basis[1][1] = acos; {0.f, 0.f, 1.f, 0.f},
xf.origin[0] = (1.f - (acos - asin)) * 0.5f; };
xf.origin[1] = (1.f - (asin + acos)) * 0.5f; GXLoadTexMtxImm(mtx, texMtx, GX_MTX3x4);
GXLoadTexMtxImm(&xf, texMtx, GX_MTX3x4);
return 3; return 3;
} }
case 4: case 4:
case 5: { case 5: {
zeus::CTransform xf; const float f1 = SBig(params[0]);
const float value = SBig(params[0]) * SBig(params[2]) * (SBig(params[3]) + CGraphics::GetSecondsMod900()); const float f2 = SBig(params[1]);
const float f3 = SBig(params[2]);
const float f4 = SBig(params[3]);
const float value = (f4 + CGraphics::GetSecondsMod900()) * f1 * f3;
const float fmod = std::fmod(value, 1.f);
const float fs = std::trunc(fmod * f2);
const float v2 = fs * f3;
if (type == 4) { if (type == 4) {
xf.origin.x() = std::trunc(SBig(params[1]) * std::fmod(value, 1.f)) * SBig(params[2]); translateMtx[0][3] = v2;
xf.origin.y() = 0.f; translateMtx[1][3] = 0.f;
} else { } else {
xf.origin.x() = 0.f; translateMtx[0][3] = 0.f;
xf.origin.y() = std::trunc(SBig(params[1]) * std::fmod(value, 1.f)) * SBig(params[2]); translateMtx[1][3] = v2;
} }
GXLoadTexMtxImm(&xf, texMtx, GX_MTX3x4); GXLoadTexMtxImm(translateMtx, texMtx, GX_MTX3x4);
return 5; return 5;
} }
case 6: { case 6: {
const zeus::CTransform mtx{CGraphics::g_GXModelMatrix.basis}; static const Mtx sTexMtx = {
const zeus::CTransform postMtx{ {0.f, 0.f, 0.f, 0.f},
{ {0.f, 0.f, 0.f, 0.f},
zeus::CVector3f{0.5f, 0.f, 0.f}, {0.f, 0.f, 0.f, 0.f},
zeus::CVector3f{0.f, 0.f, 0.f},
zeus::CVector3f{0.f, 0.5f, 0.f},
},
zeus::CVector3f{
CGraphics::g_GXModelMatrix.origin.x() * 0.05f,
CGraphics::g_GXModelMatrix.origin.y() * 0.05f,
1.f,
},
}; };
GXLoadTexMtxImm(&mtx, texMtx, GX_MTX3x4); static const Mtx sPtMtx = {
GXLoadTexMtxImm(&postMtx, pttTexMtx, GX_MTX3x4); {0.5f, 0.f, 0.f, 0.f},
{0.f, 0.f, 0.5f, 0.f},
{0.f, 0.f, 0.f, 1.f},
};
const zeus::CTransform& mm = CGraphics::GetModelMatrix();
Mtx tmpTexMtx;
Mtx tmpPtMtx;
memcpy(&tmpTexMtx, &sTexMtx, sizeof(Mtx));
tmpTexMtx[0][0] = mm.basis[0][0];
tmpTexMtx[0][1] = mm.basis[1][0];
tmpTexMtx[0][2] = mm.basis[2][0];
tmpTexMtx[1][0] = mm.basis[0][1];
tmpTexMtx[1][1] = mm.basis[1][1];
tmpTexMtx[1][2] = mm.basis[2][1];
tmpTexMtx[2][0] = mm.basis[0][2];
tmpTexMtx[2][1] = mm.basis[1][2];
tmpTexMtx[2][2] = mm.basis[2][2];
memcpy(&tmpPtMtx, &sPtMtx, sizeof(Mtx));
tmpPtMtx[0][3] = mm.origin.x() * 0.05f;
tmpPtMtx[1][3] = mm.origin.y() * 0.05f;
GXLoadTexMtxImm(tmpTexMtx, texMtx, GX_MTX3x4);
GXLoadTexMtxImm(tmpPtMtx, ptTexMtx, GX_MTX3x4);
return 1; return 1;
} }
case 7: { case 7: {
zeus::CTransform mtx = CGraphics::g_ViewMatrix.inverse().multiplyIgnoreTranslation(CGraphics::g_GXModelMatrix); static const Mtx sPtMtx = {
mtx.origin.zeroOut(); {0.f, 0.f, 0.f, 0.f},
float xy = SBig(params[1]) * (CGraphics::g_ViewMatrix.origin.x() + CGraphics::g_ViewMatrix.origin.y()) * 0.025f; {0.f, 0.f, 0.f, 0.f},
xy = (xy - static_cast<int>(xy)); {0.f, 0.f, 0.f, 1.f},
float z = SBig(params[1]) * CGraphics::g_ViewMatrix.origin.z() * 0.05f;
z = (z - static_cast<int>(z));
float halfA = SBig(params[0]) * 0.5f;
zeus::CTransform postMtx{
{
zeus::CVector3f{halfA, 0.f, 0.f},
zeus::CVector3f{0.f, 0.f, 0.f},
zeus::CVector3f{0.f, halfA, 0.f},
},
zeus::CVector3f{xy, z, 1.f},
}; };
GXLoadTexMtxImm(&mtx, texMtx, GX_MTX3x4); const zeus::CTransform& vm = CGraphics::GetViewMatrix();
GXLoadTexMtxImm(&postMtx, pttTexMtx, GX_MTX3x4); zeus::CTransform xf = vm.quickInverse().multiplyIgnoreTranslation(CGraphics::GetModelMatrix());
float v = SBig(params[0]) / 2.f;
float v03 = 0.025f * (vm.origin.x() + vm.origin.y()) * SBig(params[1]);
float v13 = 0.05f * vm.origin.z() * SBig(params[1]);
float v03f = std::fmod(v03, 1.f);
float v13f = std::fmod(v13, 1.f);
xf.origin.zeroOut();
Mtx mtx;
xf.toCStyleMatrix(mtx);
Mtx tmpPtMtx;
memcpy(&tmpPtMtx, &sPtMtx, sizeof(Mtx));
tmpPtMtx[0][0] = v;
tmpPtMtx[0][3] = v03f;
tmpPtMtx[1][2] = v;
tmpPtMtx[1][3] = v13f;
GXLoadTexMtxImm(mtx, texMtx, GX_MTX3x4);
GXLoadTexMtxImm(tmpPtMtx, ptTexMtx, GX_MTX3x4);
return 3; return 3;
} }
default: default:

View File

@ -22,10 +22,9 @@ static bool sDrawingWireframe = false;
static zeus::CVector3f sPlayerPosition; static zeus::CVector3f sPlayerPosition;
CCubeModel::CCubeModel(std::vector<CCubeSurface>* surfaces, std::vector<TCachedToken<CTexture>>* textures, CCubeModel::CCubeModel(std::vector<CCubeSurface>* surfaces, std::vector<TCachedToken<CTexture>>* textures,
u8* materialData, std::vector<zeus::CVector3f>* positions, std::vector<zeus::CColor>* colors, u8* materialData, std::span<const u8> positions, std::span<const u8> colors,
std::vector<zeus::CVector3f>* normals, std::vector<aurora::Vec2<float>>* texCoords, std::span<const u8> normals, std::span<const u8> texCoords, std::span<const u8> packedTexCoords,
std::vector<aurora::Vec2<float>>* packedTexCoords, const zeus::CAABox& aabb, u8 flags, bool b1, const zeus::CAABox& aabb, u8 flags, bool b1, u32 idx)
u32 idx)
: x0_modelInstance(surfaces, materialData, positions, colors, normals, texCoords, packedTexCoords) : x0_modelInstance(surfaces, materialData, positions, colors, normals, texCoords, packedTexCoords)
, x1c_textures(textures) , x1c_textures(textures)
, x20_worldAABB(aabb) , x20_worldAABB(aabb)
@ -148,7 +147,7 @@ void CCubeModel::DrawAlphaSurfaces(const CModelFlags& flags) {
} }
void CCubeModel::DrawFlat(TConstVectorRef positions, TConstVectorRef normals, ESurfaceSelection surfaces) { void CCubeModel::DrawFlat(TConstVectorRef positions, TConstVectorRef normals, ESurfaceSelection surfaces) {
if (positions == nullptr) { if (positions.empty()) {
SetArraysCurrent(); SetArraysCurrent();
} else { } else {
SetSkinningArraysCurrent(positions, normals); SetSkinningArraysCurrent(positions, normals);
@ -259,8 +258,8 @@ void CCubeModel::EnableShadowMaps(const CTexture& shadowTex, const zeus::CTransf
void CCubeModel::DisableShadowMaps() { sRenderModelShadow = false; } void CCubeModel::DisableShadowMaps() { sRenderModelShadow = false; }
void CCubeModel::SetArraysCurrent() { void CCubeModel::SetArraysCurrent() {
CGX::SetArray(GX_VA_POS, x0_modelInstance.GetVertexPointer(), true); CGX::SetArray(GX_VA_POS, x0_modelInstance.GetVertexPointer(), 12);
CGX::SetArray(GX_VA_NRM, x0_modelInstance.GetNormalPointer(), true); CGX::SetArray(GX_VA_NRM, x0_modelInstance.GetNormalPointer(), (x41_visorFlags & 1) != 0 ? 6 : 12);
SetStaticArraysCurrent(); SetStaticArraysCurrent();
} }
@ -280,26 +279,26 @@ void CCubeModel::SetRenderModelBlack(bool v) {
} }
void CCubeModel::SetSkinningArraysCurrent(TConstVectorRef positions, TConstVectorRef normals) { void CCubeModel::SetSkinningArraysCurrent(TConstVectorRef positions, TConstVectorRef normals) {
CGX::SetArray(GX_VA_POS, positions, false); CGX::SetArray(GX_VA_POS, positions);
CGX::SetArray(GX_VA_NRM, normals, false); CGX::SetArray(GX_VA_NRM, normals);
// colors unused // colors unused
SetStaticArraysCurrent(); SetStaticArraysCurrent();
} }
void CCubeModel::SetStaticArraysCurrent() { void CCubeModel::SetStaticArraysCurrent() {
// colors unused if (!x0_modelInstance.GetColorPointer().empty()) {
const auto* packedTexCoords = x0_modelInstance.GetPackedTCPointer(); CGX::SetArray(GX_VA_CLR0, x0_modelInstance.GetColorPointer(), 4);
const auto* texCoords = x0_modelInstance.GetTCPointer();
if (packedTexCoords == nullptr) {
sUsingPackedLightmaps = false;
} }
const auto packedTexCoords = x0_modelInstance.GetPackedTCPointer();
const auto texCoords = x0_modelInstance.GetTCPointer();
sUsingPackedLightmaps = !packedTexCoords.empty();
if (sUsingPackedLightmaps) { if (sUsingPackedLightmaps) {
CGX::SetArray(GX_VA_TEX0, packedTexCoords, true); CGX::SetArray(GX_VA_TEX0, packedTexCoords, 4);
} else { } else {
CGX::SetArray(GX_VA_TEX0, texCoords, true); CGX::SetArray(GX_VA_TEX0, texCoords, 8);
} }
for (int i = GX_VA_TEX1; i <= GX_VA_TEX7; ++i) { for (int i = GX_VA_TEX1; i <= GX_VA_TEX7; ++i) {
CGX::SetArray(static_cast<GXAttr>(i), texCoords, true); CGX::SetArray(static_cast<GXAttr>(i), texCoords, 8);
} }
CCubeMaterial::KillCachedViewDepState(); CCubeMaterial::KillCachedViewDepState();
} }
@ -307,16 +306,39 @@ void CCubeModel::SetStaticArraysCurrent() {
void CCubeModel::SetUsingPackedLightmaps(bool v) { void CCubeModel::SetUsingPackedLightmaps(bool v) {
sUsingPackedLightmaps = v; sUsingPackedLightmaps = v;
if (v) { if (v) {
CGX::SetArray(GX_VA_TEX0, x0_modelInstance.GetPackedTCPointer(), true); CGX::SetArray(GX_VA_TEX0, x0_modelInstance.GetPackedTCPointer(), 4);
} else { } else {
CGX::SetArray(GX_VA_TEX0, x0_modelInstance.GetTCPointer(), true); CGX::SetArray(GX_VA_TEX0, x0_modelInstance.GetTCPointer(), 8);
} }
} }
template <> template <>
aurora::Vec2<float> cinput_stream_helper(CInputStream& in) { aurora::Vec2<float> cinput_stream_helper(CInputStream& in) {
float x = in.ReadFloat(); const auto x = in.ReadFloat();
float y = in.ReadFloat(); const auto y = in.ReadFloat();
return {x, y}; return {x, y};
} }
template <>
aurora::Vec3<float> cinput_stream_helper(CInputStream& in) {
const auto x = in.ReadFloat();
const auto y = in.ReadFloat();
const auto z = in.ReadFloat();
return {x, y, z};
}
template <>
aurora::Vec2<u16> cinput_stream_helper(CInputStream& in) {
const auto x = in.ReadUint16();
const auto y = in.ReadUint16();
return {x, y};
}
template <>
aurora::Vec3<s16> cinput_stream_helper(CInputStream& in) {
const auto x = in.ReadInt16();
const auto y = in.ReadInt16();
const auto z = in.ReadInt16();
return {x, y, z};
}
} // namespace metaforce } // namespace metaforce

View File

@ -2,6 +2,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <span>
#include <aurora/math.hpp> #include <aurora/math.hpp>
#include "CStopwatch.hpp" #include "CStopwatch.hpp"
@ -22,8 +23,13 @@ enum class ESurfaceSelection {
}; };
// These parameters were originally float* // These parameters were originally float*
using TVectorRef = std::vector<zeus::CVector3f>*; using TVectorRef = std::vector<aurora::Vec3<float>>*;
using TConstVectorRef = const std::vector<zeus::CVector3f>*; using TConstVectorRef = std::span<const aurora::Vec3<float>>;
template <typename T>
std::span<const u8> byte_span(const std::vector<T>& vec) {
return std::span(reinterpret_cast<const u8*>(vec.data()), vec.size() * sizeof(T));
}
class CCubeModel { class CCubeModel {
friend class CModel; friend class CModel;
@ -33,16 +39,16 @@ private:
class ModelInstance { class ModelInstance {
std::vector<CCubeSurface>* x0_surfacePtrs; // was rstl::vector<void*>* std::vector<CCubeSurface>* x0_surfacePtrs; // was rstl::vector<void*>*
u8* x4_materialData; // u8* x4_materialData; //
std::vector<zeus::CVector3f>* x8_positions; // was void* std::span<const u8> x8_positions; // was void*
std::vector<zeus::CVector3f>* xc_normals; // was void* std::span<const u8> xc_normals; // was void*
std::vector<zeus::CColor>* x10_colors; // was void* std::span<const u8> x10_colors; // was void*
std::vector<aurora::Vec2<float>>* x14_texCoords; // was void* std::span<const u8> x14_texCoords; // was void*
std::vector<aurora::Vec2<float>>* x18_packedTexCoords; // was void* std::span<const u8> x18_packedTexCoords; // was void*
public: public:
ModelInstance(std::vector<CCubeSurface>* surfaces, u8* material, std::vector<zeus::CVector3f>* positions, ModelInstance(std::vector<CCubeSurface>* surfaces, u8* material, std::span<const u8> positions,
std::vector<zeus::CColor>* colors, std::vector<zeus::CVector3f>* normals, std::span<const u8> colors, std::span<const u8> normals, std::span<const u8> texCoords,
std::vector<aurora::Vec2<float>>* texCoords, std::vector<aurora::Vec2<float>>* packedTexCoords) std::span<const u8> packedTexCoords)
: x0_surfacePtrs(surfaces) : x0_surfacePtrs(surfaces)
, x4_materialData(material) , x4_materialData(material)
, x8_positions(positions) , x8_positions(positions)
@ -58,13 +64,11 @@ private:
[[nodiscard]] std::vector<CCubeSurface>* Surfaces() const { return x0_surfacePtrs; } [[nodiscard]] std::vector<CCubeSurface>* Surfaces() const { return x0_surfacePtrs; }
[[nodiscard]] u8* GetMaterialPointer() const { return x4_materialData; } [[nodiscard]] u8* GetMaterialPointer() const { return x4_materialData; }
void SetMaterialPointer(u8* mat) { x4_materialData = mat; } void SetMaterialPointer(u8* mat) { x4_materialData = mat; }
[[nodiscard]] TVectorRef GetVertexPointer() { return x8_positions; } [[nodiscard]] std::span<const u8> GetVertexPointer() const { return x8_positions; }
[[nodiscard]] TConstVectorRef GetVertexPointer() const { return x8_positions; } [[nodiscard]] std::span<const u8> GetNormalPointer() const { return xc_normals; }
[[nodiscard]] TVectorRef GetNormalPointer() { return xc_normals; } [[nodiscard]] std::span<const u8> GetColorPointer() const { return x10_colors; }
[[nodiscard]] TConstVectorRef GetNormalPointer() const { return xc_normals; } [[nodiscard]] std::span<const u8> GetTCPointer() const { return x14_texCoords; }
[[nodiscard]] std::vector<zeus::CColor>* GetColorPointer() const { return x10_colors; } [[nodiscard]] std::span<const u8> GetPackedTCPointer() const { return x18_packedTexCoords; }
[[nodiscard]] std::vector<aurora::Vec2<float>>* GetTCPointer() const { return x14_texCoords; }
[[nodiscard]] std::vector<aurora::Vec2<float>>* GetPackedTCPointer() const { return x18_packedTexCoords; }
}; };
ModelInstance x0_modelInstance; ModelInstance x0_modelInstance;
@ -79,9 +83,9 @@ private:
public: public:
CCubeModel(std::vector<CCubeSurface>* surfaces, std::vector<TCachedToken<CTexture>>* textures, u8* materialData, CCubeModel(std::vector<CCubeSurface>* surfaces, std::vector<TCachedToken<CTexture>>* textures, u8* materialData,
std::vector<zeus::CVector3f>* positions, std::vector<zeus::CColor>* colors, std::span<const u8> positions, std::span<const u8> colors, std::span<const u8> normals,
std::vector<zeus::CVector3f>* normals, std::vector<aurora::Vec2<float>>* texCoords, std::span<const u8> texCoords, std::span<const u8> packedTexCoords, const zeus::CAABox& aabb, u8 flags,
std::vector<aurora::Vec2<float>>* packedTexCoords, const zeus::CAABox& aabb, u8 flags, bool b1, u32 idx); bool b1, u32 idx);
CCubeMaterial GetMaterialByIndex(u32 idx); CCubeMaterial GetMaterialByIndex(u32 idx);
bool TryLockTextures(); bool TryLockTextures();
@ -107,10 +111,14 @@ public:
[[nodiscard]] CCubeSurface* GetFirstSortedSurface() { return x3c_firstSortedSurf; } [[nodiscard]] CCubeSurface* GetFirstSortedSurface() { return x3c_firstSortedSurf; }
[[nodiscard]] const CCubeSurface* GetFirstSortedSurface() const { return x3c_firstSortedSurf; } [[nodiscard]] const CCubeSurface* GetFirstSortedSurface() const { return x3c_firstSortedSurf; }
[[nodiscard]] TVectorRef GetPositions() { return x0_modelInstance.GetVertexPointer(); } [[nodiscard]] TConstVectorRef GetPositions() const {
[[nodiscard]] TConstVectorRef GetPositions() const { return x0_modelInstance.GetVertexPointer(); } const auto sp = x0_modelInstance.GetVertexPointer();
[[nodiscard]] TVectorRef GetNormals() { return x0_modelInstance.GetNormalPointer(); } return {reinterpret_cast<const aurora::Vec3<float>*>(sp.data()), sp.size() / sizeof(aurora::Vec3<float>)};
[[nodiscard]] TConstVectorRef GetNormals() const { return x0_modelInstance.GetNormalPointer(); } }
[[nodiscard]] TConstVectorRef GetNormals() const {
const auto sp = x0_modelInstance.GetNormalPointer();
return {reinterpret_cast<const aurora::Vec3<float>*>(sp.data()), sp.size() / sizeof(aurora::Vec3<float>)};
}
[[nodiscard]] TCachedToken<CTexture>& GetTexture(u32 idx) const { return x1c_textures->at(idx); } [[nodiscard]] TCachedToken<CTexture>& GetTexture(u32 idx) const { return x1c_textures->at(idx); }
static void EnableShadowMaps(const CTexture& shadowTex, const zeus::CTransform& textureProjXf, static void EnableShadowMaps(const CTexture& shadowTex, const zeus::CTransform& textureProjXf,
@ -142,4 +150,10 @@ private:
template <> template <>
aurora::Vec2<float> cinput_stream_helper(CInputStream& in); aurora::Vec2<float> cinput_stream_helper(CInputStream& in);
template <>
aurora::Vec3<float> cinput_stream_helper(CInputStream& in);
template <>
aurora::Vec2<u16> cinput_stream_helper(CInputStream& in);
template <>
aurora::Vec3<s16> cinput_stream_helper(CInputStream& in);
} // namespace metaforce } // namespace metaforce

View File

@ -297,15 +297,11 @@ void CCubeRenderer::AddStaticGeometry(const std::vector<CMetroidModelInstance>*
models->reserve(geometry->size()); models->reserve(geometry->size());
s32 instIdx = 0; s32 instIdx = 0;
for (const CMetroidModelInstance& inst : *geometry) { for (const CMetroidModelInstance& inst : *geometry) {
models->emplace_back( models->emplace_back(std::make_unique<CCubeModel>(
std::make_unique<CCubeModel>(const_cast<std::vector<CCubeSurface>*>(inst.GetSurfaces()), textures.get(), const_cast<std::vector<CCubeSurface>*>(inst.GetSurfaces()), textures.get(),
const_cast<u8*>(inst.GetMaterialPointer()), const_cast<u8*>(inst.GetMaterialPointer()), inst.GetVertexPointer(), inst.GetColorPointer(),
const_cast<std::vector<zeus::CVector3f>*>(inst.GetVertexPointer()), inst.GetNormalPointer(), inst.GetTCPointer(), inst.GetPackedTCPointer(), inst.GetBoundingBox(),
const_cast<std::vector<zeus::CColor>*>(inst.GetColorPointer()), inst.GetFlags(), false, instIdx));
const_cast<std::vector<zeus::CVector3f>*>(inst.GetNormalPointer()),
const_cast<std::vector<aurora::Vec2<float>>*>(inst.GetTCPointer()),
const_cast<std::vector<aurora::Vec2<float>>*>(inst.GetPackedTCPointer()),
inst.GetBoundingBox(), inst.GetFlags(), false, instIdx));
++instIdx; ++instIdx;
} }
} }
@ -329,8 +325,7 @@ void CCubeRenderer::RemoveStaticGeometry(const std::vector<CMetroidModelInstance
void CCubeRenderer::DrawUnsortedGeometry(s32 areaIdx, s32 mask, s32 targetMask) { void CCubeRenderer::DrawUnsortedGeometry(s32 areaIdx, s32 mask, s32 targetMask) {
SCOPED_GRAPHICS_DEBUG_GROUP( SCOPED_GRAPHICS_DEBUG_GROUP(
fmt::format("CCubeRenderer::DrawUnsortedGeometry areaIdx={} mask={} targetMask={}", areaIdx, mask, fmt::format("CCubeRenderer::DrawUnsortedGeometry areaIdx={} mask={} targetMask={}", areaIdx, mask, targetMask)
targetMask)
.c_str(), .c_str(),
zeus::skBlue); zeus::skBlue);
@ -407,8 +402,7 @@ void CCubeRenderer::DrawUnsortedGeometry(s32 areaIdx, s32 mask, s32 targetMask)
void CCubeRenderer::DrawSortedGeometry(s32 areaIdx, s32 mask, s32 targetMask) { void CCubeRenderer::DrawSortedGeometry(s32 areaIdx, s32 mask, s32 targetMask) {
SCOPED_GRAPHICS_DEBUG_GROUP( SCOPED_GRAPHICS_DEBUG_GROUP(
fmt::format("CCubeRenderer::DrawSortedGeometry areaIdx={} mask={} targetMask={}", areaIdx, mask, fmt::format("CCubeRenderer::DrawSortedGeometry areaIdx={} mask={} targetMask={}", areaIdx, mask, targetMask)
targetMask)
.c_str(), .c_str(),
zeus::skBlue); zeus::skBlue);
@ -441,8 +435,7 @@ void CCubeRenderer::DrawStaticGeometry(s32 areaIdx, s32 mask, s32 targetMask) {
void CCubeRenderer::DrawAreaGeometry(s32 areaIdx, s32 mask, s32 targetMask) { void CCubeRenderer::DrawAreaGeometry(s32 areaIdx, s32 mask, s32 targetMask) {
SCOPED_GRAPHICS_DEBUG_GROUP( SCOPED_GRAPHICS_DEBUG_GROUP(
fmt::format("CCubeRenderer::DrawAreaGeometry areaIdx={} mask={} targetMask={}", areaIdx, mask, fmt::format("CCubeRenderer::DrawAreaGeometry areaIdx={} mask={} targetMask={}", areaIdx, mask, targetMask)
targetMask)
.c_str(), .c_str(),
zeus::skBlue); zeus::skBlue);
@ -488,8 +481,8 @@ void CCubeRenderer::DrawAreaGeometry(s32 areaIdx, s32 mask, s32 targetMask) {
} }
void CCubeRenderer::RenderBucketItems(const CAreaListItem* item) { void CCubeRenderer::RenderBucketItems(const CAreaListItem* item) {
SCOPED_GRAPHICS_DEBUG_GROUP( SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format("CCubeRenderer::RenderBucketItems areaIdx={}", item->x18_areaIdx).c_str(),
fmt::format("CCubeRenderer::RenderBucketItems areaIdx={}", item->x18_areaIdx).c_str(), zeus::skBlue); zeus::skBlue);
CCubeModel* lastModel = nullptr; CCubeModel* lastModel = nullptr;
EDrawableType lastDrawableType = EDrawableType::Invalid; EDrawableType lastDrawableType = EDrawableType::Invalid;
@ -544,19 +537,19 @@ void CCubeRenderer::PostRenderFogs() {
x2ac_fogVolumes.sort([](const CFogVolumeListItem& a, const CFogVolumeListItem& b) { x2ac_fogVolumes.sort([](const CFogVolumeListItem& a, const CFogVolumeListItem& b) {
zeus::CAABox aabbA = a.x34_aabb.getTransformedAABox(a.x0_transform); zeus::CAABox aabbA = a.x34_aabb.getTransformedAABox(a.x0_transform);
bool insideA = bool insideA = aabbA.pointInside(
aabbA.pointInside(zeus::CVector3f(CGraphics::g_ViewPoint.x(), CGraphics::g_ViewPoint.y(), aabbA.min.z())); zeus::CVector3f(CGraphics::mViewMatrix.origin.x(), CGraphics::mViewMatrix.origin.y(), aabbA.min.z()));
zeus::CAABox aabbB = b.x34_aabb.getTransformedAABox(b.x0_transform); zeus::CAABox aabbB = b.x34_aabb.getTransformedAABox(b.x0_transform);
bool insideB = bool insideB = aabbB.pointInside(
aabbB.pointInside(zeus::CVector3f(CGraphics::g_ViewPoint.x(), CGraphics::g_ViewPoint.y(), aabbB.min.z())); zeus::CVector3f(CGraphics::mViewMatrix.origin.x(), CGraphics::mViewMatrix.origin.y(), aabbB.min.z()));
if (insideA != insideB) { if (insideA != insideB) {
return insideA; return insideA;
} }
float dotA = aabbA.furthestPointAlongVector(CGraphics::g_ViewMatrix.basis[1]).dot(CGraphics::g_ViewMatrix.basis[1]); float dotA = aabbA.furthestPointAlongVector(CGraphics::mViewMatrix.basis[1]).dot(CGraphics::mViewMatrix.basis[1]);
float dotB = aabbB.furthestPointAlongVector(CGraphics::g_ViewMatrix.basis[1]).dot(CGraphics::g_ViewMatrix.basis[1]); float dotB = aabbB.furthestPointAlongVector(CGraphics::mViewMatrix.basis[1]).dot(CGraphics::mViewMatrix.basis[1]);
return dotA < dotB; return dotA < dotB;
}); });
for (const CFogVolumeListItem& fog : x2ac_fogVolumes) { for (const CFogVolumeListItem& fog : x2ac_fogVolumes) {
@ -677,8 +670,8 @@ void CCubeRenderer::AddPlaneObject(void* obj, const zeus::CAABox& aabb, const ze
if (closestDist >= 0.f || furthestDist >= 0.f) { if (closestDist >= 0.f || furthestDist >= 0.f) {
const bool zOnly = plane.normal() == zeus::skUp; const bool zOnly = plane.normal() == zeus::skUp;
const bool invertTest = zOnly ? CGraphics::g_GXModelView.origin.z() >= plane.d() const bool invertTest = zOnly ? CGraphics::mViewMatrix.origin.z() >= plane.d()
: plane.pointToPlaneDist(CGraphics::g_GXModelView.origin) >= 0.f; : plane.pointToPlaneDist(CGraphics::mViewMatrix.origin) >= 0.f;
Buckets::InsertPlaneObject(closestDist, furthestDist, aabb, invertTest, plane, zOnly, EDrawableType(type + 2), obj); Buckets::InsertPlaneObject(closestDist, furthestDist, aabb, invertTest, plane, zOnly, EDrawableType(type + 2), obj);
} }
} }
@ -735,14 +728,14 @@ void CCubeRenderer::SetViewport(s32 left, s32 bottom, s32 width, s32 height) {
void CCubeRenderer::BeginScene() { void CCubeRenderer::BeginScene() {
CGraphics::SetUseVideoFilter(true); CGraphics::SetUseVideoFilter(true);
CGraphics::SetViewport(0, 0, CGraphics::g_Viewport.x8_width, CGraphics::g_Viewport.xc_height); CGraphics::SetViewport(0, 0, CGraphics::mRenderModeObj.fbWidth, CGraphics::mRenderModeObj.xfbHeight);
CGraphics::SetClearColor(zeus::skClear); CGraphics::SetClearColor(zeus::skClear);
CGraphics::SetCullMode(ERglCullMode::Front); CGraphics::SetCullMode(ERglCullMode::Front);
CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, true); CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, true);
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha, CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha,
ERglLogicOp::Clear); ERglLogicOp::Clear);
CGraphics::SetPerspective(75.f, CGraphics::g_Viewport.x8_width / CGraphics::g_Viewport.xc_height, 1.f, 4096.f); CGraphics::SetPerspective(75.f, CGraphics::mViewport.mWidth / CGraphics::mViewport.mHeight, 1.f, 4096.f);
CGraphics::SetModelMatrix(zeus::CTransform()); CGraphics::SetModelMatrix(zeus::CTransform());
if (x310_phazonSuitMaskCountdown != 0) { if (x310_phazonSuitMaskCountdown != 0) {
--x310_phazonSuitMaskCountdown; --x310_phazonSuitMaskCountdown;
@ -756,14 +749,14 @@ void CCubeRenderer::BeginScene() {
x318_26_requestRGBA6 = false; x318_26_requestRGBA6 = false;
} }
// GXSetPixelFmt(x318_27_currentRGBA6, GX_ZC_LINEAR); GXSetPixelFmt(x318_27_currentRGBA6 ? GX_PF_RGBA6_Z24 : GX_PF_RGB8_Z24, GX_ZC_LINEAR);
GXSetAlphaUpdate(true); GXSetAlphaUpdate(true);
GXSetDstAlpha(true, 0.f); GXSetDstAlpha(true, 0.f);
CGraphics::BeginScene(); CGraphics::BeginScene();
} }
void CCubeRenderer::EndScene() { void CCubeRenderer::EndScene() {
x318_31_persistRGBA6 = !CGraphics::g_IsBeginSceneClearFb; x318_31_persistRGBA6 = !CGraphics::mIsBeginSceneClearFb;
CGraphics::EndScene(); CGraphics::EndScene();
if (x2dc_reflectionAge < 2) { if (x2dc_reflectionAge < 2) {
@ -802,7 +795,7 @@ void CCubeRenderer::BeginPrimitive(IRenderer::EPrimitiveType type, s32 nverts) {
CGX::SetStandardTevColorAlphaOp(GX_TEVSTAGE0); CGX::SetStandardTevColorAlphaOp(GX_TEVSTAGE0);
x18_primVertCount = nverts; x18_primVertCount = nverts;
CGX::SetVtxDescv(vtxDescList.data()); CGX::SetVtxDescv(vtxDescList.data());
CGX::Begin(GXPrimitive(type), GX_VTXFMT0, nverts); CGX::Begin(static_cast<GXPrimitive>(type), GX_VTXFMT0, nverts);
} }
void CCubeRenderer::BeginLines(s32 nverts) { BeginPrimitive(EPrimitiveType::Lines, nverts); } void CCubeRenderer::BeginLines(s32 nverts) { BeginPrimitive(EPrimitiveType::Lines, nverts); }
@ -839,7 +832,7 @@ void CCubeRenderer::SetAmbientColor(const zeus::CColor& color) { CGraphics::SetA
void CCubeRenderer::DrawString(const char* string, s32 x, s32 y) { x10_font.DrawString(string, x, y, zeus::skWhite); } void CCubeRenderer::DrawString(const char* string, s32 x, s32 y) { x10_font.DrawString(string, x, y, zeus::skWhite); }
u32 CCubeRenderer::GetFPS() { return CGraphics::GetFPS(); } float CCubeRenderer::GetFPS() { return CGraphics::GetFPS(); }
void CCubeRenderer::CacheReflection(IRenderer::TReflectionCallback cb, void* ctx, bool clearAfter) { void CCubeRenderer::CacheReflection(IRenderer::TReflectionCallback cb, void* ctx, bool clearAfter) {
// TODO // TODO
@ -880,25 +873,23 @@ void CCubeRenderer::DrawModelDisintegrate(CModel& model, CTexture& tex, const ze
const auto transformedBounds = bounds.getTransformedAABox(rotation); const auto transformedBounds = bounds.getTransformedAABox(rotation);
const auto xf = zeus::CTransform::Scale(5.f / (transformedBounds.max - transformedBounds.min)) * const auto xf = zeus::CTransform::Scale(5.f / (transformedBounds.max - transformedBounds.min)) *
zeus::CTransform::Translate(-transformedBounds.min) * rotation; zeus::CTransform::Translate(-transformedBounds.min) * rotation;
const zeus::CTransform ptTex1{ Mtx mtx;
zeus::CMatrix3f{ xf.toCStyleMatrix(mtx);
1.f, 1.f, 0.f, float f1 = -(1.f - t) * 6.f + 1.f;
0.f, 0.f, 1.f, float f2 = t * -0.85f - 0.15f;
0.f, 0.f, 0.f, const Mtx ptTex0 = {
}, {1.0f, 1.0f, 0.0f, t},
zeus::CVector3f{t * -0.85f - 0.15f, -(1.f - t) * 6.f + 1.f, 1.f}, {0.0f, 0.0f, 1.0f, f1},
{0.0f, 0.0f, 0.0f, 1.0f},
}; };
const zeus::CTransform ptTex0{ const Mtx ptTex1 = {
zeus::CMatrix3f{ {1.0f, 1.0f, 0.0f, f2},
1.f, 1.f, 0.f, {0.0f, 0.0f, 1.0f, f1},
0.f, 0.f, 1.f, {0.0f, 0.0f, 0.0f, 1.0f},
0.f, 0.f, 0.f,
},
zeus::CVector3f{t, ptTex1.origin.y(), 1.f},
}; };
GXLoadTexMtxImm(&xf, GX_TEXMTX0, GX_MTX3x4); GXLoadTexMtxImm(mtx, GX_TEXMTX0, GX_MTX3x4);
GXLoadTexMtxImm(&ptTex0, GX_PTTEXMTX0, GX_MTX3x4); GXLoadTexMtxImm(ptTex0, GX_PTTEXMTX0, GX_MTX3x4);
GXLoadTexMtxImm(&ptTex1, GX_PTTEXMTX1, GX_MTX3x4); GXLoadTexMtxImm(ptTex1, GX_PTTEXMTX1, GX_MTX3x4);
CGX::SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_POS, GX_TEXMTX0, false, GX_PTTEXMTX0); CGX::SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_POS, GX_TEXMTX0, false, GX_PTTEXMTX0);
CGX::SetTexCoordGen(GX_TEXCOORD1, GX_TG_MTX3x4, GX_TG_POS, GX_TEXMTX0, false, GX_PTTEXMTX1); CGX::SetTexCoordGen(GX_TEXCOORD1, GX_TG_MTX3x4, GX_TG_POS, GX_TEXMTX0, false, GX_PTTEXMTX1);
CGX::SetAlphaCompare(GX_GREATER, 0, GX_AOP_AND, GX_ALWAYS, 0); CGX::SetAlphaCompare(GX_GREATER, 0, GX_AOP_AND, GX_ALWAYS, 0);
@ -949,7 +940,7 @@ void CCubeRenderer::SetWorldFog(ERglFogMode mode, float startz, float endz, cons
void CCubeRenderer::RenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, void CCubeRenderer::RenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb,
const TLockedToken<CModel>* model, const CSkinnedModel* sModel) { const TLockedToken<CModel>* model, const CSkinnedModel* sModel) {
if (!x318_28_disableFog) { if (!x318_28_disableFog) {
x2ac_fogVolumes.emplace_back(CGraphics::g_GXModelMatrix, color, aabb, model, sModel); x2ac_fogVolumes.emplace_back(CGraphics::mModelMatrix, color, aabb, model, sModel);
} }
} }
@ -977,7 +968,7 @@ void CCubeRenderer::DoThermalBlendCold() {
CGX::SetZMode(true, GX_LEQUAL, false); CGX::SetZMode(true, GX_LEQUAL, false);
GXSetTexCopySrc(left, top, width, height); GXSetTexCopySrc(left, top, width, height);
GXSetTexCopyDst(width, height, GX_TF_I4, false); GXSetTexCopyDst(width, height, GX_TF_I4, false);
GXCopyTex(CGraphics::sSpareTextureData, true); GXCopyTex(CGraphics::mpSpareBuffer, true);
CGraphics::LoadDolphinSpareTexture(width, height, GX_TF_I4, nullptr, GX_TEXMAP7); CGraphics::LoadDolphinSpareTexture(width, height, GX_TF_I4, nullptr, GX_TEXMAP7);
// Upload random static texture (game reads from .text) // Upload random static texture (game reads from .text)
@ -1050,7 +1041,7 @@ void CCubeRenderer::DoThermalBlendCold() {
CGX::SetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_CLEAR); CGX::SetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_CLEAR);
// Backup & set viewport/projection // Backup & set viewport/projection
const auto backupViewMatrix = CGraphics::g_ViewMatrix; const auto backupViewMatrix = CGraphics::mViewMatrix;
const auto backupProjectionState = CGraphics::GetProjectionState(); const auto backupProjectionState = CGraphics::GetProjectionState();
CGraphics::SetOrtho(0.f, static_cast<float>(width), 0.f, static_cast<float>(height), -4096.f, 4096.f); CGraphics::SetOrtho(0.f, static_cast<float>(width), 0.f, static_cast<float>(height), -4096.f, 4096.f);
CGraphics::SetViewPointMatrix({}); CGraphics::SetViewPointMatrix({});
@ -1093,7 +1084,7 @@ void CCubeRenderer::DoThermalBlendHot() {
CGX::SetZMode(true, GX_LEQUAL, true); CGX::SetZMode(true, GX_LEQUAL, true);
GXSetTexCopySrc(left, top, width, height); GXSetTexCopySrc(left, top, width, height);
GXSetTexCopyDst(width, height, GX_TF_I4, false); GXSetTexCopyDst(width, height, GX_TF_I4, false);
GXCopyTex(CGraphics::sSpareTextureData, false); GXCopyTex(CGraphics::mpSpareBuffer, false);
x288_thermoPalette.Load(); x288_thermoPalette.Load();
CGraphics::LoadDolphinSpareTexture(width, height, GX_TF_C4, GX_TLUT0, nullptr, GX_TEXMAP7); CGraphics::LoadDolphinSpareTexture(width, height, GX_TF_C4, GX_TLUT0, nullptr, GX_TEXMAP7);
CGX::SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_TEXA, GX_CC_TEXC, GX_CC_ZERO); CGX::SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_TEXA, GX_CC_TEXC, GX_CC_ZERO);
@ -1115,7 +1106,7 @@ void CCubeRenderer::DoThermalBlendHot() {
CGX::SetBlendMode(GX_BM_BLEND, GX_BL_DSTALPHA, GX_BL_INVDSTALPHA, GX_LO_CLEAR); CGX::SetBlendMode(GX_BM_BLEND, GX_BL_DSTALPHA, GX_BL_INVDSTALPHA, GX_LO_CLEAR);
// Backup & set viewport/projection // Backup & set viewport/projection
const auto backupViewMatrix = CGraphics::g_ViewMatrix; const auto backupViewMatrix = CGraphics::mViewMatrix;
const auto backupProjectionState = CGraphics::GetProjectionState(); const auto backupProjectionState = CGraphics::GetProjectionState();
CGraphics::SetOrtho(0.f, static_cast<float>(width), 0.f, static_cast<float>(height), -4096.f, 4096.f); CGraphics::SetOrtho(0.f, static_cast<float>(width), 0.f, static_cast<float>(height), -4096.f, 4096.f);
CGraphics::SetViewPointMatrix({}); CGraphics::SetViewPointMatrix({});
@ -1186,7 +1177,7 @@ void CCubeRenderer::DrawPhazonSuitIndirectEffect(const zeus::CColor& nonIndirect
const TLockedToken<CTexture>& indTex, const zeus::CColor& indirectMod, const TLockedToken<CTexture>& indTex, const zeus::CColor& indirectMod,
float blurRadius, float scale, float offX, float offY) { float blurRadius, float scale, float offX, float offY) {
if (x318_27_currentRGBA6 && x310_phazonSuitMaskCountdown != 0) { if (x318_27_currentRGBA6 && x310_phazonSuitMaskCountdown != 0) {
const auto backupViewMatrix = CGraphics::g_ViewMatrix; const auto backupViewMatrix = CGraphics::mViewMatrix;
const auto backupProjectionState = CGraphics::GetProjectionState(); const auto backupProjectionState = CGraphics::GetProjectionState();
if (!x314_phazonSuitMask || x314_phazonSuitMask->GetWidth() != CGraphics::GetViewportWidth() / 4 || if (!x314_phazonSuitMask || x314_phazonSuitMask->GetWidth() != CGraphics::GetViewportWidth() / 4 ||
x314_phazonSuitMask->GetHeight() != CGraphics::GetViewportHeight() / 4) { x314_phazonSuitMask->GetHeight() != CGraphics::GetViewportHeight() / 4) {
@ -1370,9 +1361,10 @@ void CCubeRenderer::SetupRendererStates(bool depthWrite) {
GXSetTevColor(GX_TEVREG1, to_gx_color(x2fc_tevReg1Color)); GXSetTevColor(GX_TEVREG1, to_gx_color(x2fc_tevReg1Color));
} }
constexpr zeus::CTransform MvPostXf{ constexpr Mtx MvPostXf = {
{zeus::CVector3f{0.5f, 0.f, 0.f}, {0.f, 0.f, 0.f}, {0.f, 0.5f, 0.f}}, {0.5f, 0.0f, 0.0f, 0.5f},
{0.5f, 0.5f, 1.f}, {0.0f, 0.5f, 0.5f, 0.5f},
{0.0f, 0.0f, 0.0f, 1.0f},
}; };
void CCubeRenderer::DoThermalModelDraw(CCubeModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol, void CCubeRenderer::DoThermalModelDraw(CCubeModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol,
@ -1382,10 +1374,12 @@ void CCubeRenderer::DoThermalModelDraw(CCubeModel& model, const zeus::CColor& mu
CGX::SetNumTexGens(1); CGX::SetNumTexGens(1);
CGX::SetNumChans(0); CGX::SetNumChans(0);
x220_sphereRamp.Load(GX_TEXMAP0, EClampMode::Clamp); x220_sphereRamp.Load(GX_TEXMAP0, EClampMode::Clamp);
zeus::CTransform xf = CGraphics::g_ViewMatrix.inverse().multiplyIgnoreTranslation(CGraphics::g_GXModelMatrix); zeus::CTransform xf = CGraphics::mViewMatrix.quickInverse().multiplyIgnoreTranslation(CGraphics::mModelMatrix);
xf.origin.zeroOut(); xf.origin.zeroOut();
GXLoadTexMtxImm(&xf, GX_TEXMTX0, GX_MTX3x4); Mtx mtx;
GXLoadTexMtxImm(&MvPostXf, GX_PTTEXMTX0, GX_MTX3x4); xf.toCStyleMatrix(mtx);
GXLoadTexMtxImm(mtx, GX_TEXMTX0, GX_MTX3x4);
GXLoadTexMtxImm(MvPostXf, GX_PTTEXMTX0, GX_MTX3x4);
CGX::SetStandardTevColorAlphaOp(GX_TEVSTAGE0); CGX::SetStandardTevColorAlphaOp(GX_TEVSTAGE0);
CGX::SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_C0, GX_CC_TEXC, GX_CC_KONST); CGX::SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_C0, GX_CC_TEXC, GX_CC_KONST);
CGX::SetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_TEXA, GX_CA_A0, GX_CA_KONST); CGX::SetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_TEXA, GX_CA_A0, GX_CA_KONST);
@ -1451,7 +1445,7 @@ void CCubeRenderer::ReallyDrawSpaceWarp(const zeus::CVector3f& pt, float strengt
CGX::SetFog(GX_FOG_NONE, fogStartZ, fogEndZ, fogNearZ, fogFarZ, fogColor); CGX::SetFog(GX_FOG_NONE, fogStartZ, fogEndZ, fogNearZ, fogFarZ, fogColor);
GXSetTexCopySrc(v2right.x, v2right.y, v2sub.x, v2sub.y); GXSetTexCopySrc(v2right.x, v2right.y, v2sub.x, v2sub.y);
GXSetTexCopyDst(v2sub.x, v2sub.y, GX_TF_RGBA8, false); GXSetTexCopyDst(v2sub.x, v2sub.y, GX_TF_RGBA8, false);
GXCopyTex(CGraphics::sSpareTextureData, false); GXCopyTex(CGraphics::mpSpareBuffer, false);
GXPixModeSync(); GXPixModeSync();
CGraphics::LoadDolphinSpareTexture(v2sub.x, v2sub.y, GX_TF_RGBA8, nullptr, GX_TEXMAP7); CGraphics::LoadDolphinSpareTexture(v2sub.x, v2sub.y, GX_TF_RGBA8, nullptr, GX_TEXMAP7);
x150_reflectionTex.Load(GX_TEXMAP1, EClampMode::Clamp); x150_reflectionTex.Load(GX_TEXMAP1, EClampMode::Clamp);

View File

@ -180,7 +180,7 @@ public:
void EndPrimitive() override; void EndPrimitive() override;
void SetAmbientColor(const zeus::CColor& color) override; void SetAmbientColor(const zeus::CColor& color) override;
void DrawString(const char* string, s32, s32) override; void DrawString(const char* string, s32, s32) override;
u32 GetFPS() override; float GetFPS() override;
void CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) override; void CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) override;
void DrawSpaceWarp(const zeus::CVector3f& pt, float strength) override; void DrawSpaceWarp(const zeus::CVector3f& pt, float strength) override;
void DrawThermalModel(CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol, void DrawThermalModel(CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol,

View File

@ -57,15 +57,15 @@ void CFont::LinearToTile8(u8* dest, const u8* src) {
} }
void CFont::DrawString(const char* str, int x, int y, const zeus::CColor& col) { void CFont::DrawString(const char* str, int x, int y, const zeus::CColor& col) {
bool bVar2 = CGraphics::BeginRender2D(*mpTexture.get()); // bool bVar2 = CGraphics::BeginRender2D(*mpTexture.get());
char chr = *str; // char chr = *str;
while (chr != 0) { // while (chr != 0) {
u32 cellSize = static_cast<u32>(16.f * x4_scale); // u32 cellSize = static_cast<u32>(16.f * x4_scale);
++str; // ++str;
CGraphics::DoRender2D(*mpTexture, x, y, (chr & 0xf) * 16, 0xf0, 0x10, cellSize, cellSize, col); // CGraphics::DoRender2D(*mpTexture, x, y, (chr & 0xf) * 16, 0xf0, 0x10, cellSize, cellSize, col);
chr = *str; // chr = *str;
} // }
CGraphics::EndRender2D(bVar2); // CGraphics::EndRender2D(bVar2);
} }
u32 CFont::StringWidth(const char* str) const { u32 CFont::StringWidth(const char* str) const {

View File

@ -6,6 +6,14 @@ namespace metaforce::CGX {
SGXState sGXState{}; SGXState sGXState{};
std::array<GXVtxDescList, 12> sVtxDescList{}; std::array<GXVtxDescList, 12> sVtxDescList{};
void SetLineWidth(u8 width, GXTexOffset offset) noexcept {
u16 flags = width | offset << 8;
if (flags != sGXState.x54_lineWidthAndOffset) {
sGXState.x54_lineWidthAndOffset = flags;
GXSetLineWidth(width, offset);
}
}
void ResetGXStates() noexcept { void ResetGXStates() noexcept {
sGXState.x48_descList = 0; sGXState.x48_descList = 0;
GXClearVtxDesc(); GXClearVtxDesc();

View File

@ -3,6 +3,7 @@
#include "Graphics/GX.hpp" #include "Graphics/GX.hpp"
#include "RetroTypes.hpp" #include "RetroTypes.hpp"
#include <span>
#include <zeus/CColor.hpp> #include <zeus/CColor.hpp>
namespace metaforce::CGX { namespace metaforce::CGX {
@ -118,10 +119,29 @@ static inline void SetAlphaCompare(GXCompare comp0, u8 ref0, GXAlphaOp op, GXCom
} }
} }
static inline void SetArray(GXAttr attr, std::span<const u8> data, u8 stride) noexcept {
const auto* ptr = static_cast<const void*>(data.data());
if (ptr != nullptr && sGXState.x0_arrayPtrs[attr - GX_VA_POS] != ptr) {
// sGXState.x0_arrayPtrs[attr - GX_VA_POS] = const_cast<void*>(ptr);
GXSetArray(attr, data.data(), data.size(), stride);
}
}
template <typename T> template <typename T>
static inline void SetArray(GXAttr attr, const std::vector<T>* data, bool isStatic) noexcept { static inline void SetArray(GXAttr attr, std::span<const T> data) noexcept {
if (data != nullptr && sGXState.x0_arrayPtrs[attr - GX_VA_POS] != data) { const auto* ptr = static_cast<const void*>(data.data());
GXSetArray(attr, data->data(), data->size() * sizeof(T), sizeof(T)); if (ptr != nullptr && sGXState.x0_arrayPtrs[attr - GX_VA_POS] != ptr) {
// sGXState.x0_arrayPtrs[attr - GX_VA_POS] = const_cast<void*>(ptr);
GXSetArray(attr, data.data(), data.size_bytes(), sizeof(T));
}
}
template <typename T, size_t N>
static inline void SetArray(GXAttr attr, const std::array<T, N>& data) noexcept {
const auto* ptr = static_cast<const void*>(data.data());
if (ptr != nullptr && sGXState.x0_arrayPtrs[attr - GX_VA_POS] != ptr) {
// sGXState.x0_arrayPtrs[attr - GX_VA_POS] = const_cast<void*>(ptr);
GXSetArray(attr, ptr, data.size() * sizeof(T), sizeof(T));
} }
} }
@ -403,25 +423,24 @@ static inline void SetTexCoordGen(GXTexCoordID dstCoord, u32 flags) noexcept {
} }
} }
static inline void SetVtxDescv_Compressed(u32 descList) noexcept { static inline void SetVtxDescv_Compressed(u32 flags) noexcept {
u32 currentDescList = sGXState.x48_descList; if (flags == sGXState.x48_descList) {
if (descList != currentDescList) { return;
size_t remain = sVtxDescList.size() - 1;
u32 shift = 0;
u32 attrIdx = 0;
do {
sVtxDescList[attrIdx] = {
GXAttr(GX_VA_POS + attrIdx),
GXAttrType(descList >> shift & 3),
};
shift += 2;
++attrIdx;
--remain;
} while (remain != 0);
sVtxDescList[attrIdx] = {GX_VA_NULL, GX_NONE};
GXSetVtxDescv(sVtxDescList.data());
sGXState.x48_descList = descList;
} }
GXVtxDescList* list = sVtxDescList.data();
for (u32 idx = 0; idx < sVtxDescList.size() - 1; ++idx) {
u32 shift = idx * 2;
if ((flags & 3 << shift) == (sGXState.x48_descList & 3 << shift)) {
continue;
}
list->attr = static_cast<GXAttr>(GX_VA_POS + idx);
list->type = static_cast<GXAttrType>(flags >> shift & 3);
++list;
}
list->attr = GX_VA_NULL;
list->type = GX_NONE;
GXSetVtxDescv(sVtxDescList.data());
sGXState.x48_descList = flags;
} }
static inline void SetVtxDescv(const GXVtxDescList* descList) noexcept { static inline void SetVtxDescv(const GXVtxDescList* descList) noexcept {

File diff suppressed because it is too large Load Diff

View File

@ -2,12 +2,11 @@
#include "Runtime/ConsoleVariables/CVar.hpp" #include "Runtime/ConsoleVariables/CVar.hpp"
#include "Runtime/Graphics/CLight.hpp" #include "Runtime/Graphics/CLight.hpp"
#include "Runtime/Graphics/CTexture.hpp"
#include "Runtime/Graphics/CTevCombiners.hpp" #include "Runtime/Graphics/CTevCombiners.hpp"
#include "Runtime/Graphics/GX.hpp" #include "Runtime/Graphics/GX.hpp"
#include "Runtime/RetroTypes.hpp" #include "Runtime/RetroTypes.hpp"
#include <array>
#include <chrono>
#include <vector> #include <vector>
#include <zeus/CColor.hpp> #include <zeus/CColor.hpp>
@ -17,8 +16,7 @@
#include <aurora/aurora.h> #include <aurora/aurora.h>
#include <optick.h> #include <optick.h>
#include <dolphin/mtx.h>
using frame_clock = std::chrono::high_resolution_clock;
namespace metaforce { namespace metaforce {
class CTexture; class CTexture;
@ -102,6 +100,16 @@ enum class ERglEnum : std::underlying_type_t<GXCompare> {
Always = GX_ALWAYS, Always = GX_ALWAYS,
}; };
enum class ERglPrimitive : std::underlying_type_t<GXPrimitive> {
Quads = GX_QUADS,
Triangles = GX_TRIANGLES,
TriangleStrip = GX_TRIANGLESTRIP,
TriangleFan = GX_TRIANGLEFAN,
Lines = GX_LINES,
LineStrip = GX_LINESTRIP,
Points = GX_POINTS,
};
using ERglLight = u8; using ERglLight = u8;
enum class ERglTexOffset : std::underlying_type_t<GXTexOffset> { enum class ERglTexOffset : std::underlying_type_t<GXTexOffset> {
@ -129,49 +137,20 @@ enum class ERglFogMode : std::underlying_type_t<GXFogType> {
OrthoRevExp2 = GX_FOG_ORTHO_REVEXP2, OrthoRevExp2 = GX_FOG_ORTHO_REVEXP2,
}; };
struct SViewport { struct CViewport {
u32 x0_left; int mLeft;
u32 x4_top; int mTop;
u32 x8_width; int mWidth;
u32 xc_height; int mHeight;
float x10_halfWidth; float mHalfWidth;
float x14_halfHeight; float mHalfHeight;
float aspect;
}; };
struct SClipScreenRect { // TODO
bool x0_valid = false; typedef struct {
int x4_left = 0; float x;
int x8_top = 0; float y;
int xc_width = 0; } Vec2, *Vec2Ptr;
int x10_height = 0;
int x14_dstWidth = 0;
float x18_uvXMin = 0.f;
float x1c_uvXMax = 0.f;
float x20_uvYMin = 0.f;
float x24_uvYMax = 0.f;
SClipScreenRect() = default;
SClipScreenRect(bool valid, int left, int top, int width, int height, int dstWidth, float uvXMin, float uvXMax,
float uvYMin, float uvYMax)
: x0_valid(valid)
, x4_left(left)
, x8_top(top)
, xc_width(width)
, x10_height(height)
, x14_dstWidth(dstWidth)
, x18_uvXMin(uvXMin)
, x1c_uvXMax(uvXMax)
, x20_uvYMin(uvYMin)
, x24_uvYMax(uvYMax) {}
SClipScreenRect(const SViewport& vp) {
x4_left = vp.x0_left;
x8_top = vp.x4_top;
xc_width = vp.x8_width;
x10_height = vp.xc_height;
}
};
#define DEPTH_FAR 1.f #define DEPTH_FAR 1.f
#define DEPTH_SKY 0.999f #define DEPTH_SKY 0.999f
@ -184,49 +163,171 @@ struct SClipScreenRect {
#define CUBEMAP_RES 256 #define CUBEMAP_RES 256
#define CUBEMAP_MIPS 6 #define CUBEMAP_MIPS 6
enum class ETexelFormat;
class CGraphics { class CGraphics {
public: public:
struct CProjectionState { using CVector3f = zeus::CVector3f;
using CTransform4f = zeus::CTransform;
using CColor = zeus::CColor;
using uchar = unsigned char;
using uint = unsigned int;
class CRenderState {
public:
CRenderState();
void Flush();
void ResetFlushAll();
int SetVtxState(const float* pos, const float* nrm, const uint* clr);
// In map this takes two args, but x4 is unused?
void Set(int v0) { x0_ = v0; }
private:
int x0_;
int x4_;
};
class CProjectionState {
public:
CProjectionState(bool persp, float left, float right, float top, float bottom, float near, float far)
: x0_persp(persp), x4_left(left), x8_right(right), xc_top(top), x10_bottom(bottom), x14_near(near), x18_far(far) {}
bool IsPerspective() const { return x0_persp; }
float GetLeft() const { return x4_left; }
float GetRight() const { return x8_right; }
float GetTop() const { return xc_top; }
float GetBottom() const { return x10_bottom; }
float GetNear() const { return x14_near; }
float GetFar() const { return x18_far; }
private:
bool x0_persp; bool x0_persp;
float x4_left; float x4_left;
float x8_right; float x8_right;
// TODO: I think top/bottom are flipped
float xc_top; float xc_top;
float x10_bottom; float x10_bottom;
float x14_near; float x14_near;
float x18_far; float x18_far;
}; };
static CProjectionState g_Proj; class CClippedScreenRect {
static zeus::CVector2f g_CachedDepthRange; public:
// static CFogState g_Fog; CClippedScreenRect() : x0_valid(false) {}
static SViewport g_Viewport; CClippedScreenRect(int x, int y, int width, int height, int texWidth, float minU, float maxU, float minV,
static float g_ProjAspect; float maxV)
static u32 g_NumBreakpointsWaiting; : x0_valid(true)
static u32 g_FlippingState; , x4_x(x)
static bool g_LastFrameUsedAbove; , x8_y(y)
static bool g_InterruptLastFrameUsedAbove; , xc_width(width)
static GX::LightMask g_LightActive; , x10_height(height)
static std::array<GXLightObj, GX::MaxLights> g_LightObjs; , x14_texWidth(texWidth)
static std::array<ELightType, GX::MaxLights> g_LightTypes; , x18_minU(minU)
static zeus::CTransform g_GXModelView; , x1c_maxU(maxU)
static zeus::CTransform g_GXModelViewInvXpose; , x20_minV(minV)
static zeus::CTransform g_GXModelMatrix; , x24_maxV(maxV) {}
static zeus::CTransform g_ViewMatrix;
static zeus::CVector3f g_ViewPoint;
static zeus::CTransform g_GXViewPointMatrix;
static zeus::CTransform g_CameraMatrix;
static SClipScreenRect g_CroppedViewport;
static bool g_IsGXModelMatrixIdentity;
static zeus::CColor g_ClearColor;
static float g_ClearDepthValue; // Was a 24bit value, we use a float range from [0,1]
static bool g_IsBeginSceneClearFb;
static ERglEnum g_depthFunc; bool IsValid() const { return x0_valid; }
static ERglCullMode g_cullMode; int GetX() const { return x4_x; }
int GetY() const { return x8_y; }
int GetWidth() const { return xc_width; }
int GetHeight() const { return x10_height; }
int GetTexWidth() const { return x14_texWidth; }
float GetMinU() const { return x18_minU; }
float GetMaxU() const { return x1c_maxU; }
float GetMinV() const { return x20_minV; }
float GetMaxV() const { return x24_maxV; }
static void Startup(); private:
bool x0_valid;
int x4_x;
int x8_y;
int xc_width;
int x10_height;
int x14_texWidth;
float x18_minU;
float x1c_maxU;
float x20_minV;
float x24_maxV;
};
static CRenderState sRenderState;
static VecPtr vtxBuffer;
static VecPtr nrmBuffer;
static Vec2Ptr txtBuffer0;
static Vec2Ptr txtBuffer1;
static uint* clrBuffer;
static bool mJustReset;
static ERglCullMode mCullMode;
static int mNumLightsActive;
static float mDepthNear;
static VecPtr mpVtxBuffer;
static VecPtr mpNrmBuffer;
static Vec2Ptr mpTxtBuffer0;
static Vec2Ptr mpTxtBuffer1;
static uint* mpClrBuffer;
static int mNumPrimitives;
static int mFrameCounter;
static float mFramesPerSecond;
static float mLastFramesPerSecond;
static int mNumBreakpointsWaiting;
static int mFlippingState;
static bool mLastFrameUsedAbove;
static bool mInterruptLastFrameUsedAbove;
static GX::LightMask mLightActive;
static GX::LightMask mLightsWereOn;
static void* mpFrameBuf1;
static void* mpFrameBuf2;
static void* mpCurrenFrameBuf;
static int mSpareBufferSize;
static void* mpSpareBuffer;
static int mSpareBufferTexCacheSize;
// static GXTexRegionCallback mGXDefaultTexRegionCallback;
static void* mpFifo;
static GXFifoObj* mpFifoObj;
static uint mRenderTimings;
static float mSecondsMod900;
static CTimeProvider* mpExternalTimeProvider;
static int mScreenStretch;
static int mScreenPositionX;
static int mScreenPositionY;
static CVector3f kDefaultPositionVector;
static CVector3f kDefaultDirectionVector;
static CProjectionState mProj;
static CTransform4f mViewMatrix;
static CTransform4f mModelMatrix;
static CColor mClearColor;
static CVector3f mViewPoint;
static CViewport mViewport;
static ELightType mLightTypes[8];
static GXLightObj mLightObj[8];
// static GXTexRegion mTexRegions[GX_MAX_TEXMAP];
// static GXTexRegion mTexRegionsCI[GX_MAX_TEXMAP / 2];
static GXRenderModeObj mRenderModeObj;
static Mtx mGXViewPointMatrix;
static Mtx mGXModelMatrix;
static Mtx mGxModelView;
static Mtx mCameraMtx;
static bool mIsBeginSceneClearFb;
static ERglEnum mDepthFunc;
static ERglPrimitive mCurrentPrimitive;
static float mDepthFar;
static u32 mClearDepthValue; // = GX_MAX_Z24
static bool mIsGXModelMatrixIdentity;
static bool mFirstFrame;
static GXBool mUseVideoFilter;
static float mBrightness;
static const GXTexMapID kSpareBufferTexMapID;
static bool Startup();
static void InitGraphicsVariables(); static void InitGraphicsVariables();
static void InitGraphicsDefaults(); static void InitGraphicsDefaults();
static void ConfigureFrameBuffer();
static void SetDefaultVtxAttrFmt(); static void SetDefaultVtxAttrFmt();
static void DisableAllLights(); static void DisableAllLights();
static void LoadLight(ERglLight light, const CLight& info); static void LoadLight(ERglLight light, const CLight& info);
@ -240,10 +341,6 @@ public:
static void BeginScene(); static void BeginScene();
static void EndScene(); static void EndScene();
static void Render2D(CTexture& tex, u32 x, u32 y, u32 w, u32 h, const zeus::CColor& col); static void Render2D(CTexture& tex, u32 x, u32 y, u32 w, u32 h, const zeus::CColor& col);
static bool BeginRender2D(const CTexture& tex);
static void DoRender2D(const CTexture& tex, s32 x, s32 y, s32 w1, s32 w2, s32 w3, s32 w4, s32 w5,
const zeus::CColor& col);
static void EndRender2D(bool v);
static void SetAlphaCompare(ERglAlphaFunc comp0, u8 ref0, ERglAlphaOp op, ERglAlphaFunc comp1, u8 ref1); static void SetAlphaCompare(ERglAlphaFunc comp0, u8 ref0, ERglAlphaOp op, ERglAlphaFunc comp1, u8 ref1);
static void SetViewPointMatrix(const zeus::CTransform& xf); static void SetViewPointMatrix(const zeus::CTransform& xf);
static void SetViewMatrix(); static void SetViewMatrix();
@ -256,51 +353,38 @@ public:
static void SetOrtho(float left, float right, float top, float bottom, float znear, float zfar); static void SetOrtho(float left, float right, float top, float bottom, float znear, float zfar);
static void FlushProjection(); static void FlushProjection();
static zeus::CVector2i ProjectPoint(const zeus::CVector3f& point); static zeus::CVector2i ProjectPoint(const zeus::CVector3f& point);
static SClipScreenRect ClipScreenRectFromMS(const zeus::CVector3f& p1, const zeus::CVector3f& p2); static CClippedScreenRect ClipScreenRectFromVS(const CVector3f& p1, const CVector3f& p2, ETexelFormat fmt);
static SClipScreenRect ClipScreenRectFromVS(const zeus::CVector3f& p1, const zeus::CVector3f& p2); static CClippedScreenRect ClipScreenRectFromMS(const CVector3f& p1, const CVector3f& p2, ETexelFormat fmt);
static void SetViewportResolution(const zeus::CVector2i& res); static void SetViewportResolution(const zeus::CVector2i& res);
static void SetViewport(int leftOff, int bottomOff, int width, int height); static void SetViewport(int leftOff, int bottomOff, int width, int height);
static void SetScissor(int leftOff, int bottomOff, int width, int height); static void SetScissor(int leftOff, int bottomOff, int width, int height);
static void SetDepthRange(float near, float far); static void SetDepthRange(float near, float far);
static void SetIdentityViewPointMatrix();
static void SetIdentityModelMatrix();
static void ClearBackAndDepthBuffers();
static CTimeProvider* g_ExternalTimeProvider; static void SetExternalTimeProvider(CTimeProvider* provider) { mpExternalTimeProvider = provider; }
static float g_DefaultSeconds;
static u32 g_RenderTimings;
static void SetExternalTimeProvider(CTimeProvider* provider) { g_ExternalTimeProvider = provider; }
static float GetSecondsMod900(); static float GetSecondsMod900();
static void TickRenderTimings(); static void TickRenderTimings();
static u32 g_FrameCounter; static int GetFrameCounter() { return mFrameCounter; }
static u32 g_Framerate; static float GetFPS() { return mFramesPerSecond; }
static u32 g_FramesPast;
static frame_clock::time_point g_FrameStartTime;
static u32 GetFrameCounter() { return g_FrameCounter; }
static u32 GetFPS() { return g_Framerate; }
static void UpdateFPSCounter();
static void SetUseVideoFilter(bool); static void SetUseVideoFilter(bool);
static void SetClearColor(const zeus::CColor& color); static void SetClearColor(const zeus::CColor& color);
static void SetCopyClear(const zeus::CColor& color, float depth); static void SetCopyClear(const zeus::CColor& color, float depth);
static void SetIsBeginSceneClearFb(bool clear); static void SetIsBeginSceneClearFb(bool clear);
static u32 GetViewportLeft() { return g_Viewport.x0_left; } static u32 GetViewportLeft() { return mViewport.mLeft; }
static u32 GetViewportTop() { return g_Viewport.x4_top; } static u32 GetViewportTop() { return mViewport.mTop; }
static u32 GetViewportWidth() { return g_Viewport.x8_width; } static u32 GetViewportWidth() { return mViewport.mWidth; }
static u32 GetViewportHeight() { return g_Viewport.xc_height; } static u32 GetViewportHeight() { return mViewport.mHeight; }
static float GetViewportHalfWidth() { return g_Viewport.x10_halfWidth; } static float GetViewportHalfWidth() { return mViewport.mHalfWidth; }
static float GetViewportHalfHeight() { return g_Viewport.x14_halfHeight; } static float GetViewportHalfHeight() { return mViewport.mHalfHeight; }
static float GetViewportAspect() { return g_Viewport.aspect; } static float GetViewportAspect() {
static bool IsCroppedViewportValid() { return g_CroppedViewport.x0_valid; } return static_cast<float>(mViewport.mWidth) / static_cast<float>(mViewport.mHeight);
static int GetCroppedViewportLeft() { return g_CroppedViewport.x4_left; } }
static int GetCroppedViewportTop() { return g_CroppedViewport.x8_top; } static const CVector3f& GetViewPoint() { return mViewPoint; }
static int GetCroppedViewportWidth() { return g_CroppedViewport.xc_width; } static const CTransform4f& GetViewMatrix() { return mViewMatrix; }
static int GetCroppedViewportHeight() { return g_CroppedViewport.x10_height; } static const CTransform4f& GetModelMatrix() { return mModelMatrix; }
static float GetCroppedViewportDstWidth() { return g_CroppedViewport.x14_dstWidth; }
static float GetCroppedViewportUVXMin() { return g_CroppedViewport.x18_uvXMin; }
static float GetCroppedViewportUVXMax() { return g_CroppedViewport.x1c_uvXMax; }
static float GetCroppedViewportUVYMin() { return g_CroppedViewport.x20_uvYMin; }
static float GetCroppedViewportUVYMax() { return g_CroppedViewport.x24_uvYMax; }
static const std::array<zeus::CMatrix3f, 6> skCubeBasisMats;
static u8 sSpareTextureData[];
static void LoadDolphinSpareTexture(int width, int height, GXTexFmt format, void* data, GXTexMapID id); static void LoadDolphinSpareTexture(int width, int height, GXTexFmt format, void* data, GXTexMapID id);
static void LoadDolphinSpareTexture(int width, int height, GXCITexFmt format, GXTlut tlut, void* data, GXTexMapID id); static void LoadDolphinSpareTexture(int width, int height, GXCITexFmt format, GXTlut tlut, void* data, GXTexMapID id);
@ -308,7 +392,7 @@ public:
static void ResetGfxStates() noexcept; static void ResetGfxStates() noexcept;
static void SetTevStates(u32 flags) noexcept; static void SetTevStates(u32 flags) noexcept;
static void SetTevOp(ERglTevStage stage, const CTevCombiners::CTevPass& pass); static void SetTevOp(ERglTevStage stage, const CTevCombiners::CTevPass& pass);
static void StreamBegin(GXPrimitive primitive); static void StreamBegin(ERglPrimitive primitive);
static void StreamNormal(const zeus::CVector3f& nrm); static void StreamNormal(const zeus::CVector3f& nrm);
static void StreamColor(const zeus::CColor& color); static void StreamColor(const zeus::CColor& color);
static inline void StreamColor(float r, float g, float b, float a) { StreamColor({r, g, b, a}); } static inline void StreamColor(float r, float g, float b, float a) { StreamColor({r, g, b, a}); }
@ -322,7 +406,7 @@ public:
static void ResetVertexDataStream(bool end); static void ResetVertexDataStream(bool end);
static void FlushStream(); static void FlushStream();
static void FullRender(); static void FullRender();
static void DrawPrimitive(GXPrimitive primitive, const zeus::CVector3f* pos, const zeus::CVector3f& normal, static void DrawPrimitive(ERglPrimitive primitive, const zeus::CVector3f* pos, const zeus::CVector3f& normal,
const zeus::CColor& col, s32 numVerts); const zeus::CColor& col, s32 numVerts);
static void SetLineWidth(float width, ERglTexOffset offs); static void SetLineWidth(float width, ERglTexOffset offs);
}; };

View File

@ -1,360 +0,0 @@
#include "Runtime/Graphics/CLineRenderer.hpp"
#include "Runtime/Graphics/Shaders/CLineRendererShaders.hpp"
#include "Runtime/Logging.hpp"
namespace metaforce {
void CLineRenderer::Initialize() { CLineRendererShaders::Initialize(); }
void CLineRenderer::Shutdown() {
CLineRendererShaders::Shutdown();
// s_vertPoolTex.doDestroy();
// s_vertPoolNoTex.doDestroy();
// s_uniformPool.doDestroy();
}
//hecl::VertexBufferPool<CLineRenderer::SDrawVertTex> CLineRenderer::s_vertPoolTex = {};
//hecl::VertexBufferPool<CLineRenderer::SDrawVertNoTex> CLineRenderer::s_vertPoolNoTex = {};
//hecl::UniformBufferPool<CLineRenderer::SDrawUniform> CLineRenderer::s_uniformPool = {};
CLineRenderer::CLineRenderer(EPrimitiveMode mode, u32 maxVerts, u32 texture,
bool additive, bool zTest, bool zGEqual)
: m_mode(mode), m_maxVerts(maxVerts) {
OPTICK_EVENT();
if (maxVerts < 2) {
spdlog::fatal("maxVerts < 2, maxVerts = {}", maxVerts);
return;
}
m_textured = bool(texture);
u32 maxTriVerts = 0;
switch (mode) {
case EPrimitiveMode::Lines:
case EPrimitiveMode::LineStrip:
maxTriVerts = maxVerts * 4;
break;
case EPrimitiveMode::LineLoop:
maxTriVerts = maxVerts * 4 + 4;
break;
}
// if (texture) {
// m_vertBufTex = s_vertPoolTex.allocateBlock(CGraphics::g_BooFactory, maxTriVerts);
// } else {
// m_vertBufNoTex = s_vertPoolNoTex.allocateBlock(CGraphics::g_BooFactory, maxTriVerts);
// }
//
// m_uniformBuf = s_uniformPool.allocateBlock(CGraphics::g_BooFactory);
//
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
// CLineRendererShaders::BuildShaderDataBinding(ctx, *this, texture, additive, zTest, zGEqual);
// return true;
// } BooTrace);
}
//rstl::reserved_vector<CLineRenderer::SDrawVertTex, 1024> CLineRenderer::g_StaticLineVertsTex = {};
//rstl::reserved_vector<CLineRenderer::SDrawVertNoTex, 1024> CLineRenderer::g_StaticLineVertsNoTex = {};
static bool IntersectLines(const zeus::CVector2f& pa1, const zeus::CVector2f& pa2, const zeus::CVector2f& pb1,
const zeus::CVector2f& pb2, zeus::CVector3f& intersect) {
zeus::CVector2f deltaA = pa1 - pa2;
zeus::CVector2f deltaB = pb1 - pb2;
float det = deltaA.cross(deltaB);
if (std::fabs(det) < 0.000001f)
return false;
float c0 = pa1.cross(pa2);
float c1 = pb1.cross(pb2);
intersect = (c0 * (pb1 - pb2) - c1 * (pa1 - pa2)) / det;
return true;
}
void CLineRenderer::Reset() {
m_nextVert = 0;
m_final = false;
// if (m_textured)
// g_StaticLineVertsTex.clear();
// else
// g_StaticLineVertsNoTex.clear();
}
void CLineRenderer::AddVertex(const zeus::CVector3f& position, const zeus::CColor& color, float width,
const zeus::CVector2f& uv) {
if (m_final /*|| !m_shaderBind[0]*/ || m_nextVert >= m_maxVerts)
return;
float adjWidth = width / 480.f;
float w = 0.f;
zeus::CVector3f projPt = {}; // CGraphics::ProjectModelPointToViewportSpace(position, w);
if (m_mode == EPrimitiveMode::LineLoop) {
if (m_nextVert == 0) {
m_firstPos = projPt;
m_firstW = w;
m_secondPos = projPt;
m_firstUV = uv;
m_firstColor = color;
m_firstWidth = adjWidth;
} else if (m_nextVert == 1) {
m_secondPos = projPt;
}
}
if (m_nextVert > 1) {
zeus::CVector2f dva = (m_lastPos - m_lastPos2).toVec2f();
if (!dva.canBeNormalized())
dva = {0.f, 1.f};
dva = dva.normalized().perpendicularVector() * m_lastWidth;
dva.x() /= CGraphics::g_ProjAspect;
zeus::CVector2f dvb = (projPt - m_lastPos).toVec2f();
if (!dvb.canBeNormalized())
dvb = {0.f, 1.f};
dvb = dvb.normalized().perpendicularVector() * m_lastWidth;
dvb.x() /= CGraphics::g_ProjAspect;
if (m_textured) {
if (m_mode == EPrimitiveMode::Lines) {
if (m_nextVert & 1) {
// g_StaticLineVertsTex.push_back(g_StaticLineVertsTex.back());
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back(g_StaticLineVertsTex.back());
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV});
} else {
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV});
}
} else {
zeus::CVector3f intersect1;
bool good1 = IntersectLines(m_lastPos2.toVec2f() + dva, m_lastPos.toVec2f() + dva, m_lastPos.toVec2f() + dvb,
projPt.toVec2f() + dvb, intersect1);
if ((intersect1.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 2.f)
good1 = false;
zeus::CVector3f intersect2;
bool good2 = IntersectLines(m_lastPos2.toVec2f() - dva, m_lastPos.toVec2f() - dva, m_lastPos.toVec2f() - dvb,
projPt.toVec2f() - dvb, intersect2);
if ((intersect2.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 2.f)
good2 = false;
if (good1 && good2) {
intersect1.z() = float(m_lastPos.z());
intersect2.z() = float(m_lastPos.z());
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV});
} else {
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV});
}
}
} else {
if (m_mode == EPrimitiveMode::Lines) {
if (m_nextVert & 1) {
// g_StaticLineVertsNoTex.push_back(g_StaticLineVertsNoTex.back());
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back(g_StaticLineVertsNoTex.back());
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor});
} else {
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor});
}
} else {
zeus::CVector3f intersect1;
bool good1 = IntersectLines(m_lastPos2.toVec2f() + dva, m_lastPos.toVec2f() + dva, m_lastPos.toVec2f() + dvb,
projPt.toVec2f() + dvb, intersect1);
if ((intersect1.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 2.f)
good1 = false;
zeus::CVector3f intersect2;
bool good2 = IntersectLines(m_lastPos2.toVec2f() - dva, m_lastPos.toVec2f() - dva, m_lastPos.toVec2f() - dvb,
projPt.toVec2f() - dvb, intersect2);
if ((intersect2.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 2.f)
good2 = false;
if (good1 && good2) {
intersect1.z() = float(m_lastPos.z());
intersect2.z() = float(m_lastPos.z());
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor});
} else {
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor});
}
}
}
} else if (m_nextVert == 1) {
zeus::CVector2f dv = (projPt - m_lastPos).toVec2f();
if (!dv.canBeNormalized())
dv = {0.f, 1.f};
dv = dv.normalized().perpendicularVector() * m_lastWidth;
dv.x() /= CGraphics::g_ProjAspect;
if (m_textured) {
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor, m_lastUV});
} else {
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor});
}
}
m_lastPos2 = m_lastPos;
m_lastPos = projPt;
m_lastW = w;
m_lastUV = uv;
m_lastColor = color;
m_lastWidth = adjWidth;
++m_nextVert;
}
void CLineRenderer::Render(bool alphaWrite, const zeus::CColor& moduColor) {
SCOPED_GRAPHICS_DEBUG_GROUP("CLineRenderer::Render", zeus::skGrey);
if (!m_final && m_nextVert > 1) {
if (m_mode == EPrimitiveMode::LineLoop) {
{
zeus::CVector2f dva = (m_lastPos - m_lastPos2).toVec2f();
if (!dva.canBeNormalized())
dva = {0.f, 1.f};
dva = dva.normalized().perpendicularVector() * m_lastWidth;
dva.x() /= CGraphics::g_ProjAspect;
zeus::CVector2f dvb = (m_firstPos - m_lastPos).toVec2f();
if (!dvb.canBeNormalized())
dvb = {0.f, 1.f};
dvb = dvb.normalized().perpendicularVector() * m_lastWidth;
dvb.x() /= CGraphics::g_ProjAspect;
zeus::CVector3f intersect1;
bool good1 = IntersectLines(m_lastPos2.toVec2f() + dva, m_lastPos.toVec2f() + dva, m_lastPos.toVec2f() + dvb,
m_firstPos.toVec2f() + dvb, intersect1);
if ((intersect1.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 2.f)
good1 = false;
zeus::CVector3f intersect2;
bool good2 = IntersectLines(m_lastPos2.toVec2f() - dva, m_lastPos.toVec2f() - dva, m_lastPos.toVec2f() - dvb,
m_firstPos.toVec2f() - dvb, intersect2);
if ((intersect2.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 2.f)
good2 = false;
if (m_textured) {
if (good1 && good2) {
intersect1.z() = float(m_lastPos.z());
intersect2.z() = float(m_lastPos.z());
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV});
} else {
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV});
}
} else {
if (good1 && good2) {
intersect1.z() = float(m_lastPos.z());
intersect2.z() = float(m_lastPos.z());
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor});
} else {
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor});
}
}
}
{
zeus::CVector2f dva = (m_firstPos - m_lastPos).toVec2f();
if (!dva.canBeNormalized())
dva = {0.f, 1.f};
dva = dva.normalized().perpendicularVector() * m_firstWidth;
dva.x() /= CGraphics::g_ProjAspect;
zeus::CVector2f dvb = (m_secondPos - m_firstPos).toVec2f();
if (!dvb.canBeNormalized())
dvb = {0.f, 1.f};
dvb = dvb.normalized().perpendicularVector() * m_firstWidth;
dvb.x() /= CGraphics::g_ProjAspect;
zeus::CVector3f intersect1;
bool good1 = IntersectLines(m_lastPos.toVec2f() + dva, m_firstPos.toVec2f() + dva, m_firstPos.toVec2f() + dvb,
m_secondPos.toVec2f() + dvb, intersect1);
if ((intersect1.toVec2f() - m_firstPos.toVec2f()).magnitude() > m_firstWidth * 2.f)
good1 = false;
zeus::CVector3f intersect2;
bool good2 = IntersectLines(m_lastPos.toVec2f() - dva, m_firstPos.toVec2f() - dva, m_firstPos.toVec2f() - dvb,
m_secondPos.toVec2f() - dvb, intersect2);
if ((intersect2.toVec2f() - m_firstPos.toVec2f()).magnitude() > m_firstWidth * 2.f)
good2 = false;
if (m_textured) {
if (good1 && good2) {
intersect1.z() = float(m_firstPos.z());
intersect2.z() = float(m_firstPos.z());
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV});
} else {
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dva, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dva, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dvb, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dvb, m_lastW), m_lastColor, m_lastUV});
}
} else {
if (good1 && good2) {
intersect1.z() = float(m_firstPos.z());
intersect2.z() = float(m_firstPos.z());
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor});
} else {
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dva, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dva, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dvb, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dvb, m_lastW), m_lastColor});
}
}
}
} else {
zeus::CVector2f dv = (m_lastPos - m_lastPos2).toVec2f();
if (!dv.canBeNormalized())
dv = {0.f, 1.f};
dv = dv.normalized().perpendicularVector() * m_lastWidth;
dv.x() /= CGraphics::g_ProjAspect;
if (m_textured) {
if (m_mode == EPrimitiveMode::Lines && (m_nextVert & 1)) {
} else {
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor, m_lastUV});
// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor, m_lastUV});
}
} else {
if (m_mode == EPrimitiveMode::Lines && (m_nextVert & 1)) {
} else {
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor});
// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor});
}
}
}
m_final = true;
}
// m_uniformBuf.access() = SDrawUniform{moduColor, CGraphics::g_Fog};
// if (m_textured) {
// if (!g_StaticLineVertsTex.empty()) {
// memmove(m_vertBufTex.access(), g_StaticLineVertsTex.data(), sizeof(SDrawVertTex) * g_StaticLineVertsTex.size());
// CGraphics::SetShaderDataBinding(m_shaderBind[alphaWrite]);
// CGraphics::DrawArray(0, g_StaticLineVertsTex.size());
// }
// } else {
// if (!g_StaticLineVertsNoTex.empty()) {
// memmove(m_vertBufNoTex.access(), g_StaticLineVertsNoTex.data(),
// sizeof(SDrawVertNoTex) * g_StaticLineVertsNoTex.size());
// CGraphics::SetShaderDataBinding(m_shaderBind[alphaWrite]);
// CGraphics::DrawArray(0, g_StaticLineVertsNoTex.size());
// }
// }
}
} // namespace metaforce

View File

@ -1,73 +0,0 @@
#pragma once
#include <array>
#include "Runtime/RetroTypes.hpp"
#include "Runtime/rstl.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
#include <zeus/CColor.hpp>
#include <zeus/CVector2f.hpp>
#include <zeus/CVector3f.hpp>
#include <zeus/CVector4f.hpp>
namespace metaforce {
class CLineRenderer {
public:
enum class EPrimitiveMode { Lines, LineStrip, LineLoop };
private:
EPrimitiveMode m_mode;
u32 m_maxVerts;
u32 m_nextVert = 0;
bool m_final = false;
bool m_textured;
zeus::CVector3f m_firstPos;
zeus::CVector3f m_secondPos;
zeus::CVector2f m_firstUV;
zeus::CColor m_firstColor;
float m_firstWidth;
float m_firstW;
zeus::CVector3f m_lastPos;
zeus::CVector3f m_lastPos2;
zeus::CVector2f m_lastUV;
zeus::CColor m_lastColor;
float m_lastWidth;
float m_lastW;
// static rstl::reserved_vector<SDrawVertTex, 1024> g_StaticLineVertsTex;
// static rstl::reserved_vector<SDrawVertNoTex, 1024> g_StaticLineVertsNoTex;
// static hecl::VertexBufferPool<SDrawVertTex> s_vertPoolTex;
// static hecl::VertexBufferPool<SDrawVertNoTex> s_vertPoolNoTex;
// static hecl::UniformBufferPool<SDrawUniform> s_uniformPool;
public:
// hecl::VertexBufferPool<SDrawVertTex>::Token m_vertBufTex;
// hecl::VertexBufferPool<SDrawVertNoTex>::Token m_vertBufNoTex;
// hecl::UniformBufferPool<SDrawUniform>::Token m_uniformBuf;
// std::array<boo::ObjToken<boo::IShaderDataBinding>, 2> m_shaderBind;
CLineRenderer(EPrimitiveMode mode, u32 maxVerts, u32 texture, bool additive,
bool zTest = false, bool zGEqual = false);
CLineRenderer(CLineRenderer&&) = default;
void Reset();
void AddVertex(const zeus::CVector3f& position, const zeus::CColor& color, float width,
const zeus::CVector2f& uv = zeus::skZero2f);
void Render(bool alphaWrite = false, const zeus::CColor& moduColor = zeus::skWhite);
// static void UpdateBuffers() {
// s_vertPoolTex.updateBuffers();
// s_vertPoolNoTex.updateBuffers();
// s_uniformPool.updateBuffers();
// }
static void Initialize();
static void Shutdown();
};
} // namespace metaforce

View File

@ -7,7 +7,6 @@ set(GRAPHICS_SOURCES
CCubeSurface.cpp CCubeSurface.hpp CCubeSurface.cpp CCubeSurface.hpp
CDrawable.hpp CDrawable.hpp
CDrawablePlaneObject.hpp CDrawablePlaneObject.hpp
CLineRenderer.hpp CLineRenderer.cpp
CMetroidModelInstance.cpp CMetroidModelInstance.hpp CMetroidModelInstance.cpp CMetroidModelInstance.hpp
CLight.hpp CLight.cpp CLight.hpp CLight.cpp
CTevCombiners.cpp CTevCombiners.hpp CTevCombiners.cpp CTevCombiners.hpp
@ -25,29 +24,6 @@ set(GRAPHICS_SOURCES
CSimpleShadow.hpp CSimpleShadow.cpp CSimpleShadow.hpp CSimpleShadow.cpp
CRainSplashGenerator.hpp CRainSplashGenerator.cpp CRainSplashGenerator.hpp CRainSplashGenerator.cpp
CFont.hpp CFont.cpp CFont.hpp CFont.cpp
Shaders/CLineRendererShaders.hpp Shaders/CLineRendererShaders.cpp )
Shaders/CColoredStripShader.hpp Shaders/CColoredStripShader.cpp
Shaders/CModelShaders.hpp Shaders/CModelShaders.cpp
Shaders/CThermalColdFilter.hpp Shaders/CThermalColdFilter.cpp
Shaders/CThermalHotFilter.hpp Shaders/CThermalHotFilter.cpp
Shaders/CSpaceWarpFilter.hpp Shaders/CSpaceWarpFilter.cpp
Shaders/CCameraBlurFilter.hpp Shaders/CCameraBlurFilter.cpp
Shaders/CXRayBlurFilter.hpp Shaders/CXRayBlurFilter.cpp
Shaders/CTextSupportShader.hpp Shaders/CTextSupportShader.cpp
Shaders/CFogVolumePlaneShader.hpp Shaders/CFogVolumePlaneShader.cpp
Shaders/CFogVolumeFilter.hpp Shaders/CFogVolumeFilter.cpp
Shaders/CEnergyBarShader.hpp Shaders/CEnergyBarShader.cpp
Shaders/CRadarPaintShader.hpp Shaders/CRadarPaintShader.cpp
Shaders/CMapSurfaceShader.hpp Shaders/CMapSurfaceShader.cpp
Shaders/CPhazonSuitFilter.hpp Shaders/CPhazonSuitFilter.cpp
Shaders/CScanLinesFilter.hpp Shaders/CScanLinesFilter.cpp
Shaders/CRandomStaticFilter.hpp Shaders/CRandomStaticFilter.cpp
Shaders/CElementGenShaders.hpp Shaders/CElementGenShaders.cpp
Shaders/CDecalShaders.hpp Shaders/CDecalShaders.cpp
Shaders/CParticleSwooshShaders.hpp Shaders/CParticleSwooshShaders.cpp
Shaders/CFluidPlaneShader.hpp Shaders/CFluidPlaneShader.cpp
Shaders/CAABoxShader.hpp Shaders/CAABoxShader.cpp
Shaders/CWorldShadowShader.hpp Shaders/CWorldShadowShader.cpp
Shaders/CEnvFxShaders.hpp Shaders/CEnvFxShaders.cpp)
runtime_add_list(Graphics GRAPHICS_SOURCES) runtime_add_list(Graphics GRAPHICS_SOURCES)

View File

@ -3,60 +3,57 @@
#include "Graphics/CCubeSurface.hpp" #include "Graphics/CCubeSurface.hpp"
#include "Streams/IOStreams.hpp" #include "Streams/IOStreams.hpp"
#include <zeus/CColor.hpp>
namespace metaforce { namespace metaforce {
CMetroidModelInstance::CMetroidModelInstance(std::pair<const u8*, u32> modelHeader, const u8* materialData, CMetroidModelInstance::CMetroidModelInstance(std::span<const u8> modelHeader, const u8* materialData,
std::pair<const u8*, u32> positions, std::pair<const u8*, u32> normals, std::span<const u8> positions, std::span<const u8> normals,
std::pair<const u8*, u32> colors, std::pair<const u8*, u32> texCoords, std::span<const u8> colors, std::span<const u8> texCoords,
std::pair<const u8*, u32> packedTexCoords, std::span<const u8> packedTexCoords, std::vector<CCubeSurface>&& surfaces)
std::vector<CCubeSurface>&& surfaces)
: x4c_materialData(materialData), x50_surfaces(std::move(surfaces)) { : x4c_materialData(materialData), x50_surfaces(std::move(surfaces)) {
{ {
CMemoryInStream stream{modelHeader.first, modelHeader.second}; CMemoryInStream stream{modelHeader.data(), static_cast<u32>(modelHeader.size_bytes())};
x0_visorFlags = stream.ReadUint32(); x0_visorFlags = stream.ReadUint32();
x4_worldXf = stream.Get<zeus::CTransform>(); x4_worldXf = stream.Get<zeus::CTransform>();
x34_worldAABB = stream.Get<zeus::CAABox>(); x34_worldAABB = stream.Get<zeus::CAABox>();
} }
{ {
u32 numVertices = positions.second / 12; u32 numVertices = positions.size_bytes() / 12;
CMemoryInStream stream{positions.first, positions.second}; x60_positions.reserve(numVertices);
CMemoryInStream stream{positions.data(), static_cast<u32>(positions.size_bytes())};
for (u32 i = 0; i < numVertices; ++i) { for (u32 i = 0; i < numVertices; ++i) {
x60_positions.emplace_back(stream.Get<zeus::CVector3f>()); x60_positions.push_back(stream.Get<aurora::Vec3<float>>());
} }
} }
{ {
// Always short normals in MREA // Always short normals in MREA
u32 numNormals = normals.second / 6; u32 numNormals = normals.size_bytes() / 6;
CMemoryInStream stream{normals.first, normals.second}; x64_normals.reserve(numNormals);
CMemoryInStream stream{normals.data(), static_cast<u32>(normals.size_bytes())};
for (u32 i = 0; i < numNormals; ++i) { for (u32 i = 0; i < numNormals; ++i) {
const auto x = static_cast<float>(stream.ReadInt16()) / 16384.f; x64_normals.push_back(stream.Get<aurora::Vec3<s16>>());
const auto y = static_cast<float>(stream.ReadInt16()) / 16384.f;
const auto z = static_cast<float>(stream.ReadInt16()) / 16384.f;
x64_normals.emplace_back(x, y, z);
} }
} }
{ {
u32 numColors = colors.second / 4; u32 numColors = colors.size_bytes() / 4;
CMemoryInStream stream{colors.first, colors.second}; x68_colors.reserve(numColors);
CMemoryInStream stream{colors.data(), static_cast<u32>(colors.size_bytes())};
for (u32 i = 0; i < numColors; ++i) { for (u32 i = 0; i < numColors; ++i) {
x68_colors.emplace_back(stream.ReadUint32()); x68_colors.push_back(stream.ReadUint32());
} }
} }
{ {
u32 numTexCoords = texCoords.second / 8; u32 numTexCoords = texCoords.size_bytes() / 8;
CMemoryInStream stream{texCoords.first, texCoords.second}; x6c_texCoords.reserve(numTexCoords);
CMemoryInStream stream{texCoords.data(), static_cast<u32>(texCoords.size_bytes())};
for (u32 i = 0; i < numTexCoords; ++i) { for (u32 i = 0; i < numTexCoords; ++i) {
x6c_texCoords.emplace_back(stream.Get<aurora::Vec2<float>>()); x6c_texCoords.push_back(stream.Get<aurora::Vec2<float>>());
} }
} }
{ {
u32 numPackedTexCoords = packedTexCoords.second / 4; u32 numPackedTexCoords = packedTexCoords.size_bytes() / 4;
CMemoryInStream stream{packedTexCoords.first, packedTexCoords.second}; x70_packedTexCoords.reserve(numPackedTexCoords);
CMemoryInStream stream{packedTexCoords.data(), static_cast<u32>(packedTexCoords.size_bytes())};
for (u32 i = 0; i < numPackedTexCoords; ++i) { for (u32 i = 0; i < numPackedTexCoords; ++i) {
const auto u = static_cast<float>(stream.ReadInt16()) / 32768.f; x70_packedTexCoords.push_back(stream.Get<aurora::Vec2<u16>>());
const auto v = static_cast<float>(stream.ReadInt16()) / 32768.f;
x70_packedTexCoords.emplace_back(u, v);
} }
} }
} }

View File

@ -1,10 +1,11 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <span>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "Graphics/CCubeModel.hpp" #include "Runtime/Graphics/CCubeModel.hpp"
#include "Runtime/RetroTypes.hpp" #include "Runtime/RetroTypes.hpp"
#include <zeus/CAABox.hpp> #include <zeus/CAABox.hpp>
@ -20,30 +21,27 @@ class CMetroidModelInstance {
zeus::CAABox x34_worldAABB; zeus::CAABox x34_worldAABB;
const u8* x4c_materialData = nullptr; const u8* x4c_materialData = nullptr;
std::vector<CCubeSurface> x50_surfaces; // was rstl::vector<void*>* std::vector<CCubeSurface> x50_surfaces; // was rstl::vector<void*>*
std::vector<zeus::CVector3f> x60_positions; // was void* std::vector<aurora::Vec3<float>> x60_positions; // was void*
std::vector<zeus::CVector3f> x64_normals; // was void* std::vector<aurora::Vec3<s16>> x64_normals; // was void*
std::vector<zeus::CColor> x68_colors; // was void* std::vector<u32> x68_colors; // was void*
std::vector<aurora::Vec2<float>> x6c_texCoords; // was void* std::vector<aurora::Vec2<float>> x6c_texCoords; // was void*
std::vector<aurora::Vec2<float>> x70_packedTexCoords; // was void* std::vector<aurora::Vec2<u16>> x70_packedTexCoords; // was void*
public: public:
CMetroidModelInstance() = default; CMetroidModelInstance() = default;
CMetroidModelInstance(std::pair<const u8*, u32> modelHeader, const u8* materialData, CMetroidModelInstance(std::span<const u8> modelHeader, const u8* materialData, std::span<const u8> positions,
std::pair<const u8*, u32> positions, std::pair<const u8*, u32> normals, std::span<const u8> normals, std::span<const u8> colors, std::span<const u8> texCoords,
std::pair<const u8*, u32> colors, std::pair<const u8*, u32> texCoords, std::span<const u8> packedTexCoords, std::vector<CCubeSurface>&& surfaces);
std::pair<const u8*, u32> packedTexCoords, std::vector<CCubeSurface>&& surfaces);
[[nodiscard]] u32 GetFlags() const { return x0_visorFlags; } [[nodiscard]] u32 GetFlags() const { return x0_visorFlags; }
[[nodiscard]] const zeus::CAABox& GetBoundingBox() const { return x34_worldAABB; } [[nodiscard]] const zeus::CAABox& GetBoundingBox() const { return x34_worldAABB; }
[[nodiscard]] std::vector<CCubeSurface>* GetSurfaces() { return &x50_surfaces; } [[nodiscard]] std::vector<CCubeSurface>* GetSurfaces() { return &x50_surfaces; }
[[nodiscard]] const std::vector<CCubeSurface>* GetSurfaces() const { return &x50_surfaces; } [[nodiscard]] const std::vector<CCubeSurface>* GetSurfaces() const { return &x50_surfaces; }
[[nodiscard]] const u8* GetMaterialPointer() const { return x4c_materialData; } [[nodiscard]] const u8* GetMaterialPointer() const { return x4c_materialData; }
[[nodiscard]] TVectorRef GetVertexPointer() { return &x60_positions; } [[nodiscard]] std::span<const u8> GetVertexPointer() const { return byte_span(x60_positions); }
[[nodiscard]] TConstVectorRef GetVertexPointer() const { return &x60_positions; } [[nodiscard]] std::span<const u8> GetNormalPointer() const { return byte_span(x64_normals); }
[[nodiscard]] TVectorRef GetNormalPointer() { return &x64_normals; } [[nodiscard]] std::span<const u8> GetColorPointer() const { return byte_span(x68_colors); }
[[nodiscard]] TConstVectorRef GetNormalPointer() const { return &x64_normals; } [[nodiscard]] std::span<const u8> GetTCPointer() const { return byte_span(x6c_texCoords); }
[[nodiscard]] const std::vector<zeus::CColor>* GetColorPointer() const { return &x68_colors; } [[nodiscard]] std::span<const u8> GetPackedTCPointer() const { return byte_span(x70_packedTexCoords); }
[[nodiscard]] const std::vector<aurora::Vec2<float>>* GetTCPointer() const { return &x6c_texCoords; }
[[nodiscard]] const std::vector<aurora::Vec2<float>>* GetPackedTCPointer() const { return &x70_packedTexCoords; }
}; };
} // namespace metaforce } // namespace metaforce

View File

@ -61,34 +61,38 @@ CModel::CModel(std::unique_ptr<u8[]> in, u32 dataLen, IObjectStore* store)
x4_dataLen += shader.x0_textures.size() * sizeof(TCachedToken<CTexture>); x4_dataLen += shader.x0_textures.size() * sizeof(TCachedToken<CTexture>);
} }
/* Metaforce note: Due to padding in zeus types we need to convert these and store locally */
u32 numVertices = CBasics::SwapBytes(*secSizeCur) / 12; u32 numVertices = CBasics::SwapBytes(*secSizeCur) / 12;
m_positions.reserve(numVertices);
auto positions = StreamFromPartData(dataCur, secSizeCur); auto positions = StreamFromPartData(dataCur, secSizeCur);
for (u32 i = 0; i < numVertices; ++i) { for (u32 i = 0; i < numVertices; ++i) {
m_positions.emplace_back(positions.Get<zeus::CVector3f>()); m_positions.emplace_back(positions.Get<aurora::Vec3<float>>());
} }
u32 numNormals = CBasics::SwapBytes(*secSizeCur); u32 numNormals = CBasics::SwapBytes(*secSizeCur);
numNormals /= (flags & 2) == 0 ? 12 : 6; numNormals /= (flags & 2) == 0 ? 12 : 6;
if ((flags & 2) == 0) {
m_normals.reserve(numNormals);
} else {
m_shortNormals.reserve(numNormals);
}
auto normals = StreamFromPartData(dataCur, secSizeCur); auto normals = StreamFromPartData(dataCur, secSizeCur);
for (u32 i = 0; i < numNormals; ++i) { for (u32 i = 0; i < numNormals; ++i) {
if ((flags & 2) == 0) { if ((flags & 2) == 0) {
m_normals.emplace_back(normals.Get<zeus::CVector3f>()); m_normals.emplace_back(normals.Get<aurora::Vec3<float>>());
} else { } else {
const auto x = static_cast<float>(normals.ReadShort()) / 16384.f; m_shortNormals.emplace_back(normals.Get<aurora::Vec3<s16>>());
const auto y = static_cast<float>(normals.ReadShort()) / 16384.f;
const auto z = static_cast<float>(normals.ReadShort()) / 16384.f;
m_normals.emplace_back(x, y, z);
} }
} }
u32 numColors = CBasics::SwapBytes(*secSizeCur) / 4; u32 numColors = CBasics::SwapBytes(*secSizeCur) / 4;
m_colors.reserve(numColors);
auto vtxColors = StreamFromPartData(dataCur, secSizeCur); auto vtxColors = StreamFromPartData(dataCur, secSizeCur);
for (u32 i = 0; i < numColors; ++i) { for (u32 i = 0; i < numColors; ++i) {
m_colors.emplace_back(zeus::CColor(vtxColors.ReadUint32())); m_colors.emplace_back(vtxColors.ReadUint32());
} }
u32 numFloatUVs = CBasics::SwapBytes(*secSizeCur) / 8; u32 numFloatUVs = CBasics::SwapBytes(*secSizeCur) / 8;
m_floatUVs.reserve(numFloatUVs);
auto floatUVs = StreamFromPartData(dataCur, secSizeCur); auto floatUVs = StreamFromPartData(dataCur, secSizeCur);
for (u32 i = 0; i < numFloatUVs; ++i) { for (u32 i = 0; i < numFloatUVs; ++i) {
m_floatUVs.emplace_back(floatUVs.Get<aurora::Vec2<float>>()); m_floatUVs.emplace_back(floatUVs.Get<aurora::Vec2<float>>());
@ -96,11 +100,10 @@ CModel::CModel(std::unique_ptr<u8[]> in, u32 dataLen, IObjectStore* store)
if ((flags & 4) != 0) { if ((flags & 4) != 0) {
u32 numShortUVs = CBasics::SwapBytes(*secSizeCur) / 4; u32 numShortUVs = CBasics::SwapBytes(*secSizeCur) / 4;
m_shortUVs.reserve(numShortUVs);
auto shortUVs = StreamFromPartData(dataCur, secSizeCur); auto shortUVs = StreamFromPartData(dataCur, secSizeCur);
for (u32 i = 0; i < numShortUVs; ++i) { for (u32 i = 0; i < numShortUVs; ++i) {
const auto u = static_cast<float>(shortUVs.ReadShort()) / 32768.f; m_shortUVs.emplace_back(shortUVs.Get<aurora::Vec2<u16>>());
const auto v = static_cast<float>(shortUVs.ReadShort()) / 32768.f;
m_shortUVs.emplace_back(u, v);
} }
} }
@ -122,9 +125,10 @@ CModel::CModel(std::unique_ptr<u8[]> in, u32 dataLen, IObjectStore* store)
}; };
/* This constructor has been changed from the original to take into account platform differences */ /* This constructor has been changed from the original to take into account platform differences */
x28_modelInst = x28_modelInst = std::make_unique<CCubeModel>(&x8_surfaces, &x18_matSets[0].x0_textures, x18_matSets[0].x10_data,
std::make_unique<CCubeModel>(&x8_surfaces, &x18_matSets[0].x0_textures, x18_matSets[0].x10_data, &m_positions, byte_span(m_positions), byte_span(m_colors),
&m_colors, &m_normals, &m_floatUVs, &m_shortUVs, aabb, flags, true, -1); (flags & 2) == 0 ? byte_span(m_normals) : byte_span(m_shortNormals),
byte_span(m_floatUVs), byte_span(m_shortUVs), aabb, flags, true, -1);
sThisFrameList = this; sThisFrameList = this;
if (x34_next != nullptr) { if (x34_next != nullptr) {
@ -203,12 +207,8 @@ void CModel::EnableTextureTimeout() { sIsTextureTimeoutEnabled = true; }
void CModel::DisableTextureTimeout() { sIsTextureTimeoutEnabled = false; } void CModel::DisableTextureTimeout() { sIsTextureTimeoutEnabled = false; }
TVectorRef CModel::GetPositions() { return x28_modelInst->GetPositions(); }
TConstVectorRef CModel::GetPositions() const { return x28_modelInst->GetPositions(); } TConstVectorRef CModel::GetPositions() const { return x28_modelInst->GetPositions(); }
TVectorRef CModel::GetNormals() { return x28_modelInst->GetNormals(); }
TConstVectorRef CModel::GetNormals() const { return x28_modelInst->GetNormals(); } TConstVectorRef CModel::GetNormals() const { return x28_modelInst->GetNormals(); }
void CModel::VerifyCurrentShader(u32 matIdx) { void CModel::VerifyCurrentShader(u32 matIdx) {
@ -262,7 +262,7 @@ void CModel::Touch(u32 matIdx) {
void CModel::Draw(CModelFlags flags) { void CModel::Draw(CModelFlags flags) {
if (flags.x2_flags & CModelFlagBits::DrawNormal) { if (flags.x2_flags & CModelFlagBits::DrawNormal) {
x28_modelInst->DrawNormal(nullptr, nullptr, ESurfaceSelection::All); x28_modelInst->DrawNormal({}, {}, ESurfaceSelection::All);
} }
CCubeMaterial::ResetCachedMaterials(); CCubeMaterial::ResetCachedMaterials();
MoveToThisFrameList(); MoveToThisFrameList();
@ -282,7 +282,7 @@ void CModel::Draw(TConstVectorRef positions, TConstVectorRef normals, const CMod
void CModel::DrawSortedParts(CModelFlags flags) { void CModel::DrawSortedParts(CModelFlags flags) {
if (flags.x2_flags & CModelFlagBits::DrawNormal) { if (flags.x2_flags & CModelFlagBits::DrawNormal) {
x28_modelInst->DrawNormal(nullptr, nullptr, ESurfaceSelection::Sorted); x28_modelInst->DrawNormal({}, {}, ESurfaceSelection::Sorted);
} }
CCubeMaterial::ResetCachedMaterials(); CCubeMaterial::ResetCachedMaterials();
MoveToThisFrameList(); MoveToThisFrameList();
@ -292,7 +292,7 @@ void CModel::DrawSortedParts(CModelFlags flags) {
void CModel::DrawUnsortedParts(CModelFlags flags) { void CModel::DrawUnsortedParts(CModelFlags flags) {
if (flags.x2_flags & CModelFlagBits::DrawNormal) { if (flags.x2_flags & CModelFlagBits::DrawNormal) {
x28_modelInst->DrawNormal(nullptr, nullptr, ESurfaceSelection::Unsorted); x28_modelInst->DrawNormal({}, {}, ESurfaceSelection::Unsorted);
} }
CCubeMaterial::ResetCachedMaterials(); CCubeMaterial::ResetCachedMaterials();
MoveToThisFrameList(); MoveToThisFrameList();

View File

@ -85,11 +85,12 @@ private:
u32 x38_lastFrame; u32 x38_lastFrame;
/* Resident copies of maintained data */ /* Resident copies of maintained data */
std::vector<zeus::CVector3f> m_positions; std::vector<aurora::Vec3<float>> m_positions;
std::vector<zeus::CVector3f> m_normals; std::vector<aurora::Vec3<float>> m_normals;
std::vector<zeus::CColor> m_colors; std::vector<aurora::Vec3<s16>> m_shortNormals;
std::vector<u32> m_colors;
std::vector<aurora::Vec2<float>> m_floatUVs; std::vector<aurora::Vec2<float>> m_floatUVs;
std::vector<aurora::Vec2<float>> m_shortUVs; std::vector<aurora::Vec2<u16>> m_shortUVs;
public: public:
CModel(std::unique_ptr<u8[]> in, u32 dataLen, IObjectStore* store); CModel(std::unique_ptr<u8[]> in, u32 dataLen, IObjectStore* store);
@ -106,9 +107,7 @@ public:
void DrawUnsortedParts(CModelFlags flags); void DrawUnsortedParts(CModelFlags flags);
bool IsLoaded(u32 matIdx); bool IsLoaded(u32 matIdx);
[[nodiscard]] TVectorRef GetPositions();
[[nodiscard]] TConstVectorRef GetPositions() const; [[nodiscard]] TConstVectorRef GetPositions() const;
[[nodiscard]] TVectorRef GetNormals();
[[nodiscard]] TConstVectorRef GetNormals() const; [[nodiscard]] TConstVectorRef GetNormals() const;
[[nodiscard]] u32 GetNumMaterialSets() const { return x18_matSets.size(); } [[nodiscard]] u32 GetNumMaterialSets() const { return x18_matSets.size(); }
[[nodiscard]] bool IsOpaque() const { return x28_modelInst->x3c_firstSortedSurf == nullptr; } [[nodiscard]] bool IsOpaque() const { return x28_modelInst->x3c_firstSortedSurf == nullptr; }

View File

@ -1,312 +0,0 @@
#pragma once
#include <memory>
#include <optional>
#include <unordered_map>
#include <vector>
//#include "DataSpec/DNACommon/CMDL.hpp"
//#include "DataSpec/DNAMP1/CMDLMaterials.hpp"
#include "Runtime/CFactoryMgr.hpp"
#include "Runtime/CToken.hpp"
#include "Runtime/Graphics/CTexture.hpp"
#include "Runtime/Graphics/Shaders/CModelShaders.hpp"
#include "Runtime/RetroTypes.hpp"
//#include <hecl/HMDLMeta.hpp>
#include <zeus/CAABox.hpp>
#include <zeus/CColor.hpp>
namespace metaforce {
class CLight;
class CModel;
class CPoseAsTransforms;
class CSkinRules;
class IObjectStore;
struct CModelFlags {
u8 x0_blendMode = 0; /* 2: add color, >6: additive, >4: blend, else opaque */
u8 x1_matSetIdx = 0;
EExtendedShader m_extendedShader = EExtendedShader::Lighting;
bool m_noCull = false;
bool m_noZTest = false;
bool m_noZWrite = false;
bool m_depthGreater = false;
u16 x2_flags = 0; /* Flags */
zeus::CColor x4_color; /* Set into kcolor slot specified by material */
zeus::CColor addColor = zeus::skClear;
zeus::CAABox mbShadowBox;
constexpr CModelFlags() = default;
constexpr CModelFlags(u8 blendMode, u8 shadIdx, u16 flags, const zeus::CColor& col)
: x0_blendMode(blendMode), x1_matSetIdx(shadIdx), x2_flags(flags), x4_color(col) {
/* Blend mode will override this if the surface's original material is opaque */
m_noZWrite = (x2_flags & 0x2) == 0;
m_depthGreater = (x2_flags & 0x8) != 0;
}
/* Flags
0x1: depth lequal
0x2: depth update
0x4: render without texture lock
0x8: depth greater
0x10: depth non-inclusive
*/
bool operator==(const CModelFlags& other) const {
return x0_blendMode == other.x0_blendMode && x1_matSetIdx == other.x1_matSetIdx && x2_flags == other.x2_flags &&
x4_color == other.x4_color;
}
bool operator!=(const CModelFlags& other) const { return !operator==(other); }
};
/* metaforce addition: doesn't require hacky stashing of
* pointers within loaded CMDL buffer */
struct CBooSurface {
// DataSpec::DNACMDL::SurfaceHeader_2 m_data;
size_t selfIdx;
class CBooModel* m_parent = nullptr;
CBooSurface* m_next = nullptr;
zeus::CAABox GetBounds() const {
// if (!m_data.aabbSz)
// return zeus::CAABox(m_data.centroid, m_data.centroid);
// else
// return zeus::CAABox(m_data.aabb[0], m_data.aabb[1]);
return {};
}
};
//using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet;
//struct GeometryUniformLayout {
// mutable std::vector<boo::ObjToken<boo::IGraphicsBufferD>> m_sharedBuffer;
// size_t m_geomBufferSize = 0;
// size_t m_skinBankCount = 0;
// size_t m_weightVecCount = 0;
//
// std::vector<size_t> m_skinOffs;
// std::vector<size_t> m_skinSizes;
//
// std::vector<size_t> m_uvOffs;
// std::vector<size_t> m_uvSizes;
//
// GeometryUniformLayout(const CModel* model, const MaterialSet* matSet);
// void Update(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose,
// const MaterialSet* matSet, const boo::ObjToken<boo::IGraphicsBufferD>& buf,
// const CBooModel* parent) const;
//
// void ReserveSharedBuffers(boo::IGraphicsDataFactory::Context& ctx, int size);
// boo::ObjToken<boo::IGraphicsBufferD> GetSharedBuffer(int idx) const;
//};
struct SShader {
std::unordered_map<CAssetId, TCachedToken<CTexture>> x0_textures;
// std::unordered_map<int, CModelShaders::ShaderPipelines> m_shaders;
// MaterialSet m_matSet;
// std::optional<GeometryUniformLayout> m_geomLayout;
int m_matSetIdx;
explicit SShader(int idx) : m_matSetIdx(idx) {
x0_textures.clear();
// m_shaders.clear();
}
// void InitializeLayout(const CModel* model) { m_geomLayout.emplace(model, &m_matSet); }
void UnlockTextures();
// CModelShaders::ShaderPipelines BuildShader(const hecl::HMDLMeta& meta, const MaterialSet::Material& mat);
// void BuildShaders(const hecl::HMDLMeta& meta, std::unordered_map<int, CModelShaders::ShaderPipelines>& shaders);
// void BuildShaders(const hecl::HMDLMeta& meta) { BuildShaders(meta, m_shaders); }
};
class CBooModel {
friend class CBooRenderer;
friend class CGameArea;
friend class CMetroidModelInstance;
friend class CModel;
friend class CSkinnedModel;
friend struct GeometryUniformLayout;
public:
enum class ESurfaceSelection { UnsortedOnly, SortedOnly, All };
private:
CBooModel* m_next = nullptr;
CBooModel* m_prev = nullptr;
size_t m_uniUpdateCount = 0;
TToken<CModel> m_modelTok;
CModel* m_model;
std::vector<CBooSurface>* x0_surfaces;
// const MaterialSet* x4_matSet;
// const GeometryUniformLayout* m_geomLayout;
int m_matSetIdx = -1;
// const std::unordered_map<int, CModelShaders::ShaderPipelines>* m_pipelines;
std::unordered_map<CAssetId, TCachedToken<CTexture>> x1c_textures;
zeus::CAABox x20_aabb;
CBooSurface* x38_firstUnsortedSurface = nullptr;
CBooSurface* x3c_firstSortedSurface = nullptr;
bool x40_24_texturesLoaded : 1 = false;
bool x40_25_modelVisible : 1 = false;
u8 x41_mask;
u32 x44_areaInstanceIdx = UINT32_MAX;
// struct UVAnimationBuffer {
// static void ProcessAnimation(u8*& bufOut, const MaterialSet::Material::PASS& anim);
// static void PadOutBuffer(u8*& bufStart, u8*& bufOut);
// static void Update(u8*& bufOut, const MaterialSet* matSet, const CModelFlags& flags, const CBooModel* parent);
// };
CModelShaders::LightingUniform m_lightingData;
/* metaforce addition: boo! */
// size_t m_uniformDataSize = 0;
// struct ModelInstance {
// boo::ObjToken<boo::IGraphicsBufferD> m_geomUniformBuffer;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniformBuffer;
// std::vector<std::vector<boo::ObjToken<boo::IShaderDataBinding>>> m_shaderDataBindings;
// boo::ObjToken<boo::IGraphicsBufferD> m_dynamicVbo;
//
// boo::ObjToken<boo::IGraphicsBuffer> GetBooVBO(const CBooModel& model, boo::IGraphicsDataFactory::Context& ctx);
// };
// std::vector<ModelInstance> m_instances;
// ModelInstance m_ballShadowInstance;
// boo::ObjToken<boo::IGraphicsBufferS> m_staticVbo;
// boo::ObjToken<boo::IGraphicsBufferS> m_staticIbo;
//
// boo::ObjToken<boo::ITexture> m_lastDrawnShadowMap;
// boo::ObjToken<boo::ITexture> m_lastDrawnOneTexture;
// boo::ObjToken<boo::ITextureCubeR> m_lastDrawnReflectionCube;
// ModelInstance* PushNewModelInstance(int sharedLayoutBuf = -1, boo::IGraphicsDataFactory::Context* ctx = nullptr);
void DrawAlphaSurfaces(const CModelFlags& flags) const;
void DrawNormalSurfaces(const CModelFlags& flags) const;
void DrawSurfaces(const CModelFlags& flags) const;
void DrawSurface(const CBooSurface& surf, const CModelFlags& flags) const;
void WarmupDrawSurfaces() const;
void WarmupDrawSurface(const CBooSurface& surf) const;
static inline zeus::CVector3f g_PlayerPosition;
static inline float g_ModSeconds = 0.0f;
static inline float g_TransformedTime = 0.0f;
static inline float g_TransformedTime2 = 0.0f;
static inline CBooModel* g_LastModelCached = nullptr;
static inline bool g_DummyTextures = false;
static inline bool g_RenderModelBlack = false;
public:
~CBooModel();
CBooModel(TToken<CModel>& token, CModel* parent, std::vector<CBooSurface>* surfaces, SShader& shader,
// TODO
// boo::ObjToken<boo::IGraphicsBufferS> vbo, boo::ObjToken<boo::IGraphicsBufferS> ibo,
const zeus::CAABox& aabb, u8 renderMask);
// static void MakeTexturesFromMats(const MaterialSet& matSet,
// std::unordered_map<CAssetId, TCachedToken<CTexture>>& toksOut, IObjectStore& store);
void MakeTexturesFromMats(std::unordered_map<CAssetId, TCachedToken<CTexture>>& toksOut, IObjectStore& store);
bool IsOpaque() const { return x3c_firstSortedSurface == nullptr; }
void ActivateLights(const std::vector<CLight>& lights);
void SetAmbientColor(const zeus::CColor& color) { m_lightingData.ambient = color; }
void DisableAllLights();
void RemapMaterialData(SShader& shader);
bool TryLockTextures();
void UnlockTextures();
void SyncLoadTextures();
void Touch(int shaderIdx);
void VerifyCurrentShader(int shaderIdx);
// boo::ObjToken<boo::IGraphicsBufferD> UpdateUniformData(const CModelFlags& flags, const CSkinRules* cskr,
// const CPoseAsTransforms* pose, int sharedLayoutBuf = -1);
void DrawAlpha(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose);
void DrawNormal(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose);
void Draw(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose);
void DrawFlat(ESurfaceSelection sel, EExtendedShader extendedIdx) const;
void LockParent() { m_modelTok.Lock(); }
void UnlockParent() { m_modelTok.Unlock(); }
// const MaterialSet::Material& GetMaterialByIndex(int idx) const { return x4_matSet->materials.at(idx); }
void ClearUniformCounter() { m_uniUpdateCount = 0; }
static void ClearModelUniformCounters();
static inline bool g_DrawingOccluders = false;
static void SetDrawingOccluders(bool occ) { g_DrawingOccluders = occ; }
static void SetNewPlayerPositionAndTime(const zeus::CVector3f& pos);
static inline zeus::CVector3f g_ReflectViewPos;
static void KillCachedViewDepState();
static void EnsureViewDepStateCached(const CBooModel& model, const CBooSurface* surf, zeus::CMatrix4f* mtxsOut,
float& alphaOut);
static inline aurora::gfx::TextureHandle g_shadowMap;
static inline zeus::CTransform g_shadowTexXf;
static void EnableShadowMaps(const aurora::gfx::TextureHandle& map, const zeus::CTransform& texXf);
static void DisableShadowMaps();
static inline aurora::gfx::TextureHandle g_disintegrateTexture;
static void SetDisintegrateTexture(const aurora::gfx::TextureHandle& map) { g_disintegrateTexture = map; }
static inline aurora::gfx::TextureHandle g_reflectionCube;
static void SetReflectionCube(const aurora::gfx::TextureHandle& map) { g_reflectionCube = map; }
static void SetDummyTextures(bool b) { g_DummyTextures = b; }
static void SetRenderModelBlack(bool b) { g_RenderModelBlack = b; }
static void Shutdown();
const zeus::CAABox& GetAABB() const { return x20_aabb; }
};
class CModel {
friend class CBooModel;
friend struct GeometryUniformLayout;
// std::unique_ptr<u8[]> x0_data;
// u32 x4_dataLen;
TToken<CModel> m_selfToken; /* DO NOT LOCK! */
zeus::CAABox m_aabb;
u32 m_flags;
std::vector<CBooSurface> x8_surfaces;
std::vector<SShader> x18_matSets;
std::unique_ptr<CBooModel> x28_modelInst;
// CModel* x30_next = nullptr;
// CModel* x34_prev = nullptr;
int x38_lastFrame;
/* metaforce addition: boo! */
// boo::ObjToken<boo::IGraphicsBufferS> m_staticVbo;
// hecl::HMDLMeta m_hmdlMeta;
std::unique_ptr<uint8_t[]> m_dynamicVertexData;
// boo::ObjToken<boo::IGraphicsBufferS> m_ibo;
public:
// using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet;
CModel(std::unique_ptr<u8[]>&& in, u32 dataLen, IObjectStore* store, CObjectReference* selfRef);
void DrawSortedParts(const CModelFlags& flags) const;
void DrawUnsortedParts(const CModelFlags& flags) const;
void Draw(const CModelFlags& flags) const;
bool IsLoaded(int shaderIdx) const;
void Touch(int shaderIdx) { x28_modelInst->Touch(shaderIdx); }
const zeus::CAABox& GetAABB() const { return m_aabb; }
CBooModel& GetInstance() { return *x28_modelInst; }
const CBooModel& GetInstance() const { return *x28_modelInst; }
std::unique_ptr<CBooModel> MakeNewInstance(int shaderIdx, bool lockParent = true);
void UpdateLastFrame() const { const_cast<CModel&>(*this).x38_lastFrame = CGraphics::GetFrameCounter(); }
u32 GetNumMaterialSets() const { return x18_matSets.size(); }
size_t GetPoolVertexOffset(size_t idx) const;
zeus::CVector3f GetPoolVertex(size_t idx) const;
size_t GetPoolNormalOffset(size_t idx) const;
zeus::CVector3f GetPoolNormal(size_t idx) const;
// void ApplyVerticesCPU(const boo::ObjToken<boo::IGraphicsBufferD>& vertBuf,
// const std::vector<std::pair<zeus::CVector3f, zeus::CVector3f>>& vn) const;
// void RestoreVerticesCPU(const boo::ObjToken<boo::IGraphicsBufferD>& vertBuf) const;
};
CFactoryFnReturn FPCModelFactory(const metaforce::SObjectTag& tag, std::unique_ptr<u8[]>&& in, u32 len,
const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef);
} // namespace metaforce

File diff suppressed because it is too large Load Diff

View File

@ -48,13 +48,9 @@ static void MyTHPGXYuv2RgbSetup(bool interlaced2ndFrame, bool fieldFlip) {
if (!fieldFlip) { if (!fieldFlip) {
CGX::SetNumTexGens(3); CGX::SetNumTexGens(3);
CGX::SetTexCoordGen(GX_TEXCOORD2, GX_TG_MTX2x4, GX_TG_POS, GX_TEXMTX0, false, GX_PTIDENTITY); CGX::SetTexCoordGen(GX_TEXCOORD2, GX_TG_MTX2x4, GX_TG_POS, GX_TEXMTX0, false, GX_PTIDENTITY);
aurora::Mat4x2<float> mtx; float n = interlaced2ndFrame ? 0.25f : 0.f;
mtx.m0.x = 0.125f; float mtx[8] = {0.125f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.25f, n};
mtx.m2.y = 0.25f; GXLoadTexMtxImm(mtx, GX_TEXMTX0, GX_MTX2x4);
if (interlaced2ndFrame) {
mtx.m3.y = 0.25f;
}
GXLoadTexMtxImm(&mtx, GX_TEXMTX0, GX_MTX2x4);
GXTexObj texObj; GXTexObj texObj;
GXInitTexObj(&texObj, InterlaceTex.data(), 8, 4, GX_TF_I8, GX_REPEAT, GX_REPEAT, false); GXInitTexObj(&texObj, InterlaceTex.data(), 8, 4, GX_TF_I8, GX_REPEAT, GX_REPEAT, false);
GXInitTexObjLOD(&texObj, GX_NEAR, GX_NEAR, 0.f, 0.f, 0.f, false, false, GX_ANISO_1); GXInitTexObjLOD(&texObj, GX_NEAR, GX_NEAR, 0.f, 0.f, 0.f, false, false, GX_ANISO_1);
@ -567,7 +563,7 @@ void CMoviePlayer::DrawFrame(const zeus::CVector3f& v1, const zeus::CVector3f& v
/* ensure second field is being displayed by VI to signal advance /* ensure second field is being displayed by VI to signal advance
* (faked in metaforce with continuous xor) */ * (faked in metaforce with continuous xor) */
if (xfc_fieldIndex == 0 && CGraphics::g_LastFrameUsedAbove) if (xfc_fieldIndex == 0 && CGraphics::mLastFrameUsedAbove)
xf4_26_fieldFlip = true; xf4_26_fieldFlip = true;
++xfc_fieldIndex; ++xfc_fieldIndex;

View File

@ -22,13 +22,13 @@ void CRainSplashGenerator::SSplashLine::Draw(float alpha, float dt, const zeus::
float delta = dt * xc_speed; float delta = dt * xc_speed;
float vt = std::max(0.f, x0_t - delta * x15_length); float vt = std::max(0.f, x0_t - delta * x15_length);
auto vertCount = u32((x0_t - vt) / delta + 1.f); auto vertCount = u32((x0_t - vt) / delta + 1.f);
m_renderer.Reset(); // m_renderer.Reset();
for (u32 i = 0; i < vertCount; ++i) { for (u32 i = 0; i < vertCount; ++i) {
float vertAlpha = vt * alpha; float vertAlpha = vt * alpha;
zeus::CVector3f vec(vt * x4_xEnd, vt * x8_yEnd, -4.f * vt * (vt - 1.f) * x10_zParabolaHeight); zeus::CVector3f vec(vt * x4_xEnd, vt * x8_yEnd, -4.f * vt * (vt - 1.f) * x10_zParabolaHeight);
vec += pos; vec += pos;
vt += delta; vt += delta;
m_renderer.AddVertex(vec, zeus::CColor(1.f, vertAlpha), 1); // m_renderer.AddVertex(vec, zeus::CColor(1.f, vertAlpha), 1);
} }
// m_renderer.Render(g_Renderer->IsThermalVisorHotPass()); // m_renderer.Render(g_Renderer->IsThermalVisorHotPass());
} }
@ -70,7 +70,7 @@ void CRainSplashGenerator::Draw(const zeus::CTransform& xf) {
DoDraw(xf); DoDraw(xf);
} }
CRainSplashGenerator::SSplashLine::SSplashLine() : m_renderer(CLineRenderer::EPrimitiveMode::LineStrip, 3, {}, false) {} CRainSplashGenerator::SSplashLine::SSplashLine() {}
CRainSplashGenerator::SRainSplash::SRainSplash() { CRainSplashGenerator::SRainSplash::SRainSplash() {
for (size_t i = 0; i < x0_lines.capacity(); ++i) { for (size_t i = 0; i < x0_lines.capacity(); ++i) {
@ -146,13 +146,16 @@ void CRainSplashGenerator::Update(float dt, CStateManager& mgr) {
} }
u32 CRainSplashGenerator::GetNextBestPt(u32 pt, const SSkinningWorkspace& workspace, CRandom16& rand, float minZ) { u32 CRainSplashGenerator::GetNextBestPt(u32 pt, const SSkinningWorkspace& workspace, CRandom16& rand, float minZ) {
const auto& refVert = workspace.m_vertexWorkspace[pt]; const auto& refVertA = workspace.m_vertexWorkspace[pt];
const zeus::CVector3f refVert{refVertA.x, refVertA.y, refVertA.z};
float maxDist = 0.f; float maxDist = 0.f;
u32 nextPt = pt; u32 nextPt = pt;
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
const auto idx = u32(rand.Range(0, int(workspace.m_vertexWorkspace.size() - 1))); const auto idx = u32(rand.Range(0, int(workspace.m_vertexWorkspace.size() - 1)));
const auto& vert = workspace.m_vertexWorkspace[idx]; const auto& vertA = workspace.m_vertexWorkspace[idx];
const auto& norm = workspace.m_normalWorkspace[idx]; const zeus::CVector3f vert{vertA.x, vertA.y, vertA.z};
const auto& normA = workspace.m_normalWorkspace[idx];
const zeus::CVector3f norm{normA.x, normA.y, normA.z};
const float distSq = (refVert - vert).magSquared(); const float distSq = (refVert - vert).magSquared();
if (distSq > maxDist && norm.dot(zeus::skUp) >= 0.f && (vert.z() <= 0.f || vert.z() > minZ)) { if (distSq > maxDist && norm.dot(zeus::skUp) >= 0.f && (vert.z() <= 0.f || vert.z() > minZ)) {
nextPt = idx; nextPt = idx;
@ -185,7 +188,8 @@ void CRainSplashGenerator::GeneratePoints(const SSkinningWorkspace& workspace) {
if (x40_queueSize >= x0_rainSplashes.size()) if (x40_queueSize >= x0_rainSplashes.size())
break; break;
x34_curPoint = GetNextBestPt(x34_curPoint, workspace, x10_random, x2c_minZ); x34_curPoint = GetNextBestPt(x34_curPoint, workspace, x10_random, x2c_minZ);
AddPoint(x14_scale * workspace.m_vertexWorkspace[x34_curPoint]); const auto& vert = workspace.m_vertexWorkspace[x34_curPoint];
AddPoint(x14_scale * zeus::CVector3f{vert.x, vert.y, vert.z});
} }
x20_generateTimer = 0.f; x20_generateTimer = 0.f;
} }

View File

@ -6,7 +6,6 @@
#include "Runtime/CRandom16.hpp" #include "Runtime/CRandom16.hpp"
#include "Runtime/RetroTypes.hpp" #include "Runtime/RetroTypes.hpp"
#include "Runtime/rstl.hpp" #include "Runtime/rstl.hpp"
#include "Runtime/Graphics/CLineRenderer.hpp"
#include "Runtime/Graphics/CSkinnedModel.hpp" #include "Runtime/Graphics/CSkinnedModel.hpp"
#include <zeus/CVector3f.hpp> #include <zeus/CVector3f.hpp>
@ -24,7 +23,7 @@ class CRainSplashGenerator {
u8 x14_ = 3; u8 x14_ = 3;
u8 x15_length = 1; u8 x15_length = 1;
bool x16_active = true; // used to be one-bit bitfield bool x16_active = true; // used to be one-bit bitfield
CLineRenderer m_renderer;
explicit SSplashLine(); explicit SSplashLine();
void Update(float dt, CStateManager& mgr); void Update(float dt, CStateManager& mgr);
void Draw(float alpha, float dt, const zeus::CVector3f& pos); void Draw(float alpha, float dt, const zeus::CVector3f& pos);

View File

@ -40,7 +40,7 @@ void CSimpleShadow::Render(TLockedToken<CTexture>& tex) {
CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, false); CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, false);
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha, CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha,
ERglLogicOp::Clear); ERglLogicOp::Clear);
CGraphics::StreamBegin(GX_QUADS); CGraphics::StreamBegin(ERglPrimitive::Quads);
float radius = x34_radius * x30_scale; float radius = x34_radius * x30_scale;
CGraphics::StreamColor(zeus::CColor{1.f, x3c_heightAlpha * x38_userAlpha}); CGraphics::StreamColor(zeus::CColor{1.f, x3c_heightAlpha * x38_userAlpha});
CGraphics::StreamTexcoord(0.f, 0.f); CGraphics::StreamTexcoord(0.f, 0.f);

View File

@ -68,28 +68,28 @@ void CSkinnedModel::Draw(TConstVectorRef verts, TConstVectorRef norms, const CMo
void CSkinnedModel::Draw(const CModelFlags& drawFlags) { void CSkinnedModel::Draw(const CModelFlags& drawFlags) {
if (x35_disableWorkspaces) { if (x35_disableWorkspaces) {
const auto mtx = CGraphics::g_GXModelMatrix; const auto mtx = CGraphics::mModelMatrix;
CGraphics::SetModelMatrix(mtx * x10_skinRules->x0_bones.front().x20_xf); CGraphics::SetModelMatrix(mtx * x10_skinRules->x0_bones.front().x20_xf);
x4_model->Draw(drawFlags); x4_model->Draw(drawFlags);
CGraphics::SetModelMatrix(mtx); CGraphics::SetModelMatrix(mtx);
} else if (m_workspace.IsEmpty()) { } else if (m_workspace.IsEmpty()) {
x4_model->Draw(drawFlags); x4_model->Draw(drawFlags);
} else { } else {
x4_model->Draw(&m_workspace.m_vertexWorkspace, &m_workspace.m_normalWorkspace, drawFlags); x4_model->Draw(m_workspace.m_vertexWorkspace, m_workspace.m_normalWorkspace, drawFlags);
// PostDrawFunc(); // PostDrawFunc();
} }
} }
void CSkinnedModel::DoDrawCallback(const FCustomDraw& func) const { void CSkinnedModel::DoDrawCallback(const FCustomDraw& func) const {
if (x35_disableWorkspaces) { if (x35_disableWorkspaces) {
const auto mtx = CGraphics::g_GXModelMatrix; const auto mtx = CGraphics::mModelMatrix;
CGraphics::SetModelMatrix(mtx * x10_skinRules->x0_bones.front().x20_xf); CGraphics::SetModelMatrix(mtx * x10_skinRules->x0_bones.front().x20_xf);
func(x4_model->GetPositions(), x4_model->GetNormals()); func(x4_model->GetPositions(), x4_model->GetNormals());
CGraphics::SetModelMatrix(mtx); CGraphics::SetModelMatrix(mtx);
} else if (m_workspace.IsEmpty()) { } else if (m_workspace.IsEmpty()) {
func(x4_model->GetPositions(), x4_model->GetNormals()); func(x4_model->GetPositions(), x4_model->GetNormals());
} else { } else {
func(&m_workspace.m_vertexWorkspace, &m_workspace.m_normalWorkspace); func(m_workspace.m_vertexWorkspace, m_workspace.m_normalWorkspace);
// PostDrawFunc(); // PostDrawFunc();
} }
} }
@ -102,33 +102,37 @@ CSkinnedModelWithAvgNormals::CSkinnedModelWithAvgNormals(IObjectStore& store, CA
CAssetId layoutInfo) CAssetId layoutInfo)
: CSkinnedModel(store, model, skinRules, layoutInfo) { : CSkinnedModel(store, model, skinRules, layoutInfo) {
const auto vertexCount = GetSkinRules()->GetVertexCount(); const auto vertexCount = GetSkinRules()->GetVertexCount();
const auto& modelPositions = *GetModel()->GetPositions(); const auto modelPositions = GetModel()->GetPositions();
x40_averagedNormals.resize(vertexCount); x40_averagedNormals.resize(vertexCount);
std::vector<std::pair<zeus::CVector3f, std::list<u32>>> vertMap; std::vector<std::pair<zeus::CVector3f, std::list<u32>>> vertMap;
for (int vertIdx = 0; vertIdx < vertexCount; ++vertIdx) { for (int vertIdx = 0; vertIdx < vertexCount; ++vertIdx) {
const auto curPos = modelPositions[vertIdx]; const auto curPosV = modelPositions[vertIdx];
const zeus::CVector3f curPos{curPosV.x, curPosV.y, curPosV.z};
if (std::find_if(vertMap.cbegin(), vertMap.cend(), [=](const auto& pair) { return pair.first.isEqu(curPos); }) == if (std::find_if(vertMap.cbegin(), vertMap.cend(), [=](const auto& pair) { return pair.first.isEqu(curPos); }) ==
vertMap.cend()) { vertMap.cend()) {
auto& [_, list] = vertMap.emplace_back(curPos, std::list<u32>{}); auto& [_, list] = vertMap.emplace_back(curPos, std::list<u32>{});
for (int idx = vertIdx; idx < vertexCount; ++idx) { for (int idx = vertIdx; idx < vertexCount; ++idx) {
// Originally uses ==, but adjusted to match above // Originally uses ==, but adjusted to match above
if (modelPositions[idx].isEqu(curPos)) { const auto& mpv = modelPositions[idx];
const zeus::CVector3f mpz{mpv.x, mpv.y, mpv.z};
if (mpz.isEqu(curPos)) {
list.emplace_back(idx); list.emplace_back(idx);
} }
} }
} }
} }
const auto& modelNormals = *GetModel()->GetNormals(); const auto& modelNormals = GetModel()->GetNormals();
for (const auto& [_, idxs] : vertMap) { for (const auto& [_, idxs] : vertMap) {
zeus::CVector3f averagedNormal; zeus::CVector3f averagedNormal;
for (const auto idx : idxs) { for (const auto idx : idxs) {
averagedNormal += modelNormals[idx]; const auto& mnv = modelNormals[idx];
averagedNormal += zeus::CVector3f{mnv.x, mnv.y, mnv.z};
} }
averagedNormal.normalize(); averagedNormal.normalize();
for (const auto idx : idxs) { for (const auto idx : idxs) {
x40_averagedNormals[idx] = averagedNormal; x40_averagedNormals[idx] = {averagedNormal.x(), averagedNormal.y(), averagedNormal.z()};
} }
} }
} }

View File

@ -20,8 +20,8 @@ class IObjectStore;
// Originally vert + normal workspaces were allocated together, but here separated for ease of use // Originally vert + normal workspaces were allocated together, but here separated for ease of use
struct SSkinningWorkspace { struct SSkinningWorkspace {
std::vector<zeus::CVector3f> m_vertexWorkspace; std::vector<aurora::Vec3<float>> m_vertexWorkspace;
std::vector<zeus::CVector3f> m_normalWorkspace; std::vector<aurora::Vec3<float>> m_normalWorkspace;
SSkinningWorkspace(const CSkinRules& rules) { Reset(rules); } SSkinningWorkspace(const CSkinRules& rules) { Reset(rules); }
void Reset(const CSkinRules& rules) { void Reset(const CSkinRules& rules) {
@ -83,13 +83,13 @@ public:
}; };
class CSkinnedModelWithAvgNormals : public CSkinnedModel { class CSkinnedModelWithAvgNormals : public CSkinnedModel {
std::vector<zeus::CVector3f> x40_averagedNormals; // was rstl::auto_ptr<float[]> std::vector<aurora::Vec3<float>> x40_averagedNormals; // was rstl::auto_ptr<float[]>
public: public:
CSkinnedModelWithAvgNormals(IObjectStore& store, CAssetId model, CAssetId skinRules, CAssetId layoutInfo); CSkinnedModelWithAvgNormals(IObjectStore& store, CAssetId model, CAssetId skinRules, CAssetId layoutInfo);
~CSkinnedModelWithAvgNormals() override = default; ~CSkinnedModelWithAvgNormals() override = default;
TConstVectorRef GetAveragedNormals() const { return &x40_averagedNormals; } TConstVectorRef GetAveragedNormals() const { return x40_averagedNormals; }
}; };
} // namespace metaforce } // namespace metaforce

View File

@ -1,116 +0,0 @@
#pragma once
#include <memory>
#include <string>
#include "Runtime/CFactoryMgr.hpp"
#include "Runtime/GCNTypes.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
#include "Runtime/IObj.hpp"
#include "Runtime/Streams/IOStreams.hpp"
#include "Runtime/Graphics/CGraphicsPalette.hpp"
namespace metaforce {
class CVParamTransfer;
class CTextureInfo;
class CTexture {
class CDumpedBitmapDataReloader {
int x0_;
u32 x4_;
int x8_;
u32 xc_;
bool x10_;
int x14_;
void* x18_;
};
public:
enum class EClampMode {
Clamp,
Repeat,
Mirror,
};
enum class EFontType {
None = -1,
OneLayer = 0, /* Fill bit0 */
OneLayerOutline = 1, /* Fill bit0, Outline bit1 */
FourLayers = 2,
TwoLayersOutlines = 3, /* Fill bit0/2, Outline bit1/3 */
TwoLayers = 4, /* Fill bit0/1 and copied to bit2/3 */
TwoLayersOutlines2 = 8 /* Fill bit2/3, Outline bit0/1 */
};
private:
static u32 sCurrentFrameCount;
ETexelFormat x0_fmt;
u16 x4_w;
u16 x6_h;
u8 x8_mips;
u8 x9_bitsPerPixel;
u32 xc_memoryAllocated{};
std::unique_ptr<CGraphicsPalette> x10_graphicsPalette;
std::unique_ptr<CDumpedBitmapDataReloader> x14_bitmapReloader;
u32 x18_gxFormat{};
u32 x1c_gxCIFormat{};
/* GXTexObj x20_texObj */
EClampMode x40_clampMode = EClampMode::Repeat;
/* CARAMToken x44_aramToken */
u32 x64_frameAllocated{};
aurora::gfx::TextureHandle m_tex;
aurora::gfx::TextureHandle m_paletteTex;
std::unique_ptr<u8[]> m_otex;
EFontType m_ftype = EFontType::None;
const CTextureInfo* m_textureInfo{};
size_t ComputeMippedTexelCount() const;
size_t ComputeMippedBlockCountDXT1() const;
void BuildI4FromGCN(CInputStream& in, aurora::zstring_view label);
void BuildI8FromGCN(CInputStream& in, aurora::zstring_view label);
void BuildIA4FromGCN(CInputStream& in, aurora::zstring_view label);
void BuildIA8FromGCN(CInputStream& in, aurora::zstring_view label);
void BuildC4FromGCN(CInputStream& in, aurora::zstring_view label);
void BuildC8FromGCN(CInputStream& in, aurora::zstring_view label);
void BuildC14X2FromGCN(CInputStream& in, aurora::zstring_view label);
void BuildRGB565FromGCN(CInputStream& in, aurora::zstring_view label);
void BuildRGB5A3FromGCN(CInputStream& in, aurora::zstring_view label);
void BuildRGBA8FromGCN(CInputStream& in, aurora::zstring_view label);
void BuildDXT1FromGCN(CInputStream& in, aurora::zstring_view label);
void BuildRGBA8(const void* data, size_t length, aurora::zstring_view label);
void BuildC8(const void* data, size_t length, aurora::zstring_view label);
void BuildC8Font(const void* data, EFontType ftype, aurora::zstring_view label);
void BuildDXT1(const void* data, size_t length, aurora::zstring_view label);
void BuildDXT3(const void* data, size_t length, aurora::zstring_view label);
void InitBitmapBuffers(ETexelFormat fmt, s16 width, s16 height, s32 mips);
void InitTextureObjs();
public:
CTexture(ETexelFormat, s16, s16, s32);
CTexture(std::unique_ptr<u8[]>&& in, u32 length, bool otex, const CTextureInfo* inf, CAssetId id);
[[nodiscard]] ETexelFormat GetTexelFormat() const { return x0_fmt; }
[[nodiscard]] ETexelFormat GetMemoryCardTexelFormat() const {
return x0_fmt == ETexelFormat::C8PC ? ETexelFormat::C8 : ETexelFormat::RGB5A3;
}
[[nodiscard]] u16 GetWidth() const { return x4_w; }
[[nodiscard]] u16 GetHeight() const { return x6_h; }
[[nodiscard]] u8 GetNumMips() const { return x8_mips; }
[[nodiscard]] u8 GetBitsPerPixel() const { return x9_bitsPerPixel; }
void Load(int slot, EClampMode clamp) const;
[[nodiscard]] const aurora::gfx::TextureHandle& GetTexture() const { return m_tex; }
[[nodiscard]] const aurora::gfx::TextureHandle& GetPaletteTexture() const { return m_paletteTex; }
std::unique_ptr<u8[]> BuildMemoryCardTex(u32& sizeOut, ETexelFormat& fmtOut, std::unique_ptr<u8[]>& paletteOut) const;
const aurora::gfx::TextureHandle& GetFontTexture(EFontType tp);
[[nodiscard]] const CTextureInfo* GetTextureInfo() const { return m_textureInfo; }
static u32 TexelFormatBitsPerPixel(ETexelFormat fmt);
static void SetCurrentFrameCount(u32 frameCount) { sCurrentFrameCount = frameCount; }
};
CFactoryFnReturn FTextureFactory(const metaforce::SObjectTag& tag, std::unique_ptr<u8[]>&& in, u32 len,
const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef);
} // namespace metaforce

View File

@ -1,939 +0,0 @@
#include "Runtime/Graphics/CTexture.hpp"
#include <array>
#include "Runtime/CBasics.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/CTextureCache.hpp"
#include "Runtime/CToken.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
#include <logvisor/logvisor.hpp>
namespace metaforce {
namespace {
logvisor::Module Log("metaforce::CTextureBoo");
struct RGBA8 {
u8 r;
u8 g;
u8 b;
u8 a;
};
struct DXT1Block {
u16 color1;
u16 color2;
std::array<u8, 4> lines;
};
/* GX uses this upsampling technique to extract full 8-bit range */
constexpr u8 Convert3To8(u8 v) {
/* Swizzle bits: 00000123 -> 12312312 */
return static_cast<u8>((u32{v} << 5) | (u32{v} << 2) | (u32{v} >> 1));
}
constexpr u8 Convert4To8(u8 v) {
/* Swizzle bits: 00001234 -> 12341234 */
return static_cast<u8>((u32{v} << 4) | u32{v});
}
constexpr u8 Convert5To8(u8 v) {
/* Swizzle bits: 00012345 -> 12345123 */
return static_cast<u8>((u32{v} << 3) | (u32{v} >> 2));
}
constexpr u8 Convert6To8(u8 v) {
/* Swizzle bits: 00123456 -> 12345612 */
return static_cast<u8>((u32{v} << 2) | (u32{v} >> 4));
}
} // Anonymous namespace
size_t CTexture::ComputeMippedTexelCount() const {
size_t w = x4_w;
size_t h = x6_h;
size_t ret = w * h;
for (u32 i = x8_mips; i > 1; --i) {
if (w > 1)
w /= 2;
if (h > 1)
h /= 2;
ret += w * h;
}
return ret;
}
size_t CTexture::ComputeMippedBlockCountDXT1() const {
size_t w = x4_w / 4;
size_t h = x6_h / 4;
size_t ret = w * h;
for (u32 i = x8_mips; i > 1; --i) {
if (w > 1)
w /= 2;
if (h > 1)
h /= 2;
ret += w * h;
}
return ret;
}
void CTexture::BuildI4FromGCN(CInputStream& in, aurora::zstring_view label) {
const size_t texelCount = ComputeMippedTexelCount();
std::unique_ptr<RGBA8[]> buf(new RGBA8[texelCount]);
int w = x4_w;
int h = x6_h;
RGBA8* targetMip = buf.get();
for (u32 mip = 0; mip < x8_mips; ++mip) {
const int bwidth = (w + 7) / 8;
const int bheight = (h + 7) / 8;
for (int by = 0; by < bheight; ++by) {
const int baseY = by * 8;
for (int bx = 0; bx < bwidth; ++bx) {
const int baseX = bx * 8;
for (int y = 0; y < std::min(h, 8); ++y) {
RGBA8* target = targetMip + (baseY + y) * w + baseX;
std::array<u8, 4> source;
in.Get(source.data(), std::min(size_t(w) / 4, source.size()));
for (size_t x = 0; x < std::min(w, 8); ++x) {
target[x].r = Convert4To8(source[x / 2] >> ((x & 1) ? 0 : 4) & 0xf);
target[x].g = target[x].r;
target[x].b = target[x].r;
target[x].a = target[x].r;
}
}
}
}
targetMip += w * h;
if (w > 1) {
w /= 2;
}
if (h > 1) {
h /= 2;
}
}
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8,
{reinterpret_cast<const uint8_t*>(buf.get()), texelCount * 4}, label);
}
void CTexture::BuildI8FromGCN(CInputStream& in, aurora::zstring_view label) {
const size_t texelCount = ComputeMippedTexelCount();
std::unique_ptr<RGBA8[]> buf(new RGBA8[texelCount]);
int w = x4_w;
int h = x6_h;
RGBA8* targetMip = buf.get();
for (u32 mip = 0; mip < x8_mips; ++mip) {
const int bwidth = (w + 7) / 8;
const int bheight = (h + 3) / 4;
for (int by = 0; by < bheight; ++by) {
const int baseY = by * 4;
for (int bx = 0; bx < bwidth; ++bx) {
const int baseX = bx * 8;
for (int y = 0; y < 4; ++y) {
RGBA8* target = targetMip + (baseY + y) * w + baseX;
std::array<u8, 8> source;
in.Get(source.data(), source.size());
for (size_t x = 0; x < source.size(); ++x) {
target[x].r = source[x];
target[x].g = source[x];
target[x].b = source[x];
target[x].a = source[x];
}
}
}
}
targetMip += w * h;
if (w > 1) {
w /= 2;
}
if (h > 1) {
h /= 2;
}
}
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8,
{reinterpret_cast<const uint8_t*>(buf.get()), texelCount * 4}, label);
}
void CTexture::BuildIA4FromGCN(CInputStream& in, aurora::zstring_view label) {
const size_t texelCount = ComputeMippedTexelCount();
std::unique_ptr<RGBA8[]> buf(new RGBA8[texelCount]);
int w = x4_w;
int h = x6_h;
RGBA8* targetMip = buf.get();
for (u32 mip = 0; mip < x8_mips; ++mip) {
const int bwidth = (w + 7) / 8;
const int bheight = (h + 3) / 4;
for (int by = 0; by < bheight; ++by) {
const int baseY = by * 4;
for (int bx = 0; bx < bwidth; ++bx) {
const int baseX = bx * 8;
for (int y = 0; y < 4; ++y) {
RGBA8* target = targetMip + (baseY + y) * w + baseX;
std::array<u8, 8> source;
in.Get(source.data(), source.size());
for (size_t x = 0; x < source.size(); ++x) {
const u8 intensity = Convert4To8(source[x] >> 4 & 0xf);
target[x].r = intensity;
target[x].g = intensity;
target[x].b = intensity;
target[x].a = Convert4To8(source[x] & 0xf);
}
}
}
}
targetMip += w * h;
if (w > 1) {
w /= 2;
}
if (h > 1) {
h /= 2;
}
}
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8,
{reinterpret_cast<const uint8_t*>(buf.get()), texelCount * 4}, label);
}
void CTexture::BuildIA8FromGCN(CInputStream& in, aurora::zstring_view label) {
const size_t texelCount = ComputeMippedTexelCount();
std::unique_ptr<RGBA8[]> buf(new RGBA8[texelCount]);
int w = x4_w;
int h = x6_h;
RGBA8* targetMip = buf.get();
for (u32 mip = 0; mip < x8_mips; ++mip) {
const int bwidth = (w + 3) / 4;
const int bheight = (h + 3) / 4;
for (int by = 0; by < bheight; ++by) {
const int baseY = by * 4;
for (int bx = 0; bx < bwidth; ++bx) {
const int baseX = bx * 4;
for (int y = 0; y < 4; ++y) {
RGBA8* target = targetMip + (baseY + y) * w + baseX;
std::array<u16, 4> source;
in.Get(reinterpret_cast<u8*>(source.data()), sizeof(source));
for (size_t x = 0; x < source.size(); ++x) {
const u8 intensity = source[x] >> 8;
target[x].r = intensity;
target[x].g = intensity;
target[x].b = intensity;
target[x].a = source[x] & 0xff;
}
}
}
}
targetMip += w * h;
if (w > 1) {
w /= 2;
}
if (h > 1) {
h /= 2;
}
}
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8,
{reinterpret_cast<const uint8_t*>(buf.get()), texelCount * 4}, label);
}
static std::vector<RGBA8> DecodePalette(int numEntries, CInputStream& in) {
std::vector<RGBA8> ret;
ret.reserve(numEntries);
enum class EPaletteType { IA8, RGB565, RGB5A3 };
EPaletteType format = EPaletteType(in.ReadLong());
in.ReadLong();
switch (format) {
case EPaletteType::IA8: {
for (int e = 0; e < numEntries; ++e) {
u8 intensity = in.ReadUint8();
u8 alpha = in.ReadUint8();
ret.push_back({intensity, intensity, intensity, alpha});
}
break;
}
case EPaletteType::RGB565: {
for (int e = 0; e < numEntries; ++e) {
u16 texel = in.ReadShort();
ret.push_back({Convert5To8(texel >> 11 & 0x1f), Convert6To8(texel >> 5 & 0x3f), Convert5To8(texel & 0x1f), 0xff});
}
break;
}
case EPaletteType::RGB5A3: {
for (int e = 0; e < numEntries; ++e) {
u16 texel = in.ReadShort();
if (texel & 0x8000) {
ret.push_back(
{Convert5To8(texel >> 10 & 0x1f), Convert5To8(texel >> 5 & 0x1f), Convert5To8(texel & 0x1f), 0xff});
} else {
ret.push_back({Convert4To8(texel >> 8 & 0xf), Convert4To8(texel >> 4 & 0xf), Convert4To8(texel & 0xf),
Convert3To8(texel >> 12 & 0x7)});
}
}
break;
}
}
return ret;
}
void CTexture::BuildC4FromGCN(CInputStream& in, aurora::zstring_view label) {
const size_t texelCount = ComputeMippedTexelCount();
std::unique_ptr<RGBA8[]> buf(new RGBA8[texelCount]);
std::vector<RGBA8> palette = DecodePalette(16, in);
int w = x4_w;
int h = x6_h;
RGBA8* targetMip = buf.get();
for (u32 mip = 0; mip < x8_mips; ++mip) {
const int bwidth = (w + 7) / 8;
const int bheight = (h + 7) / 8;
for (int by = 0; by < bheight; ++by) {
const int baseY = by * 8;
for (int bx = 0; bx < bwidth; ++bx) {
const int baseX = bx * 8;
for (int y = 0; y < 8; ++y) {
RGBA8* target = targetMip + (baseY + y) * w + baseX;
std::array<u8, 4> source;
in.Get(source.data(), source.size());
for (size_t x = 0; x < 8; ++x) {
target[x] = palette[source[x / 2] >> ((x & 1) ? 0 : 4) & 0xf];
}
}
}
}
targetMip += w * h;
if (w > 1) {
w /= 2;
}
if (h > 1) {
h /= 2;
}
}
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8,
{reinterpret_cast<const uint8_t*>(buf.get()), texelCount * 4}, label);
}
void CTexture::BuildC8FromGCN(CInputStream& in, aurora::zstring_view label) {
const size_t texelCount = ComputeMippedTexelCount();
std::unique_ptr<RGBA8[]> buf(new RGBA8[texelCount]);
std::vector<RGBA8> palette = DecodePalette(256, in);
int w = x4_w;
int h = x6_h;
RGBA8* targetMip = buf.get();
for (u32 mip = 0; mip < x8_mips; ++mip) {
const int bwidth = (w + 7) / 8;
const int bheight = (h + 3) / 4;
for (int by = 0; by < bheight; ++by) {
const int baseY = by * 4;
for (int bx = 0; bx < bwidth; ++bx) {
const int baseX = bx * 8;
for (int y = 0; y < 4; ++y) {
RGBA8* target = targetMip + (baseY + y) * w + baseX;
std::array<u8, 8> source;
in.Get(source.data(), source.size());
for (size_t x = 0; x < source.size(); ++x) {
target[x] = palette[source[x]];
}
}
}
}
targetMip += w * h;
if (w > 1) {
w /= 2;
}
if (h > 1) {
h /= 2;
}
}
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8,
{reinterpret_cast<const uint8_t*>(buf.get()), texelCount * 4}, label);
}
void CTexture::BuildC14X2FromGCN(CInputStream& in, aurora::zstring_view label) {
spdlog::fatal("C14X2 not implemented");
}
void CTexture::BuildRGB565FromGCN(CInputStream& in, aurora::zstring_view label) {
const size_t texelCount = ComputeMippedTexelCount();
std::unique_ptr<RGBA8[]> buf(new RGBA8[texelCount]);
int w = x4_w;
int h = x6_h;
RGBA8* targetMip = buf.get();
for (u32 mip = 0; mip < x8_mips; ++mip) {
const int bwidth = (w + 3) / 4;
const int bheight = (h + 3) / 4;
for (int by = 0; by < bheight; ++by) {
const int baseY = by * 4;
for (int bx = 0; bx < bwidth; ++bx) {
const int baseX = bx * 4;
for (int y = 0; y < 4; ++y) {
RGBA8* target = targetMip + (baseY + y) * w + baseX;
for (size_t x = 0; x < 4; ++x) {
const u16 texel = in.ReadShort();
target[x].r = Convert5To8(texel >> 11 & 0x1f);
target[x].g = Convert6To8(texel >> 5 & 0x3f);
target[x].b = Convert5To8(texel & 0x1f);
target[x].a = 0xff;
}
}
}
}
targetMip += w * h;
if (w > 1) {
w /= 2;
}
if (h > 1) {
h /= 2;
}
}
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8,
{reinterpret_cast<const uint8_t*>(buf.get()), texelCount * 4}, label);
}
void CTexture::BuildRGB5A3FromGCN(CInputStream& in, aurora::zstring_view label) {
size_t texelCount = ComputeMippedTexelCount();
std::unique_ptr<RGBA8[]> buf(new RGBA8[texelCount]);
int w = x4_w;
int h = x6_h;
RGBA8* targetMip = buf.get();
for (u32 mip = 0; mip < x8_mips; ++mip) {
const int bwidth = (w + 3) / 4;
const int bheight = (h + 3) / 4;
for (int by = 0; by < bheight; ++by) {
const int baseY = by * 4;
for (int bx = 0; bx < bwidth; ++bx) {
const int baseX = bx * 4;
for (int y = 0; y < 4; ++y) {
RGBA8* target = targetMip + (baseY + y) * w + baseX;
for (size_t x = 0; x < 4; ++x) {
const u16 texel = in.ReadShort();
if ((texel & 0x8000) != 0) {
target[x].r = Convert5To8(texel >> 10 & 0x1f);
target[x].g = Convert5To8(texel >> 5 & 0x1f);
target[x].b = Convert5To8(texel & 0x1f);
target[x].a = 0xff;
} else {
target[x].r = Convert4To8(texel >> 8 & 0xf);
target[x].g = Convert4To8(texel >> 4 & 0xf);
target[x].b = Convert4To8(texel & 0xf);
target[x].a = Convert3To8(texel >> 12 & 0x7);
}
}
}
}
}
targetMip += w * h;
if (w > 1) {
w /= 2;
}
if (h > 1) {
h /= 2;
}
}
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8,
{reinterpret_cast<const uint8_t*>(buf.get()), texelCount * 4}, label);
}
void CTexture::BuildRGBA8FromGCN(CInputStream& in, aurora::zstring_view label) {
const size_t texelCount = ComputeMippedTexelCount();
std::unique_ptr<RGBA8[]> buf(new RGBA8[texelCount]);
int w = x4_w;
int h = x6_h;
RGBA8* targetMip = buf.get();
for (u32 mip = 0; mip < x8_mips; ++mip) {
const int bwidth = (w + 3) / 4;
const int bheight = (h + 3) / 4;
for (int by = 0; by < bheight; ++by) {
const int baseY = by * 4;
for (int bx = 0; bx < bwidth; ++bx) {
const int baseX = bx * 4;
for (int c = 0; c < 2; ++c) {
for (int y = 0; y < 4; ++y) {
RGBA8* target = targetMip + (baseY + y) * w + baseX;
std::array<u8, 8> source;
in.Get(source.data(), source.size());
for (size_t x = 0; x < 4; ++x) {
if (c != 0) {
target[x].g = source[x * 2];
target[x].b = source[x * 2 + 1];
} else {
target[x].a = source[x * 2];
target[x].r = source[x * 2 + 1];
}
}
}
}
}
}
targetMip += w * h;
if (w > 1) {
w /= 2;
}
if (h > 1) {
h /= 2;
}
}
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8,
{reinterpret_cast<const uint8_t*>(buf.get()), texelCount * 4}, label);
}
void CTexture::BuildDXT1FromGCN(CInputStream& in, aurora::zstring_view label) {
const size_t blockCount = ComputeMippedBlockCountDXT1();
std::unique_ptr<DXT1Block[]> buf(new DXT1Block[blockCount]);
int w = x4_w / 4;
int h = x6_h / 4;
DXT1Block* targetMip = buf.get();
for (u32 mip = 0; mip < x8_mips; ++mip) {
const int bwidth = (w + 1) / 2;
const int bheight = (h + 1) / 2;
for (int by = 0; by < bheight; ++by) {
const int baseY = by * 2;
for (int bx = 0; bx < bwidth; ++bx) {
const int baseX = bx * 2;
for (int y = 0; y < 2; ++y) {
DXT1Block* target = targetMip + (baseY + y) * w + baseX;
std::array<DXT1Block, 2> source;
in.Get(reinterpret_cast<u8*>(source.data()), sizeof(source));
for (size_t x = 0; x < source.size(); ++x) {
target[x].color1 = CBasics::SwapBytes(source[x].color1);
target[x].color2 = CBasics::SwapBytes(source[x].color2);
for (size_t i = 0; i < 4; ++i) {
std::array<u8, 4> ind;
const u8 packed = source[x].lines[i];
ind[3] = packed & 0x3;
ind[2] = (packed >> 2) & 0x3;
ind[1] = (packed >> 4) & 0x3;
ind[0] = (packed >> 6) & 0x3;
target[x].lines[i] = ind[0] | (ind[1] << 2) | (ind[2] << 4) | (ind[3] << 6);
}
}
}
}
}
targetMip += w * h;
if (w > 1) {
w /= 2;
}
if (h > 1) {
h /= 2;
}
}
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::DXT1,
{reinterpret_cast<const uint8_t*>(buf.get()), blockCount * 8}, label);
}
void CTexture::BuildRGBA8(const void* data, size_t length, aurora::zstring_view label) {
size_t texelCount = ComputeMippedTexelCount();
size_t expectedSize = texelCount * 4;
if (expectedSize > length)
spdlog::fatal("insufficient TXTR length ({}/{})", length, expectedSize);
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8,
{reinterpret_cast<const uint8_t*>(data), expectedSize}, label);
}
void CTexture::BuildC8(const void* data, size_t length, aurora::zstring_view label) {
size_t texelCount = ComputeMippedTexelCount();
if (texelCount > length)
spdlog::fatal("insufficient TXTR length ({}/{})", length, texelCount);
uint32_t nentries = CBasics::SwapBytes(*reinterpret_cast<const uint32_t*>(data));
const u8* paletteTexels = reinterpret_cast<const u8*>(data) + 4;
const u8* texels = reinterpret_cast<const u8*>(data) + 4 + nentries * 4;
m_paletteTex = aurora::gfx::new_static_texture_2d(nentries, 1, 1, aurora::gfx::TextureFormat::RGBA8,
{paletteTexels, nentries * 4}, label);
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::R8, {texels, texelCount},
label);
}
void CTexture::BuildC8Font(const void* data, EFontType ftype, aurora::zstring_view label) {
size_t texelCount = ComputeMippedTexelCount();
size_t layerCount = 1;
switch (ftype) {
case EFontType::OneLayer:
case EFontType::OneLayerOutline:
layerCount = 1;
break;
case EFontType::FourLayers:
layerCount = 4;
break;
case EFontType::TwoLayersOutlines:
case EFontType::TwoLayers:
case EFontType::TwoLayersOutlines2:
layerCount = 2;
break;
default:
break;
}
const uint32_t nentries = CBasics::SwapBytes(*reinterpret_cast<const uint32_t*>(data));
const u8* texels = reinterpret_cast<const u8*>(data) + 4 + nentries * 4;
auto buf = std::make_unique<RGBA8[]>(texelCount * layerCount);
size_t w = x4_w;
size_t h = x6_h;
RGBA8* bufCur = buf.get();
for (size_t i = 0; i < x8_mips; ++i) {
size_t tCount = w * h;
RGBA8* l0 = bufCur;
RGBA8* l1 = bufCur + tCount;
RGBA8* l2 = bufCur + tCount * 2;
RGBA8* l3 = bufCur + tCount * 3;
for (size_t j = 0; j < tCount; ++j) {
u8 texel = texels[j];
switch (ftype) {
case EFontType::OneLayer:
l0[j].r = (texel & 0x1) ? 0xff : 0;
l0[j].a = 0xff;
break;
case EFontType::OneLayerOutline:
l0[j].r = (texel & 0x1) ? 0xff : 0;
l0[j].g = (texel & 0x2) ? 0xff : 0;
l0[j].a = 0xff;
break;
case EFontType::FourLayers:
l0[j].r = (texel & 0x1) ? 0xff : 0;
l0[j].a = 0xff;
l1[j].r = (texel & 0x2) ? 0xff : 0;
l1[j].a = 0xff;
l2[j].r = (texel & 0x4) ? 0xff : 0;
l2[j].a = 0xff;
l3[j].r = (texel & 0x8) ? 0xff : 0;
l3[j].a = 0xff;
break;
case EFontType::TwoLayersOutlines:
l0[j].r = (texel & 0x1) ? 0xff : 0;
l0[j].g = (texel & 0x2) ? 0xff : 0;
l0[j].a = 0xff;
l1[j].r = (texel & 0x4) ? 0xff : 0;
l1[j].g = (texel & 0x8) ? 0xff : 0;
l1[j].a = 0xff;
break;
case EFontType::TwoLayers:
l0[j].r = (texel & 0x1) ? 0xff : 0;
l0[j].a = 0xff;
l1[j].r = (texel & 0x2) ? 0xff : 0;
l1[j].a = 0xff;
break;
case EFontType::TwoLayersOutlines2:
l0[j].r = (texel & 0x4) ? 0xff : 0;
l0[j].g = (texel & 0x1) ? 0xff : 0;
l0[j].a = 0xff;
l1[j].r = (texel & 0x8) ? 0xff : 0;
l1[j].g = (texel & 0x2) ? 0xff : 0;
l1[j].a = 0xff;
break;
default:
break;
}
}
texels += tCount;
bufCur += tCount * layerCount;
if (w > 1)
w /= 2;
if (h > 1)
h /= 2;
}
// TODO array tex
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
// m_booTex = ctx.newStaticArrayTexture(x4_w, x6_h, layerCount, x8_mips, boo::TextureFormat::RGBA8,
// boo::TextureClampMode::Repeat, buf.get(), texelCount * layerCount * 4)
// .get();
// return true;
// } BooTrace);
}
void CTexture::BuildDXT1(const void* data, size_t length, aurora::zstring_view label) {
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::DXT1,
{reinterpret_cast<const uint8_t*>(data), length}, label);
}
void CTexture::BuildDXT3(const void* data, size_t length, aurora::zstring_view label) {
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::DXT3,
{reinterpret_cast<const uint8_t*>(data), length}, label);
}
static std::string_view TextureFormatString(ETexelFormat format) {
switch (format) {
case ETexelFormat::I4:
return "I4"sv;
case ETexelFormat::I8:
return "I8"sv;
case ETexelFormat::IA4:
return "IA4"sv;
case ETexelFormat::IA8:
return "IA8"sv;
case ETexelFormat::C4:
return "C4"sv;
case ETexelFormat::C8:
return "C8"sv;
case ETexelFormat::C14X2:
return "C14X2"sv;
case ETexelFormat::RGB565:
return "RGB565"sv;
case ETexelFormat::RGB5A3:
return "RGB5A3"sv;
case ETexelFormat::RGBA8:
return "RGBA8"sv;
case ETexelFormat::CMPR:
return "CMPR"sv;
case ETexelFormat::RGBA8PC:
return "RGBA8PC"sv;
case ETexelFormat::C8PC:
return "C8PC"sv;
case ETexelFormat::CMPRPC:
return "CMPRPC"sv;
case ETexelFormat::CMPRPCA:
return "CMPRPCA"sv;
default:
return "Invalid"sv;
}
}
u32 CTexture::TexelFormatBitsPerPixel(ETexelFormat fmt) {
switch (fmt) {
case ETexelFormat::I4:
case ETexelFormat::C4:
case ETexelFormat::CMPR:
return 4;
case ETexelFormat::I8:
case ETexelFormat::IA4:
case ETexelFormat::C8:
return 8;
case ETexelFormat::IA8:
case ETexelFormat::C14X2:
case ETexelFormat::RGB565:
case ETexelFormat::RGB5A3:
return 16;
case ETexelFormat::RGBA8:
return 32;
default:
return 0;
}
}
u32 CTexture::sCurrentFrameCount = 0;
void CTexture::InitBitmapBuffers(ETexelFormat fmt, s16 width, s16 height, s32 mips) {}
void CTexture::InitTextureObjs() {}
CTexture::CTexture(ETexelFormat fmt, s16 w, s16 h, s32 mips)
: x0_fmt(fmt)
, x4_w(w)
, x6_h(h)
, x8_mips(mips)
, x9_bitsPerPixel(TexelFormatBitsPerPixel(fmt))
, x64_frameAllocated(sCurrentFrameCount) {
InitBitmapBuffers(fmt, w, h, mips);
InitTextureObjs();
}
CTexture::CTexture(std::unique_ptr<u8[]>&& in, u32 length, bool otex, const CTextureInfo* inf, CAssetId id) {
std::unique_ptr<u8[]> owned = std::move(in);
CMemoryInStream r(owned.get(), length, CMemoryInStream::EOwnerShip::NotOwned);
x0_fmt = ETexelFormat(r.ReadLong());
x4_w = r.ReadShort();
x6_h = r.ReadShort();
x8_mips = r.ReadLong();
x9_bitsPerPixel = TexelFormatBitsPerPixel(x0_fmt);
m_textureInfo = inf;
auto label = fmt::format("TXTR {:08X} ({})", id.Value(), TextureFormatString(x0_fmt));
switch (x0_fmt) {
case ETexelFormat::I4:
BuildI4FromGCN(r, label);
break;
case ETexelFormat::I8:
BuildI8FromGCN(r, label);
break;
case ETexelFormat::IA4:
BuildIA4FromGCN(r, label);
break;
case ETexelFormat::IA8:
BuildIA8FromGCN(r, label);
break;
case ETexelFormat::C4:
BuildC4FromGCN(r, label);
break;
case ETexelFormat::C8:
BuildC8FromGCN(r, label);
break;
case ETexelFormat::C14X2:
BuildC14X2FromGCN(r, label);
break;
case ETexelFormat::RGB565:
BuildRGB565FromGCN(r, label);
break;
case ETexelFormat::RGB5A3:
BuildRGB5A3FromGCN(r, label);
break;
case ETexelFormat::RGBA8:
BuildRGBA8FromGCN(r, label);
break;
case ETexelFormat::CMPR:
if (aurora::gfx::get_dxt_compression_supported()) {
BuildDXT1FromGCN(r, label);
} else {
spdlog::error("BC/DXT1 compression is not supported on your GPU, unable to load {}", label);
x0_fmt = ETexelFormat::RGBA8PC;
x8_mips = 1;
std::unique_ptr<u8[]> data = std::make_unique<u8[]>(x4_w * x6_h * 4);
/* Build a fake texture to use */
for (u32 i = 0; i < (x4_w * x6_h) * 4; i += 4) {
data[i + 0] = 0xFF;
data[i + 1] = 0x00;
data[i + 2] = 0xFF;
data[i + 3] = 0xFF;
}
m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8,
{reinterpret_cast<const uint8_t*>(data.get()), (x4_w * x6_h * 4ul)},
label);
}
break;
case ETexelFormat::RGBA8PC:
BuildRGBA8(owned.get() + 12, length - 12, label);
break;
case ETexelFormat::C8PC:
BuildC8(owned.get() + 12, length - 12, label);
otex = true;
break;
case ETexelFormat::CMPRPC:
BuildDXT1(owned.get() + 12, length - 12, label);
break;
case ETexelFormat::CMPRPCA:
BuildDXT3(owned.get() + 12, length - 12, label);
break;
default:
spdlog::fatal("invalid texture type {} for boo", int(x0_fmt));
}
if (otex)
m_otex = std::move(owned);
}
void CTexture::Load(int slot, EClampMode clamp) const {}
std::unique_ptr<u8[]> CTexture::BuildMemoryCardTex(u32& sizeOut, ETexelFormat& fmtOut,
std::unique_ptr<u8[]>& paletteOut) const {
if (!m_otex)
spdlog::fatal("MemoryCard TXTR not loaded with 'otex'");
size_t texelCount = x4_w * x6_h;
std::unique_ptr<u8[]> ret;
if (x0_fmt == ETexelFormat::RGBA8PC) {
sizeOut = texelCount * 2;
fmtOut = ETexelFormat::RGB5A3;
ret.reset(new u8[sizeOut]);
u16* texel = reinterpret_cast<u16*>(ret.get());
int w = x4_w;
int h = x6_h;
const RGBA8* sourceMip = reinterpret_cast<const RGBA8*>(m_otex.get() + 12);
int bwidth = (w + 3) / 4;
int bheight = (h + 3) / 4;
for (int by = 0; by < bheight; ++by) {
int baseY = by * 4;
for (int bx = 0; bx < bwidth; ++bx) {
int baseX = bx * 4;
for (int y = 0; y < 4; ++y) {
const RGBA8* source = sourceMip + (x6_h - (baseY + y) - 1) * w + baseX;
for (int x = 0; x < 4; ++x) {
if (source[x].a == 0xff) {
*texel++ =
CBasics::SwapBytes(u16((source[x].r >> 3 << 10) | (source[x].g >> 3 << 5) | (source[x].b >> 3)));
} else {
*texel++ = CBasics::SwapBytes(u16((source[x].r >> 4 << 8) | (source[x].g >> 4 << 4) | (source[x].b >> 4) |
(source[x].a >> 5 << 12)));
}
}
}
}
}
} else if (x0_fmt == ETexelFormat::C8PC) {
sizeOut = texelCount;
fmtOut = ETexelFormat::C8;
ret.reset(new u8[sizeOut]);
paletteOut.reset(new u8[512]);
u8* texel = ret.get();
u16* paletteColors = reinterpret_cast<u16*>(paletteOut.get());
int w = x4_w;
int h = x6_h;
const u8* data = m_otex.get() + 12;
u32 nentries = CBasics::SwapBytes(*reinterpret_cast<const u32*>(data));
const RGBA8* paletteTexels = reinterpret_cast<const RGBA8*>(data + 4);
const u8* sourceMip = data + 4 + nentries * 4;
for (u32 i = 0; i < 256; ++i) {
u16& color = paletteColors[i];
if (i >= nentries) {
color = 0;
} else {
const RGBA8& colorIn = paletteTexels[i];
if (colorIn.a == 0xff) {
color = CBasics::SwapBytes(u16((colorIn.r >> 3 << 10) | (colorIn.g >> 3 << 5) | (colorIn.b >> 3) | 0x8000));
} else {
color = CBasics::SwapBytes(
u16((colorIn.r >> 4 << 8) | (colorIn.g >> 4 << 4) | (colorIn.b >> 4) | (colorIn.a >> 5 << 12)));
}
}
}
int bwidth = (w + 7) / 8;
int bheight = (h + 3) / 4;
for (int by = 0; by < bheight; ++by) {
int baseY = by * 4;
for (int bx = 0; bx < bwidth; ++bx) {
int baseX = bx * 8;
for (int y = 0; y < 4; ++y) {
const u8* source = sourceMip + (x6_h - (baseY + y) - 1) * w + baseX;
for (int x = 0; x < 8; ++x)
*texel++ = source[x];
}
}
}
} else
spdlog::fatal("MemoryCard texture may only use RGBA8PC or C8PC format");
return ret;
}
const aurora::gfx::TextureHandle& CTexture::GetFontTexture(EFontType tp) {
if (m_ftype != tp && x0_fmt == ETexelFormat::C8PC) {
m_ftype = tp;
BuildC8Font(m_otex.get() + 12, m_ftype, "Font (TODO)");
}
return m_tex;
}
CFactoryFnReturn FTextureFactory(const metaforce::SObjectTag& tag, std::unique_ptr<u8[]>&& in, u32 len,
const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef) {
u32 u32Owned = vparms.GetOwnedObj<u32>();
const CTextureInfo* inf = nullptr;
if (g_TextureCache)
inf = g_TextureCache->GetTextureInfo(tag.id);
return TToken<CTexture>::GetIObjObjectFor(
std::make_unique<CTexture>(std::move(in), len, u32Owned == SBIG('OTEX'), inf, tag.id));
}
} // namespace metaforce

View File

@ -13,22 +13,28 @@ void CVertexMorphEffect::MorphVertices(SSkinningWorkspace& workspace, TConstVect
TLockedToken<CSkinRules>& skinRules, const CPoseAsTransforms& pose, TLockedToken<CSkinRules>& skinRules, const CPoseAsTransforms& pose,
u32 vertexCount) { u32 vertexCount) {
if (x28_indices.empty()) { if (x28_indices.empty()) {
std::vector<zeus::CVector3f> normalsOut; std::vector<aurora::Vec3<float>> normalsOut;
normalsOut.reserve(vertexCount); normalsOut.reserve(vertexCount);
skinRules->BuildNormals(averagedNormals, &normalsOut); skinRules->BuildNormals(averagedNormals, &normalsOut);
for (int i = 0; i < vertexCount; ++i) { for (int i = 0; i < vertexCount; ++i) {
float dist = normalsOut[i].dot(x0_dir); const auto& nov = normalsOut[i];
const zeus::CVector3f noz{nov.x, nov.y, nov.z};
float dist = noz.dot(x0_dir);
if (dist > 0.5f) { if (dist > 0.5f) {
x28_indices.emplace_back(i); x28_indices.emplace_back(i);
const auto vert = workspace.m_vertexWorkspace[i]; const auto vert = workspace.m_vertexWorkspace[i];
const auto length = vert.x() + vert.y() + vert.z(); const auto length = vert.x + vert.y + vert.z;
x38_floats.emplace_back((length - std::trunc(length)) * (dist - 0.5f)); x38_floats.emplace_back((length - std::trunc(length)) * (dist - 0.5f));
} }
} }
} }
for (int i = 0; i < x28_indices.size(); ++i) { for (int i = 0; i < x28_indices.size(); ++i) {
const auto scale = x1c_elapsed / x18_duration; const auto scale = x1c_elapsed / x18_duration;
workspace.m_vertexWorkspace[x28_indices[i]] += scale * x20_diagExtent * x38_floats[i] * x0_dir; auto& out = workspace.m_vertexWorkspace[x28_indices[i]];
const auto add = scale * x20_diagExtent * x38_floats[i] * x0_dir;
out.x += add.x();
out.y += add.y();
out.z += add.z();
} }
} }

View File

@ -89,7 +89,7 @@ public:
virtual void EndPrimitive() = 0; virtual void EndPrimitive() = 0;
virtual void SetAmbientColor(const zeus::CColor& color) = 0; virtual void SetAmbientColor(const zeus::CColor& color) = 0;
virtual void DrawString(const char* string, int, int) = 0; virtual void DrawString(const char* string, int, int) = 0;
virtual u32 GetFPS() = 0; virtual float GetFPS() = 0;
virtual void CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) = 0; virtual void CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) = 0;
virtual void DrawSpaceWarp(const zeus::CVector3f& pt, float strength) = 0; virtual void DrawSpaceWarp(const zeus::CVector3f& pt, float strength) = 0;
virtual void DrawThermalModel(CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol, virtual void DrawThermalModel(CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol,

View File

@ -1,79 +0,0 @@
#include "Runtime/Graphics/Shaders/CAABoxShader.hpp"
#include <array>
#include "Runtime/Graphics/CGraphics.hpp"
//#include <hecl/Pipeline.hpp>
#include <zeus/CAABox.hpp>
namespace metaforce {
//static boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_zOnlyPipeline;
void CAABoxShader::Initialize() {
// s_Pipeline = hecl::conv->convert(Shader_CAABoxShader{});
// s_zOnlyPipeline = hecl::conv->convert(Shader_CAABoxShaderZOnly{});
}
void CAABoxShader::Shutdown() {
// s_Pipeline.reset();
// s_zOnlyPipeline.reset();
}
CAABoxShader::CAABoxShader(bool zOnly) {
// CGraphics::CommitResources([this, zOnly](boo::IGraphicsDataFactory::Context& ctx) {
// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(zeus::CVector3f), 34);
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
// m_dataBind =
// ctx.newShaderDataBinding(zOnly ? s_zOnlyPipeline : s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(),
// bufs.data(), stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr);
// return true;
// } BooTrace);
}
void CAABoxShader::setAABB(const zeus::CAABox& aabb) {
const std::array<zeus::CVector3f, 34> vboData{{
{aabb.max.x(), aabb.max.y(), aabb.min.z()}, {aabb.max.x(), aabb.min.y(), aabb.min.z()},
{aabb.max.x(), aabb.max.y(), aabb.max.z()}, {aabb.max.x(), aabb.min.y(), aabb.max.z()},
{aabb.max.x(), aabb.min.y(), aabb.max.z()},
{aabb.min.x(), aabb.max.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.min.z()},
{aabb.max.x(), aabb.max.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.max.z()},
{aabb.max.x(), aabb.max.y(), aabb.max.z()}, {aabb.max.x(), aabb.max.y(), aabb.max.z()},
{aabb.min.x(), aabb.max.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.min.z()},
{aabb.min.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.max.z()},
{aabb.min.x(), aabb.min.y(), aabb.max.z()}, {aabb.min.x(), aabb.min.y(), aabb.max.z()},
{aabb.min.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.min.y(), aabb.min.z()},
{aabb.max.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.min.y(), aabb.max.z()},
{aabb.max.x(), aabb.min.y(), aabb.max.z()}, {aabb.max.x(), aabb.min.y(), aabb.max.z()},
{aabb.min.x(), aabb.min.y(), aabb.max.z()}, {aabb.min.x(), aabb.min.y(), aabb.max.z()},
{aabb.max.x(), aabb.min.y(), aabb.max.z()}, {aabb.min.x(), aabb.max.y(), aabb.max.z()},
{aabb.max.x(), aabb.max.y(), aabb.max.z()}, {aabb.max.x(), aabb.max.y(), aabb.max.z()},
{aabb.min.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.min.y(), aabb.min.z()},
{aabb.max.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.min.z()},
{aabb.max.x(), aabb.max.y(), aabb.min.z()},
}};
// m_vbo->load(vboData.data(), sizeof(vboData));
}
void CAABoxShader::draw(const zeus::CColor& color) {
SCOPED_GRAPHICS_DEBUG_GROUP("CAABoxShader::draw", zeus::skMagenta);
m_uniform.m_xf = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f();
m_uniform.m_color = color;
// m_uniBuf->load(&m_uniform, sizeof(Uniform));
//
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, 34);
}
} // namespace metaforce

View File

@ -1,32 +0,0 @@
#pragma once
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <zeus/CColor.hpp>
#include <zeus/CMatrix4f.hpp>
namespace zeus {
class CAABox;
}
namespace metaforce {
class CAABoxShader {
struct Uniform {
zeus::CMatrix4f m_xf;
zeus::CColor m_color;
};
// boo::ObjToken<boo::IGraphicsBufferD> m_vbo;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
Uniform m_uniform;
public:
static void Initialize();
static void Shutdown();
explicit CAABoxShader(bool zOnly = false);
void setAABB(const zeus::CAABox& aabb);
void draw(const zeus::CColor& color);
};
} // namespace metaforce

View File

@ -1,88 +0,0 @@
#include "Runtime/Graphics/Shaders/CCameraBlurFilter.hpp"
#include <algorithm>
#include <array>
#include <cmath>
#include "Runtime/Graphics/CGraphics.hpp"
//#include <hecl/Pipeline.hpp>
#include <zeus/CVector2f.hpp>
namespace metaforce {
namespace {
struct Vert {
zeus::CVector2f m_pos;
zeus::CVector2f m_uv;
};
//boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
} // Anonymous namespace
void CCameraBlurFilter::Initialize() {
// s_Pipeline = hecl::conv->convert(Shader_CCameraBlurFilter{});
}
void CCameraBlurFilter::Shutdown() {
// s_Pipeline.reset();
}
CCameraBlurFilter::CCameraBlurFilter() {
// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) {
// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4);
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
// constexpr std::array stages{boo::PipelineStage::Vertex};
// const std::array<boo::ObjToken<boo::ITexture>, 1> texs{CGraphics::g_SpareTexture.get()};
// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr);
// return true;
// } BooTrace);
}
void CCameraBlurFilter::draw(float amount, bool clearDepth) {
if (amount <= 0.f) {
return;
}
SCOPED_GRAPHICS_DEBUG_GROUP("CCameraBlurFilter::draw", zeus::skMagenta);
const SClipScreenRect clipRect(CGraphics::g_Viewport);
// CGraphics::ResolveSpareTexture(clipRect, 0, clearDepth);
const float aspect = float(CGraphics::g_CroppedViewport.xc_width) / float(CGraphics::g_CroppedViewport.x10_height);
const float xFac = float(CGraphics::GetCroppedViewportWidth()) / float(CGraphics::GetViewportWidth());
const float yFac = float(CGraphics::GetCroppedViewportHeight()) / float(CGraphics::GetViewportHeight());
const float xBias = float(CGraphics::GetCroppedViewportLeft()) / float(CGraphics::GetViewportWidth());
const float yBias = float(CGraphics::GetCroppedViewportTop()) / float(CGraphics::GetViewportHeight());
const std::array<Vert, 4> verts{{
{{-1.0, -1.0}, {xBias, yBias}},
{{-1.0, 1.0}, {xBias, yBias + yFac}},
{{1.0, -1.0}, {xBias + xFac, yBias}},
{{1.0, 1.0}, {xBias + xFac, yBias + yFac}},
}};
// m_vbo->load(verts.data(), sizeof(verts));
for (size_t i = 0; i < m_uniform.m_uv.size(); ++i) {
auto tmp = static_cast<float>(i);
tmp *= 2.f * M_PIF;
tmp /= 6.f;
float amtX = std::cos(tmp);
amtX *= amount / 448.f / aspect;
float amtY = std::sin(tmp);
amtY *= amount / 448.f;
m_uniform.m_uv[i][0] = amtX * xFac;
m_uniform.m_uv[i][1] = amtY * yFac;
}
m_uniform.m_opacity = std::min(amount / 2.f, 1.f);
// m_uniBuf->load(&m_uniform, sizeof(m_uniform));
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, 4);
}
} // namespace metaforce

View File

@ -1,27 +0,0 @@
#pragma once
#include <array>
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <zeus/CVector4f.hpp>
namespace metaforce {
class CCameraBlurFilter {
struct Uniform {
std::array<zeus::CVector4f, 6> m_uv;
float m_opacity = 1.f;
};
// boo::ObjToken<boo::IGraphicsBufferD> m_vbo;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
Uniform m_uniform;
public:
static void Initialize();
static void Shutdown();
CCameraBlurFilter();
void draw(float amount, bool clearDepth = false);
};
} // namespace metaforce

View File

@ -1,117 +0,0 @@
#include "Runtime/Graphics/Shaders/CColoredQuadFilter.hpp"
#include <array>
#include "Runtime/Camera/CCameraFilter.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
// static boo::ObjToken<boo::IShaderPipeline> s_AlphaPipeline;
// static boo::ObjToken<boo::IShaderPipeline> s_AddPipeline;
// static boo::ObjToken<boo::IShaderPipeline> s_MultPipeline;
void CColoredQuadFilter::Initialize() {
// s_AlphaPipeline = hecl::conv->convert(Shader_CColoredQuadFilter{});
// s_AddPipeline = hecl::conv->convert(Shader_CColoredQuadFilterAdd{});
// s_MultPipeline = hecl::conv->convert(Shader_CColoredQuadFilterMul{});
}
void CColoredQuadFilter::Shutdown() {
// s_AlphaPipeline.reset();
// s_AddPipeline.reset();
// s_MultPipeline.reset();
}
// static boo::ObjToken<boo::IShaderPipeline> SelectPipeline(EFilterType type) {
// switch (type) {
// case EFilterType::Blend:
// return s_AlphaPipeline;
// case EFilterType::Add:
// return s_AddPipeline;
// case EFilterType::Multiply:
// return s_MultPipeline;
// default:
// return s_AlphaPipeline;
// }
// }
CColoredQuadFilter::CColoredQuadFilter(EFilterType type) {
// CGraphics::CommitResources([this, type](boo::IGraphicsDataFactory::Context& ctx) {
// struct Vert {
// zeus::CVector2f m_pos;
// };
//
// const std::array<Vert, 4> verts{{
// {{0.0, 0.0}},
// {{0.0, 1.0}},
// {{1.0, 0.0}},
// {{1.0, 1.0}},
// }};
//
// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 16, verts.size());
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
//
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
// m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), m_vbo.get(), nullptr, nullptr, bufs.size(),
// bufs.data(),
// stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr);
// return true;
// } BooTrace);
}
void CColoredQuadFilter::draw(const zeus::CColor& color, const zeus::CRectangle& rect) {
SCOPED_GRAPHICS_DEBUG_GROUP("CColoredQuadFilter::draw", zeus::skMagenta);
m_uniform.m_matrix[0][0] = rect.size.x() * 2.f;
m_uniform.m_matrix[1][1] = rect.size.y() * 2.f;
m_uniform.m_matrix[3][0] = rect.position.x() * 2.f - 1.f;
m_uniform.m_matrix[3][1] = rect.position.y() * 2.f - 1.f;
m_uniform.m_color = color;
// m_uniBuf->load(&m_uniform, sizeof(m_uniform));
//
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, 4);
}
void CWideScreenFilter::draw(const zeus::CColor& color, float t) {
if (CGraphics::GetViewportAspect() < 1.7777f) {
float targetHeight = CGraphics::GetViewportWidth() / 1.7777f;
float delta = (CGraphics::GetViewportHeight() - targetHeight) * t / 2.f;
delta /= float(CGraphics::GetViewportHeight());
zeus::CRectangle rect(0.f, 0.f, 1.f, delta);
m_bottom.draw(color, rect);
rect.position.y() = 1.f - delta;
m_top.draw(color, rect);
}
}
float CWideScreenFilter::SetViewportToMatch(float t) {
if (CGraphics::GetViewportAspect() < 1.7777f) {
float targetHeight = CGraphics::GetViewportWidth() / 1.7777f;
float delta = (CGraphics::GetViewportHeight() - targetHeight) * t / 2.f;
// boo::SWindowRect rect = {};
// rect.size[0] = g_Viewport.x8_width;
// rect.size[1] = g_Viewport.xc_height - delta * 2.f;
// rect.location[1] = delta;
// CGraphics::g_CroppedViewport = rect;
// CGraphics::g_BooMainCommandQueue->setViewport(rect);
return 1.7777f;
}
SetViewportToFull();
return CGraphics::GetViewportAspect();
}
void CWideScreenFilter::SetViewportToFull() {
// boo::SWindowRect rect = {};
// rect.size[0] = g_Viewport.x8_width;
// rect.size[1] = g_Viewport.xc_height;
// CGraphics::g_CroppedViewport = rect;
// CGraphics::g_BooMainCommandQueue->setViewport(rect);
}
} // namespace metaforce

View File

@ -1,52 +0,0 @@
#pragma once
#include "Runtime/CToken.hpp"
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <zeus/CColor.hpp>
#include <zeus/CMatrix4f.hpp>
#include <zeus/CRectangle.hpp>
namespace metaforce {
class CTexture;
enum class EFilterShape;
enum class EFilterType;
class CColoredQuadFilter {
struct Uniform {
zeus::CMatrix4f m_matrix;
zeus::CColor m_color;
};
// boo::ObjToken<boo::IGraphicsBufferS> m_vbo;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
Uniform m_uniform;
public:
static void Initialize();
static void Shutdown();
static constexpr zeus::CRectangle DefaultRect{0.f, 0.f, 1.f, 1.f};
explicit CColoredQuadFilter(EFilterType type);
explicit CColoredQuadFilter(EFilterType type, const TLockedToken<CTexture>&) : CColoredQuadFilter(type) {}
void draw(const zeus::CColor& color, const zeus::CRectangle& rect = DefaultRect);
void DrawFilter(EFilterShape shape, const zeus::CColor& color, float t) { draw(color); }
};
class CWideScreenFilter {
CColoredQuadFilter m_top;
CColoredQuadFilter m_bottom;
public:
explicit CWideScreenFilter(EFilterType type) : m_top(type), m_bottom(type) {}
explicit CWideScreenFilter(EFilterType type, const TLockedToken<CTexture>&) : CWideScreenFilter(type) {}
void draw(const zeus::CColor& color, float t);
void DrawFilter(EFilterShape shape, const zeus::CColor& color, float t) { draw(color, t); }
static float SetViewportToMatch(float t);
static void SetViewportToFull();
};
} // namespace metaforce

View File

@ -1,84 +0,0 @@
#include "Runtime/Graphics/Shaders/CColoredStripShader.hpp"
#include <array>
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Graphics/CCubeRenderer.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
//static boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_AdditivePipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_FullAdditivePipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_SubtractivePipeline;
void CColoredStripShader::Initialize() {
// s_Pipeline = hecl::conv->convert(Shader_CColoredStripShader{});
// s_AdditivePipeline = hecl::conv->convert(Shader_CColoredStripShaderAdditive{});
// s_FullAdditivePipeline = hecl::conv->convert(Shader_CColoredStripShaderFullAdditive{});
// s_SubtractivePipeline = hecl::conv->convert(Shader_CColoredStripShaderSubtractive{});
}
void CColoredStripShader::Shutdown() {
// s_Pipeline.reset();
// s_AdditivePipeline.reset();
// s_FullAdditivePipeline.reset();
// s_SubtractivePipeline.reset();
}
//static const boo::ObjToken<boo::IShaderPipeline>& SelectPipeline(CColoredStripShader::Mode mode) {
// switch (mode) {
// case CColoredStripShader::Mode::Alpha:
// default:
// return s_Pipeline;
// case CColoredStripShader::Mode::Additive:
// return s_AdditivePipeline;
// case CColoredStripShader::Mode::FullAdditive:
// return s_FullAdditivePipeline;
// case CColoredStripShader::Mode::Subtractive:
// return s_SubtractivePipeline;
// }
//}
//
//void CColoredStripShader::BuildResources(boo::IGraphicsDataFactory::Context& ctx, size_t maxVerts, Mode mode,
// boo::ObjToken<boo::ITexture> tex) {
// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vert), maxVerts);
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
//
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
// std::array<boo::ObjToken<boo::ITexture>, 1> texs;
// if (tex) {
// texs[0] = tex;
// } else {
// texs[0] = g_Renderer->GetWhiteTexture();
// }
//
// m_dataBind = ctx.newShaderDataBinding(SelectPipeline(mode), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr);
//}
CColoredStripShader::CColoredStripShader(size_t maxVerts, Mode mode, CTexture& tex) {
// CGraphics::CommitResources([this, maxVerts, mode, tex](boo::IGraphicsDataFactory::Context& ctx) {
// BuildResources(ctx, maxVerts, mode, tex);
// return true;
// } BooTrace);
}
void CColoredStripShader::draw(const zeus::CColor& color, size_t numVerts, const Vert* verts) {
SCOPED_GRAPHICS_DEBUG_GROUP("CColoredStripShader::draw", zeus::skMagenta);
// m_vbo->load(verts, sizeof(Vert) * numVerts);
m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f();
m_uniform.m_color = color;
// m_uniBuf->load(&m_uniform, sizeof(m_uniform));
//
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, numVerts);
}
} // namespace metaforce

View File

@ -1,39 +0,0 @@
#pragma once
#include "Runtime/Graphics/CGraphics.hpp"
#include <zeus/CColor.hpp>
#include <zeus/CMatrix4f.hpp>
namespace metaforce {
class CColoredStripShader {
public:
enum class Mode { Alpha, Additive, FullAdditive, Subtractive };
private:
struct Uniform {
zeus::CMatrix4f m_matrix;
zeus::CColor m_color;
};
// boo::ObjToken<boo::IGraphicsBufferD> m_vbo;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
Uniform m_uniform;
// void BuildResources(boo::IGraphicsDataFactory::Context& ctx, size_t maxVerts, Mode mode,
// boo::ObjToken<boo::ITexture> tex);
public:
struct Vert {
zeus::CVector3f m_pos;
zeus::CColor m_color;
zeus::CVector2f m_uv;
};
static void Initialize();
static void Shutdown();
CColoredStripShader(size_t maxVerts, Mode mode, CTexture& tex);
void draw(const zeus::CColor& color, size_t numVerts, const Vert* verts);
};
} // namespace metaforce

View File

@ -1,72 +0,0 @@
#include "Runtime/Graphics/Shaders/CDecalShaders.hpp"
#include <array>
#include "Runtime/Particle/CDecal.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
void CDecalShaders::Initialize() {
// m_texZTestNoZWrite = hecl::conv->convert(Shader_CDecalShaderTexZTest{});
// m_texAdditiveZTest = hecl::conv->convert(Shader_CDecalShaderTexAdditiveZTest{});
// m_texRedToAlphaZTest = hecl::conv->convert(Shader_CDecalShaderTexRedToAlphaZTest{});
// m_noTexZTestNoZWrite = hecl::conv->convert(Shader_CDecalShaderNoTexZTest{});
// m_noTexAdditiveZTest = hecl::conv->convert(Shader_CDecalShaderNoTexAdditiveZTest{});
}
void CDecalShaders::Shutdown() {
// m_texZTestNoZWrite.reset();
// m_texAdditiveZTest.reset();
// m_texRedToAlphaZTest.reset();
// m_noTexZTestNoZWrite.reset();
// m_noTexAdditiveZTest.reset();
}
void CDecalShaders::BuildShaderDataBinding(CQuadDecal& decal) {
// boo::ObjToken<boo::IShaderPipeline> regPipeline;
// boo::ObjToken<boo::IShaderPipeline> redToAlphaPipeline;
// if (decal.m_desc->x14_TEX) {
// if (decal.m_desc->x18_ADD)
// regPipeline = m_texAdditiveZTest;
// else
// regPipeline = m_texZTestNoZWrite;
// redToAlphaPipeline = m_texRedToAlphaZTest;
// } else {
// if (decal.m_desc->x18_ADD)
// regPipeline = m_noTexAdditiveZTest;
// else
// regPipeline = m_noTexZTestNoZWrite;
// }
//
// const SQuadDescr* const desc = decal.m_desc;
// const CUVElement* const texr = desc->x14_TEX.get();
// size_t texCount = 0;
// std::array<boo::ObjToken<boo::ITexture>, 1> textures;
//
// if (texr != nullptr) {
// textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture();
// texCount = 1;
// }
//
// if (!decal.m_instBuf) {
// return;
// }
//
// std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> uniforms{decal.m_uniformBuf.get()};
//
// if (regPipeline) {
// decal.m_normalDataBind =
// ctx.newShaderDataBinding(regPipeline, nullptr, decal.m_instBuf.get(), nullptr, uniforms.size(), uniforms.data(),
// nullptr, texCount, textures.data(), nullptr, nullptr);
// }
// if (redToAlphaPipeline) {
// decal.m_redToAlphaDataBind =
// ctx.newShaderDataBinding(redToAlphaPipeline, nullptr, decal.m_instBuf.get(), nullptr, uniforms.size(),
// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr);
// }
}
} // namespace metaforce

View File

@ -1,23 +0,0 @@
#pragma once
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
namespace metaforce {
struct CQuadDecal;
class CDecalShaders {
private:
// static inline boo::ObjToken<boo::IShaderPipeline> m_texZTestNoZWrite;
// static inline boo::ObjToken<boo::IShaderPipeline> m_texAdditiveZTest;
// static inline boo::ObjToken<boo::IShaderPipeline> m_texRedToAlphaZTest;
//
// static inline boo::ObjToken<boo::IShaderPipeline> m_noTexZTestNoZWrite;
// static inline boo::ObjToken<boo::IShaderPipeline> m_noTexAdditiveZTest;
public:
static void Initialize();
static void Shutdown();
static void BuildShaderDataBinding(CQuadDecal& decal);
};
} // namespace metaforce

View File

@ -1,298 +0,0 @@
#include "Runtime/Graphics/Shaders/CElementGenShaders.hpp"
#include <iterator>
#include "Runtime/Particle/CElementGen.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
void CElementGenShaders::Initialize() {
// m_texZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexZTestZWrite{}),
// hecl::conv->convert(Shader_CElementGenShaderTexZTestZWrite{})};
// m_texNoZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestZWrite{}),
// hecl::conv->convert(Shader_CElementGenShaderTexNoZTestZWriteAWrite{})};
// m_texZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWrite{}),
// hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteAWrite{})};
// m_texNoZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWrite{}),
// hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteAWrite{})};
// m_texAdditiveZTest = {hecl::conv->convert(Shader_CElementGenShaderTexAdditiveZTest{}),
// hecl::conv->convert(Shader_CElementGenShaderTexAdditiveZTestAWrite{})};
// m_texAdditiveNoZTest = {hecl::conv->convert(Shader_CElementGenShaderTexAdditiveNoZTest{}),
// hecl::conv->convert(Shader_CElementGenShaderTexAdditiveNoZTestAWrite{})};
// m_texRedToAlphaZTest = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTest{}),
// hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestAWrite{})};
// m_texRedToAlphaNoZTest = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTest{}),
// hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestAWrite{})};
// m_texZTestNoZWriteSub = {hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteSub{}),
// hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteSubAWrite{})};
// m_texNoZTestNoZWriteSub = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteSub{}),
// hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteSubAWrite{})};
// m_texRedToAlphaZTestSub = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestSub{}),
// hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestSubAWrite{})};
// m_texRedToAlphaNoZTestSub = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestSub{}),
// hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestSubAWrite{})};
//
// m_indTexZWrite = {hecl::conv->convert(Shader_CElementGenShaderIndTexZWrite{}),
// hecl::conv->convert(Shader_CElementGenShaderIndTexZWriteAWrite{})};
// m_indTexNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderIndTexNoZWrite{}),
// hecl::conv->convert(Shader_CElementGenShaderIndTexNoZWriteAWrite{})};
// m_indTexAdditive = {hecl::conv->convert(Shader_CElementGenShaderIndTexAdditive{}),
// hecl::conv->convert(Shader_CElementGenShaderIndTexAdditiveAWrite{})};
//
// m_cindTexZWrite = {hecl::conv->convert(Shader_CElementGenShaderCindTexZWrite{}),
// hecl::conv->convert(Shader_CElementGenShaderCindTexZWriteAWrite{})};
// m_cindTexNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderCindTexNoZWrite{}),
// hecl::conv->convert(Shader_CElementGenShaderCindTexNoZWriteAWrite{})};
// m_cindTexAdditive = {hecl::conv->convert(Shader_CElementGenShaderCindTexAdditive{}),
// hecl::conv->convert(Shader_CElementGenShaderCindTexAdditiveAWrite{})};
//
// m_noTexZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexZTestZWrite{}),
// hecl::conv->convert(Shader_CElementGenShaderNoTexZTestZWriteAWrite{})};
// m_noTexNoZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestZWrite{}),
// hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestZWriteAWrite{})};
// m_noTexZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexZTestNoZWrite{}),
// hecl::conv->convert(Shader_CElementGenShaderNoTexZTestNoZWriteAWrite{})};
// m_noTexNoZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestNoZWrite{}),
// hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestNoZWriteAWrite{})};
// m_noTexAdditiveZTest = {hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveZTest{}),
// hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveZTestAWrite{})};
// m_noTexAdditiveNoZTest = {hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveNoZTest{}),
// hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveNoZTestAWrite{})};
}
void CElementGenShaders::Shutdown() {
// for (auto& s : m_texZTestZWrite)
// s.reset();
// for (auto& s : m_texNoZTestZWrite)
// s.reset();
// for (auto& s : m_texZTestNoZWrite)
// s.reset();
// for (auto& s : m_texNoZTestNoZWrite)
// s.reset();
// for (auto& s : m_texAdditiveZTest)
// s.reset();
// for (auto& s : m_texAdditiveNoZTest)
// s.reset();
// for (auto& s : m_texRedToAlphaZTest)
// s.reset();
// for (auto& s : m_texRedToAlphaNoZTest)
// s.reset();
// for (auto& s : m_texZTestNoZWriteSub)
// s.reset();
// for (auto& s : m_texNoZTestNoZWriteSub)
// s.reset();
// for (auto& s : m_texRedToAlphaZTestSub)
// s.reset();
// for (auto& s : m_texRedToAlphaNoZTestSub)
// s.reset();
//
// for (auto& s : m_indTexZWrite)
// s.reset();
// for (auto& s : m_indTexNoZWrite)
// s.reset();
// for (auto& s : m_indTexAdditive)
// s.reset();
//
// for (auto& s : m_cindTexZWrite)
// s.reset();
// for (auto& s : m_cindTexNoZWrite)
// s.reset();
// for (auto& s : m_cindTexAdditive)
// s.reset();
//
// for (auto& s : m_noTexZTestZWrite)
// s.reset();
// for (auto& s : m_noTexNoZTestZWrite)
// s.reset();
// for (auto& s : m_noTexZTestNoZWrite)
// s.reset();
// for (auto& s : m_noTexNoZTestNoZWrite)
// s.reset();
// for (auto& s : m_noTexAdditiveZTest)
// s.reset();
// for (auto& s : m_noTexAdditiveNoZTest)
// s.reset();
}
CElementGenShaders::EShaderClass CElementGenShaders::GetShaderClass(CElementGen& gen) {
CGenDescription* desc = gen.x1c_genDesc.GetObj();
if (desc->x54_x40_TEXR) {
if (desc->x58_x44_TIND)
return EShaderClass::IndTex;
else
return EShaderClass::Tex;
} else
return EShaderClass::NoTex;
}
void CElementGenShaders::BuildShaderDataBinding(CElementGen& gen) {
CGenDescription* desc = gen.x1c_genDesc.GetObj();
// std::array<boo::ObjToken<boo::IShaderPipeline>, 2>* regPipeline = nullptr;
// std::array<boo::ObjToken<boo::IShaderPipeline>, 2>* regPipelineSub = nullptr;
// std::array<boo::ObjToken<boo::IShaderPipeline>, 2>* redToAlphaPipeline = nullptr;
// std::array<boo::ObjToken<boo::IShaderPipeline>, 2>* redToAlphaPipelineSub = nullptr;
// std::array<boo::ObjToken<boo::IShaderPipeline>, 2>* regPipelinePmus = nullptr;
// std::array<boo::ObjToken<boo::IShaderPipeline>, 2>* redToAlphaPipelinePmus = nullptr;
//
// if (gen.x26c_28_zTest) {
// redToAlphaPipeline = &m_texRedToAlphaZTest;
// regPipelineSub = &m_texZTestNoZWriteSub;
// redToAlphaPipelineSub = &m_texRedToAlphaZTestSub;
// } else {
// redToAlphaPipeline = &m_texRedToAlphaNoZTest;
// regPipelineSub = &m_texNoZTestNoZWriteSub;
// redToAlphaPipelineSub = &m_texRedToAlphaNoZTestSub;
// }
//
// if (desc->x54_x40_TEXR) {
// if (desc->x58_x44_TIND) {
// if (desc->x45_30_x32_24_CIND) {
// if (gen.x26c_26_AAPH)
// regPipeline = &m_cindTexAdditive;
// else {
// if (gen.x26c_27_ZBUF)
// regPipeline = &m_cindTexZWrite;
// else
// regPipeline = &m_cindTexNoZWrite;
// }
// } else {
// if (gen.x26c_26_AAPH)
// regPipeline = &m_indTexAdditive;
// else {
// if (gen.x26c_27_ZBUF)
// regPipeline = &m_indTexZWrite;
// else
// regPipeline = &m_indTexNoZWrite;
// }
// }
// } else {
// if (gen.x26c_26_AAPH) {
// if (gen.x26c_28_zTest)
// regPipeline = &m_texAdditiveZTest;
// else
// regPipeline = &m_texAdditiveNoZTest;
// } else {
// if (gen.x26c_28_zTest) {
// if (gen.x26c_27_ZBUF)
// regPipeline = &m_texZTestZWrite;
// else
// regPipeline = &m_texZTestNoZWrite;
// } else {
// if (gen.x26c_27_ZBUF)
// regPipeline = &m_texNoZTestZWrite;
// else
// regPipeline = &m_texNoZTestNoZWrite;
// }
// }
// }
// } else {
// if (gen.x26c_26_AAPH) {
// if (gen.x26c_28_zTest)
// regPipeline = &m_noTexAdditiveZTest;
// else
// regPipeline = &m_noTexAdditiveNoZTest;
// } else {
// if (gen.x26c_28_zTest) {
// if (gen.x26c_27_ZBUF)
// regPipeline = &m_noTexZTestZWrite;
// else
// regPipeline = &m_noTexZTestNoZWrite;
// } else {
// if (gen.x26c_27_ZBUF)
// regPipeline = &m_noTexNoZTestZWrite;
// else
// regPipeline = &m_noTexNoZTestNoZWrite;
// }
// }
// }
//
// if (desc->x45_24_x31_26_PMUS) {
// if (desc->x54_x40_TEXR) {
// redToAlphaPipelinePmus = &m_texRedToAlphaZTest;
// if (desc->x44_31_x31_25_PMAB)
// regPipelinePmus = &m_texAdditiveZTest;
// else
// regPipelinePmus = &m_texZTestZWrite;
// } else {
// if (desc->x44_31_x31_25_PMAB)
// regPipelinePmus = &m_noTexAdditiveZTest;
// else
// regPipelinePmus = &m_noTexZTestZWrite;
// }
// }
//
// const CUVElement* const texr = desc->x54_x40_TEXR.get();
// const CUVElement* const tind = desc->x58_x44_TIND.get();
// int texCount = 0;
// std::array<boo::ObjToken<boo::ITexture>, 3> textures;
//
// if (texr) {
// textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture();
// texCount = 1;
// if (gen.m_instBuf) {
// if (tind) {
// textures[1] = CGraphics::g_SpareTexture.get();
// textures[2] = tind->GetValueTexture(0).GetObj()->GetBooTexture();
// texCount = 3;
// }
// }
// }
//
// if (gen.m_instBuf) {
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> uniforms{gen.m_uniformBuf.get()};
//
// if (regPipeline != nullptr) {
// for (size_t i = 0; i < gen.m_normalDataBind.size(); ++i) {
// gen.m_normalDataBind[i] =
// ctx.newShaderDataBinding((*regPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(),
// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr);
// }
// }
// if (regPipelineSub != nullptr) {
// for (size_t i = 0; i < gen.m_normalSubDataBind.size(); ++i) {
// gen.m_normalSubDataBind[i] =
// ctx.newShaderDataBinding((*regPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(),
// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr);
// }
// }
// if (redToAlphaPipeline != nullptr) {
// for (size_t i = 0; i < gen.m_redToAlphaDataBind.size(); ++i) {
// gen.m_redToAlphaDataBind[i] =
// ctx.newShaderDataBinding((*redToAlphaPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(),
// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr);
// }
// }
// if (redToAlphaPipelineSub != nullptr) {
// for (size_t i = 0; i < gen.m_redToAlphaSubDataBind.size(); ++i) {
// gen.m_redToAlphaSubDataBind[i] = ctx.newShaderDataBinding(
// (*redToAlphaPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), uniforms.data(),
// nullptr, texCount, textures.data(), nullptr, nullptr);
// }
// }
// }
//
// if (gen.m_instBufPmus) {
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> uniforms{gen.m_uniformBufPmus.get()};
// texCount = std::min(texCount, 1);
//
// if (regPipelinePmus != nullptr) {
// for (size_t i = 0; i < gen.m_normalDataBindPmus.size(); ++i) {
// gen.m_normalDataBindPmus[i] =
// ctx.newShaderDataBinding((*regPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(),
// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr);
// }
// }
// if (redToAlphaPipelinePmus != nullptr) {
// for (size_t i = 0; i < gen.m_redToAlphaDataBindPmus.size(); ++i) {
// gen.m_redToAlphaDataBindPmus[i] = ctx.newShaderDataBinding(
// (*redToAlphaPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(), uniforms.data(),
// nullptr, texCount, textures.data(), nullptr, nullptr);
// }
// }
// }
}
} // namespace metaforce

View File

@ -1,50 +0,0 @@
#pragma once
#include <array>
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
namespace metaforce {
class CElementGen;
class CElementGenShaders {
public:
enum class EShaderClass { Tex, IndTex, NoTex };
private:
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texZTestZWrite;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texNoZTestZWrite;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texZTestNoZWrite;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texNoZTestNoZWrite;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texAdditiveZTest;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texAdditiveNoZTest;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texRedToAlphaZTest;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texRedToAlphaNoZTest;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texZTestNoZWriteSub;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texNoZTestNoZWriteSub;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texRedToAlphaZTestSub;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texRedToAlphaNoZTestSub;
//
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_indTexZWrite;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_indTexNoZWrite;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_indTexAdditive;
//
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_cindTexZWrite;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_cindTexNoZWrite;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_cindTexAdditive;
//
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexZTestZWrite;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexNoZTestZWrite;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexZTestNoZWrite;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexNoZTestNoZWrite;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexAdditiveZTest;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexAdditiveNoZTest;
public:
static void Initialize();
static void Shutdown();
static EShaderClass GetShaderClass(CElementGen& gen);
static void BuildShaderDataBinding(CElementGen& gen);
};
} // namespace metaforce

View File

@ -1,95 +0,0 @@
#include "Runtime/Graphics/Shaders/CEnergyBarShader.hpp"
#include <cstring>
#include "Runtime/Graphics/CGraphics.hpp"
#include "Runtime/Graphics/CTexture.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
//static boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
void CEnergyBarShader::Initialize() {
// s_Pipeline = hecl::conv->convert(Shader_CEnergyBarShader{});
}
void CEnergyBarShader::Shutdown() {
// s_Pipeline.reset();
}
void CEnergyBarShader::updateModelMatrix() {
m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f();
}
void CEnergyBarShader::draw(const zeus::CColor& color0, const std::vector<Vertex>& verts0, const zeus::CColor& color1,
const std::vector<Vertex>& verts1, const zeus::CColor& color2,
const std::vector<Vertex>& verts2, const CTexture* tex) {
SCOPED_GRAPHICS_DEBUG_GROUP("CEnergyBarShader::draw", zeus::skMagenta);
size_t totalVerts = verts0.size() + verts1.size() + verts2.size();
if (!totalVerts)
return;
if (totalVerts > m_maxVerts) {
m_maxVerts = totalVerts;
m_tex = tex;
// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) {
// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vertex), m_maxVerts);
//
// std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs;
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
// const std::array<boo::ObjToken<boo::ITexture>, 1> texs{m_tex->GetBooTexture()};
//
// for (size_t i = 0; i < m_uniBuf.size(); ++i) {
// m_uniBuf[i] = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
// bufs[0] = m_uniBuf[i].get();
// m_dataBind[i] =
// ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), stages.data(),
// nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr);
// }
//
// return true;
// } BooTrace);
}
size_t vertIter = 0;
// Vertex* verts = reinterpret_cast<Vertex*>(m_vbo->map(sizeof(Vertex) * totalVerts));
// if (verts0.size()) {
// memmove(verts, verts0.data(), sizeof(Vertex) * verts0.size());
// vertIter += verts0.size();
// }
// if (verts1.size()) {
// memmove(verts + vertIter, verts1.data(), sizeof(Vertex) * verts1.size());
// vertIter += verts1.size();
// }
// if (verts2.size()) {
// memmove(verts + vertIter, verts2.data(), sizeof(Vertex) * verts2.size());
// }
// m_vbo->unmap();
vertIter = 0;
if (verts0.size()) {
m_uniform.m_color = color0;
// m_uniBuf[0]->load(&m_uniform, sizeof(Uniform));
// CGraphics::SetShaderDataBinding(m_dataBind[0]);
// CGraphics::DrawArray(0, verts0.size());
vertIter += verts0.size();
}
if (verts1.size()) {
m_uniform.m_color = color1;
// m_uniBuf[1]->load(&m_uniform, sizeof(Uniform));
// CGraphics::SetShaderDataBinding(m_dataBind[1]);
// CGraphics::DrawArray(vertIter, verts1.size());
vertIter += verts1.size();
}
if (verts2.size()) {
m_uniform.m_color = color2;
// m_uniBuf[2]->load(&m_uniform, sizeof(Uniform));
// CGraphics::SetShaderDataBinding(m_dataBind[2]);
// CGraphics::DrawArray(vertIter, verts2.size());
}
}
} // namespace metaforce

View File

@ -1,44 +0,0 @@
#pragma once
#include <array>
#include <vector>
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <zeus/CColor.hpp>
#include <zeus/CMatrix4f.hpp>
#include <zeus/CVector2f.hpp>
#include <zeus/CVector3f.hpp>
namespace metaforce {
class CTexture;
class CEnergyBarShader {
public:
struct Vertex {
zeus::CVector3f pos;
zeus::CVector2f uv;
};
private:
struct Uniform {
zeus::CMatrix4f m_matrix;
zeus::CColor m_color;
};
// boo::ObjToken<boo::IGraphicsBufferD> m_vbo;
// std::array<boo::ObjToken<boo::IGraphicsBufferD>, 3> m_uniBuf;
// std::array<boo::ObjToken<boo::IShaderDataBinding>, 3> m_dataBind;
Uniform m_uniform;
const CTexture* m_tex = nullptr;
size_t m_maxVerts = 0;
public:
static void Initialize();
static void Shutdown();
void updateModelMatrix();
void draw(const zeus::CColor& color0, const std::vector<Vertex>& verts0, const zeus::CColor& color1,
const std::vector<Vertex>& verts1, const zeus::CColor& color2, const std::vector<Vertex>& verts2,
const CTexture* tex);
};
} // namespace metaforce

View File

@ -1,57 +0,0 @@
#include "Runtime/Graphics/Shaders/CEnvFxShaders.hpp"
#include "Runtime/World/CEnvFxManager.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
//boo::ObjToken<boo::IShaderPipeline> CEnvFxShaders::m_snowPipeline;
//boo::ObjToken<boo::IShaderPipeline> CEnvFxShaders::m_underwaterPipeline;
void CEnvFxShaders::Initialize() {
// m_snowPipeline = hecl::conv->convert(Shader_CEnvFxSnowShader{});
// m_underwaterPipeline = hecl::conv->convert(Shader_CEnvFxUnderwaterShader{});
}
void CEnvFxShaders::Shutdown() {
// m_snowPipeline.reset();
// m_underwaterPipeline.reset();
}
void CEnvFxShaders::BuildShaderDataBinding(CEnvFxManager& fxMgr,
CEnvFxManagerGrid& grid) {
// const auto uBufInfo = grid.m_uniformBuf.getBufferInfo();
// const auto iBufInfo = grid.m_instBuf.getBufferInfo();
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 2> uniforms{{
// uBufInfo.first.get(),
// fxMgr.m_fogUniformBuf.get(),
// }};
// const std::array<size_t, 2> ubufOffsets{
// size_t(uBufInfo.second),
// 0,
// };
// constexpr std::array<size_t, 2> ubufSizes{
// sizeof(CEnvFxShaders::Uniform),
// sizeof(CGraphics::g_Fog),
// };
// constexpr std::array<boo::PipelineStage, 2> uniformStages{
// boo::PipelineStage::Vertex,
// boo::PipelineStage::Fragment,
// };
// std::array<boo::ObjToken<boo::ITexture>, 2> textures{
// fxMgr.xb74_txtrSnowFlake->GetBooTexture(),
// fxMgr.x40_txtrEnvGradient->GetBooTexture(),
// };
//
// grid.m_snowBinding = ctx.newShaderDataBinding(
// m_snowPipeline, nullptr, iBufInfo.first.get(), nullptr, uniforms.size(), uniforms.data(), uniformStages.data(),
// ubufOffsets.data(), ubufSizes.data(), textures.size(), textures.data(), nullptr, nullptr, 0, iBufInfo.second);
// textures[0] = fxMgr.xc48_underwaterFlake->GetBooTexture();
// grid.m_underwaterBinding =
// ctx.newShaderDataBinding(m_underwaterPipeline, nullptr, iBufInfo.first.get(), nullptr, uniforms.size(),
// uniforms.data(), uniformStages.data(), ubufOffsets.data(), ubufSizes.data(),
// textures.size(), textures.data(), nullptr, nullptr, 0, iBufInfo.second);
}
} // namespace metaforce

View File

@ -1,41 +0,0 @@
#pragma once
#include <array>
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <zeus/CColor.hpp>
#include <zeus/CMatrix4f.hpp>
#include <zeus/CVector2f.hpp>
#include <zeus/CVector3f.hpp>
namespace metaforce {
class CEnvFxManager;
class CEnvFxManagerGrid;
class CEnvFxShaders {
public:
struct Instance {
std::array<zeus::CVector3f, 4> positions;
zeus::CColor color;
std::array<zeus::CVector2f, 4> uvs;
};
struct Uniform {
zeus::CMatrix4f mv;
zeus::CMatrix4f proj;
zeus::CMatrix4f envMtx;
zeus::CColor moduColor;
};
private:
// static boo::ObjToken<boo::IShaderPipeline> m_snowPipeline;
// static boo::ObjToken<boo::IShaderPipeline> m_underwaterPipeline;
public:
static void Initialize();
static void Shutdown();
static void BuildShaderDataBinding(CEnvFxManager& fxMgr,
CEnvFxManagerGrid& grid);
};
} // namespace metaforce

View File

@ -1,292 +0,0 @@
#include "Runtime/Graphics/Shaders/CFluidPlaneShader.hpp"
#include "Runtime/World/CRipple.hpp"
#include "Runtime/World/CRippleManager.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
//CFluidPlaneShader::Cache CFluidPlaneShader::_cache = {};
//
//u16 CFluidPlaneShader::Cache::MakeCacheKey(const SFluidPlaneShaderInfo& info) {
// u16 ret = 0;
//
// switch (info.m_type) {
// case EFluidType::NormalWater:
// case EFluidType::PhazonFluid:
// case EFluidType::Four:
// if (info.m_hasLightmap) {
// ret |= 1 << 2;
// if (info.m_doubleLightmapBlend)
// ret |= 1 << 3;
// }
//
// if (!info.m_hasEnvMap && info.m_hasEnvBumpMap)
// ret |= 1 << 4;
//
// if (info.m_hasEnvMap)
// ret |= 1 << 5;
//
// break;
//
// case EFluidType::PoisonWater:
// ret |= 1;
//
// if (info.m_hasLightmap) {
// ret |= 1 << 2;
// if (info.m_doubleLightmapBlend)
// ret |= 1 << 3;
// }
//
// if (info.m_hasEnvBumpMap)
// ret |= 1 << 4;
//
// break;
//
// case EFluidType::Lava:
// ret |= 2;
//
// if (info.m_hasBumpMap)
// ret |= 1 << 2;
//
// break;
//
// case EFluidType::ThickLava:
// ret |= 3;
//
// if (info.m_hasBumpMap)
// ret |= 1 << 2;
//
// break;
// }
//
// if (info.m_hasPatternTex1)
// ret |= 1 << 6;
// if (info.m_hasPatternTex2)
// ret |= 1 << 7;
// if (info.m_hasColorTex)
// ret |= 1 << 8;
//
// if (info.m_additive)
// ret |= 1 << 9;
//
// return ret;
//}
//
//u16 CFluidPlaneShader::Cache::MakeCacheKey(const SFluidPlaneDoorShaderInfo& info) {
// u16 ret = 0;
//
// if (info.m_hasPatternTex1)
// ret |= 1 << 0;
// if (info.m_hasPatternTex2)
// ret |= 1 << 1;
// if (info.m_hasColorTex)
// ret |= 1 << 2;
//
// return ret;
//}
//
//template <>
//CFluidPlaneShader::ShaderPair
//CFluidPlaneShader::Cache::GetOrBuildShader<SFluidPlaneShaderInfo>(const SFluidPlaneShaderInfo& info) {
// OPTICK_EVENT();
// u16 key = MakeCacheKey(info);
// auto& slot = CacheSlot(info, key);
// if (slot.m_regular)
// return slot;
//
// slot.m_regular = hecl::conv->convert(Shader_CFluidPlaneShader{info, false});
// if (info.m_tessellation)
// slot.m_tessellation = hecl::conv->convert(Shader_CFluidPlaneShader{info, true});
//
// return slot;
//}
//template <>
//CFluidPlaneShader::ShaderPair
//CFluidPlaneShader::Cache::GetOrBuildShader<SFluidPlaneDoorShaderInfo>(const SFluidPlaneDoorShaderInfo& info) {
// OPTICK_EVENT();
// u16 key = MakeCacheKey(info);
// auto& slot = CacheSlot(info, key);
// if (slot.m_regular)
// return slot;
//
// slot.m_regular = hecl::conv->convert(Shader_CFluidPlaneDoorShader{info});
//
// return slot;
//}
//
//void CFluidPlaneShader::Cache::Clear() {
// for (auto& p : m_cache)
// p.reset();
// for (auto& p : m_doorCache)
// p.reset();
//}
void CFluidPlaneShader::PrepareBinding(u32 maxVertCount) {
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vertex), maxVertCount);
// if (m_pipelines.m_tessellation) {
// m_pvbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(PatchVertex), maxVertCount);
// }
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
//
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 3> ubufs{{
// m_uniBuf.get(),
// m_uniBuf.get(),
// m_uniBuf.get(),
// }};
// constexpr std::array<boo::PipelineStage, 3> ubufStages{
// boo::PipelineStage::Vertex,
// boo::PipelineStage::Vertex,
// boo::PipelineStage::Fragment,
// };
// constexpr std::array<size_t, 3> ubufOffs{
// 0,
// 0,
// 1280,
// };
// constexpr std::array<size_t, 3> ubufSizes{
// 1280,
// 1280,
// sizeof(CModelShaders::LightingUniform),
// };
//
// size_t texCount = 0;
// std::array<boo::ObjToken<boo::ITexture>, 8> texs;
// if (m_patternTex1) {
// texs[texCount++] = m_patternTex1->GetBooTexture();
// }
// if (m_patternTex2) {
// texs[texCount++] = m_patternTex2->GetBooTexture();
// }
// if (m_colorTex) {
// texs[texCount++] = m_colorTex->GetBooTexture();
// }
// if (m_bumpMap) {
// texs[texCount++] = m_bumpMap->GetBooTexture();
// }
// if (m_envMap) {
// texs[texCount++] = m_envMap->GetBooTexture();
// }
// if (m_envBumpMap) {
// texs[texCount++] = m_envBumpMap->GetBooTexture();
// }
// if (m_lightmap) {
// texs[texCount++] = m_lightmap->GetBooTexture();
// }
// auto regular = ctx.newShaderDataBinding(m_pipelines.m_regular, m_vbo.get(), nullptr, nullptr, ubufs.size(),
// ubufs.data(), ubufStages.data(), ubufOffs.data(), ubufSizes.data(),
// texCount, texs.data(), nullptr, nullptr);
// boo::ObjToken<boo::IShaderDataBinding> tessellation;
// if (m_pipelines.m_tessellation) {
// texs[texCount++] = m_rippleMap.get();
// tessellation = ctx.newShaderDataBinding(m_pipelines.m_tessellation, m_pvbo.get(), nullptr, nullptr, ubufs.size(),
// ubufs.data(), ubufStages.data(), ubufOffs.data(), ubufSizes.data(),
// texCount, texs.data(), nullptr, nullptr);
// }
// m_dataBind = {regular, tessellation};
// return true;
// } BooTrace);
}
void CFluidPlaneShader::Shutdown() {
// _cache.Clear();
}
CFluidPlaneShader::CFluidPlaneShader(EFluidType type, const TLockedToken<CTexture>& patternTex1,
const TLockedToken<CTexture>& patternTex2, const TLockedToken<CTexture>& colorTex,
const TLockedToken<CTexture>& bumpMap, const TLockedToken<CTexture>& envMap,
const TLockedToken<CTexture>& envBumpMap, const TLockedToken<CTexture>& lightmap,
CTexture& rippleMap, bool doubleLightmapBlend,
bool additive, u32 maxVertCount)
: m_patternTex1(patternTex1)
, m_patternTex2(patternTex2)
, m_colorTex(colorTex)
, m_bumpMap(bumpMap)
, m_envMap(envMap)
, m_envBumpMap(envBumpMap)
, m_lightmap(lightmap)
//, m_rippleMap(rippleMap)
{
SFluidPlaneShaderInfo shaderInfo(type, m_patternTex1.HasReference(), m_patternTex2.HasReference(),
m_colorTex.HasReference(), m_bumpMap.HasReference(), m_envMap.HasReference(),
m_envBumpMap.HasReference(), m_lightmap.HasReference(), false/*m_rippleMap.operator bool()*/,
doubleLightmapBlend, additive);
// m_pipelines = _cache.GetOrBuildShader(shaderInfo);
PrepareBinding(maxVertCount);
}
CFluidPlaneShader::CFluidPlaneShader(const TLockedToken<CTexture>& patternTex1,
const TLockedToken<CTexture>& patternTex2, const TLockedToken<CTexture>& colorTex,
u32 maxVertCount)
: m_patternTex1(patternTex1), m_patternTex2(patternTex2), m_colorTex(colorTex) {
SFluidPlaneDoorShaderInfo shaderInfo(m_patternTex1.HasReference(), m_patternTex2.HasReference(),
m_colorTex.HasReference());
// m_pipelines = _cache.GetOrBuildShader(shaderInfo);
PrepareBinding(maxVertCount);
}
void CFluidPlaneShader::prepareDraw(const RenderSetupInfo& info) {
// Uniform& uni = *reinterpret_cast<Uniform*>(m_uniBuf->map(sizeof(Uniform)));
// uni.m_mv = CGraphics::g_GXModelView.toMatrix4f();
// uni.m_mvNorm = info.normMtx;
// uni.m_proj = CGraphics::GetPerspectiveProjectionMatrix(true);
// uni.m_texMtxs = info.texMtxs;
// uni.m_lighting.ActivateLights(info.lights);
// for (size_t i = 0; i < uni.m_lighting.colorRegs.size(); ++i) {
// uni.m_lighting.colorRegs[i] = info.kColors[i];
// }
// uni.m_lighting.mulColor = info.kColors[3];
// uni.m_lighting.fog = CGraphics::g_Fog;
// uni.m_pad2.x() = info.indScale;
// m_uniBuf->unmap();
}
void CFluidPlaneShader::prepareDraw(const RenderSetupInfo& info, const zeus::CVector3f& waterCenter,
const CRippleManager& rippleManager, const zeus::CColor& colorMul,
float rippleNormResolution) {
// Uniform& uni = *reinterpret_cast<Uniform*>(m_uniBuf->map(sizeof(Uniform)));
// uni.m_mv = CGraphics::g_GXModelView.toMatrix4f();
// uni.m_mvNorm = info.normMtx;
// uni.m_proj = CGraphics::GetPerspectiveProjectionMatrix(true);
// uni.m_texMtxs = info.texMtxs;
//
// size_t i = 0;
// for (const CRipple& ripple : rippleManager.GetRipples()) {
// assert(i < uni.m_ripple.size() && "Too many ripples");
// Ripple& rOut = uni.m_ripple[i++];
// if (ripple.GetTime() >= ripple.GetTimeFalloff()) {
// rOut.center.zeroOut();
// rOut.params.zeroOut();
// continue;
// }
// zeus::CVector3f localPos = ripple.GetCenter() - waterCenter;
// rOut.center.x() = float(localPos.x());
// rOut.center.y() = float(localPos.y());
// rOut.center.z() = ripple.GetTime() * ripple.GetOOTimeFalloff();
// rOut.center.w() = ripple.GetOODistanceFalloff();
// rOut.params.x() = ripple.GetAmplitude();
// rOut.params.y() = ripple.GetPhase();
// rOut.params.z() =
// (1.f - ripple.GetTime() * ripple.GetOOTimeFalloff() * ripple.GetOOTimeFalloff()) * ripple.GetFrequency();
// }
// uni.m_colorMul = colorMul;
// uni.m_pad[0].x() = rippleNormResolution;
// uni.m_lighting.ActivateLights(info.lights);
// for (i = 0; i < uni.m_lighting.colorRegs.size(); ++i) {
// uni.m_lighting.colorRegs[i] = info.kColors[i];
// }
// uni.m_lighting.mulColor = info.kColors[3];
// uni.m_lighting.fog = CGraphics::g_Fog;
// uni.m_pad2.x() = info.indScale;
// m_uniBuf->unmap();
}
void CFluidPlaneShader::loadVerts(const std::vector<Vertex>& verts, const std::vector<PatchVertex>& pVerts) {
// m_vbo->load(verts.data(), verts.size() * sizeof(Vertex));
// if (m_pvbo)
// m_pvbo->load(pVerts.data(), pVerts.size() * sizeof(PatchVertex));
}
} // namespace metaforce

View File

@ -1,178 +0,0 @@
#pragma once
#include <array>
#include <vector>
#include "Runtime/CToken.hpp"
#include "Runtime/Graphics/CTexture.hpp"
#include "Runtime/Graphics/Shaders/CModelShaders.hpp"
#include "Runtime/World/CFluidPlaneManager.hpp"
#include "Shaders/shader_CFluidPlaneShader.hpp"
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <zeus/CColor.hpp>
#include <zeus/CMatrix4f.hpp>
#include <zeus/CVector3f.hpp>
#include <zeus/CVector4f.hpp>
namespace metaforce {
class CFluidPlaneShader {
public:
struct Vertex {
zeus::CVector3f m_pos;
zeus::CVector3f m_norm;
zeus::CVector3f m_binorm;
zeus::CVector3f m_tangent;
zeus::CColor m_color;
Vertex() = default;
Vertex(const zeus::CVector3f& position) : m_pos(position) {}
Vertex(const zeus::CVector3f& position, const zeus::CColor& color) : m_pos(position), m_color(color) {}
Vertex(const zeus::CVector3f& position, const zeus::CVector3f& normal, const zeus::CColor& color)
: m_pos(position), m_norm(normal), m_color(color) {}
Vertex(const zeus::CVector3f& position, const zeus::CVector3f& normal, const zeus::CVector3f& binormal,
const zeus::CVector3f& tangent, const zeus::CColor& color)
: m_pos(position), m_norm(normal), m_binorm(binormal), m_tangent(tangent), m_color(color) {}
};
struct PatchVertex {
zeus::CVector4f m_pos;
std::array<float, 4> m_outerLevels{};
std::array<float, 4> m_innerLevels{};
};
struct RenderSetupInfo {
std::array<zeus::CMatrix4f, 6> texMtxs;
zeus::CMatrix4f normMtx;
float indScale = 1.f;
std::array<zeus::CColor, 4> kColors;
std::vector<CLight> lights;
};
private:
// struct ShaderPair {
// boo::ObjToken<boo::IShaderPipeline> m_regular;
// boo::ObjToken<boo::IShaderPipeline> m_tessellation;
// void reset() {
// m_regular.reset();
// m_tessellation.reset();
// }
// };
//
// struct BindingPair {
// boo::ObjToken<boo::IShaderDataBinding> m_regular;
// boo::ObjToken<boo::IShaderDataBinding> m_tessellation;
// };
// class Cache {
// std::array<ShaderPair, 1024> m_cache{};
// std::array<ShaderPair, 8> m_doorCache{};
// ShaderPair& CacheSlot(const SFluidPlaneShaderInfo& info, int i) { return m_cache[i]; }
// ShaderPair& CacheSlot(const SFluidPlaneDoorShaderInfo& info, int i) { return m_doorCache[i]; }
// static u16 MakeCacheKey(const SFluidPlaneShaderInfo& info);
// static u16 MakeCacheKey(const SFluidPlaneDoorShaderInfo& info);
//
// public:
// template <class T>
// ShaderPair GetOrBuildShader(const T& info);
// void Clear();
// };
// static Cache _cache;
struct Ripple {
zeus::CVector4f center; // time, distFalloff
zeus::CVector4f params; // amplitude, lookupPhase, lookupTime
};
// struct Uniform {
// zeus::CMatrix4f m_mv;
// zeus::CMatrix4f m_mvNorm;
// zeus::CMatrix4f m_proj;
// std::array<zeus::CMatrix4f, 6> m_texMtxs;
// std::array<Ripple, 20> m_ripple;
// zeus::CVector4f m_colorMul;
// std::array<zeus::CVector4f, 3> m_pad; // rippleNormResolution, Pad out to 1280 bytes
// CModelShaders::LightingUniform m_lighting;
// zeus::CVector3f m_pad2; // Pad out to 768 bytes, also holds ind scale
// };
TLockedToken<CTexture> m_patternTex1;
TLockedToken<CTexture> m_patternTex2;
TLockedToken<CTexture> m_colorTex;
TLockedToken<CTexture> m_bumpMap;
TLockedToken<CTexture> m_envMap;
TLockedToken<CTexture> m_envBumpMap;
TLockedToken<CTexture> m_lightmap;
// aurora::gfx::TextureHandle m_rippleMap;
// boo::ObjToken<boo::IGraphicsBufferD> m_vbo;
// boo::ObjToken<boo::IGraphicsBufferD> m_pvbo;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// ShaderPair m_pipelines;
// BindingPair m_dataBind;
int m_lastBind = -1;
//#if BOO_HAS_GL
// static ShaderPair BuildShader(boo::GLDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info);
// static ShaderPair BuildShader(boo::GLDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info);
// BindingPair BuildBinding(boo::GLDataFactory::Context& ctx, const ShaderPair& pipeline);
//#endif
//#if _WIN32
// static ShaderPair BuildShader(boo::D3D11DataFactory::Context& ctx, const SFluidPlaneShaderInfo& info);
// static ShaderPair BuildShader(boo::D3D11DataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info);
// BindingPair BuildBinding(boo::D3D11DataFactory::Context& ctx, const ShaderPair& pipeline);
//#endif
//#if BOO_HAS_METAL
// static ShaderPair BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info);
// static ShaderPair BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info);
// BindingPair BuildBinding(boo::MetalDataFactory::Context& ctx, const ShaderPair& pipeline);
//#endif
//#if BOO_HAS_VULKAN
// static ShaderPair BuildShader(boo::VulkanDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info);
// static ShaderPair BuildShader(boo::VulkanDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info);
// BindingPair BuildBinding(boo::VulkanDataFactory::Context& ctx, const ShaderPair& pipeline);
//#endif
template <class F>
static void _Shutdown();
void PrepareBinding(u32 maxVertCount);
public:
CFluidPlaneShader(EFluidType type, const TLockedToken<CTexture>& patternTex1,
const TLockedToken<CTexture>& patternTex2, const TLockedToken<CTexture>& colorTex,
const TLockedToken<CTexture>& bumpMap, const TLockedToken<CTexture>& envMap,
const TLockedToken<CTexture>& envBumpMap, const TLockedToken<CTexture>& lightmap,
CTexture& rippleMap, bool doubleLightmapBlend, bool additive,
u32 maxVertCount);
CFluidPlaneShader(const TLockedToken<CTexture>& patternTex1, const TLockedToken<CTexture>& patternTex2,
const TLockedToken<CTexture>& colorTex, u32 maxVertCount);
void prepareDraw(const RenderSetupInfo& info);
void prepareDraw(const RenderSetupInfo& info, const zeus::CVector3f& waterCenter, const CRippleManager& rippleManager,
const zeus::CColor& colorMul, float rippleNormResolution);
void bindRegular() {
if (m_lastBind != 0) {
// CGraphics::SetShaderDataBinding(m_dataBind.m_regular);
m_lastBind = 0;
}
}
bool bindTessellation() {
if (m_lastBind != 1) {
// CGraphics::SetShaderDataBinding(m_dataBind.m_tessellation);
m_lastBind = 1;
}
return true;
}
void doneDrawing() { m_lastBind = -1; }
void loadVerts(const std::vector<Vertex>& verts, const std::vector<PatchVertex>& pVerts);
bool isReady() const {
// return m_pipelines.m_regular->isReady() && (!m_pipelines.m_tessellation || m_pipelines.m_tessellation->isReady());
return false;
}
static void Shutdown();
};
} // namespace metaforce

View File

@ -1,77 +0,0 @@
#include "Runtime/Graphics/Shaders/CFogVolumeFilter.hpp"
#include <array>
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Graphics/CCubeRenderer.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
//#include <hecl/Pipeline.hpp>
#include <zeus/CColor.hpp>
namespace metaforce {
//static boo::ObjToken<boo::IShaderPipeline> s_1WayPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_2WayPipeline;
void CFogVolumeFilter::Initialize() {
// s_1WayPipeline = hecl::conv->convert(Shader_CFogVolumeFilter1Way{});
// s_2WayPipeline = hecl::conv->convert(Shader_CFogVolumeFilter2Way{});
}
void CFogVolumeFilter::Shutdown() {
// s_1WayPipeline.reset();
// s_2WayPipeline.reset();
}
CFogVolumeFilter::CFogVolumeFilter() {
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
// struct Vert {
// zeus::CVector2f m_pos;
// zeus::CVector2f m_uv;
// };
// constexpr std::array<Vert, 4> verts{{
// {{-1.0, -1.0}, {0.0, 0.0}},
// {{-1.0, 1.0}, {0.0, 1.0}},
// {{1.0, -1.0}, {1.0, 0.0}},
// {{1.0, 1.0}, {1.0, 1.0}},
// }};
// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size());
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CColor), 1);
// const std::array<boo::ObjToken<boo::ITexture>, 3> texs{
// CGraphics::g_SpareTexture.get(),
// CGraphics::g_SpareTexture.get(),
// g_Renderer->GetFogRampTex().get(),
// };
// constexpr std::array bindIdxs{0, 1, 0};
// constexpr std::array bindDepth{true, true, false};
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> ubufs{m_uniBuf.get()};
//
// m_dataBind1Way =
// ctx.newShaderDataBinding(s_1WayPipeline, m_vbo.get(), nullptr, nullptr, ubufs.size(), ubufs.data(), nullptr,
// nullptr, nullptr, texs.size(), texs.data(), bindIdxs.data(), bindDepth.data());
// m_dataBind2Way =
// ctx.newShaderDataBinding(s_2WayPipeline, m_vbo.get(), nullptr, nullptr, ubufs.size(), ubufs.data(), nullptr,
// nullptr, nullptr, texs.size(), texs.data(), bindIdxs.data(), bindDepth.data());
// return true;
// } BooTrace);
}
void CFogVolumeFilter::draw2WayPass(const zeus::CColor& color) {
SCOPED_GRAPHICS_DEBUG_GROUP("CFogVolumeFilter::draw2WayPass", zeus::skMagenta);
// m_uniBuf->load(&color, sizeof(zeus::CColor));
// CGraphics::SetShaderDataBinding(m_dataBind2Way);
// CGraphics::DrawArray(0, 4);
}
void CFogVolumeFilter::draw1WayPass(const zeus::CColor& color) {
SCOPED_GRAPHICS_DEBUG_GROUP("CFogVolumeFilter::draw1WayPass", zeus::skMagenta);
// m_uniBuf->load(&color, sizeof(zeus::CColor));
// CGraphics::SetShaderDataBinding(m_dataBind1Way);
// CGraphics::DrawArray(0, 4);
}
} // namespace metaforce

View File

@ -1,23 +0,0 @@
#pragma once
namespace zeus {
class CColor;
} // namespace zeus
namespace metaforce {
class CFogVolumeFilter {
// boo::ObjToken<boo::IGraphicsBufferS> m_vbo;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind1Way;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind2Way;
public:
static void Initialize();
static void Shutdown();
CFogVolumeFilter();
void draw2WayPass(const zeus::CColor& color);
void draw1WayPass(const zeus::CColor& color);
};
} // namespace metaforce

View File

@ -1,65 +0,0 @@
#include "Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
//static std::array<boo::ObjToken<boo::IShaderPipeline>, 4> s_Pipelines;
//
//void CFogVolumePlaneShader::Initialize() {
// s_Pipelines[0] = hecl::conv->convert(Shader_CFogVolumePlaneShader0{});
// s_Pipelines[1] = hecl::conv->convert(Shader_CFogVolumePlaneShader1{});
// s_Pipelines[2] = hecl::conv->convert(Shader_CFogVolumePlaneShader2{});
// s_Pipelines[3] = hecl::conv->convert(Shader_CFogVolumePlaneShader3{});
//}
//
//void CFogVolumePlaneShader::Shutdown() {
// s_Pipelines[0].reset();
// s_Pipelines[1].reset();
// s_Pipelines[2].reset();
// s_Pipelines[3].reset();
//}
//
//void CFogVolumePlaneShader::CommitResources(size_t capacity) {
// m_vertCapacity = capacity;
// CGraphics::CommitResources([this, capacity](boo::IGraphicsDataFactory::Context& ctx) {
// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(zeus::CVector4f), capacity);
// for (size_t i = 0; i < m_dataBinds.size(); ++i) {
// m_dataBinds[i] = ctx.newShaderDataBinding(s_Pipelines[i], m_vbo.get(), nullptr, nullptr, 0, nullptr, nullptr,
// nullptr, nullptr, 0, nullptr, nullptr, nullptr);
// }
// return true;
// } BooTrace);
//}
void CFogVolumePlaneShader::addFan(const zeus::CVector3f* verts, int numVerts) {
zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(/*true*/);
zeus::CVector4f vert0 = proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[0]);
if (!m_verts.empty()) {
m_verts.push_back(m_verts.back());
m_verts.push_back(vert0);
if (m_verts.size() & 1)
m_verts.push_back(vert0);
}
TriFanToStrip<zeus::CVector4f> fanToStrip(m_verts);
fanToStrip.AddVert(vert0);
for (int i = 1; i < numVerts; ++i)
fanToStrip.AddVert(proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[i]));
}
void CFogVolumePlaneShader::draw(int pass) {
if (m_verts.empty())
return;
SCOPED_GRAPHICS_DEBUG_GROUP("CFogVolumePlaneShader::draw", zeus::skMagenta);
// if (pass == 0) {
// if (m_vertCapacity < m_verts.size())
// CommitResources(m_verts.size());
// m_vbo->load(m_verts.data(), m_verts.size() * sizeof(zeus::CVector4f));
// }
// CGraphics::SetShaderDataBinding(m_dataBinds[pass]);
// CGraphics::DrawArray(0, m_verts.size());
}
} // namespace metaforce

View File

@ -1,35 +0,0 @@
#pragma once
#include <array>
#include <cstddef>
#include <vector>
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <zeus/CRectangle.hpp>
#include <zeus/CVector4f.hpp>
namespace zeus {
class CVector3f;
} // namespace zeus
namespace metaforce {
class CFogVolumePlaneShader {
// boo::ObjToken<boo::IGraphicsBufferD> m_vbo;
// std::array<boo::ObjToken<boo::IShaderDataBinding>, 4> m_dataBinds;
size_t m_vertCapacity = 0;
public:
std::vector<zeus::CVector4f> m_verts;
public:
static const zeus::CRectangle DefaultRect;
void reset(int numVerts) {
m_verts.clear();
m_verts.reserve(numVerts);
}
void addFan(const zeus::CVector3f* verts, int numVerts);
void draw(int pass);
};
} // namespace metaforce

View File

@ -1,116 +0,0 @@
#include "Runtime/Graphics/Shaders/CLineRendererShaders.hpp"
#include <utility>
#include "Runtime/Graphics/CLineRenderer.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
void CLineRendererShaders::Initialize() {
// CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) {
// m_texAlpha = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlpha{}),
// hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaAWrite{})};
// m_texAdditive = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditive{}),
// hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveAWrite{})};
// m_noTexAlpha = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlpha{}),
// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaAWrite{})};
// m_noTexAdditive = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditive{}),
// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveAWrite{})};
// m_texAlphaZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaZ{}),
// hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaZAWrite{})};
// m_texAdditiveZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveZ{}),
// hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveZAWrite{})};
// m_noTexAlphaZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZ{}),
// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZAWrite{})};
// m_noTexAdditiveZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveZ{}),
// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveZAWrite{})};
// m_noTexAlphaZGEqual = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZGEqual{}),
// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZGEqualAWrite{})};
// return true;
// } BooTrace);
}
void CLineRendererShaders::Shutdown() {
// for (auto& s : m_texAlpha)
// s.reset();
// for (auto& s : m_texAdditive)
// s.reset();
// for (auto& s : m_noTexAlpha)
// s.reset();
// for (auto& s : m_noTexAdditive)
// s.reset();
// for (auto& s : m_texAlphaZ)
// s.reset();
// for (auto& s : m_texAdditiveZ)
// s.reset();
// for (auto& s : m_noTexAlphaZ)
// s.reset();
// for (auto& s : m_noTexAdditiveZ)
// s.reset();
// for (auto& s : m_noTexAlphaZGEqual)
// s.reset();
}
void CLineRendererShaders::BuildShaderDataBinding(CLineRenderer& renderer,
CTexture& texture, bool additive,
bool zTest, bool zGEqual) {
// std::array<boo::ObjToken<boo::IShaderPipeline>, 2>* pipeline = nullptr;
//
// if (zGEqual) {
// pipeline = &m_noTexAlphaZGEqual;
// } else if (zTest) {
// if (texture) {
// if (additive)
// pipeline = &m_texAdditiveZ;
// else
// pipeline = &m_texAlphaZ;
// } else {
// if (additive)
// pipeline = &m_noTexAdditiveZ;
// else
// pipeline = &m_noTexAlphaZ;
// }
// } else {
// if (texture) {
// if (additive)
// pipeline = &m_texAdditive;
// else
// pipeline = &m_texAlpha;
// } else {
// if (additive)
// pipeline = &m_noTexAdditive;
// else
// pipeline = &m_noTexAlpha;
// }
// }
//
// size_t texCount = 0;
// std::array<boo::ObjToken<boo::ITexture>, 1> textures;
//
// std::pair<boo::ObjToken<boo::IGraphicsBufferD>, hecl::VertexBufferPool<CLineRenderer::SDrawVertTex>::IndexTp>
// vbufInfo;
// std::pair<boo::ObjToken<boo::IGraphicsBufferD>, hecl::UniformBufferPool<CLineRenderer::SDrawUniform>::IndexTp>
// ubufInfo = renderer.m_uniformBuf.getBufferInfo();
// if (texture) {
// vbufInfo = renderer.m_vertBufTex.getBufferInfo();
// textures[0] = texture;
// texCount = 1;
// } else {
// vbufInfo = renderer.m_vertBufNoTex.getBufferInfo();
// }
//
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> uniforms{ubufInfo.first.get()};
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Fragment};
// const std::array<size_t, 1> ubufOffs{size_t(ubufInfo.second)};
// const std::array<size_t, 1> ubufSizes{sizeof(CLineRenderer::SDrawUniform)};
//
// for (size_t i = 0; i < renderer.m_shaderBind.size(); ++i) {
// renderer.m_shaderBind[i] = ctx.newShaderDataBinding(
// (*pipeline)[i], vbufInfo.first.get(), nullptr, nullptr, uniforms.size(), uniforms.data(), stages.data(),
// ubufOffs.data(), ubufSizes.data(), texCount, textures.data(), nullptr, nullptr, vbufInfo.second);
// }
}
} // namespace metaforce

View File

@ -1,33 +0,0 @@
#pragma once
#include <array>
#include "Runtime/Graphics/CGraphics.hpp"
namespace metaforce {
class CLineRenderer;
class CLineRendererShaders {
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texAlpha;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texAdditive;
//
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexAlpha;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexAdditive;
//
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texAlphaZ;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texAdditiveZ;
//
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexAlphaZ;
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexAdditiveZ;
//
// static inline std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexAlphaZGEqual;
public:
static void Initialize();
static void Shutdown();
static void BuildShaderDataBinding(CLineRenderer& renderer,
CTexture& texture, bool additive, bool zTest,
bool zGEqual);
};
} // namespace metaforce

View File

@ -1,40 +0,0 @@
#include "Runtime/Graphics/Shaders/CMapSurfaceShader.hpp"
#include <array>
#include "Runtime/Graphics/CGraphics.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
//static boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
void CMapSurfaceShader::Initialize() {
// s_Pipeline = hecl::conv->convert(Shader_CMapSurfaceShader{});
}
void CMapSurfaceShader::Shutdown() {
// s_Pipeline.reset();
}
CMapSurfaceShader::CMapSurfaceShader(std::vector<zeus::CVector3f> vbo,
std::vector<uint16_t> ibo)
//: m_vbo(vbo), m_ibo(ibo)
{
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, m_ibo.get(), bufs.size(), bufs.data(),
// stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr);
}
void CMapSurfaceShader::draw(const zeus::CColor& color, u32 start, u32 count) {
SCOPED_GRAPHICS_DEBUG_GROUP("CMapSurfaceShader::draw", zeus::skMagenta);
Uniform uniform = {CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(), color};
// m_uniBuf->load(&uniform, sizeof(Uniform));
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArrayIndexed(start, count);
}
} // namespace metaforce

View File

@ -1,30 +0,0 @@
#pragma once
#include "Runtime/GCNTypes.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
#include <zeus/CColor.hpp>
#include <zeus/CMatrix4f.hpp>
namespace metaforce {
class CMapSurfaceShader {
struct Uniform {
zeus::CMatrix4f mtx;
zeus::CColor color;
};
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// boo::ObjToken<boo::IGraphicsBufferS> m_vbo;
// boo::ObjToken<boo::IGraphicsBufferS> m_ibo;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
public:
static void Initialize();
static void Shutdown();
CMapSurfaceShader(std::vector<zeus::CVector3f> vbo,
std::vector<uint16_t> ibo);
void draw(const zeus::CColor& color, u32 start, u32 count);
};
} // namespace metaforce

View File

@ -1,235 +0,0 @@
#include "Runtime/Graphics/Shaders/CModelShaders.hpp"
#include "Runtime/CStopwatch.hpp"
#include "Runtime/Graphics/CLight.hpp"
//#include <hecl/Backend.hpp>
//#include <hecl/Pipeline.hpp>
namespace metaforce {
//std::unordered_map<uint64_t, CModelShaders::ShaderPipelines> CModelShaders::g_ShaderPipelines;
//void CModelShaders::LightingUniform::ActivateLights(const std::vector<CLight>& lts) {
// ambient = zeus::skClear;
// size_t curLight = 0;
//
// for (const CLight& light : lts) {
// switch (light.GetType()) {
// case ELightType::LocalAmbient:
// ambient += light.GetColor();
// break;
// case ELightType::Point:
// case ELightType::Spot:
// case ELightType::Custom:
// case ELightType::Directional: {
// if (curLight >= lights.size()) {
// continue;
// }
// CModelShaders::Light& lightOut = lights[curLight++];
// lightOut.pos = CGraphics::g_CameraMatrix * light.GetPosition();
// lightOut.dir = CGraphics::g_CameraMatrix.basis * light.GetDirection();
// lightOut.dir.normalize();
// lightOut.color = light.GetColor();
// lightOut.linAtt[0] = light.GetAttenuationConstant();
// lightOut.linAtt[1] = light.GetAttenuationLinear();
// lightOut.linAtt[2] = light.GetAttenuationQuadratic();
// lightOut.angAtt[0] = light.GetAngleAttenuationConstant();
// lightOut.angAtt[1] = light.GetAngleAttenuationLinear();
// lightOut.angAtt[2] = light.GetAngleAttenuationQuadratic();
//
// if (light.GetType() == ELightType::Directional)
// lightOut.pos = (-lightOut.dir) * 1048576.f;
// break;
// }
// }
// }
//
// for (; curLight < lights.size(); ++curLight) {
// CModelShaders::Light& lightOut = lights[curLight];
// lightOut.pos = zeus::skZero3f;
// lightOut.dir = zeus::skDown;
// lightOut.color = zeus::skClear;
// lightOut.linAtt[0] = 1.f;
// lightOut.linAtt[1] = 0.f;
// lightOut.linAtt[2] = 0.f;
// lightOut.angAtt[0] = 1.f;
// lightOut.angAtt[1] = 0.f;
// lightOut.angAtt[2] = 0.f;
// }
//}
//using TexCoordSource = hecl::Backend::TexCoordSource;
//
//constexpr std::array<hecl::Backend::TextureInfo, 1> ThermalTextures{{
// {TexCoordSource::Normal, 7, true},
//}};
//
//constexpr std::array<hecl::Backend::TextureInfo, 3> BallFadeTextures{{
// {TexCoordSource::Position, 0, false}, // ID tex
// {TexCoordSource::Position, 0, false}, // Sphere ramp
// {TexCoordSource::Position, 1, false}, // TXTR_BallFade
//}};
//
//constexpr std::array<hecl::Backend::TextureInfo, 1> WorldShadowTextures{{
// {TexCoordSource::Position, 7, false}, // Shadow tex
//}};
//
//constexpr std::array<hecl::Backend::TextureInfo, 2> DisintegrateTextures{{
// {TexCoordSource::Position, 0, false}, // Ashy tex
// {TexCoordSource::Position, 1, false}, // Ashy tex
//}};
//static std::array<hecl::Backend::ExtensionSlot, size_t(EExtendedShader::MAX)> g_ExtensionSlots{{
// /* Default solid shading */
// {},
// /* Normal lit shading */
// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original,
// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true},
// /* Thermal model shading */
// {1, ThermalTextures.data(), hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One,
// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, false, true},
// /* Thermal model shading without Z-test or Z-write */
// {1, ThermalTextures.data(), hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One,
// hecl::Backend::ZTest::None, hecl::Backend::CullMode::Backface, true, false, false, true},
// /* Thermal static shading */
// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
// hecl::Backend::CullMode::Backface, false, false, false, true, false, false, true},
// /* Thermal static shading without Z-write */
// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
// hecl::Backend::CullMode::Backface, true, false, false, true, false, false, false},
// /* Forced alpha shading */
// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha,
// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true},
// /* Forced additive shading */
// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
// hecl::Backend::CullMode::Backface, false, false, true},
// /* Solid color */
// {0, nullptr, hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual,
// hecl::Backend::CullMode::Backface, false, false, false},
// /* Solid color additive */
// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual,
// hecl::Backend::CullMode::Backface, true, false, true},
// /* Alpha-only Solid color frontface cull, LEqual */
// {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual,
// hecl::Backend::CullMode::Frontface, false, true, false},
// /* Alpha-only Solid color frontface cull, Always, No Z-write */
// {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::None,
// hecl::Backend::CullMode::Frontface, true, true, false},
// /* Alpha-only Solid color backface cull, LEqual */
// {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual,
// hecl::Backend::CullMode::Backface, false, true, false},
// /* Alpha-only Solid color backface cull, Greater, No Z-write */
// {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater,
// hecl::Backend::CullMode::Backface, true, true, false},
// /* MorphBall shadow shading */
// {3, BallFadeTextures.data(), hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha,
// hecl::Backend::ZTest::Equal, hecl::Backend::CullMode::Backface, false, false, true, false, true},
// /* World shadow shading (modified lighting) */
// {1, WorldShadowTextures.data(), hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original,
// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true},
// /* Forced alpha shading without culling */
// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha,
// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::None, false, false, true},
// /* Forced additive shading without culling */
// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
// hecl::Backend::CullMode::None, false, false, true},
// /* Forced alpha shading without Z-write */
// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha,
// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original, true, false, true},
// /* Forced additive shading without Z-write */
// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
// hecl::Backend::CullMode::Original, true, false, true},
// /* Forced alpha shading without culling or Z-write */
// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha,
// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::None, true, false, true},
// /* Forced additive shading without culling or Z-write */
// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
// hecl::Backend::CullMode::None, true, false, true},
// /* Depth GEqual no Z-write */
// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha,
// hecl::Backend::ZTest::GEqual, hecl::Backend::CullMode::Backface, true, false, true},
// /* Disintegration */
// {2, DisintegrateTextures.data(), hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha,
// hecl::Backend::ZTest::LEqual, hecl::Backend::CullMode::Original, false, false, true, false, false, true},
// /* Forced additive shading without culling or Z-write and greater depth test */
// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater,
// hecl::Backend::CullMode::None, true, false, true},
// /* Thermal cold shading */
// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original,
// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original, false, false, true, false, false, false, true},
// /* Normal lit shading with alpha */
// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original,
// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface},
// /* Normal lit shading with alpha without Z-write or depth test */
// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::None,
// hecl::Backend::CullMode::Backface, true},
// /* Normal lit shading with cube reflection */
// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original,
// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true},
// /* Normal lit shading with cube reflection and world shadow */
// {1, WorldShadowTextures.data(), hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original,
// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true},
//}};
//constexpr std::array<const char*, size_t(EExtendedShader::MAX)> ShaderMacros{
// "URDE_LIGHTING",
// "URDE_LIGHTING",
// "URDE_THERMAL_MODEL",
// "URDE_THERMAL_MODEL",
// "URDE_THERMAL_STATIC",
// "URDE_THERMAL_STATIC",
// "URDE_LIGHTING",
// "URDE_LIGHTING",
// "URDE_SOLID",
// "URDE_SOLID",
// "URDE_SOLID",
// "URDE_SOLID",
// "URDE_SOLID",
// "URDE_SOLID",
// "URDE_MB_SHADOW",
// "URDE_LIGHTING_SHADOW",
// "URDE_LIGHTING",
// "URDE_LIGHTING",
// "URDE_LIGHTING",
// "URDE_LIGHTING",
// "URDE_LIGHTING",
// "URDE_LIGHTING",
// "URDE_LIGHTING",
// "URDE_DISINTEGRATE",
// "URDE_LIGHTING",
// "URDE_THERMAL_COLD",
// "URDE_LIGHTING",
// "URDE_LIGHTING",
// "URDE_LIGHTING_CUBE_REFLECTION",
// "URDE_LIGHTING_CUBE_REFLECTION_SHADOW",
//};
void CModelShaders::Initialize() {
// for (size_t i = 0; i < g_ExtensionSlots.size(); i++) {
// g_ExtensionSlots[i].shaderMacro = ShaderMacros[i];
// }
}
void CModelShaders::Shutdown() {
// g_ShaderPipelines.clear();
}
//CModelShaders::ShaderPipelines CModelShaders::BuildExtendedShader(const hecl::Backend::ShaderTag& tag,
// const Material& material) {
// auto search = g_ShaderPipelines.find(tag.val64());
// if (search != g_ShaderPipelines.cend())
// return search->second;
//
// ShaderPipelines& newPipelines = g_ShaderPipelines[tag.val64()];
// newPipelines = std::make_shared<ShaderPipelinesData>();
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
// size_t idx = 0;
// for (const auto& ext : g_ExtensionSlots)
// (*newPipelines)[idx++] = hecl::conv->convert(ctx, Shader_CModelShaders(SModelShadersInfo(material, tag, ext)));
// return true;
// } BooTrace);
// return newPipelines;
//}
} // namespace metaforce

View File

@ -1,113 +0,0 @@
#pragma once
#include <array>
#include <cstdint>
#include <memory>
//#include "DataSpec/DNAMP1/CMDLMaterials.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
#include <zeus/CColor.hpp>
#include <zeus/CVector3f.hpp>
#include <zeus/CVector4f.hpp>
#define URDE_MAX_LIGHTS 8
namespace hecl::Backend {
class ShaderTag;
}
namespace metaforce {
class CLight;
enum class EExtendedShader : uint8_t {
Flat,
Lighting,
ThermalModel,
ThermalModelNoZTestNoZWrite,
ThermalStatic,
ThermalStaticNoZWrite,
ForcedAlpha,
ForcedAdditive,
SolidColor,
SolidColorAdditive,
SolidColorFrontfaceCullLEqualAlphaOnly,
SolidColorFrontfaceCullAlwaysAlphaOnly, // No Z-write or test
SolidColorBackfaceCullLEqualAlphaOnly,
SolidColorBackfaceCullGreaterAlphaOnly, // No Z-write
MorphBallShadow,
WorldShadow,
ForcedAlphaNoCull,
ForcedAdditiveNoCull,
ForcedAlphaNoZWrite,
ForcedAdditiveNoZWrite,
ForcedAlphaNoCullNoZWrite,
ForcedAdditiveNoCullNoZWrite,
DepthGEqualNoZWrite,
Disintegrate,
ForcedAdditiveNoZWriteDepthGreater,
ThermalCold,
LightingAlphaWrite,
LightingAlphaWriteNoZTestNoZWrite,
LightingCubeReflection,
LightingCubeReflectionWorldShadow,
MAX
};
class CModelShaders {
friend class CModel;
public:
// struct Light {
// zeus::CVector3f pos;
// zeus::CVector3f dir;
// zeus::CColor color = zeus::skClear;
// std::array<float, 4> linAtt{1.f, 0.f, 0.f};
// std::array<float, 4> angAtt{1.f, 0.f, 0.f};
// };
//
// struct LightingUniform {
// std::array<Light, URDE_MAX_LIGHTS> lights;
// zeus::CColor ambient;
// std::array<zeus::CColor, 3> colorRegs;
// zeus::CColor mulColor;
// zeus::CColor addColor;
// CFogState fog;
//
// void ActivateLights(const std::vector<CLight>& lts);
// };
//
// struct ThermalUniform {
// zeus::CColor mulColor;
// zeus::CColor addColor;
// };
//
// struct SolidUniform {
// zeus::CColor solidColor;
// };
//
// struct MBShadowUniform {
// zeus::CVector4f shadowUp;
// float shadowId;
// };
//
// struct OneTextureUniform {
// zeus::CColor addColor;
// CFogState fog;
// };
static void Initialize();
static void Shutdown();
// using ShaderPipelinesData = std::array<boo::ObjToken<boo::IShaderPipeline>, size_t(EExtendedShader::MAX)>;
// using ShaderPipelines = std::shared_ptr<ShaderPipelinesData>;
// using Material = DataSpec::DNAMP1::HMDLMaterialSet::Material;
// static ShaderPipelines BuildExtendedShader(const hecl::Backend::ShaderTag& tag, const Material& material);
private:
// static std::unordered_map<uint64_t, ShaderPipelines> g_ShaderPipelines;
};
} // namespace metaforce

View File

@ -1,112 +0,0 @@
#include "Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp"
#include <iterator>
#include "Runtime/Particle/CParticleSwoosh.hpp"
#include "Runtime/Particle/CSwooshDescription.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
//std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_texZWrite;
//std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_texNoZWrite;
//std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_texAdditiveZWrite;
//std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_texAdditiveNoZWrite;
//
//std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_noTexZWrite;
//std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_noTexNoZWrite;
//std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_noTexAdditiveZWrite;
//std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_noTexAdditiveNoZWrite;
void CParticleSwooshShaders::Initialize() {
// m_texZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexZWrite{}),
// hecl::conv->convert(Shader_CParticleSwooshShaderTexZWriteAWrite{})};
// m_texNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexNoZWrite{}),
// hecl::conv->convert(Shader_CParticleSwooshShaderTexNoZWriteAWrite{})};
// m_texAdditiveZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveZWrite{}),
// hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveZWriteAWrite{})};
// m_texAdditiveNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveNoZWrite{}),
// hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveNoZWriteAWrite{})};
// m_noTexZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexZWrite{}),
// hecl::conv->convert(Shader_CParticleSwooshShaderNoTexZWriteAWrite{})};
// m_noTexNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexNoZWrite{}),
// hecl::conv->convert(Shader_CParticleSwooshShaderNoTexNoZWriteAWrite{})};
// m_noTexAdditiveZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveZWrite{}),
// hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveZWriteAWrite{})};
// m_noTexAdditiveNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveNoZWrite{}),
// hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveNoZWriteAWrite{})};
}
void CParticleSwooshShaders::Shutdown() {
// for (auto& s : m_texZWrite)
// s.reset();
// for (auto& s : m_texNoZWrite)
// s.reset();
// for (auto& s : m_texAdditiveZWrite)
// s.reset();
// for (auto& s : m_texAdditiveNoZWrite)
// s.reset();
// for (auto& s : m_noTexZWrite)
// s.reset();
// for (auto& s : m_noTexNoZWrite)
// s.reset();
// for (auto& s : m_noTexAdditiveZWrite)
// s.reset();
// for (auto& s : m_noTexAdditiveNoZWrite)
// s.reset();
}
CParticleSwooshShaders::EShaderClass CParticleSwooshShaders::GetShaderClass(CParticleSwoosh& gen) {
CSwooshDescription* desc = gen.GetDesc();
if (desc->x3c_TEXR)
return EShaderClass::Tex;
else
return EShaderClass::NoTex;
}
void CParticleSwooshShaders::BuildShaderDataBinding(CParticleSwoosh& gen) {
CSwooshDescription* desc = gen.GetDesc();
// std::array<boo::ObjToken<boo::IShaderPipeline>, 2>* pipeline = nullptr;
//
// if (desc->x3c_TEXR) {
// if (desc->x44_31_AALP) {
// if (desc->x45_24_ZBUF)
// pipeline = &m_texAdditiveZWrite;
// else
// pipeline = &m_texAdditiveNoZWrite;
// } else {
// if (desc->x45_24_ZBUF)
// pipeline = &m_texZWrite;
// else
// pipeline = &m_texNoZWrite;
// }
// } else {
// if (desc->x44_31_AALP) {
// if (desc->x45_24_ZBUF)
// pipeline = &m_noTexAdditiveZWrite;
// else
// pipeline = &m_noTexAdditiveNoZWrite;
// } else {
// if (desc->x45_24_ZBUF)
// pipeline = &m_noTexZWrite;
// else
// pipeline = &m_noTexNoZWrite;
// }
// }
//
// const CUVElement* const texr = desc->x3c_TEXR.get();
// const std::array<boo::ObjToken<boo::ITexture>, 1> textures{
// texr ? texr->GetValueTexture(0).GetObj()->GetBooTexture() : nullptr,
// };
//
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> uniforms{gen.m_uniformBuf.get()};
// for (size_t i = 0; i < gen.m_dataBind.size(); ++i) {
// gen.m_dataBind[i] =
// ctx.newShaderDataBinding((*pipeline)[i], gen.m_vertBuf.get(), nullptr, nullptr, uniforms.size(),
// uniforms.data(), nullptr, texr ? 1 : 0, textures.data(), nullptr, nullptr);
// }
}
} // namespace metaforce

View File

@ -1,42 +0,0 @@
#pragma once
#include <array>
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <zeus/CColor.hpp>
#include <zeus/CVector2f.hpp>
#include <zeus/CVector3f.hpp>
namespace metaforce {
class CParticleSwoosh;
class CParticleSwooshShaders {
public:
enum class EShaderClass { Tex, NoTex };
struct Vert {
zeus::CVector3f m_pos;
zeus::CVector2f m_uv;
zeus::CColor m_color;
};
private:
// static std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texZWrite;
// static std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texNoZWrite;
// static std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texAdditiveZWrite;
// static std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_texAdditiveNoZWrite;
//
// static std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexZWrite;
// static std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexNoZWrite;
// static std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexAdditiveZWrite;
// static std::array<boo::ObjToken<boo::IShaderPipeline>, 2> m_noTexAdditiveNoZWrite;
public:
static void Initialize();
static void Shutdown();
static EShaderClass GetShaderClass(CParticleSwoosh& gen);
static void BuildShaderDataBinding(CParticleSwoosh& gen);
};
} // namespace metaforce

View File

@ -1,154 +0,0 @@
#include "Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp"
#include <array>
#include "Runtime/Graphics/CCubeRenderer.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
#include "Runtime/Graphics/CTexture.hpp"
//#include <hecl/Pipeline.hpp>
#include <zeus/CColor.hpp>
#include <zeus/CVector2f.hpp>
#include <zeus/CVector3f.hpp>
#include <zeus/CVector4f.hpp>
namespace metaforce {
// static boo::ObjToken<boo::IShaderPipeline> s_IndPipeline;
// static boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
// static boo::ObjToken<boo::IShaderPipeline> s_BlurPipeline;
void CPhazonSuitFilter::Initialize() {
// s_IndPipeline = hecl::conv->convert(Shader_CPhazonSuitFilterInd{});
// s_Pipeline = hecl::conv->convert(Shader_CPhazonSuitFilterNoInd{});
// s_BlurPipeline = hecl::conv->convert(Shader_CPhazonSuitFilterBlur{});
}
void CPhazonSuitFilter::Shutdown() {
// s_IndPipeline.reset();
// s_Pipeline.reset();
// s_BlurPipeline.reset();
}
void CPhazonSuitFilter::drawBlurPasses(float radius, const CTexture* indTex) {
SCOPED_GRAPHICS_DEBUG_GROUP("CPhazonSuitFilter::drawBlurPasses", zeus::skMagenta);
// if (!m_dataBind || indTex != m_indTex) {
// m_indTex = indTex;
// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) {
// m_uniBufBlurX = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f), 1);
// m_uniBufBlurY = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f), 1);
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f) * 2, 1);
//
// struct BlurVert {
// zeus::CVector3f pos;
// zeus::CVector2f uv;
// };
// const std::array<BlurVert, 4> blurVerts{{
// {{-1.f, 1.f, 0.f}, {0.f, 1.f}},
// {{-1.f, -1.f, 0.f}, {0.f, 0.f}},
// {{1.f, 1.f, 0.f}, {1.f, 1.f}},
// {{1.f, -1.f, 0.f}, {1.f, 0.f}},
// }};
// m_blurVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, blurVerts.data(), sizeof(BlurVert), blurVerts.size());
//
// struct Vert {
// zeus::CVector3f pos;
// zeus::CVector2f screenUv;
// zeus::CVector2f indUv;
// zeus::CVector2f maskUv;
// };
// const std::array<Vert, 4> verts{{
// {{-1.f, 1.f, 0.f}, {0.01f, 0.99f}, {0.f, 4.f}, {0.f, 1.f}},
// {{-1.f, -1.f, 0.f}, {0.01f, 0.01f}, {0.f, 0.f}, {0.f, 0.f}},
// {{1.f, 1.f, 0.f}, {0.99f, 0.99f}, {g_Viewport.aspect * 4.f, 4.f}, {1.f, 1.f}},
// {{1.f, -1.f, 0.f}, {0.99f, 0.01f}, {g_Viewport.aspect * 4.f, 0.f}, {1.f, 0.f}},
// }};
// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size());
//
// std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBufBlurX.get()};
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
// std::array<boo::ObjToken<boo::ITexture>, 4> texs;
// std::array<int, 4> texBindIdxs;
//
// texs[0] = CGraphics::g_SpareTexture.get();
// texBindIdxs[0] = 1;
// m_dataBindBlurX =
// ctx.newShaderDataBinding(s_BlurPipeline, m_blurVbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
// stages.data(), nullptr, nullptr, 1, texs.data(), texBindIdxs.data(), nullptr);
//
// bufs[0] = m_uniBufBlurY.get();
// texs[0] = CGraphics::g_SpareTexture.get();
// texBindIdxs[0] = 2;
// m_dataBindBlurY =
// ctx.newShaderDataBinding(s_BlurPipeline, m_blurVbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
// stages.data(), nullptr, nullptr, 1, texs.data(), texBindIdxs.data(), nullptr);
//
// bufs[0] = m_uniBuf.get();
// size_t texCount;
// if (m_indTex) {
// texs[0] = CGraphics::g_SpareTexture.get();
// texBindIdxs[0] = 0;
// texs[1] = m_indTex->GetBooTexture();
// texBindIdxs[1] = 0;
// texs[2] = CGraphics::g_SpareTexture.get();
// texBindIdxs[2] = 1;
// texs[3] = CGraphics::g_SpareTexture.get();
// texBindIdxs[3] = 2;
// texCount = 4;
// } else {
// texs[0] = CGraphics::g_SpareTexture.get();
// texBindIdxs[0] = 0;
// texs[1] = CGraphics::g_SpareTexture.get();
// texBindIdxs[1] = 1;
// texs[2] = CGraphics::g_SpareTexture.get();
// texBindIdxs[2] = 2;
// texCount = 3;
// }
//
// m_dataBind = ctx.newShaderDataBinding(m_indTex ? s_IndPipeline : s_Pipeline, m_vbo.get(), nullptr, nullptr,
// bufs.size(), bufs.data(), stages.data(), nullptr, nullptr, texCount,
// texs.data(), texBindIdxs.data(), nullptr);
// return true;
// } BooTrace);
// }
SClipScreenRect rect;
rect.x4_left = CGraphics::GetViewportLeft();
rect.x8_top = CGraphics::GetViewportTop();
rect.xc_width = CGraphics::GetViewportWidth();
rect.x10_height = CGraphics::GetViewportTop();
constexpr float blurScale = 1.0f / 128.0f;
/* X Pass */
auto blurDir = zeus::CVector4f{
CGraphics::GetViewportHeight() / float(CGraphics::GetViewportWidth()) * radius * blurScale, 0.f, 0.f, 0.f};
// m_uniBufBlurX->load(&blurDir, sizeof(zeus::CVector4f));
// CGraphics::SetShaderDataBinding(m_dataBindBlurX);
// CGraphics::DrawArray(0, 4);
// CGraphics::ResolveSpareTexture(rect, 2);
/* Y Pass */
blurDir = zeus::CVector4f{0.f, radius * blurScale, 0.f, 0.f};
// m_uniBufBlurY->load(&blurDir, sizeof(zeus::CVector4f));
// CGraphics::SetShaderDataBinding(m_dataBindBlurY);
// CGraphics::DrawArray(0, 4);
// CGraphics::ResolveSpareTexture(rect, 2);
}
void CPhazonSuitFilter::draw(const zeus::CColor& color, float indScale, float indOffX, float indOffY) {
SCOPED_GRAPHICS_DEBUG_GROUP("CPhazonSuitFilter::draw", zeus::skMagenta);
struct Uniform {
zeus::CColor color;
zeus::CVector4f indScaleOff;
} uniform = {color, zeus::CVector4f(indScale, indScale, indOffX, indOffY)};
// m_uniBuf->load(&uniform, sizeof(Uniform));
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, 4);
}
} // namespace metaforce

View File

@ -1,30 +0,0 @@
#pragma once
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
namespace zeus {
class CColor;
} // namespace zeus
namespace metaforce {
class CTexture;
class CPhazonSuitFilter {
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBufBlurX;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBufBlurY;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// boo::ObjToken<boo::IGraphicsBufferS> m_blurVbo;
// boo::ObjToken<boo::IGraphicsBufferS> m_vbo;
const CTexture* m_indTex = nullptr;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBindBlurX;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBindBlurY;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
public:
static void Initialize();
static void Shutdown();
void drawBlurPasses(float radius, const CTexture* indTex);
void draw(const zeus::CColor& color, float indScale, float indOffX, float indOffY);
};
} // namespace metaforce

View File

@ -1,57 +0,0 @@
#include "Runtime/Graphics/Shaders/CRadarPaintShader.hpp"
#include <cstring>
#include "Runtime/Graphics/CGraphics.hpp"
#include "Runtime/Graphics/CTexture.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
//static boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
void CRadarPaintShader::Initialize() {
// s_Pipeline = hecl::conv->convert(Shader_CRadarPaintShader{});
}
void CRadarPaintShader::Shutdown() {
// s_Pipeline.reset();
}
void CRadarPaintShader::draw(const std::vector<Instance>& instances, const CTexture* tex) {
if (!instances.size())
return;
SCOPED_GRAPHICS_DEBUG_GROUP("CRadarPaintShader::draw", zeus::skMagenta);
if (instances.size() > m_maxInsts) {
m_maxInsts = instances.size();
m_tex = tex;
// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) {
// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Instance), m_maxInsts);
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CMatrix4f), 1);
//
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
// const std::array<boo::ObjToken<boo::ITexture>, 1> texs{m_tex->GetBooTexture()};
//
// m_dataBind =
// ctx.newShaderDataBinding(s_Pipeline, nullptr, m_vbo.get(), nullptr, bufs.size(), bufs.data(), stages.data(),
// nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr);
// return true;
// } BooTrace);
}
zeus::CMatrix4f uniMtx = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f();
// m_uniBuf->load(&uniMtx, sizeof(zeus::CMatrix4f));
size_t mapSz = sizeof(Instance) * instances.size();
// Instance* insts = reinterpret_cast<Instance*>(m_vbo->map(mapSz));
// memmove(insts, instances.data(), mapSz);
// m_vbo->unmap();
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawInstances(0, 4, instances.size());
}
} // namespace metaforce

View File

@ -1,36 +0,0 @@
#pragma once
#include <array>
#include <vector>
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <zeus/CColor.hpp>
#include <zeus/CVector2f.hpp>
#include <zeus/CVector3f.hpp>
namespace metaforce {
class CTexture;
class CRadarPaintShader {
public:
struct Instance {
std::array<zeus::CVector3f, 4> pos;
std::array<zeus::CVector2f, 4> uv;
zeus::CColor color;
};
private:
// boo::ObjToken<boo::IGraphicsBufferD> m_vbo;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
const CTexture* m_tex = nullptr;
size_t m_maxInsts = 0;
public:
static void Initialize();
static void Shutdown();
void draw(const std::vector<Instance>& instances, const CTexture* tex);
};
} // namespace metaforce

View File

@ -1,83 +0,0 @@
#include "Runtime/Graphics/Shaders/CRandomStaticFilter.hpp"
#include <array>
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Camera/CCameraFilter.hpp"
#include "Runtime/Graphics/CCubeRenderer.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
//static boo::ObjToken<boo::IShaderPipeline> s_AlphaPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_AddPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_MultPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_CookieCutterPipeline;
void CRandomStaticFilter::Initialize() {
// s_AlphaPipeline = hecl::conv->convert(Shader_CRandomStaticFilterAlpha{});
// s_AddPipeline = hecl::conv->convert(Shader_CRandomStaticFilterAdd{});
// s_MultPipeline = hecl::conv->convert(Shader_CRandomStaticFilterMult{});
// s_CookieCutterPipeline = hecl::conv->convert(Shader_CRandomStaticFilterCookieCutter{});
}
void CRandomStaticFilter::Shutdown() {
// s_AlphaPipeline.reset();
// s_AddPipeline.reset();
// s_MultPipeline.reset();
// s_CookieCutterPipeline.reset();
}
//static boo::ObjToken<boo::IShaderPipeline> SelectPipeline(EFilterType type) {
// switch (type) {
// case EFilterType::Blend:
// return s_AlphaPipeline;
// case EFilterType::Add:
// return s_AddPipeline;
// case EFilterType::Multiply:
// return s_MultPipeline;
// default:
// return {};
// }
//}
CRandomStaticFilter::CRandomStaticFilter(EFilterType type, bool cookieCutter) : m_cookieCutter(cookieCutter) {
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
// struct Vert {
// zeus::CVector2f m_pos;
// zeus::CVector2f m_uv;
// };
// const std::array<Vert, 4> verts{{
// {{-1.f, -1.f}, {0.f, 0.f}},
// {{-1.f, 1.f}, {0.f, 448.f}},
// {{1.f, -1.f}, {640.f, 0.f}},
// {{1.f, 1.f}, {640.f, 448.f}},
// }};
// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size());
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
//
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
// const std::array<boo::ObjToken<boo::ITexture>, 1> texs{g_Renderer->GetRandomStaticEntropyTex()};
// m_dataBind = ctx.newShaderDataBinding(m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type), m_vbo.get(),
// nullptr, nullptr, bufs.size(), bufs.data(), stages.data(), nullptr, nullptr,
// texs.size(), texs.data(), nullptr, nullptr);
// return true;
// } BooTrace);
}
void CRandomStaticFilter::draw(const zeus::CColor& color, float t) {
SCOPED_GRAPHICS_DEBUG_GROUP("CRandomStaticFilter::draw", zeus::skMagenta);
m_uniform.color = color;
m_uniform.randOff = ROUND_UP_32(int64_t(rand()) * 32767 / RAND_MAX);
m_uniform.discardThres = 1.f - t;
// m_uniBuf->load(&m_uniform, sizeof(Uniform));
//
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, 4);
}
} // namespace metaforce

View File

@ -1,42 +0,0 @@
#pragma once
#include "Runtime/CToken.hpp"
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <zeus/CColor.hpp>
namespace metaforce {
class CTexture;
enum class EFilterShape;
enum class EFilterType;
class CRandomStaticFilter {
struct Uniform {
zeus::CColor color;
float randOff;
float discardThres;
};
// boo::ObjToken<boo::IGraphicsBufferS> m_vbo;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
Uniform m_uniform;
bool m_cookieCutter;
public:
static void Initialize();
static void Shutdown();
explicit CRandomStaticFilter(EFilterType type, bool cookieCutter = false);
explicit CRandomStaticFilter(EFilterType type, const TLockedToken<CTexture>&) : CRandomStaticFilter(type) {}
void draw(const zeus::CColor& color, float t);
void DrawFilter(EFilterShape, const zeus::CColor& color, float t) { draw(color, t); }
};
class CCookieCutterDepthRandomStaticFilter : public CRandomStaticFilter {
public:
explicit CCookieCutterDepthRandomStaticFilter(EFilterType type) : CRandomStaticFilter(type, true) {}
explicit CCookieCutterDepthRandomStaticFilter(EFilterType type, const TLockedToken<CTexture>&)
: CCookieCutterDepthRandomStaticFilter(type) {}
};
} // namespace metaforce

View File

@ -1,67 +0,0 @@
#include "Runtime/Graphics/Shaders/CScanLinesFilter.hpp"
#include <array>
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Camera/CCameraFilter.hpp"
#include "Runtime/Graphics/CCubeRenderer.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
//static boo::ObjToken<boo::IShaderPipeline> s_AlphaPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_AddPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_MultPipeline;
void CScanLinesFilter::Initialize() {
// s_AlphaPipeline = hecl::conv->convert(Shader_CScanLinesFilterAlpha{});
// s_AddPipeline = hecl::conv->convert(Shader_CScanLinesFilterAdd{});
// s_MultPipeline = hecl::conv->convert(Shader_CScanLinesFilterMult{});
}
void CScanLinesFilter::Shutdown() {
// s_AlphaPipeline.reset();
// s_AddPipeline.reset();
// s_MultPipeline.reset();
}
//static boo::ObjToken<boo::IShaderPipeline> SelectPipeline(EFilterType type) {
// switch (type) {
// case EFilterType::Blend:
// return s_AlphaPipeline;
// case EFilterType::Add:
// return s_AddPipeline;
// case EFilterType::Multiply:
// return s_MultPipeline;
// default:
// return {};
// }
//}
CScanLinesFilter::CScanLinesFilter(EFilterType type, bool even) : m_even(even) {
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
// boo::ObjToken<boo::IGraphicsBuffer> vbo =
// m_even ? g_Renderer->GetScanLinesEvenVBO().get() : g_Renderer->GetScanLinesOddVBO().get();
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
//
// m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), vbo, nullptr, nullptr, bufs.size(), bufs.data(),
// stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr);
// return true;
// } BooTrace);
}
void CScanLinesFilter::draw(const zeus::CColor& color) {
SCOPED_GRAPHICS_DEBUG_GROUP("CScanLinesFilter::draw", zeus::skMagenta);
m_uniform.color = color;
// m_uniBuf->load(&m_uniform, sizeof(Uniform));
//
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, 670);
}
} // namespace metaforce

View File

@ -1,43 +0,0 @@
#pragma once
#include "Runtime/CToken.hpp"
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <zeus/CColor.hpp>
namespace metaforce {
class CTexture;
enum class EFilterShape;
enum class EFilterType;
class CScanLinesFilter {
struct Uniform {
zeus::CColor color;
};
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
Uniform m_uniform;
bool m_even;
public:
static void Initialize();
static void Shutdown();
explicit CScanLinesFilter(EFilterType type, bool even);
void draw(const zeus::CColor& color);
void DrawFilter(EFilterShape, const zeus::CColor& color, float) { draw(color); }
};
class CScanLinesFilterEven : public CScanLinesFilter {
public:
explicit CScanLinesFilterEven(EFilterType type) : CScanLinesFilter(type, true) {}
explicit CScanLinesFilterEven(EFilterType type, const TLockedToken<CTexture>&) : CScanLinesFilterEven(type) {}
};
class CScanLinesFilterOdd : public CScanLinesFilter {
public:
explicit CScanLinesFilterOdd(EFilterType type) : CScanLinesFilter(type, false) {}
explicit CScanLinesFilterOdd(EFilterType type, const TLockedToken<CTexture>&) : CScanLinesFilterOdd(type) {}
};
} // namespace metaforce

View File

@ -1,171 +0,0 @@
#include "Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp"
#include "Runtime/Graphics/CCubeRenderer.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
//#include <hecl/Pipeline.hpp>
#define WARP_RAMP_RES 32
namespace metaforce {
// static boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
void CSpaceWarpFilter::Initialize() {
// s_Pipeline = hecl::conv->convert(Shader_CSpaceWarpFilter{});
}
void CSpaceWarpFilter::Shutdown() {
// s_Pipeline.reset();
}
void CSpaceWarpFilter::GenerateWarpRampTex() {
std::array<std::array<std::array<u8, 4>, WARP_RAMP_RES + 1>, WARP_RAMP_RES + 1> data{};
const float halfRes = WARP_RAMP_RES / 2.f;
for (int y = 0; y < WARP_RAMP_RES + 1; ++y) {
for (int x = 0; x < WARP_RAMP_RES + 1; ++x) {
zeus::CVector2f vec((x - halfRes) / halfRes, (y - halfRes) / halfRes);
const float mag = vec.magnitude();
if (mag < 1.f && vec.canBeNormalized()) {
vec.normalize();
vec *= zeus::CVector2f(std::sqrt(mag));
}
data[y][x][3] = zeus::clamp(0, int((((vec.x() / 2.f + 0.5f) - x / float(WARP_RAMP_RES)) + 0.5f) * 255), 255);
data[y][x][2] = zeus::clamp(0, int((((vec.y() / 2.f + 0.5f) - y / float(WARP_RAMP_RES)) + 0.5f) * 255), 255);
data[y][x][0] = data[y][x][1] = data[y][x][2];
}
}
m_warpTex.emplace(ETexelFormat::RGBA8PC, WARP_RAMP_RES + 1, WARP_RAMP_RES + 1, 1, "Warp Ramp");
}
CSpaceWarpFilter::CSpaceWarpFilter() {
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
// GenerateWarpRampTex(ctx);
//
// struct Vert {
// zeus::CVector2f m_pos;
// zeus::CVector2f m_uv;
// };
// const std::array<Vert, 4> verts{{
// {{-1.f, -1.f}, {0.f, 0.f}},
// {{-1.f, 1.f}, {0.f, 1.f}},
// {{1.f, -1.f}, {1.f, 0.f}},
// {{1.f, 1.f}, {1.f, 1.f}},
// }};
//
// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size());
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
//
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
// const std::array<boo::ObjToken<boo::ITexture>, 2> texs{
// CGraphics::g_SpareTexture.get(),
// m_warpTex.get(),
// };
// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr,
// nullptr);
// return true;
// } BooTrace);
}
void CSpaceWarpFilter::draw(const zeus::CVector3f& pt) {
SCOPED_GRAPHICS_DEBUG_GROUP("CSpaceWarpFilter::draw", zeus::skMagenta);
/* Indirect coords are full-texture sampling when warp is completely in viewport */
m_uniform.m_indXf[1][1] = 1.f;
m_uniform.m_indXf[0][0] = 1.f;
m_uniform.m_indXf[2][0] = 0.f;
m_uniform.m_indXf[2][1] = 0.f;
/* Warp effect is fixed at 192x192 rectangle in original (1/2.5 viewport height) */
float aspect = CGraphics::g_CroppedViewport.xc_width / float(CGraphics::g_CroppedViewport.x10_height);
m_uniform.m_matrix[1][1] = 1.f / 2.5f;
m_uniform.m_matrix[0][0] = m_uniform.m_matrix[1][1] / aspect;
SClipScreenRect clipRect = {};
clipRect.x4_left = ((pt[0] - m_uniform.m_matrix[0][0]) / 2.f + 0.5f) * CGraphics::g_CroppedViewport.xc_width;
if (clipRect.x4_left >= CGraphics::g_CroppedViewport.xc_width)
return;
clipRect.x8_top = ((pt[1] - m_uniform.m_matrix[1][1]) / 2.f + 0.5f) * CGraphics::g_CroppedViewport.x10_height;
if (clipRect.x8_top >= CGraphics::g_CroppedViewport.x10_height)
return;
clipRect.xc_width = CGraphics::g_CroppedViewport.xc_width * m_uniform.m_matrix[0][0];
if (clipRect.x4_left + clipRect.xc_width <= 0)
return;
clipRect.x10_height = CGraphics::g_CroppedViewport.x10_height * m_uniform.m_matrix[1][1];
if (clipRect.x8_top + clipRect.x10_height <= 0)
return;
float oldW = clipRect.xc_width;
if (clipRect.x4_left < 0) {
clipRect.xc_width += clipRect.x4_left;
m_uniform.m_indXf[0][0] = clipRect.xc_width / oldW;
m_uniform.m_indXf[2][0] = -clipRect.x4_left / oldW;
clipRect.x4_left = 0;
}
float oldH = clipRect.x10_height;
if (clipRect.x8_top < 0) {
clipRect.x10_height += clipRect.x8_top;
m_uniform.m_indXf[1][1] = clipRect.x10_height / oldH;
m_uniform.m_indXf[2][1] = -clipRect.x8_top / oldH;
clipRect.x8_top = 0;
}
float tmp = clipRect.x4_left + clipRect.xc_width;
if (tmp >= CGraphics::g_CroppedViewport.xc_width) {
clipRect.xc_width = CGraphics::g_CroppedViewport.xc_width - clipRect.x4_left;
m_uniform.m_indXf[0][0] = clipRect.xc_width / oldW;
}
tmp = clipRect.x8_top + clipRect.x10_height;
if (tmp >= CGraphics::g_CroppedViewport.x10_height) {
clipRect.x10_height = CGraphics::g_CroppedViewport.x10_height - clipRect.x8_top;
m_uniform.m_indXf[1][1] = clipRect.x10_height / oldH;
}
/* Transform UV coordinates of rectangle within viewport and sampled scene texels (clamped to viewport bounds) */
zeus::CVector2f vp{float(CGraphics::g_CroppedViewport.xc_width), float(CGraphics::g_CroppedViewport.x10_height)};
m_uniform.m_matrix[0][0] = clipRect.xc_width / vp.x();
m_uniform.m_matrix[1][1] = clipRect.x10_height / vp.y();
m_uniform.m_matrix[3][0] = pt.x() + (1.f / vp.x());
m_uniform.m_matrix[3][1] = pt.y() + (1.f / vp.y());
// if (CGraphics::g_BooPlatform == boo::IGraphicsDataFactory::Platform::OpenGL) {
// m_uniform.m_matrix[3][2] = pt.z() * 2.f - 1.f;
// } else if (CGraphics::g_BooPlatform == boo::IGraphicsDataFactory::Platform::Vulkan) {
// m_uniform.m_matrix[1][1] *= -1.f;
// m_uniform.m_matrix[3][1] *= -1.f;
// m_uniform.m_matrix[3][2] = pt.z();
// } else {
// m_uniform.m_matrix[3][2] = pt.z();
// }
if (clipRect.x4_left) {
clipRect.x4_left -= 1;
clipRect.xc_width += 1;
}
if (clipRect.x8_top) {
clipRect.x8_top -= 1;
clipRect.x10_height += 1;
}
if (clipRect.x4_left + clipRect.xc_width < CGraphics::g_CroppedViewport.xc_width)
clipRect.xc_width += 1;
if (clipRect.x8_top + clipRect.x10_height < CGraphics::g_CroppedViewport.x10_height)
clipRect.x10_height += 1;
clipRect.x4_left += CGraphics::g_CroppedViewport.x4_left;
clipRect.x8_top += CGraphics::g_CroppedViewport.x8_top;
clipRect.x8_top = CGraphics::GetViewportHeight() - clipRect.x10_height - clipRect.x8_top;
// CGraphics::ResolveSpareTexture(clipRect);
m_uniform.m_strength.x() =
m_uniform.m_matrix[0][0] * m_strength * 0.5f * (clipRect.x10_height / float(clipRect.xc_width));
m_uniform.m_strength.y() = m_uniform.m_matrix[1][1] * m_strength * 0.5f;
// m_uniBuf->load(&m_uniform, sizeof(m_uniform));
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, 4);
}
} // namespace metaforce

View File

@ -1,38 +0,0 @@
#pragma once
#include <array>
#include "Runtime/GCNTypes.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
#include "Runtime/Graphics/CTexture.hpp"
#include <zeus/CMatrix4f.hpp>
#include <zeus/CVector3f.hpp>
namespace metaforce {
class CSpaceWarpFilter {
struct Uniform {
zeus::CMatrix4f m_matrix;
zeus::CMatrix4f m_indXf;
zeus::CVector3f m_strength;
};
std::array<std::array<std::array<u8, 4>, 8>, 4> m_shiftTexture{};
std::optional<CTexture> m_warpTex;
// boo::ObjToken<boo::IGraphicsBufferS> m_vbo;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
Uniform m_uniform;
float m_strength = 1.f;
void GenerateWarpRampTex();
public:
static void Initialize();
static void Shutdown();
CSpaceWarpFilter();
void setStrength(float strength) { m_strength = strength; }
void draw(const zeus::CVector3f& pt);
};
} // namespace metaforce

View File

@ -1,81 +0,0 @@
#include "Runtime/Graphics/Shaders/CTextSupportShader.hpp"
#include "Runtime/GuiSys/CFontImageDef.hpp"
#include "Runtime/GuiSys/CRasterFont.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
//boo::ObjToken<boo::IShaderPipeline> CTextSupportShader::s_TextAlphaPipeline;
//boo::ObjToken<boo::IShaderPipeline> CTextSupportShader::s_TextAddPipeline;
//boo::ObjToken<boo::IShaderPipeline> CTextSupportShader::s_TextAddOverdrawPipeline;
//
//boo::ObjToken<boo::IShaderPipeline> CTextSupportShader::s_ImageAlphaPipeline;
//boo::ObjToken<boo::IShaderPipeline> CTextSupportShader::s_ImageAddPipeline;
//boo::ObjToken<boo::IShaderPipeline> CTextSupportShader::s_ImageAddOverdrawPipeline;
//
//hecl::VertexBufferPool<CTextSupportShader::CharacterInstance> CTextSupportShader::s_CharInsts;
//hecl::VertexBufferPool<CTextSupportShader::ImageInstance> CTextSupportShader::s_ImgInsts;
//hecl::UniformBufferPool<CTextSupportShader::Uniform> CTextSupportShader::s_Uniforms;
void CTextSupportShader::Initialize() {
// s_TextAlphaPipeline = hecl::conv->convert(Shader_CTextSupportShaderAlpha{});
// s_TextAddPipeline = hecl::conv->convert(Shader_CTextSupportShaderAdd{});
// s_TextAddOverdrawPipeline = hecl::conv->convert(Shader_CTextSupportShaderAddOverdraw{});
// s_ImageAlphaPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAlpha{});
// s_ImageAddPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAdd{});
// s_ImageAddOverdrawPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAddOverdraw{});
}
void CTextSupportShader::Shutdown() {
// s_TextAlphaPipeline.reset();
// s_TextAddPipeline.reset();
// s_TextAddOverdrawPipeline.reset();
// s_ImageAlphaPipeline.reset();
// s_ImageAddPipeline.reset();
// s_ImageAddOverdrawPipeline.reset();
//
// s_CharInsts.doDestroy();
// s_ImgInsts.doDestroy();
// s_Uniforms.doDestroy();
}
void CTextSupportShader::CharacterInstance::SetMetrics(const CGlyph& glyph, const zeus::CVector2i& offset) {
float layer = glyph.GetLayer();
m_pos[0].assign(offset.x, 0.f, offset.y);
m_uv[0].assign(glyph.GetStartU(), 1.f - glyph.GetStartV(), layer);
m_pos[1].assign(offset.x + glyph.GetCellWidth(), 0.f, offset.y);
m_uv[1].assign(glyph.GetEndU(), 1.f - glyph.GetStartV(), layer);
m_pos[2].assign(offset.x, 0.f, offset.y + glyph.GetCellHeight());
m_uv[2].assign(glyph.GetStartU(), 1.f - glyph.GetEndV(), layer);
m_pos[3].assign(offset.x + glyph.GetCellWidth(), 0.f, offset.y + glyph.GetCellHeight());
m_uv[3].assign(glyph.GetEndU(), 1.f - glyph.GetEndV(), layer);
}
void CTextSupportShader::ImageInstance::SetMetrics(const CFontImageDef& imgDef, const zeus::CVector2i& offset) {
zeus::CVector2f imgSize;
if (imgDef.x4_texs.size()) {
const CTexture& tex = *imgDef.x4_texs[0].GetObj();
imgSize.assign(tex.GetWidth() * imgDef.x14_cropFactor.x(), tex.GetHeight() * imgDef.x14_cropFactor.y());
}
zeus::CVector2f cropPad = imgDef.x14_cropFactor * 0.5f;
m_pos[0].assign(offset.x, 0.f, offset.y);
m_uv[0].assign(0.5f - cropPad.x(), 0.5f + cropPad.y());
m_pos[1].assign(offset.x + imgSize.x(), 0.f, offset.y);
m_uv[1].assign(0.5f + cropPad.x(), 0.5f + cropPad.y());
m_pos[2].assign(offset.x, 0.f, offset.y + imgSize.y());
m_uv[2].assign(0.5f - cropPad.x(), 0.5f - cropPad.y());
m_pos[3].assign(offset.x + imgSize.x(), 0.f, offset.y + imgSize.y());
m_uv[3].assign(0.5f + cropPad.x(), 0.5f - cropPad.y());
}
} // namespace metaforce

View File

@ -1,100 +0,0 @@
#pragma once
#include <array>
#include "Runtime/GuiSys/CGuiWidget.hpp"
//#include <hecl/UniformBufferPool.hpp>
//#include <hecl/VertexBufferPool.hpp>
#include <zeus/CColor.hpp>
#include <zeus/CMatrix4f.hpp>
#include <zeus/CVector2f.hpp>
#include <zeus/CVector2i.hpp>
#include <zeus/CVector3f.hpp>
namespace metaforce {
class CGlyph;
class CFontImageDef;
class CTextRenderBuffer;
class CTextSupportShader {
friend class CTextRenderBuffer;
// static boo::ObjToken<boo::IShaderPipeline> s_TextAlphaPipeline;
// static boo::ObjToken<boo::IShaderPipeline> s_TextAddPipeline;
// static boo::ObjToken<boo::IShaderPipeline> s_TextAddOverdrawPipeline;
//
// static boo::ObjToken<boo::IShaderPipeline> s_ImageAlphaPipeline;
// static boo::ObjToken<boo::IShaderPipeline> s_ImageAddPipeline;
// static boo::ObjToken<boo::IShaderPipeline> s_ImageAddOverdrawPipeline;
struct Uniform {
zeus::CMatrix4f m_mvp;
zeus::CColor m_uniformColor;
};
struct CharacterInstance {
std::array<zeus::CVector3f, 4> m_pos;
std::array<zeus::CVector3f, 4> m_uv;
zeus::CColor m_fontColor;
zeus::CColor m_outlineColor;
zeus::CColor m_mulColor;
void SetMetrics(const CGlyph& glyph, const zeus::CVector2i& offset);
};
struct ImageInstance {
std::array<zeus::CVector3f, 4> m_pos;
std::array<zeus::CVector2f, 4> m_uv;
zeus::CColor m_color;
void SetMetrics(const CFontImageDef& imgDef, const zeus::CVector2i& offset);
};
// static hecl::VertexBufferPool<CharacterInstance> s_CharInsts;
// static hecl::VertexBufferPool<ImageInstance> s_ImgInsts;
// static hecl::UniformBufferPool<Uniform> s_Uniforms;
public:
// static boo::ObjToken<boo::IShaderPipeline> SelectTextPipeline(CGuiWidget::EGuiModelDrawFlags df) {
// switch (df) {
// case CGuiWidget::EGuiModelDrawFlags::Shadeless:
// case CGuiWidget::EGuiModelDrawFlags::Opaque:
// case CGuiWidget::EGuiModelDrawFlags::Alpha:
// case CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw:
// return s_TextAlphaPipeline;
// case CGuiWidget::EGuiModelDrawFlags::Additive:
// return s_TextAddPipeline;
// default:
// return {};
// }
// }
//
// static boo::ObjToken<boo::IShaderPipeline> SelectImagePipeline(CGuiWidget::EGuiModelDrawFlags df) {
// switch (df) {
// case CGuiWidget::EGuiModelDrawFlags::Shadeless:
// case CGuiWidget::EGuiModelDrawFlags::Opaque:
// case CGuiWidget::EGuiModelDrawFlags::Alpha:
// case CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw:
// return s_ImageAlphaPipeline;
// case CGuiWidget::EGuiModelDrawFlags::Additive:
// return s_ImageAddPipeline;
// default:
// return {};
// }
// }
//
// static boo::ObjToken<boo::IShaderPipeline> GetTextAdditiveOverdrawPipeline() { return s_TextAddOverdrawPipeline; }
//
// static boo::ObjToken<boo::IShaderPipeline> GetImageAdditiveOverdrawPipeline() { return s_ImageAddOverdrawPipeline; }
static void UpdateBuffers() {
// s_CharInsts.updateBuffers();
// s_ImgInsts.updateBuffers();
// s_Uniforms.updateBuffers();
}
static void Initialize();
static void Shutdown();
};
} // namespace metaforce

View File

@ -1,346 +0,0 @@
#include "Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp"
#include <array>
#include "Runtime/Camera/CCameraFilter.hpp"
#include "Runtime/Graphics/CTexture.hpp"
//#include <hecl/Pipeline.hpp>
namespace metaforce {
//static boo::ObjToken<boo::IShaderPipeline> s_AlphaPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_AlphaGEqualPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_AlphaGEqualZWritePipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_AlphaLEqualPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_AddPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_AddGEqualPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_AddGEqualZWritePipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_AddLEqualPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_SubtractPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_SubtractGEqualPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_SubtractGEqualZWritePipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_SubtractLEqualPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_MultPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_MultGEqualPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_MultGEqualZWritePipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_MultLEqualPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_InvDstMultPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_InvDstMultGEqualPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_InvDstMultLEqualPipeline;
//
//static boo::ObjToken<boo::IShaderPipeline> s_AAlphaPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_AAddPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_ASubtractPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_AMultPipeline;
//static boo::ObjToken<boo::IShaderPipeline> s_AInvDstMultPipeline;
void CTexturedQuadFilter::Initialize() {
// s_AlphaPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlpha{});
// s_AlphaGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaGEqual{});
// s_AlphaGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaGEqualZWrite{});
// s_AlphaLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaLEqual{});
// s_AddPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAdd{});
// s_AddGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddGEqual{});
// s_AddGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddGEqualZWrite{});
// s_AddLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddLEqual{});
// s_SubtractPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtract{});
// s_SubtractGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractGEqual{});
// s_SubtractGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractGEqualZWrite{});
// s_SubtractLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractLEqual{});
// s_MultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMult{});
// s_MultGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMultGEqual{});
// s_MultGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMultGEqualZWrite{});
// s_MultLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMultLEqual{});
// s_InvDstMultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterInvDstMult{});
// s_InvDstMultGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterInvDstMultGEqual{});
// s_InvDstMultLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterInvDstMultLEqual{});
}
void CTexturedQuadFilter::Shutdown() {
// s_AlphaPipeline.reset();
// s_AlphaGEqualPipeline.reset();
// s_AlphaGEqualZWritePipeline.reset();
// s_AlphaLEqualPipeline.reset();
// s_AddPipeline.reset();
// s_AddGEqualPipeline.reset();
// s_AddGEqualZWritePipeline.reset();
// s_AddLEqualPipeline.reset();
// s_SubtractPipeline.reset();
// s_SubtractGEqualPipeline.reset();
// s_SubtractGEqualZWritePipeline.reset();
// s_SubtractLEqualPipeline.reset();
// s_MultPipeline.reset();
// s_MultGEqualPipeline.reset();
// s_MultGEqualZWritePipeline.reset();
// s_MultLEqualPipeline.reset();
// s_InvDstMultPipeline.reset();
// s_InvDstMultGEqualPipeline.reset();
// s_InvDstMultLEqualPipeline.reset();
}
void CTexturedQuadFilterAlpha::Initialize() {
// s_AAlphaPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexAlpha{});
// s_AAddPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexAdd{});
// s_ASubtractPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexSubtract{});
// s_AMultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexMult{});
// s_AInvDstMultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexInvDstMult{});
}
void CTexturedQuadFilterAlpha::Shutdown() {
// s_AAlphaPipeline.reset();
// s_AAddPipeline.reset();
// s_ASubtractPipeline.reset();
// s_AMultPipeline.reset();
// s_AInvDstMultPipeline.reset();
}
//static boo::ObjToken<boo::IShaderPipeline> SelectPipeline(EFilterType type, CTexturedQuadFilter::ZTest zTest) {
// switch (zTest) {
// case CTexturedQuadFilter::ZTest::GEqual:
// switch (type) {
// case EFilterType::Blend:
// return s_AlphaGEqualPipeline;
// case EFilterType::Add:
// return s_AddGEqualPipeline;
// case EFilterType::Subtract:
// return s_SubtractGEqualPipeline;
// case EFilterType::Multiply:
// return s_MultGEqualPipeline;
// default:
// break;
// }
// break;
// case CTexturedQuadFilter::ZTest::GEqualZWrite:
// switch (type) {
// case EFilterType::Blend:
// return s_AlphaGEqualZWritePipeline;
// case EFilterType::Add:
// return s_AddGEqualZWritePipeline;
// case EFilterType::Subtract:
// return s_SubtractGEqualZWritePipeline;
// case EFilterType::Multiply:
// return s_MultGEqualZWritePipeline;
// default:
// break;
// }
// break;
// case CTexturedQuadFilter::ZTest::LEqual:
// switch (type) {
// case EFilterType::Blend:
// return s_AlphaLEqualPipeline;
// case EFilterType::Add:
// return s_AddLEqualPipeline;
// case EFilterType::Subtract:
// return s_SubtractLEqualPipeline;
// case EFilterType::Multiply:
// return s_MultLEqualPipeline;
// case EFilterType::InvDstMultiply:
// return s_InvDstMultLEqualPipeline;
// default:
// break;
// }
// break;
// default:
// break;
// }
//
// switch (type) {
// case EFilterType::Blend:
// return s_AlphaPipeline;
// case EFilterType::Add:
// return s_AddPipeline;
// case EFilterType::Subtract:
// return s_SubtractPipeline;
// case EFilterType::Multiply:
// return s_MultPipeline;
// case EFilterType::InvDstMultiply:
// return s_InvDstMultPipeline;
// default:
// return {};
// }
//}
//static boo::ObjToken<boo::IShaderPipeline> SelectAlphaPipeline(EFilterType type) {
// switch (type) {
// case EFilterType::Blend:
// return s_AAlphaPipeline;
// case EFilterType::Add:
// return s_AAddPipeline;
// case EFilterType::Subtract:
// return s_ASubtractPipeline;
// case EFilterType::Multiply:
// return s_AMultPipeline;
// case EFilterType::InvDstMultiply:
// return s_AInvDstMultPipeline;
// default:
// return {};
// }
//}
CTexturedQuadFilter::CTexturedQuadFilter(const aurora::gfx::TextureHandle& tex) : m_booTex(tex) {
m_flipRect = true; // TODO?
}
CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, const aurora::gfx::TextureHandle& tex, ERglEnum ztest)
: m_booTex(tex), m_zTest(ztest) {
m_flipRect = true; // TODO?
// tex->setClampMode(boo::TextureClampMode::ClampToEdge);
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 16);
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
//
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
// const std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
// const std::array<boo::ObjToken<boo::ITexture>, 1> texs{m_booTex.get()};
// m_dataBind =
// ctx.newShaderDataBinding(SelectPipeline(type, m_zTest), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr);
// return true;
// } BooTrace);
}
CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, TLockedToken<CTexture> tex, ERglEnum ztest)
: CTexturedQuadFilter(type, aurora::gfx::TextureHandle{}, ztest) {
m_flipRect = true; // TODO?
m_tex = tex;
}
void CTexturedQuadFilter::draw(const zeus::CColor& color, float uvScale, const zeus::CRectangle& rect, float z) {
SCOPED_GRAPHICS_DEBUG_GROUP("CTexturedQuadFilter::draw", zeus::skMagenta);
const std::array<Vert, 4> verts{{
{{0.f, 0.f, z}, {0.f, 0.f}},
{{0.f, 1.f, z}, {0.f, uvScale}},
{{1.f, 0.f, z}, {uvScale, 0.f}},
{{1.f, 1.f, z}, {uvScale, uvScale}},
}};
// m_vbo->load(verts.data(), sizeof(verts));
if (!m_flipRect) {
m_uniform.m_matrix[0][0] = rect.size.x() * 2.f;
m_uniform.m_matrix[1][1] = rect.size.y() * 2.f;
m_uniform.m_matrix[3][0] = rect.position.x() * 2.f - 1.f;
m_uniform.m_matrix[3][1] = rect.position.y() * 2.f - 1.f;
} else {
m_uniform.m_matrix[0][0] = rect.size.x() * 2.f;
m_uniform.m_matrix[1][1] = rect.size.y() * -2.f;
m_uniform.m_matrix[3][0] = rect.position.x() * 2.f - 1.f;
m_uniform.m_matrix[3][1] = rect.position.y() * -2.f + 1.f;
}
m_uniform.m_color = color;
// m_uniBuf->load(&m_uniform, sizeof(m_uniform));
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, 4);
}
void CTexturedQuadFilter::drawCropped(const zeus::CColor& color, float uvScale) {
SCOPED_GRAPHICS_DEBUG_GROUP("CTexturedQuadFilter::drawCropped", zeus::skMagenta);
const float xFac = CGraphics::GetCroppedViewportWidth() / float(CGraphics::GetViewportWidth());
const float yFac = CGraphics::GetCroppedViewportHeight() / float(CGraphics::GetViewportHeight());
const float xBias = CGraphics::GetCroppedViewportLeft() / float(CGraphics::GetViewportWidth());
const float yBias = CGraphics::GetCroppedViewportTop() / float(CGraphics::GetViewportHeight());
const std::array<Vert, 4> verts{{
{{-1.f, -1.f, 0.f}, {xBias * uvScale, yBias * uvScale}},
{{-1.f, 1.f, 0.f}, {xBias * uvScale, (yBias + yFac) * uvScale}},
{{1.f, -1.f, 0.f}, {(xBias + xFac) * uvScale, yBias * uvScale}},
{{1.f, 1.f, 0.f}, {(xBias + xFac) * uvScale, (yBias + yFac) * uvScale}},
}};
// m_vbo->load(verts.data(), sizeof(verts));
m_uniform.m_color = color;
// m_uniBuf->load(&m_uniform, sizeof(m_uniform));
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, 4);
}
void CTexturedQuadFilter::drawVerts(const zeus::CColor& color, std::array<Vert, 4> verts, float lod) {
SCOPED_GRAPHICS_DEBUG_GROUP("CTexturedQuadFilter::drawVerts", zeus::skMagenta);
// m_vbo->load(verts.data(), sizeof(Vert) * verts.size());
m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f();
m_uniform.m_color = color;
m_uniform.m_lod = lod;
// m_uniBuf->load(&m_uniform, sizeof(m_uniform));
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, verts.size());
}
void CTexturedQuadFilter::DrawFilter(EFilterShape shape, const zeus::CColor& color, float t) {
SCOPED_GRAPHICS_DEBUG_GROUP("CTexturedQuadFilter::DrawFilter", zeus::skMagenta);
m_uniform.m_matrix = zeus::CMatrix4f();
m_uniform.m_lod = 0.f;
m_uniform.m_color = color;
// m_uniBuf->load(&m_uniform, sizeof(m_uniform));
// CGraphics::SetShaderDataBinding(m_dataBind);
if (shape == EFilterShape::FullscreenQuarters) {
const std::array<Vert, 16> QuadVerts{{
// ll
{{-1.f, -1.f, 0.f}, {t, t}},
{{-1.f, 0.f, 0.f}, {t, 0.f}},
{{0.f, -1.f, 0.f}, {0.f, t}},
{{0.f, 0.f, 0.f}, {0.f, 0.f}},
// ul
{{-1.f, 1.f, 0.f}, {t, t}},
{{-1.f, 0.f, 0.f}, {t, 0.f}},
{{0.f, 1.f, 0.f}, {0.f, t}},
{{0.f, 0.f, 0.f}, {0.f, 0.f}},
// lr
{{1.f, -1.f, 0.f}, {t, t}},
{{1.f, 0.f, 0.f}, {t, 0.f}},
{{0.f, -1.f, 0.f}, {0.f, t}},
{{0.f, 0.f, 0.f}, {0.f, 0.f}},
// ur
{{1.f, 1.f, 0.f}, {t, t}},
{{1.f, 0.f, 0.f}, {t, 0.f}},
{{0.f, 1.f, 0.f}, {0.f, t}},
{{0.f, 0.f, 0.f}, {0.f, 0.f}},
}};
// m_vbo->load(QuadVerts.data(), sizeof(QuadVerts));
// CGraphics::DrawArray(0, 4);
// CGraphics::DrawArray(4, 4);
// CGraphics::DrawArray(8, 4);
// CGraphics::DrawArray(12, 4);
} else {
const std::array<Vert, 4> FullscreenVerts{{
{{-1.f, -1.f, 0.f}, {0.f, 0.f}},
{{-1.f, 1.f, 0.f}, {0.f, t}},
{{1.f, -1.f, 0.f}, {t, 0.f}},
{{1.f, 1.f, 0.f}, {t, t}},
}};
// m_vbo->load(FullscreenVerts.data(), sizeof(FullscreenVerts));
// CGraphics::DrawArray(0, FullscreenVerts.size());
}
}
CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, const aurora::gfx::TextureHandle& tex)
: CTexturedQuadFilter(tex) {
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4);
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
//
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
// const std::array<boo::ObjToken<boo::ITexture>, 1> texs{m_booTex.get()};
// m_dataBind =
// ctx.newShaderDataBinding(SelectAlphaPipeline(type), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr);
// return true;
// } BooTrace);
}
CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, TLockedToken<CTexture> tex)
: CTexturedQuadFilterAlpha(type, aurora::gfx::TextureHandle{}) {
m_tex = tex;
}
} // namespace metaforce

View File

@ -1,70 +0,0 @@
#pragma once
#include "Runtime/CToken.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
#include <zeus/CColor.hpp>
#include <zeus/CMatrix4f.hpp>
#include <zeus/CRectangle.hpp>
#include <zeus/CVector2f.hpp>
#include <zeus/CVector3f.hpp>
namespace metaforce {
class CTexture;
enum class EFilterShape;
enum class EFilterType;
class CTexturedQuadFilter {
public:
enum class ZTest { Never, Less, Equal, LEqual, Greater, NEqual, GEqual, Always };
protected:
struct Uniform {
zeus::CMatrix4f m_matrix;
zeus::CColor m_color;
float m_lod = 0.f;
};
TLockedToken<CTexture> m_tex;
aurora::gfx::TextureHandle m_booTex;
// boo::ObjToken<boo::IGraphicsBufferD> m_vbo;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
Uniform m_uniform;
ERglEnum m_zTest;
bool m_flipRect = false;
explicit CTexturedQuadFilter(const aurora::gfx::TextureHandle& tex);
public:
struct Vert {
zeus::CVector3f m_pos;
zeus::CVector2f m_uv;
};
static void Initialize();
static void Shutdown();
static constexpr zeus::CRectangle DefaultRect{0.f, 0.f, 1.f, 1.f};
explicit CTexturedQuadFilter(EFilterType type, TLockedToken<CTexture> tex, ERglEnum zTest = ERglEnum::Never);
explicit CTexturedQuadFilter(EFilterType type, const aurora::gfx::TextureHandle& tex,
ERglEnum zTest = ERglEnum::Never);
CTexturedQuadFilter(const CTexturedQuadFilter&) = delete;
CTexturedQuadFilter& operator=(const CTexturedQuadFilter&) = delete;
CTexturedQuadFilter(CTexturedQuadFilter&&) = default;
CTexturedQuadFilter& operator=(CTexturedQuadFilter&&) = default;
void draw(const zeus::CColor& color, float uvScale, const zeus::CRectangle& rect = DefaultRect, float z = 0.f);
void drawCropped(const zeus::CColor& color, float uvScale);
void drawVerts(const zeus::CColor& color, std::array<Vert, 4> verts, float lod = 0.f);
void DrawFilter(EFilterShape shape, const zeus::CColor& color, float t);
const TLockedToken<CTexture>& GetTex() const { return m_tex; }
const aurora::gfx::TextureHandle& GetBooTex() const { return m_booTex; }
};
class CTexturedQuadFilterAlpha : public CTexturedQuadFilter {
public:
static void Initialize();
static void Shutdown();
explicit CTexturedQuadFilterAlpha(EFilterType type, TLockedToken<CTexture> tex);
explicit CTexturedQuadFilterAlpha(EFilterType type, const aurora::gfx::TextureHandle& tex);
};
} // namespace metaforce

View File

@ -1,62 +0,0 @@
#include "Runtime/Graphics/Shaders/CThermalColdFilter.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Graphics/CCubeRenderer.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
//#include <hecl/Pipeline.hpp>
#include <zeus/CVector2f.hpp>
namespace metaforce {
//static boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
void CThermalColdFilter::Initialize() {
// s_Pipeline = hecl::conv->convert(Shader_CThermalColdFilter{});
}
void CThermalColdFilter::Shutdown() {
// s_Pipeline.reset();
}
CThermalColdFilter::CThermalColdFilter() {
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
// struct Vert {
// zeus::CVector2f m_pos;
// zeus::CVector2f m_uv;
// zeus::CVector2f m_uvNoise;
// };
// const std::array<Vert, 4> verts{{
// {{-1.f, -1.f}, {0.f, 0.f}, {0.f, 0.f}},
// {{-1.f, 1.f}, {0.f, 1.f}, {0.f, 448.f}},
// {{1.f, -1.f}, {1.f, 0.f}, {640.f, 0.f}},
// {{1.f, 1.f}, {1.f, 1.f}, {640.f, 448.f}},
// }};
// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 48, verts.size());
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
//
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
// const std::array<boo::ObjToken<boo::ITexture>, 2> texs{
// CGraphics::g_SpareTexture.get(),
// g_Renderer->GetRandomStaticEntropyTex(),
// };
// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr);
// return true;
// } BooTrace);
setNoiseOffset(0);
setScale(0.f);
}
void CThermalColdFilter::draw() {
SCOPED_GRAPHICS_DEBUG_GROUP("CThermalColdFilter::draw", zeus::skMagenta);
// CGraphics::ResolveSpareTexture(CGraphics::g_CroppedViewport);
// m_uniBuf->load(&m_uniform, sizeof(m_uniform));
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, 4);
}
} // namespace metaforce

View File

@ -1,39 +0,0 @@
#pragma once
#include <array>
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <zeus/CColor.hpp>
#include <zeus/CMatrix4f.hpp>
namespace metaforce {
class CThermalColdFilter {
struct Uniform {
zeus::CMatrix4f m_indMtx;
std::array<zeus::CColor, 3> m_colorRegs;
float m_randOff = 0.f;
};
// boo::ObjToken<boo::IGraphicsBufferS> m_vbo;
// boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
// boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
Uniform m_uniform;
public:
static void Initialize();
static void Shutdown();
CThermalColdFilter();
void setNoiseOffset(unsigned shift) { m_uniform.m_randOff = float(shift); }
void setColorA(const zeus::CColor& color) { m_uniform.m_colorRegs[0] = color; }
void setColorB(const zeus::CColor& color) { m_uniform.m_colorRegs[1] = color; }
void setColorC(const zeus::CColor& color) { m_uniform.m_colorRegs[2] = color; }
void setScale(float scale) {
scale = 0.025f * (1.f - scale);
m_uniform.m_indMtx[0][0] = scale;
m_uniform.m_indMtx[1][1] = scale;
}
void draw();
};
} // namespace metaforce

View File

@ -1,60 +0,0 @@
#include "Runtime/Graphics/Shaders/CThermalHotFilter.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Graphics/CCubeRenderer.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
//#include <hecl/Pipeline.hpp>
#include <zeus/CVector2f.hpp>
namespace metaforce {
//static boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
void CThermalHotFilter::Initialize() {
// s_Pipeline = hecl::conv->convert(Shader_CThermalHotFilter{});
}
void CThermalHotFilter::Shutdown() {
// s_Pipeline.reset();
}
CThermalHotFilter::CThermalHotFilter() {
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
// struct Vert {
// zeus::CVector2f m_pos;
// zeus::CVector2f m_uv;
// };
// const std::array<Vert, 4> verts{{
// {{-1.0, -1.0}, {0.0, 0.0}},
// {{-1.0, 1.0}, {0.0, 1.0}},
// {{1.0, -1.0}, {1.0, 0.0}},
// {{1.0, 1.0}, {1.0, 1.0}},
// }};
// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size());
// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
//
// const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
// constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
// const std::array<boo::ObjToken<boo::ITexture>, 2> texs{
// CGraphics::g_SpareTexture.get(),
// g_Renderer->GetThermoPalette(),
// };
// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr);
// return true;
// } BooTrace);
}
void CThermalHotFilter::draw() {
SCOPED_GRAPHICS_DEBUG_GROUP("CThermalHotFilter::draw", zeus::skMagenta);
// CGraphics::ResolveSpareTexture(CGraphics::g_CroppedViewport);
// m_uniBuf->load(&m_uniform, sizeof(m_uniform));
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, 4);
}
} // namespace metaforce

Some files were not shown because too many files have changed in this diff Show More