metaforce/Runtime/Graphics/CBooRenderer.cpp

1411 lines
51 KiB
C++
Raw Permalink Normal View History

#include "Runtime/Graphics/CBooRenderer.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/rstl.hpp"
#include "Runtime/Collision/CAreaOctTree.hpp"
#include "Runtime/Graphics/CMetroidModelInstance.hpp"
#include "Runtime/Graphics/CModel.hpp"
#include "Runtime/Graphics/CSkinnedModel.hpp"
#include "Runtime/Particle/CDecal.hpp"
#include "Runtime/Particle/CElementGen.hpp"
#include "Runtime/Particle/CGenDescription.hpp"
#include "Runtime/Particle/CParticleGen.hpp"
#include "Runtime/World/CActor.hpp"
#include <algorithm>
#include <array>
#include <logvisor/logvisor.hpp>
#include <zeus/CColor.hpp>
#include <zeus/CUnitVector.hpp>
#include <zeus/CVector3d.hpp>
#include <zeus/CVector4f.hpp>
2016-07-25 22:52:02 +00:00
#define FOGVOL_RAMP_RES 256
#define FOGVOL_FAR 750.0
#define FOGVOL_NEAR 0.2
2016-07-25 22:52:02 +00:00
#define SPHERE_RAMP_RES 32
2016-07-21 05:21:45 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
namespace {
struct FogVolumeControl {
std::array<std::array<u32, 2>, 12> xfc_{
{{0, 1}, {1, 3}, {3, 2}, {2, 0}, {4, 5}, {5, 7}, {7, 6}, {6, 4}, {0, 4}, {1, 5}, {3, 7}, {2, 6}},
};
std::array<u32, 8> x15c_{};
// GXVtxDescList x17c_; {{POS, DIRECT}, {TEX0, DIRECT}}
};
logvisor::Module Log("CBooRenderer");
2016-07-21 05:21:45 +00:00
rstl::reserved_vector<CDrawable, 512> sDataHolder;
rstl::reserved_vector<rstl::reserved_vector<CDrawable*, 128>, 50> sBucketsHolder;
rstl::reserved_vector<CDrawablePlaneObject, 8> sPlaneObjectDataHolder;
rstl::reserved_vector<u16, 8> sPlaneObjectBucketHolder;
constexpr FogVolumeControl s_FogVolumeCtrl{};
constexpr std::array<std::array<int, 2>, 3> OrthogonalAxis{
{{1, 2}, {0, 2}, {0, 1}},
};
2017-11-12 05:14:57 +00:00
constexpr bool TestBit(const u32* words, size_t bit) { return (words[bit / 32] & (1U << (bit & 0x1f))) != 0; }
float GetPlaneInterpolant(const zeus::CPlane& plane, const zeus::CVector3f& vert1, const zeus::CVector3f& vert2) {
return zeus::clamp(0.f, -plane.pointToPlaneDist(vert1) / (vert2 - vert1).dot(plane.normal()), 1.f);
}
} // Anonymous namespace
2016-07-25 22:52:02 +00:00
class Buckets {
friend class CBooRenderer;
static inline rstl::reserved_vector<u16, 50> sBucketIndex;
static inline rstl::reserved_vector<CDrawable, 512>* sData = nullptr;
static inline rstl::reserved_vector<rstl::reserved_vector<CDrawable*, 128>, 50>* sBuckets = nullptr;
static inline rstl::reserved_vector<CDrawablePlaneObject, 8>* sPlaneObjectData = nullptr;
static inline rstl::reserved_vector<u16, 8>* sPlaneObjectBucket = nullptr;
static constexpr std::array skWorstMinMaxDistance{99999.0f, -99999.0f};
static inline std::array sMinMaxDistance{0.0f, 0.0f};
public:
static void Clear();
static void Sort();
static void InsertPlaneObject(float closeDist, float farDist, const zeus::CAABox& aabb, bool invertTest,
const zeus::CPlane& plane, bool zOnly, EDrawableType dtype, void* data);
static void Insert(const zeus::CVector3f& pos, const zeus::CAABox& aabb, EDrawableType dtype, void* data,
const zeus::CPlane& plane, u16 extraSort);
static void Shutdown();
static void Init();
};
2016-07-25 22:52:02 +00:00
2018-12-08 05:30:43 +00:00
void Buckets::Clear() {
sData->clear();
sBucketIndex.clear();
sPlaneObjectData->clear();
sPlaneObjectBucket->clear();
for (rstl::reserved_vector<CDrawable*, 128>& bucket : *sBuckets) {
2018-12-08 05:30:43 +00:00
bucket.clear();
}
sMinMaxDistance = skWorstMinMaxDistance;
2018-12-08 05:30:43 +00:00
}
void Buckets::Sort() {
float delta = std::max(1.f, sMinMaxDistance[1] - sMinMaxDistance[0]);
float pitch = 49.f / delta;
for (auto it = sPlaneObjectData->begin(); it != sPlaneObjectData->end(); ++it)
if (sPlaneObjectBucket->size() != sPlaneObjectBucket->capacity())
sPlaneObjectBucket->push_back(s16(it - sPlaneObjectData->begin()));
u32 precision = 50;
if (sPlaneObjectBucket->size()) {
std::sort(sPlaneObjectBucket->begin(), sPlaneObjectBucket->end(),
2019-03-08 04:16:42 +00:00
[](u16 a, u16 b) { return (*sPlaneObjectData)[a].GetDistance() < (*sPlaneObjectData)[b].GetDistance(); });
2018-12-08 05:30:43 +00:00
precision = 50 / u32(sPlaneObjectBucket->size() + 1);
pitch = 1.f / (delta / float(precision - 2));
int accum = 0;
for (u16 idx : *sPlaneObjectBucket) {
++accum;
CDrawablePlaneObject& planeObj = (*sPlaneObjectData)[idx];
planeObj.x24_targetBucket = u16(precision * accum);
2016-07-26 02:43:55 +00:00
}
2018-12-08 05:30:43 +00:00
}
for (CDrawable& drawable : *sData) {
int slot;
float relDist = drawable.GetDistance() - sMinMaxDistance[0];
if (sPlaneObjectBucket->empty()) {
slot = zeus::clamp(1, int(relDist * pitch), 49);
} else {
slot = zeus::clamp(0, int(relDist * pitch), int(precision) - 2);
for (u16 idx : *sPlaneObjectBucket) {
CDrawablePlaneObject& planeObj = (*sPlaneObjectData)[idx];
bool partial, full;
if (planeObj.x3c_25_zOnly) {
partial = drawable.GetBounds().max.z() > planeObj.GetPlane().d();
full = drawable.GetBounds().min.z() > planeObj.GetPlane().d();
} else {
partial = planeObj.GetPlane().pointToPlaneDist(
2018-12-08 01:49:15 +00:00
drawable.GetBounds().closestPointAlongVector(planeObj.GetPlane().normal())) > 0.f;
2018-12-08 05:30:43 +00:00
full = planeObj.GetPlane().pointToPlaneDist(
drawable.GetBounds().furthestPointAlongVector(planeObj.GetPlane().normal())) > 0.f;
2016-07-26 02:43:55 +00:00
}
2018-12-08 05:30:43 +00:00
bool cont;
if (drawable.GetType() == EDrawableType::Particle)
cont = planeObj.x3c_24_invertTest ? !partial : full;
else
cont = planeObj.x3c_24_invertTest ? (!partial || !full) : (partial || full);
if (!cont)
break;
slot += precision;
}
2016-07-26 02:43:55 +00:00
}
2018-12-08 05:30:43 +00:00
if (slot == -1)
slot = 49;
rstl::reserved_vector<CDrawable*, 128>& bucket = (*sBuckets)[slot];
if (bucket.size() < bucket.capacity())
bucket.push_back(&drawable);
// else
2020-04-11 22:51:39 +00:00
// Log.report(logvisor::Fatal, FMT_STRING("Full bucket!!!"));
2018-12-08 05:30:43 +00:00
}
u16 bucketIdx = u16(sBuckets->size());
for (auto it = sBuckets->rbegin(); it != sBuckets->rend(); ++it) {
--bucketIdx;
sBucketIndex.push_back(bucketIdx);
rstl::reserved_vector<CDrawable*, 128>& bucket = *it;
if (bucket.size()) {
std::sort(bucket.begin(), bucket.end(), [](CDrawable* a, CDrawable* b) {
if (a->GetDistance() == b->GetDistance())
return a->GetExtraSort() > b->GetExtraSort();
return a->GetDistance() > b->GetDistance();
});
2016-07-26 02:43:55 +00:00
}
2018-12-08 05:30:43 +00:00
}
2016-07-26 02:43:55 +00:00
2018-12-08 05:30:43 +00:00
for (auto it = sPlaneObjectBucket->rbegin(); it != sPlaneObjectBucket->rend(); ++it) {
CDrawablePlaneObject& planeObj = (*sPlaneObjectData)[*it];
rstl::reserved_vector<CDrawable*, 128>& bucket = (*sBuckets)[planeObj.x24_targetBucket];
bucket.push_back(&planeObj);
}
2016-07-25 22:52:02 +00:00
}
2018-06-03 06:11:39 +00:00
void Buckets::InsertPlaneObject(float closeDist, float farDist, const zeus::CAABox& aabb, bool invertTest,
const zeus::CPlane& plane, bool zOnly, EDrawableType dtype, void* data) {
if (sPlaneObjectData->size() == sPlaneObjectData->capacity()) {
2018-12-08 05:30:43 +00:00
return;
}
sPlaneObjectData->emplace_back(dtype, closeDist, farDist, aabb, invertTest, plane, zOnly, data);
2018-12-08 05:30:43 +00:00
}
void Buckets::Insert(const zeus::CVector3f& pos, const zeus::CAABox& aabb, EDrawableType dtype, void* data,
2018-12-08 05:30:43 +00:00
const zeus::CPlane& plane, u16 extraSort) {
if (sData->size() == sData->capacity()) {
2020-04-11 22:51:39 +00:00
Log.report(logvisor::Fatal, FMT_STRING("Rendering buckets filled to capacity"));
return;
}
const float dist = plane.pointToPlaneDist(pos);
sData->emplace_back(dtype, extraSort, dist, aabb, data);
sMinMaxDistance[0] = std::min(sMinMaxDistance[0], dist);
sMinMaxDistance[1] = std::max(sMinMaxDistance[1], dist);
2018-12-08 05:30:43 +00:00
}
void Buckets::Shutdown() {
sData = nullptr;
sBuckets = nullptr;
sPlaneObjectData = nullptr;
sPlaneObjectBucket = nullptr;
}
void Buckets::Init() {
sData = &sDataHolder;
sBuckets = &sBucketsHolder;
sBuckets->resize(50);
sPlaneObjectData = &sPlaneObjectDataHolder;
sPlaneObjectBucket = &sPlaneObjectBucketHolder;
sMinMaxDistance = skWorstMinMaxDistance;
2016-07-25 22:52:02 +00:00
}
2018-03-04 23:23:21 +00:00
CBooRenderer::CAreaListItem::CAreaListItem(const std::vector<CMetroidModelInstance>* geom,
const CAreaRenderOctTree* octTree,
std::unordered_map<CAssetId, TCachedToken<CTexture>>&& textures,
2018-12-08 05:30:43 +00:00
std::vector<CBooModel*>&& models, int areaIdx, const SShader* shaderSet)
: x0_geometry(geom)
, x4_octTree(octTree)
, x8_textures(std::move(textures))
, x10_models(std::move(models))
, x18_areaIdx(areaIdx)
, m_shaderSet(shaderSet) {}
2016-07-26 22:05:59 +00:00
CBooRenderer::CAreaListItem::~CAreaListItem() = default;
2016-07-26 22:05:59 +00:00
2018-12-08 05:30:43 +00:00
void CBooRenderer::ActivateLightsForModel(CAreaListItem* item, CBooModel& model) {
2021-04-03 16:48:39 +00:00
OPTICK_EVENT();
2020-09-16 17:07:53 +00:00
constexpr size_t lightCount = 4;
2018-12-08 05:30:43 +00:00
std::vector<CLight> thisLights;
2020-09-16 17:07:53 +00:00
thisLights.reserve(lightCount);
2016-07-28 04:55:06 +00:00
if (!x300_dynamicLights.empty()) {
2018-12-08 05:30:43 +00:00
u32 lightOctreeWordCount = 0;
const u32* lightOctreeWords = nullptr;
if (item != nullptr && model.x44_areaInstanceIdx != UINT32_MAX) {
2018-12-08 05:30:43 +00:00
lightOctreeWordCount = item->x4_octTree->x14_bitmapWordCount;
lightOctreeWords = item->x1c_lightOctreeWords.data();
2016-07-28 04:55:06 +00:00
}
2020-09-16 17:07:53 +00:00
std::array<float, lightCount> lightRads{-1.f, -1.f, -1.f, -1.f};
std::array<CLight*, lightCount> lightRefs{};
2018-12-08 05:30:43 +00:00
auto it = x300_dynamicLights.begin();
2020-09-16 17:07:53 +00:00
for (size_t i = 0; i < lightCount && it != x300_dynamicLights.end();
++it, lightOctreeWords += lightOctreeWordCount) {
2018-12-08 05:30:43 +00:00
CLight& refLight = *it;
if (lightOctreeWords != nullptr && !TestBit(lightOctreeWords, model.x44_areaInstanceIdx)) {
2018-12-08 05:30:43 +00:00
continue;
}
2018-12-08 05:30:43 +00:00
const float radius =
model.x20_aabb.intersectionRadius(zeus::CSphere(refLight.GetPosition(), refLight.GetRadius()));
2019-02-08 07:56:54 +00:00
2018-12-08 05:30:43 +00:00
bool foundLight = false;
for (size_t j = 0; j < i; ++j) {
if (lightRefs[j] == &refLight) {
2018-12-08 05:30:43 +00:00
continue;
}
if (radius < 0.f) {
2018-12-08 05:30:43 +00:00
break;
}
if (lightRads[j] <= radius) {
2018-12-08 05:30:43 +00:00
break;
}
2018-12-08 05:30:43 +00:00
lightRads[j] = radius;
thisLights.push_back(refLight);
foundLight = true;
2019-02-08 07:56:54 +00:00
break;
2018-12-08 05:30:43 +00:00
}
if (foundLight) {
2018-12-08 05:30:43 +00:00
continue;
}
2018-12-08 05:30:43 +00:00
2019-02-08 07:56:54 +00:00
lightRads[i] = radius;
if (radius < 0.f) {
2018-12-08 05:30:43 +00:00
continue;
}
2018-12-08 05:30:43 +00:00
lightRefs[i] = &refLight;
thisLights.push_back(refLight);
++i;
}
}
model.ActivateLights(thisLights);
}
void CBooRenderer::RenderBucketItems(CAreaListItem* item) {
CModelFlags flags;
flags.m_noZWrite = true;
flags.m_extendedShader = EExtendedShader::Lighting;
for (u16 idx : Buckets::sBucketIndex) {
rstl::reserved_vector<CDrawable*, 128>& bucket = (*Buckets::sBuckets)[idx];
for (CDrawable* drawable : bucket) {
switch (drawable->GetType()) {
case EDrawableType::Particle: {
static_cast<CParticleGen*>(drawable->GetData())->Render();
2018-12-08 05:30:43 +00:00
break;
}
case EDrawableType::WorldSurface: {
// SetupRendererStates();
auto* surf = static_cast<CBooSurface*>(drawable->GetData());
2018-12-08 05:30:43 +00:00
CBooModel* model = surf->m_parent;
if (model) {
ActivateLightsForModel(item, *model);
model->DrawSurface(*surf, flags);
}
break;
}
default: {
if (xa8_drawableCallback) {
xa8_drawableCallback(drawable->GetData(), xac_callbackContext, int(drawable->GetType()) - 2);
2016-07-25 22:52:02 +00:00
}
2018-12-08 05:30:43 +00:00
break;
}
}
2016-07-25 22:52:02 +00:00
}
2018-12-08 05:30:43 +00:00
}
2016-07-25 22:52:02 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::HandleUnsortedModel(CAreaListItem* item, CBooModel& model, const CModelFlags& flags) {
// ActivateLightsForModel(item, model);
CBooSurface* surf = model.x38_firstUnsortedSurface;
while (surf) {
model.DrawSurface(*surf, flags);
surf = surf->m_next;
}
2016-07-28 04:55:06 +00:00
}
void CBooRenderer::CalcDrawFogFan(const zeus::CPlane* planes, size_t numPlanes, const zeus::CVector3f* verts,
size_t numVerts, size_t iteration, size_t level, CFogVolumePlaneShader& fogVol) {
2018-12-08 05:30:43 +00:00
if (level == iteration) {
CalcDrawFogFan(planes, numPlanes, verts, numVerts, iteration, level + 1, fogVol);
return;
}
if (level == numPlanes) {
fogVol.addFan(verts, numVerts);
return;
}
const zeus::CPlane& plane = planes[level];
size_t insidePlaneCount = 0;
std::array<bool, 20> outsidePlane;
for (size_t i = 0; i < numVerts; ++i) {
2018-12-08 05:30:43 +00:00
outsidePlane[insidePlaneCount++] = plane.normal().dot(verts[i]) < plane.d();
}
2018-12-08 05:30:43 +00:00
size_t numUseVerts = 0;
std::array<zeus::CVector3f, 20> useVerts;
for (size_t i = 0; i < numVerts; ++i) {
const size_t nextIdx = (i + 1) % numVerts;
const int insidePair = int(outsidePlane[i]) | (int(outsidePlane[nextIdx]) << 1);
if ((insidePair & 0x1) == 0) {
2018-12-08 05:30:43 +00:00
useVerts[numUseVerts++] = verts[i];
}
2018-12-08 05:30:43 +00:00
if (insidePair == 1 || insidePair == 2) {
/* Inside/outside transition; clip verts to other plane boundary */
const zeus::CVector3f vert1 = verts[i];
const zeus::CVector3f vert2 = verts[nextIdx];
const float interp = GetPlaneInterpolant(plane, vert1, vert2);
if (interp > 0.f || interp < 1.f) {
2018-12-08 05:30:43 +00:00
useVerts[numUseVerts++] = (vert1 * (1.f - interp)) + (vert2 * interp);
}
}
2018-12-08 05:30:43 +00:00
}
if (numUseVerts < 3) {
return;
}
CalcDrawFogFan(planes, numPlanes, useVerts.data(), numUseVerts, iteration, level + 1, fogVol);
2018-12-08 05:30:43 +00:00
}
void CBooRenderer::DrawFogSlices(const zeus::CPlane* planes, size_t numPlanes, size_t iteration,
2018-12-08 05:30:43 +00:00
const zeus::CVector3f& center, float longestAxis, CFogVolumePlaneShader& fogVol) {
u32 vertCount = 0;
std::array<zeus::CVector3d, 4> verts;
2018-12-08 05:30:43 +00:00
u32 vert2Count = 0;
std::array<zeus::CVector3f, 4> verts2;
2018-12-08 05:30:43 +00:00
const zeus::CPlane& plane = planes[iteration];
int longestNormAxis = std::fabs(plane[1]) > std::fabs(plane[0]);
if (std::fabs(plane[2]) > std::fabs(plane[longestNormAxis])) {
2018-12-08 05:30:43 +00:00
longestNormAxis = 2;
}
2018-12-08 05:30:43 +00:00
const zeus::CVector3d pointOnPlane = center - (plane.pointToPlaneDist(center) * plane.normal());
2018-12-08 05:30:43 +00:00
float deltaSign = plane[longestNormAxis] >= 0.f ? -1.f : 1.f;
if (longestNormAxis == 1) {
2018-12-08 05:30:43 +00:00
deltaSign = -deltaSign;
}
2018-12-08 05:30:43 +00:00
zeus::CVector3d vec1;
zeus::CVector3d vec2;
vec1[OrthogonalAxis[longestNormAxis][0]] = longestAxis;
vec2[OrthogonalAxis[longestNormAxis][1]] = deltaSign * longestAxis;
verts[vertCount++] = pointOnPlane - vec1 - vec2;
verts[vertCount++] = pointOnPlane + vec1 - vec2;
verts[vertCount++] = pointOnPlane + vec1 + vec2;
verts[vertCount++] = pointOnPlane - vec1 + vec2;
const zeus::CVector3d planeNormal = plane.normal();
for (const zeus::CVector3d& vert : verts) {
2018-12-08 05:30:43 +00:00
verts2[vert2Count++] = vert - (planeNormal * zeus::CVector3f(planeNormal.dot(vert) - plane.d()));
}
2018-12-08 05:30:43 +00:00
CalcDrawFogFan(planes, numPlanes, verts2.data(), vert2Count, iteration, 0, fogVol);
2018-12-08 05:30:43 +00:00
}
void CBooRenderer::RenderFogVolumeModel(const zeus::CAABox& aabb, const CModel* model, const zeus::CTransform& modelMtx,
2022-02-01 00:06:54 +00:00
const zeus::CTransform& viewMtx, const CSkinnedModel* sModel, int pass) {
2018-12-08 05:30:43 +00:00
if (!model && !sModel) {
if (pass == 0) {
zeus::CAABox xfAABB = aabb.getTransformedAABox(modelMtx);
zeus::CUnitVector3f viewNormal(viewMtx.basis[1]);
const std::array<zeus::CPlane, 7> planes{{
{zeus::skRight, xfAABB.min.x()},
{zeus::skLeft, -xfAABB.max.x()},
{zeus::skForward, xfAABB.min.y()},
{zeus::skBack, -xfAABB.max.y()},
{zeus::skUp, xfAABB.min.z()},
{zeus::skDown, -xfAABB.max.z()},
{viewNormal, viewNormal.dot(viewMtx.origin) + 0.2f + 0.1f},
}};
2018-12-08 05:30:43 +00:00
CGraphics::SetModelMatrix(zeus::CTransform());
2018-12-08 05:30:43 +00:00
const float longestAxis = std::max(std::max(xfAABB.max.x() - xfAABB.min.x(), xfAABB.max.y() - xfAABB.min.y()),
xfAABB.max.z() - xfAABB.min.z()) *
2.f;
2018-12-08 05:30:43 +00:00
2022-02-01 00:06:54 +00:00
CFogVolumePlaneShader fvs;
fvs.reset(7 * 6);
for (size_t i = 0; i < planes.size(); ++i) {
2022-02-01 00:06:54 +00:00
DrawFogSlices(planes.data(), planes.size(), i, xfAABB.center(), longestAxis, fvs);
}
2022-02-16 05:21:24 +00:00
aurora::gfx::queue_fog_volume_plane(fvs.m_verts, 0);
2018-12-08 05:30:43 +00:00
} else {
2022-02-16 05:21:24 +00:00
aurora::gfx::queue_fog_volume_plane({}, pass);
}
2018-12-08 05:30:43 +00:00
} else {
CModelFlags flags;
switch (pass) {
case 0:
default:
flags.m_extendedShader = EExtendedShader::SolidColorFrontfaceCullLEqualAlphaOnly;
flags.x4_color = zeus::CColor(1.f, 1.f, 1.f, 1.f);
break;
case 1:
flags.m_extendedShader = EExtendedShader::SolidColorFrontfaceCullAlwaysAlphaOnly;
flags.x4_color = zeus::CColor(1.f, 1.f, 1.f, 1.f);
break;
case 2:
flags.m_extendedShader = EExtendedShader::SolidColorBackfaceCullLEqualAlphaOnly;
flags.x4_color = zeus::CColor(1.f, 1.f, 1.f, 0.f);
break;
case 3:
flags.m_extendedShader = EExtendedShader::SolidColorBackfaceCullGreaterAlphaOnly;
flags.x4_color = zeus::CColor(1.f, 1.f, 1.f, 0.f);
break;
}
2018-12-08 05:30:43 +00:00
if (sModel) {
sModel->Draw(flags);
} else {
model->UpdateLastFrame();
model->Draw(flags);
}
2018-12-08 05:30:43 +00:00
}
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::SetupRendererStates() const {
CGraphics::SetModelMatrix(zeus::CTransform());
2018-12-08 05:30:43 +00:00
CGraphics::g_ColorRegs[1] = x2fc_tevReg1Color;
2017-04-13 19:28:31 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::ReallyRenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, const CModel* model,
const CSkinnedModel* sModel) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::ReallyRenderFogVolume", zeus::skPurple);
2018-12-08 05:30:43 +00:00
zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(false);
std::array<zeus::CVector4f, 8> points;
for (size_t i = 0; i < points.size(); ++i) {
const zeus::CVector3f xfPt = CGraphics::g_GXModelView * aabb.getPoint(i);
2018-12-08 05:30:43 +00:00
points[i] = proj * zeus::CVector4f(xfPt);
}
2018-12-08 05:30:43 +00:00
zeus::CVector2i vpMax(0, 0);
zeus::CVector2i vpMin(g_Viewport.x8_width, g_Viewport.xc_height);
for (size_t i = 0; i < 20; ++i) {
2018-12-08 05:30:43 +00:00
zeus::CVector3f overW;
if (i < points.size()) {
2018-12-08 05:30:43 +00:00
overW = points[i].toVec3f() * (1.f / points[i].w());
} else {
const zeus::CVector4f& pt1 = points[s_FogVolumeCtrl.xfc_[i - 8][0]];
const zeus::CVector4f& pt2 = points[s_FogVolumeCtrl.xfc_[i - 8][1]];
const bool eq1 = (pt1.z() / pt1.w()) == 1.f;
const bool eq2 = (pt2.z() / pt2.w()) == 1.f;
if (eq1 == eq2) {
2018-12-08 05:30:43 +00:00
continue;
}
const float interp = -(pt1.w() - 1.f) / (pt2.w() - pt1.w());
if (interp <= 0.f || interp >= 1.f) {
2018-12-08 05:30:43 +00:00
continue;
}
const float wRecip = 1.f / (interp * (pt2.w() - pt1.w()) + pt1.w());
const zeus::CVector3f pt1_3 = pt1.toVec3f();
const zeus::CVector3f pt2_3 = pt2.toVec3f();
2018-12-08 05:30:43 +00:00
overW = (pt1_3 + interp * (pt2_3 - pt1_3)) * wRecip;
}
2018-12-08 05:30:43 +00:00
// if (overW.z > 1.001f)
// continue;
const int vpX = zeus::clamp(0, int(g_Viewport.x8_width * overW.x() * 0.5f + (g_Viewport.x8_width / 2)),
int(g_Viewport.x8_width));
const int vpY = zeus::clamp(0, int(g_Viewport.xc_height * overW.y() * 0.5f + (g_Viewport.xc_height / 2)),
int(g_Viewport.xc_height));
2018-12-08 05:30:43 +00:00
vpMax.x = std::max(vpMax.x, vpX);
vpMin.x = std::min(vpMin.x, vpX);
vpMax.y = std::max(vpMax.y, vpY);
vpMin.y = std::min(vpMin.y, vpY);
}
zeus::CVector2i vpSize = {vpMax.x - vpMin.x, vpMax.y - vpMin.y};
if (vpSize.x <= 0 || vpSize.y <= 0)
return;
SClipScreenRect rect = {};
rect.x4_left = vpMin.x;
rect.x8_top = vpMin.y;
rect.xc_width = vpSize.x;
rect.x10_height = vpSize.y;
rect.x4_left = 0;
rect.x8_top = 0;
rect.xc_width = g_Viewport.x8_width;
rect.x10_height = g_Viewport.xc_height;
// CGraphics::SetScissor(vpMin.x, vpMin.y, vpSize.x, vpSize.y);
zeus::CAABox marginAABB((CGraphics::g_GXModelView * aabb.min) - 1.f, (CGraphics::g_GXModelView * aabb.max) + 1.f);
bool camInModel = marginAABB.pointInside(CGraphics::g_ViewMatrix.origin) && (model || sModel);
2022-02-01 00:06:54 +00:00
// CFogVolumePlaneShader* fvs;
// if (!model && !sModel) {
// fvs = &*((m_nextFogVolumePlaneShader == m_fogVolumePlaneShaders.end())
// ? m_fogVolumePlaneShaders.insert(m_fogVolumePlaneShaders.end(), CFogVolumePlaneShader())
// : m_nextFogVolumePlaneShader++);
// } else {
// fvs = nullptr;
// }
2018-12-08 05:30:43 +00:00
2022-02-01 00:06:54 +00:00
RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 0);
2018-12-08 05:30:43 +00:00
if (camInModel)
2022-02-01 00:06:54 +00:00
RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 1);
2018-12-08 05:30:43 +00:00
CGraphics::ResolveSpareDepth(rect, 0);
2022-02-01 00:06:54 +00:00
RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 2);
2018-12-08 05:30:43 +00:00
if (camInModel)
2022-02-01 00:06:54 +00:00
RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 3);
2018-12-08 05:30:43 +00:00
CGraphics::ResolveSpareDepth(rect, 1);
2022-02-16 05:21:24 +00:00
aurora::gfx::queue_fog_volume_filter(color, true);
2018-12-08 05:30:43 +00:00
if (camInModel)
2022-02-16 05:21:24 +00:00
aurora::gfx::queue_fog_volume_filter(color, false);
2018-12-08 05:30:43 +00:00
// CGraphics::SetScissor(g_Viewport.x0_left, g_Viewport.x4_top, g_Viewport.x8_width, g_Viewport.xc_height);
}
2022-02-01 00:06:54 +00:00
//void CBooRenderer::GenerateFogVolumeRampTex() {
// std::array<std::array<float, FOGVOL_RAMP_RES>, FOGVOL_RAMP_RES> data{};
// for (size_t y = 0; y < data.size(); ++y) {
// for (size_t x = 0; x < data[y].size(); ++x) {
// const int tmp = int(y << 16 | x << 8 | 0x7f);
// const double a =
// zeus::clamp(0.0,
// (-150.0 / (tmp / double(0xffffff) * (FOGVOL_FAR - FOGVOL_NEAR) - FOGVOL_FAR) - FOGVOL_NEAR) *
// 3.0 / (FOGVOL_FAR - FOGVOL_NEAR),
// 1.0);
// data[y][x] = (a * a + a) / 2.0;
// }
// }
// x1b8_fogVolumeRamp =
2022-02-16 05:21:24 +00:00
// aurora::new_static_texture_2d(FOGVOL_RAMP_RES, FOGVOL_RAMP_RES, 1, aurora::gfx::TextureFormat::R32Float,
2022-02-01 00:06:54 +00:00
// {data[0].data(), FOGVOL_RAMP_RES * FOGVOL_RAMP_RES * 2});
//}
//
//void CBooRenderer::GenerateSphereRampTex() {
// std::array<std::array<u8, SPHERE_RAMP_RES>, SPHERE_RAMP_RES> data{};
// constexpr float halfRes = SPHERE_RAMP_RES / 2.f;
// for (size_t y = 0; y < data.size(); ++y) {
// for (size_t x = 0; x < data[y].size(); ++x) {
// const zeus::CVector2f vec((float(x) - halfRes) / halfRes, (float(y) - halfRes) / halfRes);
// data[y][x] = 255 - zeus::clamp(0.f, vec.canBeNormalized() ? vec.magnitude() : 0.f, 1.f) * 255;
// }
// }
// x220_sphereRamp =
2022-02-16 05:21:24 +00:00
// aurora::new_static_texture_2d(SPHERE_RAMP_RES, SPHERE_RAMP_RES, 1, aurora::gfx::TextureFormat::R8,
2022-02-01 00:06:54 +00:00
// {data[0].data(), SPHERE_RAMP_RES * SPHERE_RAMP_RES});
//}
//
//void CBooRenderer::GenerateScanLinesVBO() {
// std::vector<zeus::CVector3f> verts;
// verts.reserve(670);
//
// for (int i = 0; i < 112; ++i) {
// verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f);
// if (i != 0) {
// verts.emplace_back(verts.back());
// }
// verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) - (1.f / 448.f)) * 2.f - 1.f, 0.f);
// verts.emplace_back(1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f);
// verts.emplace_back(1.f, (float(i) * (4.f / 448.f) - (1.f / 448.f)) * 2.f - 1.f, 0.f);
// if (i != 111) {
// verts.emplace_back(verts.back());
// }
// }
//
// m_scanLinesEvenVBO = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(zeus::CVector3f), verts.size());
//
// verts.clear();
//
// for (int i = 0; i < 112; ++i) {
// verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) + (3.f / 448.f)) * 2.f - 1.f, 0.f);
// if (i != 0) {
// verts.emplace_back(verts.back());
// }
// verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f);
// verts.emplace_back(1.f, (float(i) * (4.f / 448.f) + (3.f / 448.f)) * 2.f - 1.f, 0.f);
// verts.emplace_back(1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f);
// if (i != 111) {
// verts.emplace_back(verts.back());
// }
// }
//
// m_scanLinesOddVBO = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(zeus::CVector3f), verts.size());
//}
2022-02-18 00:38:31 +00:00
aurora::gfx::TextureHandle CBooRenderer::GetColorTexture(const zeus::CColor& color) {
const auto search = m_colorTextures.find(color);
if (search != m_colorTextures.end()) {
return search->second;
}
2022-02-01 00:06:54 +00:00
std::array<u8, 4> pixel{};
color.toRGBA8(pixel[0], pixel[1], pixel[2], pixel[3]);
2022-02-18 00:38:31 +00:00
auto tex = aurora::gfx::new_static_texture_2d(1, 1, 1, aurora::gfx::TextureFormat::RGBA8, pixel, "Color Texture");
m_colorTextures.emplace(color, tex);
return tex;
}
2022-02-01 00:06:54 +00:00
//void CBooRenderer::LoadThermoPalette() {
// m_thermoPaletteTex = xc_store.GetObj("TXTR_ThermoPalette");
// CTexture* thermoTexObj = m_thermoPaletteTex.GetObj();
// if (thermoTexObj)
// x288_thermoPalette = thermoTexObj->GetPaletteTexture();
//}
//
//void CBooRenderer::LoadBallFade() {
// m_ballFadeTex = xc_store.GetObj("TXTR_BallFade");
// CTexture* ballFadeTexObj = m_ballFadeTex.GetObj();
// if (ballFadeTexObj) {
// m_ballFade = ballFadeTexObj->GetBooTexture();
// m_ballFade->setClampMode(boo::TextureClampMode::ClampToEdge);
// }
//}
2017-03-05 07:57:12 +00:00
CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac)
: x8_factory(resFac), xc_store(store), x2a8_thermalRand(20) {
2018-12-08 05:30:43 +00:00
g_Renderer = this;
m_staticEntropy = store.GetObj("RandomStaticEntropy");
2022-02-01 00:06:54 +00:00
constexpr std::array<u8, 4> clearPixel{0, 0, 0, 0};
2022-02-16 05:21:24 +00:00
m_clearTexture =
2022-02-18 00:38:31 +00:00
aurora::gfx::new_static_texture_2d(1, 1, 1, aurora::gfx::TextureFormat::RGBA8, clearPixel, "Clear Texture");
2022-02-01 00:06:54 +00:00
constexpr std::array<u8, 4> blackPixel{0, 0, 0, 255};
2022-02-16 05:21:24 +00:00
m_blackTexture =
2022-02-18 00:38:31 +00:00
aurora::gfx::new_static_texture_2d(1, 1, 1, aurora::gfx::TextureFormat::RGBA8, blackPixel, "Black Texture");
2022-02-01 00:06:54 +00:00
constexpr std::array<u8, 4> whitePixel{255, 255, 255, 255};
2022-02-16 05:21:24 +00:00
m_whiteTexture =
2022-02-18 00:38:31 +00:00
aurora::gfx::new_static_texture_2d(1, 1, 1, aurora::gfx::TextureFormat::RGBA8, whitePixel, "White Texture");
2022-02-01 00:06:54 +00:00
2022-02-16 05:21:24 +00:00
// GenerateFogVolumeRampTex();
2022-02-01 00:06:54 +00:00
// GenerateSphereRampTex();
2022-02-16 05:21:24 +00:00
m_ballShadowId = aurora::gfx::new_render_texture(m_ballShadowIdW, m_ballShadowIdH, 1, 0, "Ball Shadow");
2022-02-01 00:06:54 +00:00
// m_ballShadowId = ctx.newRenderTexture(m_ballShadowIdW, m_ballShadowIdH, boo::TextureClampMode::Repeat, 1, 0);
2022-02-16 05:21:24 +00:00
x14c_reflectionTex = aurora::gfx::new_render_texture(256, 256, 1, 0, "Reflection");
2022-02-01 00:06:54 +00:00
// x14c_reflectionTex = ctx.newRenderTexture(256, 256, boo::TextureClampMode::ClampToBlack, 1, 0);
// GenerateScanLinesVBO();
// LoadThermoPalette();
// LoadBallFade();
m_thermColdFilter.emplace();
2018-12-08 05:30:43 +00:00
m_thermHotFilter.emplace();
Buckets::Init();
2022-02-01 00:06:54 +00:00
// m_nextFogVolumePlaneShader = m_fogVolumePlaneShaders.end();
// m_nextFogVolumeFilter = m_fogVolumeFilters.end();
2018-12-08 05:30:43 +00:00
}
CBooRenderer::~CBooRenderer() { g_Renderer = nullptr; }
void CBooRenderer::AddWorldSurfaces(CBooModel& model) {
CBooSurface* surf = model.x3c_firstSortedSurface;
while (surf) {
// const MaterialSet::Material& mat = model.GetMaterialByIndex(surf->m_data.matIdx);
2018-12-08 05:30:43 +00:00
zeus::CAABox aabb = surf->GetBounds();
zeus::CVector3f pt = aabb.closestPointAlongVector(xb0_viewPlane.normal());
Buckets::Insert(pt, aabb, EDrawableType::WorldSurface, surf, xb0_viewPlane,
/*mat.blendMode == MaterialSet::Material::BlendMaterial::BlendMode::Alpha*/ false);
2018-12-08 05:30:43 +00:00
surf = surf->m_next;
}
2016-07-21 05:21:45 +00:00
}
2016-07-26 22:05:59 +00:00
std::list<CBooRenderer::CAreaListItem>::iterator
2018-12-08 05:30:43 +00:00
CBooRenderer::FindStaticGeometry(const std::vector<CMetroidModelInstance>* geometry) {
return std::find_if(x1c_areaListItems.begin(), x1c_areaListItems.end(),
[&](const CAreaListItem& item) { return item.x0_geometry == geometry; });
2016-07-26 22:05:59 +00:00
}
void CBooRenderer::AddStaticGeometry(const std::vector<CMetroidModelInstance>* geometry,
2018-12-08 05:30:43 +00:00
const CAreaRenderOctTree* octTree, int areaIdx, const SShader* shaderSet) {
auto search = FindStaticGeometry(geometry);
if (search == x1c_areaListItems.end()) {
std::unordered_map<CAssetId, TCachedToken<CTexture>> textures;
2018-12-08 05:30:43 +00:00
std::vector<CBooModel*> models;
if (geometry->size()) {
(*geometry)[0].m_instance->MakeTexturesFromMats(textures, xc_store);
models.reserve(geometry->size());
int instIdx = 0;
for (const CMetroidModelInstance& inst : *geometry) {
models.push_back(inst.m_instance.get());
models.back()->x44_areaInstanceIdx = instIdx++;
}
2016-07-26 22:05:59 +00:00
}
2018-12-08 05:30:43 +00:00
x1c_areaListItems.emplace_back(geometry, octTree, std::move(textures), std::move(models), areaIdx, shaderSet);
}
2016-07-26 22:05:59 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::EnablePVS(const CPVSVisSet& set, u32 areaIdx) {
xc8_pvs.emplace(set);
xe0_pvsAreaIdx = areaIdx;
2016-07-27 23:06:57 +00:00
}
void CBooRenderer::DisablePVS() { xc8_pvs = std::nullopt; }
2016-07-27 23:06:57 +00:00
void CBooRenderer::UpdateAreaUniforms(int areaIdx, EWorldShadowMode shadowMode, bool activateLights, int cubeFace,
const CModelFlags* ballShadowFlags) {
2021-04-03 16:48:39 +00:00
OPTICK_EVENT();
2018-12-08 05:30:43 +00:00
SetupRendererStates();
2017-11-12 05:14:57 +00:00
2018-12-08 05:30:43 +00:00
CModelFlags flags;
int bufIdx;
if (shadowMode == EWorldShadowMode::WorldOnActorShadow) {
2018-12-08 05:30:43 +00:00
flags.m_extendedShader = EExtendedShader::SolidColor;
flags.x4_color = zeus::skBlack;
2018-12-08 05:30:43 +00:00
bufIdx = 1;
} else if (shadowMode == EWorldShadowMode::BallOnWorldShadow) {
flags = *ballShadowFlags;
bufIdx = 2;
} else if (shadowMode == EWorldShadowMode::BallOnWorldIds) {
flags.m_extendedShader = EExtendedShader::SolidColor;
bufIdx = 3;
2018-12-08 05:30:43 +00:00
} else {
flags.m_extendedShader = EExtendedShader::Lighting;
bufIdx = cubeFace == -1 ? 0 : 4 + cubeFace;
2018-12-08 05:30:43 +00:00
}
for (CAreaListItem& item : x1c_areaListItems) {
if (areaIdx != -1 && item.x18_areaIdx != areaIdx)
continue;
2022-02-01 00:06:54 +00:00
// item.m_shaderSet->m_geomLayout->Update(flags, nullptr, nullptr, &item.m_shaderSet->m_matSet,
// item.m_shaderSet->m_geomLayout->GetSharedBuffer(bufIdx), nullptr);
2018-12-08 05:30:43 +00:00
if (shadowMode == EWorldShadowMode::BallOnWorldShadow || shadowMode == EWorldShadowMode::BallOnWorldIds)
continue;
2022-02-01 00:06:54 +00:00
for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it) {
CBooModel* model = *it;
if (model->TryLockTextures()) {
if (activateLights)
ActivateLightsForModel(&item, *model);
// model->UpdateUniformData(flags, nullptr, nullptr, bufIdx);
2018-12-08 05:30:43 +00:00
}
2022-02-01 00:06:54 +00:00
}
2018-12-08 05:30:43 +00:00
}
}
void CBooRenderer::RemoveStaticGeometry(const std::vector<CMetroidModelInstance>* geometry) {
auto search = FindStaticGeometry(geometry);
if (search != x1c_areaListItems.end())
x1c_areaListItems.erase(search);
}
void CBooRenderer::DrawAreaGeometry(int areaIdx, int mask, int targetMask) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawAreaGeometry", zeus::skPurple);
2018-12-08 05:30:43 +00:00
x318_30_inAreaDraw = true;
// SetupRendererStates();
CModelFlags flags;
for (CAreaListItem& item : x1c_areaListItems) {
if (areaIdx != -1 || item.x18_areaIdx == areaIdx) {
CPVSVisSet* pvs = xc8_pvs ? &*xc8_pvs : nullptr;
if (xe0_pvsAreaIdx != item.x18_areaIdx)
pvs = nullptr;
int modelIdx = 0;
for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it, ++modelIdx) {
CBooModel* model = *it;
if (pvs) {
bool visible = pvs->GetVisible(modelIdx) != EPVSVisSetState::EndOfTree;
if ((xc4_pvsMode == EPVSMode::PVS && !visible) || (xc4_pvsMode == EPVSMode::PVSAndMask && visible))
2017-11-12 05:14:57 +00:00
continue;
}
2018-12-08 05:30:43 +00:00
if ((model->x41_mask & mask) != targetMask)
continue;
if (!x44_frustumPlanes.aabbFrustumTest(model->x20_aabb))
continue;
for (const CBooSurface* surf = model->x38_firstUnsortedSurface; surf; surf = surf->m_next)
model->DrawSurface(*surf, flags);
for (const CBooSurface* surf = model->x3c_firstSortedSurface; surf; surf = surf->m_next)
model->DrawSurface(*surf, flags);
}
2017-11-12 05:14:57 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-11-12 05:14:57 +00:00
2018-12-08 05:30:43 +00:00
x318_30_inAreaDraw = false;
2016-07-21 05:21:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::DrawUnsortedGeometry(int areaIdx, int mask, int targetMask, bool shadowRender) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawUnsortedGeometry", zeus::skPurple);
2018-12-08 05:30:43 +00:00
// SetupRendererStates();
CModelFlags flags;
flags.m_extendedShader = shadowRender ? EExtendedShader::SolidColor : EExtendedShader::Lighting;
2017-03-06 06:33:51 +00:00
2018-12-08 05:30:43 +00:00
CAreaListItem* lastOctreeItem = nullptr;
2017-03-06 06:33:51 +00:00
2018-12-08 05:30:43 +00:00
for (CAreaListItem& item : x1c_areaListItems) {
if (areaIdx != -1 && item.x18_areaIdx != areaIdx)
continue;
2017-03-06 06:33:51 +00:00
2018-12-08 05:30:43 +00:00
if (item.x4_octTree)
lastOctreeItem = &item;
2018-01-15 07:39:25 +00:00
2018-12-08 05:30:43 +00:00
CPVSVisSet* pvs = nullptr;
if (xc8_pvs)
pvs = &*xc8_pvs;
if (xe0_pvsAreaIdx != item.x18_areaIdx)
pvs = nullptr;
2016-07-27 23:06:57 +00:00
2018-12-08 05:30:43 +00:00
u32 idx = 0;
for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it, ++idx) {
CBooModel* model = *it;
if (pvs) {
bool vis = pvs->GetVisible(idx) != EPVSVisSetState::EndOfTree;
switch (xc4_pvsMode) {
case EPVSMode::PVS: {
if (!vis) {
model->x40_25_modelVisible = false;
2016-07-27 23:06:57 +00:00
continue;
2018-12-08 05:30:43 +00:00
}
break;
2016-07-27 23:06:57 +00:00
}
2018-12-08 05:30:43 +00:00
case EPVSMode::PVSAndMask: {
if (!vis && (model->x41_mask & mask) != targetMask) {
model->x40_25_modelVisible = false;
continue;
}
2019-02-18 05:47:46 +00:00
break;
2018-12-08 05:30:43 +00:00
}
default:
break;
}
}
if ((model->x41_mask & mask) != targetMask) {
model->x40_25_modelVisible = false;
continue;
}
if (!x44_frustumPlanes.aabbFrustumTest(model->x20_aabb)) {
model->x40_25_modelVisible = false;
continue;
}
if (x318_25_drawWireframe) {
model->x40_25_modelVisible = false;
// HandleUnsortedModelWireframe();
continue;
}
model->x40_25_modelVisible = true;
HandleUnsortedModel(lastOctreeItem, *model, flags);
2016-07-27 23:06:57 +00:00
}
2018-12-08 05:30:43 +00:00
}
2016-07-27 23:06:57 +00:00
2018-12-08 05:30:43 +00:00
// SetupCGraphicsStates();
2016-07-21 05:21:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::DrawSortedGeometry(int areaIdx, int mask, int targetMask) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawSortedGeometry", zeus::skPurple);
2018-12-08 05:30:43 +00:00
// SetupRendererStates();
2016-07-28 04:55:06 +00:00
2018-12-08 05:30:43 +00:00
CAreaListItem* lastOctreeItem = nullptr;
2016-07-28 04:55:06 +00:00
2018-12-08 05:30:43 +00:00
for (CAreaListItem& item : x1c_areaListItems) {
if (areaIdx != -1 && item.x18_areaIdx != areaIdx)
continue;
2016-07-28 04:55:06 +00:00
2018-12-08 05:30:43 +00:00
if (item.x4_octTree)
lastOctreeItem = &item;
2016-07-28 04:55:06 +00:00
2018-12-08 05:30:43 +00:00
for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it) {
CBooModel* model = *it;
if (model->x40_25_modelVisible)
AddWorldSurfaces(*model);
2016-07-28 04:55:06 +00:00
}
2018-12-08 05:30:43 +00:00
}
2016-07-28 04:55:06 +00:00
2018-12-08 05:30:43 +00:00
Buckets::Sort();
RenderBucketItems(lastOctreeItem);
2016-07-28 04:55:06 +00:00
2018-12-08 05:30:43 +00:00
// SetupCGraphicsStates();
// DrawRenderBucketsDebug();
Buckets::Clear();
2016-07-21 05:21:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::DrawStaticGeometry(int modelCount, int mask, int targetMask) {
DrawUnsortedGeometry(modelCount, mask, targetMask);
DrawSortedGeometry(modelCount, mask, targetMask);
2016-07-21 05:21:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly) {
model.GetInstance().DrawFlat(unsortedOnly ? CBooModel::ESurfaceSelection::UnsortedOnly
: CBooModel::ESurfaceSelection::All,
flags.m_extendedShader);
2017-05-06 05:21:42 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::PostRenderFogs() {
for (const auto& warp : x2c4_spaceWarps)
DrawSpaceWarp(warp.first, warp.second);
x2c4_spaceWarps.clear();
2018-12-08 05:30:43 +00:00
x2ac_fogVolumes.sort([](const CFogVolumeListItem& a, const CFogVolumeListItem& b) {
zeus::CAABox aabbA = a.x34_aabb.getTransformedAABox(a.x0_transform);
bool insideA =
aabbA.pointInside(zeus::CVector3f(CGraphics::g_ViewPoint.x(), CGraphics::g_ViewPoint.y(), aabbA.min.z()));
2016-07-21 05:21:45 +00:00
2018-12-08 05:30:43 +00:00
zeus::CAABox aabbB = b.x34_aabb.getTransformedAABox(b.x0_transform);
bool insideB =
aabbB.pointInside(zeus::CVector3f(CGraphics::g_ViewPoint.x(), CGraphics::g_ViewPoint.y(), aabbB.min.z()));
if (insideA != insideB)
return insideA;
float dotA = aabbA.furthestPointAlongVector(CGraphics::g_ViewMatrix.basis[1]).dot(CGraphics::g_ViewMatrix.basis[1]);
float dotB = aabbB.furthestPointAlongVector(CGraphics::g_ViewMatrix.basis[1]).dot(CGraphics::g_ViewMatrix.basis[1]);
return dotA < dotB;
});
for (const CFogVolumeListItem& fog : x2ac_fogVolumes) {
CGraphics::SetModelMatrix(fog.x0_transform);
ReallyRenderFogVolume(fog.x30_color, fog.x34_aabb, fog.x4c_model.GetObj(), fog.x5c_skinnedModel);
}
x2ac_fogVolumes.clear();
2016-07-21 05:21:45 +00:00
}
2021-06-07 19:29:18 +00:00
void CBooRenderer::SetModelMatrix(const zeus::CTransform& xf) { CGraphics::SetModelMatrix(xf); }
void CBooRenderer::AddParticleGen(CParticleGen& gen) {
2018-12-08 05:30:43 +00:00
if (auto bounds = gen.GetBounds()) {
zeus::CVector3f pt = bounds.value().closestPointAlongVector(xb0_viewPlane.normal());
Buckets::Insert(pt, bounds.value(), EDrawableType::Particle, &gen, xb0_viewPlane, 0);
}
2018-09-09 01:13:56 +00:00
}
void CBooRenderer::AddParticleGen(CParticleGen& gen, const zeus::CVector3f& pos, const zeus::CAABox& bounds) {
2018-12-08 05:30:43 +00:00
Buckets::Insert(pos, bounds, EDrawableType::Particle, &gen, xb0_viewPlane, 0);
2016-07-21 05:21:45 +00:00
}
void CBooRenderer::AddPlaneObject(void* obj, const zeus::CAABox& aabb, const zeus::CPlane& plane, int type) {
2018-12-08 05:30:43 +00:00
zeus::CVector3f closePoint = aabb.closestPointAlongVector(xb0_viewPlane.normal());
zeus::CVector3f farPoint = aabb.furthestPointAlongVector(xb0_viewPlane.normal());
float closeDist = xb0_viewPlane.pointToPlaneDist(closePoint);
float farDist = xb0_viewPlane.pointToPlaneDist(farPoint);
if (closeDist >= 0.f || farDist >= 0.f) {
bool zOnly = plane.normal() == zeus::skUp;
2018-12-08 05:30:43 +00:00
bool invert;
if (zOnly)
invert = CGraphics::g_ViewMatrix.origin.z() >= plane.d();
2016-07-26 22:05:59 +00:00
else
2018-12-08 05:30:43 +00:00
invert = plane.pointToPlaneDist(CGraphics::g_ViewMatrix.origin) >= 0.f;
Buckets::InsertPlaneObject(closeDist, farDist, aabb, invert, plane, zOnly, EDrawableType(type + 2), obj);
}
2016-07-21 05:21:45 +00:00
}
void CBooRenderer::AddDrawable(void* obj, const zeus::CVector3f& pos, const zeus::CAABox& aabb, int mode,
2018-12-08 05:30:43 +00:00
EDrawableSorting sorting) {
if (sorting == EDrawableSorting::UnsortedCallback)
xa8_drawableCallback(obj, xac_callbackContext, mode);
else
Buckets::Insert(pos, aabb, EDrawableType(mode + 2), obj, xb0_viewPlane, 0);
2016-07-21 05:21:45 +00:00
}
void CBooRenderer::SetDrawableCallback(TDrawableCallback cb, void* ctx) {
2018-12-08 05:30:43 +00:00
xa8_drawableCallback = cb;
xac_callbackContext = ctx;
2016-07-21 05:21:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::SetWorldViewpoint(const zeus::CTransform& xf) {
CGraphics::SetViewPointMatrix(xf);
xb0_viewPlane = zeus::CPlane(xf.basis[1], xf.basis[1].dot(xf.origin));
2016-07-21 05:21:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::SetPerspective(float fovy, float width, float height, float znear, float zfar) {
CGraphics::SetPerspective(fovy, width / height, znear, zfar);
2016-07-21 05:21:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::SetPerspective(float fovy, float aspect, float znear, float zfar) {
CGraphics::SetPerspective(fovy, aspect, znear, zfar);
}
2016-07-29 17:38:44 +00:00
2018-12-08 05:30:43 +00:00
std::pair<zeus::CVector2f, zeus::CVector2f> CBooRenderer::SetViewportOrtho(bool centered, float znear, float zfar) {
float left = centered ? g_Viewport.x0_left - g_Viewport.x10_halfWidth : 0.f;
float bottom = centered ? g_Viewport.x4_top - g_Viewport.x14_halfHeight : 0.f;
float top = centered ? g_Viewport.x0_left + g_Viewport.x14_halfHeight : g_Viewport.xc_height;
float right = centered ? g_Viewport.x4_top + g_Viewport.x10_halfWidth : g_Viewport.x8_width;
2016-12-18 04:16:04 +00:00
2018-12-08 05:30:43 +00:00
CGraphics::SetOrtho(left, right, top, bottom, znear, zfar);
CGraphics::SetViewPointMatrix(zeus::CTransform());
CGraphics::SetModelMatrix(zeus::CTransform());
2016-07-21 05:21:45 +00:00
2018-12-08 05:30:43 +00:00
return {{left, bottom}, {right, top}};
2016-07-21 05:21:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::SetClippingPlanes(const zeus::CFrustum& frustum) { x44_frustumPlanes = frustum; }
2016-07-21 05:21:45 +00:00
void CBooRenderer::SetViewport(int left, int bottom, int width, int height) {
CGraphics::SetViewport(left, bottom, width, height);
CGraphics::SetScissor(left, bottom, width, height);
2016-07-21 05:21:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::SetDebugOption(EDebugOption, int) {}
void CBooRenderer::BeginScene() {
2021-04-03 16:48:39 +00:00
OPTICK_EVENT();
2018-12-08 05:30:43 +00:00
CGraphics::SetViewport(0, 0, g_Viewport.x8_width, g_Viewport.xc_height);
CGraphics::SetPerspective(75.f, CGraphics::g_ProjAspect, 1.f, 4096.f);
CGraphics::SetModelMatrix(zeus::CTransform());
2017-05-06 05:21:42 +00:00
#if 0
if (x310_phazonSuitMaskCountdown != 0)
{
--x310_phazonSuitMaskCountdown;
if (x310_phazonSuitMaskCountdown == 0)
x314_phazonSuitMask.reset();
}
#endif
2018-12-08 05:30:43 +00:00
x318_27_currentRGBA6 = x318_26_requestRGBA6;
if (!x318_31_persistRGBA6)
x318_26_requestRGBA6 = false;
// GXSetPixelFmt(x318_27_currentRGBA6);
CGraphics::BeginScene();
2022-02-01 00:06:54 +00:00
// m_nextFogVolumePlaneShader = m_fogVolumePlaneShaders.begin();
// m_nextFogVolumeFilter = m_fogVolumeFilters.begin();
2018-12-08 05:30:43 +00:00
}
void CBooRenderer::EndScene() {
2021-04-03 16:48:39 +00:00
OPTICK_EVENT();
2018-12-08 05:30:43 +00:00
CGraphics::EndScene();
if (x2dc_reflectionAge >= 2) {
// Delete reflection tex x14c_
} else {
++x2dc_reflectionAge;
}
}
void CBooRenderer::SetAmbientColor(const zeus::CColor& color) { CGraphics::SetAmbientColor(color); }
void CBooRenderer::DrawString(const char*, int, int) {}
u32 CBooRenderer::GetFPS() { return 0; }
void CBooRenderer::CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::CacheReflection", zeus::skPurple);
2018-12-08 05:30:43 +00:00
if (!x318_24_refectionDirty)
return;
x318_24_refectionDirty = false;
x2dc_reflectionAge = 0;
2022-02-01 00:06:54 +00:00
// TODO
// BindReflectionDrawTarget();
// SViewport backupVp = g_Viewport;
// SetViewport(0, 0, 256, 256);
// CGraphics::g_BooMainCommandQueue->clearTarget();
// cb(ctx, CBooModel::g_ReflectViewPos);
// boo::SWindowRect rect(0, 0, 256, 256);
// CGraphics::g_BooMainCommandQueue->resolveBindTexture(x14c_reflectionTex, rect, false, 0, true, false);
// BindMainDrawTarget();
// SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height);
2018-12-08 05:30:43 +00:00
}
void CBooRenderer::DrawSpaceWarp(const zeus::CVector3f& pt, float strength) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawSpaceWarp", zeus::skPurple);
2018-12-08 05:30:43 +00:00
m_spaceWarpFilter.setStrength(strength);
m_spaceWarpFilter.draw(pt);
}
void CBooRenderer::DrawThermalModel(const CModel& model, const zeus::CColor& mulCol, const zeus::CColor& addCol) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawThermalModel", zeus::skPurple);
2018-12-08 05:30:43 +00:00
CModelFlags flags;
flags.m_extendedShader = EExtendedShader::ThermalModel;
2018-12-08 05:30:43 +00:00
flags.x4_color = mulCol;
flags.addColor = addCol;
model.UpdateLastFrame();
model.Draw(flags);
}
void CBooRenderer::DrawXRayOutline(const zeus::CAABox& aabb) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawXRayOutline", zeus::skPurple);
2018-12-08 05:30:43 +00:00
CModelFlags flags;
flags.m_extendedShader = EExtendedShader::ForcedAlpha;
for (CAreaListItem& item : x1c_areaListItems) {
if (item.x4_octTree) {
std::vector<u32> bitmap;
item.x4_octTree->FindOverlappingModels(bitmap, aabb);
for (u32 c = 0; c < item.x4_octTree->x14_bitmapWordCount; ++c) {
for (u32 b = 0; b < 32; ++b) {
if ((bitmap[c] & (1U << b)) != 0) {
2018-12-08 05:30:43 +00:00
CBooModel* model = item.x10_models[c * 32 + b];
2022-02-01 00:06:54 +00:00
// model->UpdateUniformData(flags, nullptr, nullptr);
2018-12-08 05:30:43 +00:00
const CBooSurface* surf = model->x38_firstUnsortedSurface;
while (surf) {
if (surf->GetBounds().intersects(aabb))
model->DrawSurface(*surf, flags);
surf = surf->m_next;
2016-08-07 00:20:02 +00:00
}
2018-12-08 05:30:43 +00:00
}
2016-08-05 20:26:23 +00:00
}
2018-12-08 05:30:43 +00:00
}
2016-08-05 20:26:23 +00:00
}
2018-12-08 05:30:43 +00:00
}
2016-07-21 05:21:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::SetWireframeFlags(int) {}
2016-07-21 05:21:45 +00:00
2018-12-08 05:30:43 +00:00
void CBooRenderer::SetWorldFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color) {
if (x318_28_disableFog)
mode = ERglFogMode::None;
CGraphics::SetFog(mode, startz, endz, color);
2016-07-21 05:21:45 +00:00
}
2017-08-13 07:56:35 +00:00
void CBooRenderer::RenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb,
2018-12-08 05:30:43 +00:00
const TLockedToken<CModel>* model, const CSkinnedModel* sModel) {
if (!x318_28_disableFog)
x2ac_fogVolumes.emplace_back(CGraphics::g_GXModelMatrix, color, aabb, model, sModel);
}
void CBooRenderer::SetThermal(bool thermal, float level, const zeus::CColor& color) {
x318_29_thermalVisor = thermal;
x2f0_thermalVisorLevel = level;
x2f4_thermColor = color;
CDecal::SetMoveRedToAlphaBuffer(false);
CElementGen::SetMoveRedToAlphaBuffer(false);
m_thermalHotPass = false;
2018-12-08 05:30:43 +00:00
}
void CBooRenderer::SetThermalColdScale(float scale) { x2f8_thermColdScale = zeus::clamp(0.f, scale, 1.f); }
void CBooRenderer::DoThermalBlendCold() {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DoThermalBlendCold", zeus::skMagenta);
zeus::CColor a = zeus::CColor::lerp(x2f4_thermColor, zeus::skWhite, x2f8_thermColdScale);
m_thermColdFilter->setColorA(a);
2018-12-08 05:30:43 +00:00
float bAlpha = 1.f;
if (x2f8_thermColdScale < 0.5f)
2018-12-08 05:30:43 +00:00
bAlpha = x2f8_thermColdScale * 2.f;
float bFac = (1.f - bAlpha) / 8.f;
m_thermColdFilter->setColorB(zeus::CColor(bFac, bAlpha));
float cFac;
if (x2f8_thermColdScale < 0.25f)
cFac = 0.f;
else if (x2f8_thermColdScale >= 1.f)
cFac = 1.f;
else
cFac = (x2f8_thermColdScale - 0.25f) * 4.f / 3.f;
m_thermColdFilter->setColorC(zeus::CColor(cFac, cFac));
2018-12-08 05:30:43 +00:00
m_thermColdFilter->setScale(x2f8_thermColdScale);
2018-12-08 05:30:43 +00:00
m_thermColdFilter->setNoiseOffset(x2a8_thermalRand.Next() % 32);
m_thermColdFilter->draw();
2018-12-08 05:30:43 +00:00
CElementGen::SetMoveRedToAlphaBuffer(true);
CDecal::SetMoveRedToAlphaBuffer(true);
2019-02-25 08:14:59 +00:00
m_thermalHotPass = true;
2018-12-08 05:30:43 +00:00
}
2019-02-25 08:14:59 +00:00
void CBooRenderer::DoThermalBlendHot() {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DoThermalBlendHot", zeus::skMagenta);
2019-02-25 08:14:59 +00:00
m_thermHotFilter->draw();
m_thermalHotPass = false;
}
2018-12-08 05:30:43 +00:00
u32 CBooRenderer::GetStaticWorldDataSize() { return 0; }
void CBooRenderer::PrepareDynamicLights(const std::vector<CLight>& lights) {
x300_dynamicLights = lights;
for (CAreaListItem& area : x1c_areaListItems) {
if (const CAreaRenderOctTree* arot = area.x4_octTree) {
area.x1c_lightOctreeWords.clear();
area.x1c_lightOctreeWords.resize(arot->x14_bitmapWordCount * lights.size());
u32* wordPtr = area.x1c_lightOctreeWords.data();
for (const CLight& light : lights) {
float radius = light.GetRadius();
zeus::CVector3f vMin = light.GetPosition() - radius;
zeus::CVector3f vMax = light.GetPosition() + radius;
zeus::CAABox aabb(vMin, vMax);
arot->FindOverlappingModels(wordPtr, aabb);
wordPtr += arot->x14_bitmapWordCount;
}
2016-07-25 22:52:02 +00:00
}
2018-12-08 05:30:43 +00:00
}
2016-07-21 05:21:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::SetGXRegister1Color(const zeus::CColor& color) { CGraphics::g_ColorRegs[1] = color; }
2017-04-13 19:28:31 +00:00
2018-12-08 05:30:43 +00:00
void CBooRenderer::SetWorldLightFadeLevel(float level) { x2fc_tevReg1Color = zeus::CColor(level, level, level, 1.f); }
2021-06-07 19:29:18 +00:00
void CBooRenderer::SetWorldLightMultiplyColor(const zeus::CColor& color) { CGraphics::g_ColorRegs[2] = color; }
2017-05-06 05:21:42 +00:00
void CBooRenderer::ReallyDrawPhazonSuitIndirectEffect(const zeus::CColor& vertColor, /*const CTexture& maskTex,*/
2018-12-08 05:30:43 +00:00
const CTexture& indTex, const zeus::CColor& modColor, float scale,
float offX, float offY) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::ReallyDrawPhazonSuitIndirectEffect", zeus::skMagenta);
2018-12-08 05:30:43 +00:00
float qScale = scale / 8.f; // Adjustment for URDE
m_phazonSuitFilter.draw(modColor, scale, offX * qScale, offY * qScale);
2017-05-06 05:21:42 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::ReallyDrawPhazonSuitEffect(const zeus::CColor& modColor /*, const CTexture& maskTex*/) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::ReallyDrawPhazonSuitEffect", zeus::skMagenta);
2018-12-08 05:30:43 +00:00
m_phazonSuitFilter.draw(modColor, 0.f, 0.f, 0.f);
2017-05-06 05:21:42 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::DoPhazonSuitIndirectAlphaBlur(float blurRadius /*, float f2*/,
const TLockedToken<CTexture>& indTex) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DoPhazonSuitIndirectAlphaBlur", zeus::skMagenta);
2018-12-08 05:30:43 +00:00
m_phazonSuitFilter.drawBlurPasses(blurRadius, indTex.IsLoaded() ? indTex.GetObj() : nullptr);
2017-05-06 05:21:42 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::DrawPhazonSuitIndirectEffect(const zeus::CColor& nonIndirectMod,
const TLockedToken<CTexture>& indTex, const zeus::CColor& indirectMod,
float blurRadius, float scale, float offX, float offY) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawPhazonSuitIndirectEffect", zeus::skPurple);
2018-12-08 05:30:43 +00:00
/* Indirect background already in binding 0 */
2017-05-06 05:21:42 +00:00
2018-12-08 05:30:43 +00:00
/* Resolve alpha channel of just-drawn phazon suit into binding 1 */
SClipScreenRect rect(g_Viewport);
CGraphics::ResolveSpareTexture(rect, 1);
2017-05-06 05:21:42 +00:00
2018-12-08 05:30:43 +00:00
/* Perform blur filter and resolve into binding 2 */
DoPhazonSuitIndirectAlphaBlur(blurRadius, indTex);
2017-05-06 05:21:42 +00:00
2018-12-08 05:30:43 +00:00
/* Draw effect; subtracting binding 1 from binding 2 for the filter 'cutout' */
if (indTex && indTex.IsLoaded())
ReallyDrawPhazonSuitIndirectEffect(zeus::skWhite, *indTex, indirectMod, scale, offX, offY);
2018-12-08 05:30:43 +00:00
else
ReallyDrawPhazonSuitEffect(nonIndirectMod);
2017-05-06 05:21:42 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::AllocatePhazonSuitMaskTexture() {
x318_26_requestRGBA6 = true;
x310_phazonSuitMaskCountdown = 2;
2017-05-06 05:21:42 +00:00
}
2018-12-08 05:30:43 +00:00
void CBooRenderer::FindOverlappingWorldModels(std::vector<u32>& modelBits, const zeus::CAABox& aabb) const {
u32 bitmapWords = 0;
for (const CAreaListItem& item : x1c_areaListItems)
if (item.x4_octTree)
bitmapWords += item.x4_octTree->x14_bitmapWordCount;
2017-03-05 07:57:12 +00:00
2018-12-08 05:30:43 +00:00
if (!bitmapWords) {
2017-03-05 07:57:12 +00:00
modelBits.clear();
2018-12-08 05:30:43 +00:00
return;
}
modelBits.clear();
modelBits.resize(bitmapWords);
u32 curWord = 0;
for (const CAreaListItem& item : x1c_areaListItems) {
if (!item.x4_octTree)
continue;
item.x4_octTree->FindOverlappingModels(modelBits.data() + curWord, aabb);
u32 wordModel = 0;
for (u32 i = 0; i < item.x4_octTree->x14_bitmapWordCount; ++i, wordModel += 32) {
2018-12-08 05:30:43 +00:00
u32& word = modelBits[curWord + i];
if (word == 0) {
2018-12-08 05:30:43 +00:00
continue;
}
for (u32 j = 0; j < 32; ++j) {
if (((1U << j) & word) != 0) {
2018-12-08 05:30:43 +00:00
const zeus::CAABox& modelAABB = item.x10_models[wordModel + j]->x20_aabb;
if (!modelAABB.intersects(aabb))
word &= ~(1U << j);
2017-03-05 07:57:12 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-03-05 07:57:12 +00:00
}
2018-12-08 05:30:43 +00:00
curWord += item.x4_octTree->x14_bitmapWordCount;
}
2017-03-05 07:57:12 +00:00
}
int CBooRenderer::DrawOverlappingWorldModelIDs(int alphaVal, const std::vector<u32>& modelBits,
const zeus::CAABox& aabb) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawOverlappingWorldModelIDs", zeus::skGrey);
2018-12-08 05:30:43 +00:00
SetupRendererStates();
UpdateAreaUniforms(-1, EWorldShadowMode::BallOnWorldIds, false);
2018-12-08 05:30:43 +00:00
CModelFlags flags;
flags.m_extendedShader = EExtendedShader::SolidColor; // Do solid color draw
u32 curWord = 0;
for (const CAreaListItem& item : x1c_areaListItems) {
if (!item.x4_octTree)
continue;
u32 wordModel = 0;
for (u32 i = 0; i < item.x4_octTree->x14_bitmapWordCount; ++i, wordModel += 32) {
2018-12-08 05:30:43 +00:00
const u32& word = modelBits[curWord + i];
if (word == 0) {
2018-12-08 05:30:43 +00:00
continue;
}
for (u32 j = 0; j < 32; ++j) {
if (((1U << j) & word) != 0) {
if (alphaVal > 255) {
2018-12-08 05:30:43 +00:00
return alphaVal;
}
2018-12-08 05:30:43 +00:00
flags.x4_color.a() = static_cast<float>(alphaVal) / 255.f;
CBooModel& model = *item.x10_models[wordModel + j];
2022-02-01 00:06:54 +00:00
// model.UpdateUniformData(flags, nullptr, nullptr, 3);
model.VerifyCurrentShader(0);
for (const CBooSurface* surf = model.x38_firstUnsortedSurface; surf; surf = surf->m_next) {
if (surf->GetBounds().intersects(aabb)) {
2018-12-08 05:30:43 +00:00
model.DrawSurface(*surf, flags);
}
}
2018-12-08 05:30:43 +00:00
alphaVal += 4;
2017-03-05 07:57:12 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-03-05 07:57:12 +00:00
}
2018-12-08 05:30:43 +00:00
curWord += item.x4_octTree->x14_bitmapWordCount;
}
return alphaVal;
2017-03-05 07:57:12 +00:00
}
2017-03-06 06:33:51 +00:00
void CBooRenderer::DrawOverlappingWorldModelShadows(int alphaVal, const std::vector<u32>& modelBits,
const zeus::CAABox& aabb, float alpha) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawOverlappingWorldModelShadows", zeus::skGrey);
2018-12-08 05:30:43 +00:00
CModelFlags flags;
flags.x4_color.a() = alpha;
flags.m_extendedShader = EExtendedShader::MorphBallShadow; // Do shadow draw
flags.mbShadowBox = aabb;
UpdateAreaUniforms(-1, EWorldShadowMode::BallOnWorldShadow, false, -1, &flags);
2018-12-08 05:30:43 +00:00
u32 curWord = 0;
for (const CAreaListItem& item : x1c_areaListItems) {
if (!item.x4_octTree)
continue;
u32 wordModel = 0;
for (u32 i = 0; i < item.x4_octTree->x14_bitmapWordCount; ++i, wordModel += 32) {
2018-12-08 05:30:43 +00:00
const u32& word = modelBits[curWord + i];
if (word == 0) {
2018-12-08 05:30:43 +00:00
continue;
}
for (u32 j = 0; j < 32; ++j) {
if (((1U << j) & word) != 0) {
if (alphaVal > 255) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
flags.x4_color.r() = static_cast<float>(alphaVal) / 255.f;
CBooModel& model = *item.x10_models[wordModel + j];
2022-02-01 00:06:54 +00:00
// model.UpdateUniformData(flags, nullptr, nullptr, 2);
model.VerifyCurrentShader(0);
2018-12-08 05:30:43 +00:00
for (const CBooSurface* surf = model.x38_firstUnsortedSurface; surf; surf = surf->m_next)
if (surf->GetBounds().intersects(aabb))
model.DrawSurface(*surf, flags);
alphaVal += 4;
2017-03-06 06:33:51 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-03-06 06:33:51 +00:00
}
2018-12-08 05:30:43 +00:00
curWord += item.x4_octTree->x14_bitmapWordCount;
}
2016-07-21 05:21:45 +00:00
}
2018-12-08 05:30:43 +00:00
2021-04-10 08:42:06 +00:00
} // namespace metaforce