2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CMorphBallShadow.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
2022-02-25 07:45:25 +00:00
|
|
|
#include "Runtime/Graphics/CCubeRenderer.hpp"
|
2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/Particle/CGenDescription.hpp"
|
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
|
|
|
#include "Runtime/World/CWorld.hpp"
|
2017-03-05 07:57:12 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
void CMorphBallShadow::GatherAreas(const CStateManager& mgr) {
|
|
|
|
x18_areas.clear();
|
|
|
|
for (const CGameArea& area : *mgr.GetWorld()) {
|
|
|
|
CGameArea::EOcclusionState occState = CGameArea::EOcclusionState::Occluded;
|
|
|
|
if (area.IsPostConstructed())
|
|
|
|
occState = area.GetPostConstructed()->x10dc_occlusionState;
|
|
|
|
if (occState == CGameArea::EOcclusionState::Visible)
|
2020-10-21 22:55:45 +00:00
|
|
|
x18_areas.push_back(area.GetAreaId());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-05 07:57:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMorphBallShadow::RenderIdBuffer(const zeus::CAABox& aabb, const CStateManager& mgr, CPlayer& player) {
|
|
|
|
xb8_shadowVolume = aabb;
|
|
|
|
x0_actors.clear();
|
|
|
|
x18_areas.clear();
|
|
|
|
x30_worldModelBits.clear();
|
|
|
|
g_Renderer->x318_26_requestRGBA6 = true;
|
|
|
|
|
|
|
|
if (!g_Renderer->x318_27_currentRGBA6) {
|
|
|
|
xd0_hasIds = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GatherAreas(mgr);
|
|
|
|
|
|
|
|
SViewport backupVp = g_Viewport;
|
2022-02-25 07:45:25 +00:00
|
|
|
// g_Renderer->BindBallShadowIdTarget();
|
|
|
|
// CGraphics::g_BooMainCommandQueue->clearTarget();
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
zeus::CTransform backupViewMtx = CGraphics::g_ViewMatrix;
|
|
|
|
CGraphics::CProjectionState backupProjection = CGraphics::g_Proj;
|
|
|
|
zeus::CVector2f backupDepth = CGraphics::g_CachedDepthRange;
|
|
|
|
zeus::CTransform viewMtx(
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::skRight, zeus::skDown, zeus::skForward,
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f((aabb.min.x() + aabb.max.x()) * 0.5f, (aabb.min.y() + aabb.max.y()) * 0.5f, aabb.max.z()));
|
|
|
|
|
|
|
|
CGraphics::SetDepthRange(DEPTH_NEAR, DEPTH_FAR);
|
|
|
|
float vpX = (aabb.max.x() - aabb.min.x()) * 0.5f;
|
|
|
|
float vpY = (aabb.max.y() - aabb.min.y()) * 0.5f;
|
|
|
|
float vpZ = (aabb.max.z() - aabb.min.z()) + FLT_EPSILON;
|
|
|
|
CGraphics::SetOrtho(-vpX, vpX, vpY, -vpY, 0.f, vpZ);
|
|
|
|
|
2021-06-07 00:07:45 +00:00
|
|
|
EntityList nearItems;
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.BuildNearList(nearItems, aabb, CMaterialFilter::skPassEverything, &player);
|
|
|
|
|
|
|
|
CGraphics::SetViewPointMatrix(viewMtx);
|
|
|
|
|
|
|
|
int alphaVal = 4;
|
|
|
|
for (TUniqueId id : nearItems) {
|
|
|
|
if (alphaVal > 255)
|
|
|
|
break;
|
2017-03-05 07:57:12 +00:00
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
CActor* actor = static_cast<CActor*>(mgr.ObjectById(id));
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!actor || !actor->CanDrawStatic())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
x0_actors.push_back(actor);
|
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
auto* modelData = actor->GetModelData();
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CTransform modelXf = actor->GetTransform() * zeus::CTransform::Scale(modelData->GetScale());
|
|
|
|
CGraphics::SetModelMatrix(modelXf);
|
|
|
|
|
|
|
|
CModelFlags flags(0, 0, 3, zeus::CColor{1.f, 1.f, 1.f, alphaVal / 255.f});
|
2022-02-25 07:45:25 +00:00
|
|
|
// flags.m_extendedShader = EExtendedShader::SolidColor; // Do solid color draw
|
|
|
|
auto& model = *modelData->PickStaticModel(CModelData::EWhichModel::Normal);
|
2020-03-18 05:14:36 +00:00
|
|
|
model.VerifyCurrentShader(flags.x1_matSetIdx);
|
2022-02-25 07:45:25 +00:00
|
|
|
model.DrawUnsortedParts(flags);
|
2018-12-08 05:30:43 +00:00
|
|
|
alphaVal += 4;
|
|
|
|
}
|
|
|
|
|
2019-02-24 07:15:54 +00:00
|
|
|
CGraphics::SetModelMatrix(zeus::CTransform());
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
g_Renderer->FindOverlappingWorldModels(x30_worldModelBits, aabb);
|
|
|
|
alphaVal = g_Renderer->DrawOverlappingWorldModelIDs(alphaVal, x30_worldModelBits, aabb);
|
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
// g_Renderer->ResolveBallShadowIdTarget();
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
// g_Renderer->BindMainDrawTarget();
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::SetViewPointMatrix(backupViewMtx);
|
|
|
|
CGraphics::SetProjectionState(backupProjection);
|
|
|
|
g_Renderer->SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height);
|
|
|
|
CGraphics::SetDepthRange(backupDepth[0], backupDepth[1]);
|
|
|
|
|
|
|
|
xd0_hasIds = alphaVal != 4;
|
2017-03-05 07:57:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CMorphBallShadow::AreasValid(const CStateManager& mgr) const {
|
|
|
|
auto it = x18_areas.begin();
|
|
|
|
for (const CGameArea& area : *mgr.GetWorld()) {
|
|
|
|
CGameArea::EOcclusionState occState = CGameArea::EOcclusionState::Occluded;
|
|
|
|
if (area.IsPostConstructed())
|
|
|
|
occState = area.GetPostConstructed()->x10dc_occlusionState;
|
|
|
|
if (occState != CGameArea::EOcclusionState::Visible)
|
|
|
|
continue;
|
|
|
|
if (it == x18_areas.end())
|
|
|
|
return false;
|
2020-10-21 22:55:45 +00:00
|
|
|
if (*it != area.GetAreaId())
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
return true;
|
2017-03-05 07:57:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMorphBallShadow::Render(const CStateManager& mgr, float alpha) {
|
|
|
|
if (!xd0_hasIds || !AreasValid(mgr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
CModelFlags flags;
|
|
|
|
flags.x4_color.a() = alpha;
|
2022-02-25 07:45:25 +00:00
|
|
|
// flags.m_extendedShader = EExtendedShader::MorphBallShadow;
|
|
|
|
// flags.mbShadowBox = xb8_shadowVolume;
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
int alphaVal = 4;
|
2022-02-25 07:45:25 +00:00
|
|
|
for (auto* actor : x0_actors) {
|
|
|
|
auto* modelData = actor->GetModelData();
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CTransform modelXf = actor->GetTransform() * zeus::CTransform::Scale(modelData->GetScale());
|
|
|
|
CGraphics::SetModelMatrix(modelXf);
|
|
|
|
|
|
|
|
flags.x4_color.r() = alphaVal / 255.f;
|
2022-02-25 07:45:25 +00:00
|
|
|
auto& model = *modelData->PickStaticModel(CModelData::EWhichModel::Normal);
|
2020-03-18 05:14:36 +00:00
|
|
|
model.VerifyCurrentShader(flags.x1_matSetIdx);
|
2022-02-25 07:45:25 +00:00
|
|
|
model.DrawUnsortedParts(flags);
|
2018-12-08 05:30:43 +00:00
|
|
|
alphaVal += 4;
|
|
|
|
}
|
|
|
|
|
2019-02-24 07:15:54 +00:00
|
|
|
CGraphics::SetModelMatrix(zeus::CTransform());
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->DrawOverlappingWorldModelShadows(alphaVal, x30_worldModelBits, xb8_shadowVolume, alpha);
|
2017-03-05 07:57:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|