2016-07-24 06:05:12 +00:00
|
|
|
#if _WIN32
|
|
|
|
#include <D3Dcommon.h>
|
|
|
|
#endif
|
2016-07-25 22:52:02 +00:00
|
|
|
#include "GameGlobalObjects.hpp"
|
2016-07-21 05:21:45 +00:00
|
|
|
#include "CBooRenderer.hpp"
|
2016-07-25 22:52:02 +00:00
|
|
|
#include "CTexture.hpp"
|
|
|
|
#include "CModel.hpp"
|
|
|
|
#include "Particle/CParticleGen.hpp"
|
2016-07-26 22:05:59 +00:00
|
|
|
#include "CMetroidModelInstance.hpp"
|
2016-07-28 04:55:06 +00:00
|
|
|
#include "World/CAreaOctTree.hpp"
|
2016-07-25 22:52:02 +00:00
|
|
|
|
|
|
|
#define FOGVOL_RAMP_RES 256
|
|
|
|
#define SPHERE_RAMP_RES 32
|
2016-07-21 05:21:45 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2016-07-25 22:52:02 +00:00
|
|
|
static rstl::reserved_vector<CDrawable, 50> sDataHolder;
|
|
|
|
static rstl::reserved_vector<rstl::reserved_vector<CDrawable*, 128>, 50> sBucketsHolder;
|
|
|
|
static rstl::reserved_vector<CDrawablePlaneObject, 8> sPlaneObjectDataHolder;
|
|
|
|
static rstl::reserved_vector<u16, 8> sPlaneObjectBucketHolder;
|
|
|
|
|
|
|
|
rstl::reserved_vector<u16, 50> Buckets::sBucketIndex;
|
|
|
|
rstl::reserved_vector<CDrawable, 50>* Buckets::sData = nullptr;
|
|
|
|
rstl::reserved_vector<rstl::reserved_vector<CDrawable*, 128>, 50>* Buckets::sBuckets = nullptr;
|
|
|
|
rstl::reserved_vector<CDrawablePlaneObject, 8>* Buckets::sPlaneObjectData = nullptr;
|
|
|
|
rstl::reserved_vector<u16, 8>* Buckets::sPlaneObjectBucket = nullptr;
|
|
|
|
const float Buckets::skWorstMinMaxDistance[2] = {99999.f, -99999.f};
|
|
|
|
float Buckets::sMinMaxDistance[2];
|
|
|
|
|
|
|
|
void Buckets::Clear()
|
|
|
|
{
|
|
|
|
sData->clear();
|
2016-07-26 02:43:55 +00:00
|
|
|
sBucketIndex.clear();
|
2016-07-25 22:52:02 +00:00
|
|
|
sPlaneObjectData->clear();
|
|
|
|
sPlaneObjectBucket->clear();
|
|
|
|
for (rstl::reserved_vector<CDrawable*, 128>& bucket : *sBuckets)
|
|
|
|
bucket.clear();
|
|
|
|
sMinMaxDistance[0] = skWorstMinMaxDistance[0];
|
|
|
|
sMinMaxDistance[1] = skWorstMinMaxDistance[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
void Buckets::Sort()
|
|
|
|
{
|
2016-07-26 02:43:55 +00:00
|
|
|
float delta = std::max(1.f, sMinMaxDistance[1] - sMinMaxDistance[0]);
|
|
|
|
sPlaneObjectBucket->resize(8);
|
|
|
|
|
|
|
|
std::sort(sPlaneObjectBucket->begin(), sPlaneObjectBucket->end(),
|
|
|
|
[](u16 a, u16 b) -> bool
|
|
|
|
{
|
|
|
|
return (*sPlaneObjectData)[a].GetDistance() >= (*sPlaneObjectData)[b].GetDistance();
|
|
|
|
});
|
|
|
|
|
|
|
|
u32 precision = 50 / (8 + 1);
|
|
|
|
float pitch = 1.f / (delta / float(precision - 2));
|
|
|
|
|
|
|
|
int accum = 0;
|
|
|
|
for (u16 idx : *sPlaneObjectBucket)
|
|
|
|
{
|
|
|
|
++accum;
|
|
|
|
CDrawablePlaneObject& planeObj = (*sPlaneObjectData)[idx];
|
|
|
|
planeObj.x24_targetBucket = precision * accum;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (CDrawable& drawable : *sData)
|
|
|
|
{
|
|
|
|
int slot;
|
|
|
|
if (sPlaneObjectBucket->empty())
|
|
|
|
{
|
|
|
|
slot = zeus::clamp(1, int((drawable.GetDistance() - sMinMaxDistance[0]) * pitch), 49);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* TODO: Planar sort distribution */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slot == -1)
|
|
|
|
slot = 49;
|
|
|
|
(*sBuckets)[slot].push_back(&drawable);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bucketIdx = sBuckets->size();
|
|
|
|
for (auto it = sBuckets->rbegin() ; it != sBuckets->rend() ; ++it)
|
|
|
|
{
|
|
|
|
--bucketIdx;
|
|
|
|
rstl::reserved_vector<CDrawable*, 128>& bucket = *it;
|
|
|
|
if (bucket.size())
|
|
|
|
{
|
2016-08-03 21:53:03 +00:00
|
|
|
sBucketIndex.push_back(bucketIdx);
|
2016-07-26 02:43:55 +00:00
|
|
|
std::sort(bucket.begin(), bucket.end(),
|
|
|
|
[](CDrawable* a, CDrawable* b) -> bool
|
|
|
|
{
|
|
|
|
return a->GetDistance() >= b->GetDistance();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void Buckets::InsertPlaneObject(float dist, float something, const zeus::CAABox& aabb, bool b1,
|
|
|
|
const zeus::CPlane& plane, bool b2, EDrawableType dtype, const void* data)
|
|
|
|
{
|
|
|
|
sPlaneObjectData->push_back(CDrawablePlaneObject(dtype, dist, something, aabb, b1, plane, b2, data));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Buckets::Insert(const zeus::CVector3f& pos, const zeus::CAABox& aabb, EDrawableType dtype,
|
|
|
|
const void* data, const zeus::CPlane& plane, u16 extraSort)
|
|
|
|
{
|
|
|
|
float dist = plane.pointToPlaneDist(pos);
|
|
|
|
sData->push_back(CDrawable(dtype, extraSort, dist, aabb, data));
|
|
|
|
if (sMinMaxDistance[0] > dist)
|
|
|
|
sMinMaxDistance[0] = dist;
|
|
|
|
if (sMinMaxDistance[1] < dist)
|
|
|
|
sMinMaxDistance[1] = dist;
|
|
|
|
}
|
|
|
|
|
|
|
|
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[0] = skWorstMinMaxDistance[0];
|
|
|
|
sMinMaxDistance[1] = skWorstMinMaxDistance[1];
|
|
|
|
}
|
|
|
|
|
2016-07-26 22:05:59 +00:00
|
|
|
CBooRenderer::CAreaListItem::CAreaListItem
|
|
|
|
(const std::vector<CMetroidModelInstance>* geom, const CAreaOctTree* octTree,
|
2016-07-28 04:55:06 +00:00
|
|
|
std::vector<CBooModel*>&& models, int areaIdx)
|
|
|
|
: x0_geometry(geom), x4_octTree(octTree), x10_models(std::move(models)), x18_areaIdx(areaIdx) {}
|
2016-07-26 22:05:59 +00:00
|
|
|
|
|
|
|
CBooRenderer::CAreaListItem::~CAreaListItem() {}
|
|
|
|
|
2016-07-28 04:55:06 +00:00
|
|
|
void CBooRenderer::ActivateLightsForModel(CAreaListItem* item, CBooModel& model)
|
|
|
|
{
|
|
|
|
std::vector<CLight> thisLights;
|
|
|
|
thisLights.reserve(4);
|
|
|
|
|
|
|
|
if (x304_lights.size())
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
void* unk3 = nullptr;
|
|
|
|
int x14 = 0;
|
|
|
|
if (item && item->x18_areaIdx != -1)
|
|
|
|
{
|
|
|
|
unk3 = item->x28_unk3;
|
|
|
|
x14 = item->x4_octTree->x14_;
|
|
|
|
}
|
|
|
|
void* unk3Cur = unk3;
|
|
|
|
*/
|
|
|
|
|
|
|
|
float lightRads[] = {-1.f, -1.f, -1.f, -1.f};
|
|
|
|
for (int i=0 ; i<4 ; ++i)
|
|
|
|
{
|
|
|
|
for (CLight& light : x304_lights)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
if (unk3)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if (light.x40_loadedIdx == i)
|
|
|
|
continue;
|
|
|
|
float rad = light.GetRadius();
|
|
|
|
if (model.x20_aabb.intersects(zeus::CSphere{light.x0_pos, rad}))
|
|
|
|
{
|
|
|
|
if (rad > lightRads[i])
|
|
|
|
{
|
|
|
|
lightRads[i] = rad;
|
|
|
|
light.x40_loadedIdx = i;
|
|
|
|
thisLights.push_back(light);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-03 21:53:03 +00:00
|
|
|
//model.ActivateLights(thisLights);
|
2016-07-28 04:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::RenderBucketItems(CAreaListItem* item)
|
2016-07-25 22:52:02 +00:00
|
|
|
{
|
2016-08-03 21:53:03 +00:00
|
|
|
CModelFlags flags;
|
|
|
|
flags.m_extendedShaderIdx = 1;
|
|
|
|
|
2016-07-25 22:52:02 +00:00
|
|
|
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*>((void*)drawable->GetData())->Render();
|
|
|
|
break;
|
|
|
|
}
|
2016-08-03 21:53:03 +00:00
|
|
|
case EDrawableType::WorldSurface:
|
2016-07-25 22:52:02 +00:00
|
|
|
{
|
|
|
|
CBooSurface* surf = static_cast<CBooSurface*>((void*)drawable->GetData());
|
|
|
|
CBooModel* model = surf->m_parent;
|
|
|
|
if (model)
|
|
|
|
{
|
2016-07-28 04:55:06 +00:00
|
|
|
ActivateLightsForModel(item, *model);
|
2016-08-03 21:53:03 +00:00
|
|
|
model->DrawSurface(*surf, flags);
|
2016-07-25 22:52:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2016-07-28 04:55:06 +00:00
|
|
|
if (xa8_drawableCallback)
|
2016-07-25 22:52:02 +00:00
|
|
|
{
|
2016-07-28 04:55:06 +00:00
|
|
|
xa8_drawableCallback(drawable->GetData(), xac_callbackContext,
|
2016-07-25 22:52:02 +00:00
|
|
|
int(drawable->GetType()) - 2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-28 04:55:06 +00:00
|
|
|
void CBooRenderer::HandleUnsortedModel(CAreaListItem* item, CBooModel& model)
|
|
|
|
{
|
|
|
|
ActivateLightsForModel(item, model);
|
|
|
|
CBooSurface* surf = model.x38_firstUnsortedSurface;
|
2016-08-03 21:53:03 +00:00
|
|
|
CModelFlags flags;
|
|
|
|
flags.m_extendedShaderIdx = 1;
|
2016-07-28 04:55:06 +00:00
|
|
|
while (surf)
|
|
|
|
{
|
2016-08-03 21:53:03 +00:00
|
|
|
model.DrawSurface(*surf, flags);
|
2016-07-28 04:55:06 +00:00
|
|
|
surf = surf->m_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 22:52:02 +00:00
|
|
|
void CBooRenderer::GenerateFogVolumeRampTex(boo::IGraphicsDataFactory::Context& ctx)
|
|
|
|
{
|
|
|
|
u8 data[FOGVOL_RAMP_RES][FOGVOL_RAMP_RES] = {};
|
|
|
|
for (int y=0 ; y<FOGVOL_RAMP_RES ; ++y)
|
|
|
|
{
|
|
|
|
for (int x=0 ; x<FOGVOL_RAMP_RES ; ++x)
|
|
|
|
{
|
|
|
|
int tmp = y << 16 | x << 8 | 0x7f;
|
|
|
|
double a = zeus::clamp(0.0, (-150.0 / (tmp * 749.7998 - 750.0) - 0.2) * 3.0 / 749.7998, 1.0);
|
|
|
|
data[y][x] = (a * a + a) / 2.f * 255;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x1b8_fogVolumeRamp = ctx.newStaticTexture(FOGVOL_RAMP_RES, FOGVOL_RAMP_RES, 1,
|
|
|
|
boo::TextureFormat::I8, data[0],
|
|
|
|
FOGVOL_RAMP_RES * FOGVOL_RAMP_RES);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::GenerateSphereRampTex(boo::IGraphicsDataFactory::Context& ctx)
|
|
|
|
{
|
|
|
|
u8 data[SPHERE_RAMP_RES][SPHERE_RAMP_RES] = {};
|
|
|
|
float halfRes = SPHERE_RAMP_RES / 2.f;
|
|
|
|
for (int y=0 ; y<SPHERE_RAMP_RES ; ++y)
|
|
|
|
{
|
|
|
|
for (int x=0 ; x<SPHERE_RAMP_RES ; ++x)
|
|
|
|
{
|
|
|
|
zeus::CVector2f vec((x - halfRes) / halfRes, (y - halfRes) / halfRes);
|
2016-07-31 05:06:05 +00:00
|
|
|
data[y][x] = 255 - zeus::clamp(0.f, vec.canBeNormalized() ? vec.magnitude() : 0.f, 1.f) * 255;
|
2016-07-25 22:52:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
x220_sphereRamp = ctx.newStaticTexture(SPHERE_RAMP_RES, SPHERE_RAMP_RES, 1,
|
|
|
|
boo::TextureFormat::I8, data[0],
|
|
|
|
SPHERE_RAMP_RES * SPHERE_RAMP_RES);
|
|
|
|
}
|
|
|
|
|
2016-07-27 19:07:46 +00:00
|
|
|
void CBooRenderer::LoadThermoPalette()
|
2016-07-25 22:52:02 +00:00
|
|
|
{
|
|
|
|
m_thermoPaletteTex = xc_store.GetObj("TXTR_ThermoPalette");
|
|
|
|
CTexture* thermoTexObj = m_thermoPaletteTex.GetObj();
|
|
|
|
if (thermoTexObj)
|
2016-08-03 21:53:03 +00:00
|
|
|
x288_thermoPalette = thermoTexObj->GetPaletteTexture();
|
2016-07-25 22:52:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-22 02:32:23 +00:00
|
|
|
CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac)
|
2016-07-25 22:52:02 +00:00
|
|
|
: x8_factory(resFac), xc_store(store), x2a8_thermalRand(20)
|
2016-07-22 02:32:23 +00:00
|
|
|
{
|
2016-08-03 21:53:03 +00:00
|
|
|
g_Renderer = this;
|
2016-07-25 22:52:02 +00:00
|
|
|
xee_24_ = true;
|
|
|
|
|
|
|
|
m_gfxToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
|
|
|
|
{
|
|
|
|
GenerateFogVolumeRampTex(ctx);
|
|
|
|
GenerateSphereRampTex(ctx);
|
|
|
|
return true;
|
|
|
|
});
|
2016-07-27 19:07:46 +00:00
|
|
|
LoadThermoPalette();
|
2016-08-03 21:53:03 +00:00
|
|
|
m_thermHotFilter.emplace();
|
2016-07-25 22:52:02 +00:00
|
|
|
|
|
|
|
Buckets::Init();
|
2016-07-22 02:32:23 +00:00
|
|
|
}
|
|
|
|
|
2016-07-26 22:05:59 +00:00
|
|
|
void CBooRenderer::AddWorldSurfaces(CBooModel& model)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-26 22:05:59 +00:00
|
|
|
CBooSurface* surf = model.x3c_firstSortedSurface;
|
|
|
|
while (surf)
|
|
|
|
{
|
2016-08-03 21:53:03 +00:00
|
|
|
const CBooModel::MaterialSet::Material& mat = model.GetMaterialByIndex(surf->m_data.matIdx);
|
2016-07-26 22:05:59 +00:00
|
|
|
zeus::CAABox aabb = surf->GetBounds();
|
2016-07-28 04:55:06 +00:00
|
|
|
zeus::CVector3f pt = aabb.closestPointAlongVector(xb0_viewPlane.vec);
|
2016-08-03 21:53:03 +00:00
|
|
|
Buckets::Insert(pt, aabb, EDrawableType::WorldSurface, surf, xb0_viewPlane,
|
2016-07-26 22:05:59 +00:00
|
|
|
mat.heclIr.m_blendDst != boo::BlendFactor::Zero);
|
|
|
|
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
|
|
|
|
CBooRenderer::FindStaticGeometry(const std::vector<CMetroidModelInstance>* geometry)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-26 22:05:59 +00:00
|
|
|
return std::find_if(x1c_areaListItems.begin(), x1c_areaListItems.end(),
|
|
|
|
[&](CAreaListItem& item) -> bool {return item.x0_geometry == geometry;});
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::AddStaticGeometry(const std::vector<CMetroidModelInstance>* geometry,
|
2016-07-28 04:55:06 +00:00
|
|
|
const CAreaOctTree* octTree, int areaIdx)
|
2016-07-26 22:05:59 +00:00
|
|
|
{
|
|
|
|
auto search = FindStaticGeometry(geometry);
|
|
|
|
if (search == x1c_areaListItems.end())
|
|
|
|
{
|
|
|
|
std::vector<CBooModel*> models;
|
|
|
|
if (geometry->size())
|
|
|
|
{
|
|
|
|
models.reserve(geometry->size());
|
|
|
|
for (const CMetroidModelInstance& inst : *geometry)
|
2016-07-31 02:06:47 +00:00
|
|
|
models.push_back(inst.m_instance);
|
2016-07-26 22:05:59 +00:00
|
|
|
}
|
2016-07-28 04:55:06 +00:00
|
|
|
x1c_areaListItems.emplace_back(geometry, octTree, std::move(models), areaIdx);
|
2016-07-26 22:05:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 23:06:57 +00:00
|
|
|
void CBooRenderer::EnablePVS(const CPVSVisSet* set, u32 modelCount)
|
|
|
|
{
|
|
|
|
xc8_pvs.emplace(*set);
|
|
|
|
xe0_pvsModelCount = modelCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::DisablePVS()
|
|
|
|
{
|
|
|
|
xc8_pvs = std::experimental::nullopt;
|
|
|
|
}
|
|
|
|
|
2016-07-26 22:05:59 +00:00
|
|
|
void CBooRenderer::RemoveStaticGeometry(const std::vector<CMetroidModelInstance>* geometry)
|
|
|
|
{
|
|
|
|
auto search = FindStaticGeometry(geometry);
|
|
|
|
if (search != x1c_areaListItems.end())
|
|
|
|
x1c_areaListItems.erase(search);
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 04:55:06 +00:00
|
|
|
void CBooRenderer::DrawUnsortedGeometry(int areaIdx, int mask, int targetMask)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-27 23:06:57 +00:00
|
|
|
//SetupRendererStates(true);
|
|
|
|
|
|
|
|
CAreaListItem* lastOctreeItem = nullptr;
|
|
|
|
|
|
|
|
for (CAreaListItem& item : x1c_areaListItems)
|
|
|
|
{
|
2016-07-28 04:55:06 +00:00
|
|
|
if (areaIdx != -1 && item.x18_areaIdx != areaIdx)
|
2016-07-27 23:06:57 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (item.x4_octTree)
|
|
|
|
lastOctreeItem = &item;
|
|
|
|
|
|
|
|
CPVSVisSet* pvs = nullptr;
|
|
|
|
if (xc8_pvs)
|
|
|
|
pvs = &*xc8_pvs;
|
|
|
|
if (xe0_pvsModelCount != item.x10_models.size())
|
|
|
|
pvs = nullptr;
|
|
|
|
|
|
|
|
int idx = 0;
|
|
|
|
for (auto it = item.x10_models.begin() ; it != item.x10_models.end() ; ++it, ++idx)
|
|
|
|
{
|
|
|
|
CBooModel* model = *it;
|
|
|
|
if (pvs)
|
|
|
|
{
|
|
|
|
bool vis = pvs->GetVisible(idx);
|
|
|
|
switch (xc4_pvsMode)
|
|
|
|
{
|
|
|
|
case EPVSMode::PVS:
|
|
|
|
{
|
|
|
|
if (!vis)
|
|
|
|
{
|
|
|
|
model->x40_25_modelVisible = false;
|
|
|
|
continue;
|
|
|
|
}
|
2016-07-28 04:55:06 +00:00
|
|
|
break;
|
2016-07-27 23:06:57 +00:00
|
|
|
}
|
|
|
|
case EPVSMode::PVSAndMask:
|
|
|
|
{
|
|
|
|
if (!vis && (model->x41_mask & mask) != targetMask)
|
|
|
|
{
|
|
|
|
model->x40_25_modelVisible = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((model->x41_mask & mask) != targetMask)
|
|
|
|
{
|
|
|
|
model->x40_25_modelVisible = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!x44_frustumPlanes.aabbFrustumTest(model->x20_aabb))
|
|
|
|
{
|
|
|
|
model->x40_25_modelVisible = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x318_25_drawWireframe)
|
|
|
|
{
|
|
|
|
model->x40_25_modelVisible = false;
|
|
|
|
//HandleUnsortedModelWireframe();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
model->x40_25_modelVisible = true;
|
2016-07-28 04:55:06 +00:00
|
|
|
HandleUnsortedModel(lastOctreeItem, *model);
|
2016-07-27 23:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//SetupCGraphicsStates();
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 04:55:06 +00:00
|
|
|
void CBooRenderer::DrawSortedGeometry(int areaIdx, int mask, int targetMask)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-27 23:06:57 +00:00
|
|
|
//SetupRendererStates(true);
|
2016-07-28 04:55:06 +00:00
|
|
|
|
|
|
|
CAreaListItem* lastOctreeItem = nullptr;
|
|
|
|
|
|
|
|
for (CAreaListItem& item : x1c_areaListItems)
|
|
|
|
{
|
|
|
|
if (areaIdx != -1 && item.x18_areaIdx != areaIdx)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (item.x4_octTree)
|
|
|
|
lastOctreeItem = &item;
|
|
|
|
|
|
|
|
for (auto it = item.x10_models.begin() ; it != item.x10_models.end() ; ++it)
|
|
|
|
{
|
|
|
|
CBooModel* model = *it;
|
|
|
|
if (model->x40_25_modelVisible)
|
|
|
|
AddWorldSurfaces(*model);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Buckets::Sort();
|
|
|
|
RenderBucketItems(lastOctreeItem);
|
|
|
|
|
|
|
|
//SetupCGraphicsStates();
|
|
|
|
//DrawRenderBucketsDebug();
|
|
|
|
Buckets::Clear();
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 04:55:06 +00:00
|
|
|
void CBooRenderer::DrawStaticGeometry(int modelCount, int mask, int targetMask)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-28 04:55:06 +00:00
|
|
|
DrawUnsortedGeometry(modelCount, mask, targetMask);
|
|
|
|
DrawSortedGeometry(modelCount, mask, targetMask);
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::PostRenderFogs()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-26 22:05:59 +00:00
|
|
|
void CBooRenderer::AddParticleGen(const CParticleGen& gen)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-26 22:05:59 +00:00
|
|
|
std::pair<zeus::CAABox, bool> bounds = gen.GetBounds();
|
|
|
|
if (bounds.second)
|
|
|
|
{
|
2016-07-28 04:55:06 +00:00
|
|
|
zeus::CVector3f pt = bounds.first.closestPointAlongVector(xb0_viewPlane.vec);
|
|
|
|
Buckets::Insert(pt, bounds.first, EDrawableType::Particle, &gen, xb0_viewPlane, 0);
|
2016-07-26 22:05:59 +00:00
|
|
|
}
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::AddPlaneObject(const void*, const zeus::CAABox&, const zeus::CPlane&, int)
|
|
|
|
{
|
2016-07-26 22:05:59 +00:00
|
|
|
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-26 22:05:59 +00:00
|
|
|
void CBooRenderer::AddDrawable(const void* obj, const zeus::CVector3f& pos, const zeus::CAABox& aabb, int mode, EDrawableSorting sorting)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-26 22:05:59 +00:00
|
|
|
if (sorting == EDrawableSorting::UnsortedCallback)
|
2016-07-28 04:55:06 +00:00
|
|
|
xa8_drawableCallback(obj, xac_callbackContext, mode);
|
2016-07-26 22:05:59 +00:00
|
|
|
else
|
2016-07-28 04:55:06 +00:00
|
|
|
Buckets::Insert(pos, aabb, EDrawableType(mode + 2), obj, xb0_viewPlane, 0);
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-26 22:05:59 +00:00
|
|
|
void CBooRenderer::SetDrawableCallback(TDrawableCallback&& cb, const void* ctx)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-28 04:55:06 +00:00
|
|
|
xa8_drawableCallback = std::move(cb);
|
2016-07-26 22:05:59 +00:00
|
|
|
xac_callbackContext = ctx;
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 04:55:06 +00:00
|
|
|
void CBooRenderer::SetWorldViewpoint(const zeus::CTransform& xf)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-28 04:55:06 +00:00
|
|
|
CGraphics::SetViewPointMatrix(xf);
|
|
|
|
xb0_viewPlane.vec = xf.basis[1];
|
|
|
|
xb0_viewPlane.d = xf.basis[1].dot(xf.origin);
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 04:55:06 +00:00
|
|
|
void CBooRenderer::SetPerspective(float fovy, float width, float height, float znear, float zfar)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-28 04:55:06 +00:00
|
|
|
CGraphics::SetPerspective(fovy, width / height, znear, zfar);
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 04:55:06 +00:00
|
|
|
void CBooRenderer::SetPerspective(float fovy, float aspect, float znear, float zfar)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-28 04:55:06 +00:00
|
|
|
CGraphics::SetPerspective(fovy, aspect, znear, zfar);
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 17:38:44 +00:00
|
|
|
void CBooRenderer::SetViewportOrtho(bool centered, float znear, float zfar)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-29 17:38:44 +00:00
|
|
|
float left = centered ? CGraphics::g_ViewportResolutionHalf.x : 0;
|
|
|
|
float bottom = centered ? CGraphics::g_ViewportResolutionHalf.y : 0;
|
|
|
|
float top = centered ? CGraphics::g_ViewportResolutionHalf.y : CGraphics::g_ViewportResolution.y;
|
|
|
|
float right = centered ? CGraphics::g_ViewportResolutionHalf.x : CGraphics::g_ViewportResolution.x;
|
|
|
|
|
|
|
|
CGraphics::SetOrtho(left, right, top, bottom, znear, zfar);
|
|
|
|
CGraphics::SetViewPointMatrix(zeus::CTransform::Identity());
|
|
|
|
CGraphics::SetModelMatrix(zeus::CTransform::Identity());
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-26 22:05:59 +00:00
|
|
|
void CBooRenderer::SetClippingPlanes(const zeus::CFrustum& frustum)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-26 22:05:59 +00:00
|
|
|
x44_frustumPlanes = frustum;
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 17:38:44 +00:00
|
|
|
void CBooRenderer::SetViewport(int l, int b, int w, int h)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-29 17:38:44 +00:00
|
|
|
CGraphics::SetViewport(l, b, w, h);
|
|
|
|
CGraphics::SetScissor(l, b, w, h);
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::SetDebugOption(EDebugOption, int)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::BeginScene()
|
|
|
|
{
|
2016-07-29 17:38:44 +00:00
|
|
|
CGraphics::SetViewport(0, 0, CGraphics::g_ViewportResolution.x, CGraphics::g_ViewportResolution.y);
|
|
|
|
CGraphics::SetPerspective(75.f, CGraphics::g_ProjAspect, 1.f, 4096.f);
|
|
|
|
CGraphics::SetModelMatrix(zeus::CTransform::Identity());
|
|
|
|
CGraphics::BeginScene();
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::EndScene()
|
|
|
|
{
|
2016-07-29 17:38:44 +00:00
|
|
|
CGraphics::EndScene();
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 17:38:44 +00:00
|
|
|
void CBooRenderer::SetAmbientColor(const zeus::CColor& color)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-29 17:38:44 +00:00
|
|
|
CGraphics::SetAmbientColor(color);
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::DrawString(const char*, int, int)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 CBooRenderer::GetFPS()
|
|
|
|
{
|
2016-07-24 06:05:12 +00:00
|
|
|
return 0;
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-31 02:06:47 +00:00
|
|
|
void CBooRenderer::DrawSpaceWarp(const zeus::CVector3f& pt, float strength)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-31 02:06:47 +00:00
|
|
|
m_spaceWarpFilter.setStrength(strength);
|
|
|
|
m_spaceWarpFilter.draw(pt);
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-31 02:06:47 +00:00
|
|
|
void CBooRenderer::DrawThermalModel(const CModel& model, const zeus::CColor& mulCol, const zeus::CColor& addCol)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-31 04:46:03 +00:00
|
|
|
CModelFlags flags;
|
|
|
|
flags.m_extendedShaderIdx = 2;
|
|
|
|
flags.color = mulCol;
|
|
|
|
flags.addColor = addCol;
|
|
|
|
model.Draw(flags);
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::DrawXRayOutline(const CModel&, const float*, const float*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::SetWireframeFlags(int)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::SetWorldFog(ERglFogMode, float, float, const zeus::CColor&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::RenderFogVolume(const zeus::CColor&, const zeus::CAABox&, const TLockedToken<CModel>*, const CSkinnedModel*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-31 02:06:47 +00:00
|
|
|
void CBooRenderer::SetThermal(bool thermal, float level, const zeus::CColor& color)
|
2016-07-21 05:21:45 +00:00
|
|
|
{
|
2016-07-31 02:06:47 +00:00
|
|
|
x318_29_thermalVisor = thermal;
|
|
|
|
x2f0_thermalVisorLevel = level;
|
|
|
|
x2f4_thermColor = color;
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-22 19:46:30 +00:00
|
|
|
void CBooRenderer::SetThermalColdScale(float scale)
|
|
|
|
{
|
|
|
|
x2f8_thermColdScale = zeus::clamp(0.f, scale, 1.f);
|
|
|
|
}
|
|
|
|
|
2016-07-21 05:21:45 +00:00
|
|
|
void CBooRenderer::DoThermalBlendCold()
|
2016-07-25 22:52:02 +00:00
|
|
|
{
|
|
|
|
zeus::CColor a = zeus::CColor::lerp(x2f4_thermColor, zeus::CColor::skWhite, x2f8_thermColdScale);
|
|
|
|
m_thermColdFilter.setColorA(a);
|
|
|
|
float bFac = 0.f;
|
|
|
|
float bAlpha = 1.f;
|
|
|
|
if (x2f8_thermColdScale < 0.5f)
|
|
|
|
{
|
|
|
|
bAlpha = x2f8_thermColdScale * 2.f;
|
|
|
|
bFac = (1.f - bAlpha) / 8.f;
|
|
|
|
}
|
|
|
|
zeus::CColor b{bFac, bFac, bFac, bAlpha};
|
|
|
|
m_thermColdFilter.setColorB(b);
|
|
|
|
zeus::CColor c = zeus::CColor::lerp(zeus::CColor::skBlack, zeus::CColor::skWhite,
|
2016-07-28 04:55:06 +00:00
|
|
|
zeus::clamp(0.f, (x2f8_thermColdScale - 0.25f) * 4.f / 3.f, 1.f));
|
2016-07-25 22:52:02 +00:00
|
|
|
m_thermColdFilter.setColorC(c);
|
|
|
|
|
|
|
|
m_thermColdFilter.setScale(x2f8_thermColdScale);
|
|
|
|
|
|
|
|
m_thermColdFilter.setShift(x2a8_thermalRand.Next() % 32);
|
|
|
|
m_thermColdFilter.draw();
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBooRenderer::DoThermalBlendHot()
|
|
|
|
{
|
2016-08-03 21:53:03 +00:00
|
|
|
m_thermHotFilter->draw();
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 CBooRenderer::GetStaticWorldDataSize()
|
|
|
|
{
|
2016-07-24 06:05:12 +00:00
|
|
|
return 0;
|
2016-07-21 05:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|