mirror of https://github.com/AxioDL/metaforce.git
Merge branch 'master' of https://github.com/AxioDL/urde
This commit is contained in:
commit
d7f31b5b7a
|
@ -1,14 +1,200 @@
|
|||
#if _WIN32
|
||||
#include <D3Dcommon.h>
|
||||
#endif
|
||||
#include "GameGlobalObjects.hpp"
|
||||
#include "CBooRenderer.hpp"
|
||||
#include "CTexture.hpp"
|
||||
#include "CModel.hpp"
|
||||
#include "Particle/CParticleGen.hpp"
|
||||
|
||||
#define MIRROR_RAMP_RES 32
|
||||
#define FOGVOL_RAMP_RES 256
|
||||
#define SPHERE_RAMP_RES 32
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
||||
CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac)
|
||||
: x8_factory(resFac), xc_store(store)
|
||||
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();
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
void CBooRenderer::RenderBucketItems(const std::vector<CLight>& lights)
|
||||
{
|
||||
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;
|
||||
}
|
||||
case EDrawableType::World:
|
||||
{
|
||||
CBooSurface* surf = static_cast<CBooSurface*>((void*)drawable->GetData());
|
||||
CBooModel* model = surf->m_parent;
|
||||
if (model)
|
||||
{
|
||||
model->ActivateLights(lights);
|
||||
CModelFlags flags;
|
||||
model->DrawSurface(*surf, flags);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (xa8_renderCallback)
|
||||
{
|
||||
xa8_renderCallback(drawable->GetData(), xac_callbackContext,
|
||||
int(drawable->GetType()) - 2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CBooRenderer::GenerateMirrorRampTex(boo::IGraphicsDataFactory::Context& ctx)
|
||||
{
|
||||
u8 data[MIRROR_RAMP_RES][MIRROR_RAMP_RES][4] = {};
|
||||
float halfRes = MIRROR_RAMP_RES / 2.f;
|
||||
for (int y=0 ; y<MIRROR_RAMP_RES ; ++y)
|
||||
{
|
||||
for (int x=0 ; x<MIRROR_RAMP_RES ; ++x)
|
||||
{
|
||||
zeus::CVector2f vec((x - halfRes) / halfRes, (y - halfRes) / halfRes);
|
||||
if (vec.magnitude() <= halfRes && vec.canBeNormalized())
|
||||
vec.normalize();
|
||||
data[y][x][0] = zeus::clamp(0.f, vec.x, 1.f) * 255;
|
||||
data[y][x][1] = zeus::clamp(0.f, vec.y, 1.f) * 255;
|
||||
}
|
||||
}
|
||||
x150_mirrorRamp = ctx.newStaticTexture(MIRROR_RAMP_RES, MIRROR_RAMP_RES, 1,
|
||||
boo::TextureFormat::RGBA8, data[0],
|
||||
MIRROR_RAMP_RES * MIRROR_RAMP_RES * 4);
|
||||
}
|
||||
|
||||
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);
|
||||
data[y][x] = zeus::clamp(0.f, vec.canBeNormalized() ? vec.magnitude() : 0.f, 1.f) * 255;
|
||||
}
|
||||
}
|
||||
x220_sphereRamp = ctx.newStaticTexture(SPHERE_RAMP_RES, SPHERE_RAMP_RES, 1,
|
||||
boo::TextureFormat::I8, data[0],
|
||||
SPHERE_RAMP_RES * SPHERE_RAMP_RES);
|
||||
}
|
||||
|
||||
void CBooRenderer::LoadThermoPalette(boo::IGraphicsDataFactory::Context& ctx)
|
||||
{
|
||||
m_thermoPaletteTex = xc_store.GetObj("TXTR_ThermoPalette");
|
||||
CTexture* thermoTexObj = m_thermoPaletteTex.GetObj();
|
||||
if (thermoTexObj)
|
||||
x288_thermoPalette = thermoTexObj->GetBooTexture();
|
||||
}
|
||||
|
||||
CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac)
|
||||
: x8_factory(resFac), xc_store(store), x2a8_thermalRand(20)
|
||||
{
|
||||
xee_24_ = true;
|
||||
|
||||
m_gfxToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
|
||||
{
|
||||
GenerateMirrorRampTex(ctx);
|
||||
GenerateFogVolumeRampTex(ctx);
|
||||
GenerateSphereRampTex(ctx);
|
||||
LoadThermoPalette(ctx);
|
||||
return true;
|
||||
});
|
||||
|
||||
Buckets::Init();
|
||||
}
|
||||
|
||||
void CBooRenderer::AddStaticGeometry(const std::vector<CMetroidModelInstance>&, const CAreaOctTree*, int)
|
||||
|
@ -227,7 +413,26 @@ void CBooRenderer::SetThermalColdScale(float scale)
|
|||
}
|
||||
|
||||
void CBooRenderer::DoThermalBlendCold()
|
||||
{
|
||||
{
|
||||
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,
|
||||
(x2f8_thermColdScale - 0.25f) * 4.f / 3.f);
|
||||
m_thermColdFilter.setColorC(c);
|
||||
|
||||
m_thermColdFilter.setScale(x2f8_thermColdScale);
|
||||
|
||||
m_thermColdFilter.setShift(x2a8_thermalRand.Next() % 32);
|
||||
m_thermColdFilter.draw();
|
||||
}
|
||||
|
||||
void CBooRenderer::DoThermalBlendHot()
|
||||
|
|
|
@ -1,25 +1,39 @@
|
|||
#ifndef __URDE_CBOORENDERER_HPP__
|
||||
#define __URDE_CBOORENDERER_HPP__
|
||||
|
||||
#include <functional>
|
||||
#include "IRenderer.hpp"
|
||||
#include "CDrawable.hpp"
|
||||
#include "CDrawablePlaneObject.hpp"
|
||||
#include "Shaders/CThermalColdFilter.hpp"
|
||||
#include "CRandom16.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
class IObjectStore;
|
||||
class CMemorySys;
|
||||
class IFactory;
|
||||
class CTexture;
|
||||
|
||||
class Buckets
|
||||
{
|
||||
friend class CBooRenderer;
|
||||
|
||||
static rstl::reserved_vector<u16, 50> sBucketIndex;
|
||||
static rstl::reserved_vector<CDrawable, 50>* sData;
|
||||
static rstl::reserved_vector<rstl::reserved_vector<CDrawable*, 128>, 50>* sBuckets;
|
||||
static rstl::reserved_vector<CDrawablePlaneObject, 8>* sPlaneObjectData;
|
||||
static rstl::reserved_vector<u16, 8>* sPlaneObjectBucket;
|
||||
static const float skWorstMinMaxDistance[2];
|
||||
static float sMinMaxDistance[2];
|
||||
|
||||
public:
|
||||
static void Clear();
|
||||
static void Sort();
|
||||
static void InsertPlaneObject(float, float, const zeus::CAABox&, bool, const zeus::CPlane&,
|
||||
bool, EDrawableType, const void*);
|
||||
static void Insert(const zeus::CVector3f&, const zeus::CAABox&, EDrawableType, const void*,
|
||||
const zeus::CPlane&, unsigned short);
|
||||
static void InsertPlaneObject(float dist, float something, const zeus::CAABox& aabb, bool b1,
|
||||
const zeus::CPlane& plane, bool b2, EDrawableType dtype, const void* data);
|
||||
static void Insert(const zeus::CVector3f& pos, const zeus::CAABox& aabb, EDrawableType dtype,
|
||||
const void* data, const zeus::CPlane& plane, u16 extraSort);
|
||||
static void Shutdown();
|
||||
static void Init();
|
||||
};
|
||||
|
@ -28,15 +42,61 @@ class CBooRenderer : public IRenderer
|
|||
{
|
||||
IFactory& x8_factory;
|
||||
IObjectStore& xc_store;
|
||||
boo::GraphicsDataToken m_gfxToken;
|
||||
// CFont x10_fnt;
|
||||
u32 x18_ = 0;
|
||||
std::list<u32> x1c_;
|
||||
zeus::CFrustum x44_frustumPlanes;
|
||||
|
||||
float x2f8_thermColdScale = 0.f;
|
||||
TDrawableCallback xa8_renderCallback;
|
||||
const void* xac_callbackContext;
|
||||
|
||||
zeus::CVector3f xb0_ = {0.f, 1.f, 0.f};
|
||||
float xbc_ = 0;
|
||||
|
||||
//boo::ITextureS* xe4_blackTex = nullptr;
|
||||
bool xee_24_ : 1;
|
||||
|
||||
boo::ITextureR* x14c_reflectionTex = nullptr;
|
||||
boo::ITextureS* x150_mirrorRamp = nullptr;
|
||||
boo::ITextureS* x1b8_fogVolumeRamp = nullptr;
|
||||
boo::ITextureS* x220_sphereRamp = nullptr;
|
||||
TLockedToken<CTexture> m_thermoPaletteTex;
|
||||
boo::ITexture* x288_thermoPalette = nullptr;
|
||||
|
||||
CRandom16 x2a8_thermalRand;
|
||||
std::list<u32> x2b8_;
|
||||
std::list<u32> x2d0_;
|
||||
zeus::CColor x2e0_ = zeus::CColor::skWhite;
|
||||
zeus::CVector3f x2e4_ = {0.f, 1.f, 0.f};
|
||||
|
||||
zeus::CColor x2f4_thermColor;
|
||||
float x2f8_thermColdScale = 0.f;
|
||||
CThermalColdFilter m_thermColdFilter;
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
bool x318_24_refectionDirty : 1;
|
||||
bool x318_25_ : 1;
|
||||
bool x318_26_ : 1;
|
||||
bool x318_27_ : 1;
|
||||
bool x318_28_ : 1;
|
||||
bool x318_29_ : 1;
|
||||
bool x318_30_ : 1;
|
||||
bool x318_31_ : 1;
|
||||
};
|
||||
u16 dummy = 0;
|
||||
};
|
||||
|
||||
void GenerateMirrorRampTex(boo::IGraphicsDataFactory::Context& ctx);
|
||||
void GenerateFogVolumeRampTex(boo::IGraphicsDataFactory::Context& ctx);
|
||||
void GenerateSphereRampTex(boo::IGraphicsDataFactory::Context& ctx);
|
||||
void LoadThermoPalette(boo::IGraphicsDataFactory::Context& ctx);
|
||||
|
||||
void RenderBucketItems(const std::vector<CLight>& lights);
|
||||
|
||||
public:
|
||||
CBooRenderer(IObjectStore& store, IFactory& resFac);
|
||||
|
||||
|
@ -96,6 +156,9 @@ public:
|
|||
void DoThermalBlendCold();
|
||||
void DoThermalBlendHot();
|
||||
u32 GetStaticWorldDataSize();
|
||||
|
||||
void BindMainDrawTarget() {CGraphics::g_BooMainCommandQueue->setRenderTarget(CGraphics::g_SpareTexture);}
|
||||
void BindReflectionDrawTarget() {CGraphics::g_BooMainCommandQueue->setRenderTarget(x14c_reflectionTex);}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
namespace urde
|
||||
{
|
||||
enum class EDrawableType
|
||||
enum class EDrawableType : u16
|
||||
{
|
||||
World,
|
||||
Particle,
|
||||
|
@ -16,14 +16,20 @@ enum class EDrawableType
|
|||
|
||||
class CDrawable
|
||||
{
|
||||
EDrawableType x0_type;
|
||||
u16 x2_extraSort;
|
||||
const void* x4_data;
|
||||
zeus::CAABox x8_aabb;
|
||||
float x20_viewDist;
|
||||
public:
|
||||
CDrawable(EDrawableType, u16, float, const zeus::CAABox&, const void*);
|
||||
CDrawable(EDrawableType dtype, u16 extraSort, float planeDot, const zeus::CAABox& aabb, const void* data)
|
||||
: x0_type(dtype), x2_extraSort(extraSort), x4_data(data), x8_aabb(aabb), x20_viewDist(planeDot) {}
|
||||
|
||||
EDrawableType GetType() const;
|
||||
const zeus::CAABox& GetBounds() const;
|
||||
float GetDistance() const;
|
||||
void* GetData() const;
|
||||
void GetExtraSort() const;
|
||||
EDrawableType GetType() const {return x0_type;}
|
||||
const zeus::CAABox& GetBounds() const {return x8_aabb;}
|
||||
float GetDistance() const {return x20_viewDist;}
|
||||
const void* GetData() const {return x4_data;}
|
||||
u16 GetExtraSort() const {return x2_extraSort;}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,18 @@
|
|||
|
||||
namespace urde
|
||||
{
|
||||
class CDrawablePlaneObject
|
||||
class CDrawablePlaneObject : public CDrawable
|
||||
{
|
||||
CDrawablePlaneObject(EDrawableType, float, float, const zeus::CAABox&, bool, const zeus::CPlane&, bool, const void*);
|
||||
u16 x24_extraSort2;
|
||||
float x28_something;
|
||||
zeus::CPlane x2c_plane;
|
||||
bool x3c_24 : 1;
|
||||
bool x3c_25 : 1;
|
||||
public:
|
||||
CDrawablePlaneObject(EDrawableType dtype, float dist, float something, const zeus::CAABox& aabb,
|
||||
bool b1, const zeus::CPlane& plane, bool b2, const void* data)
|
||||
: CDrawable(dtype, 0, dist, aabb, data), x24_extraSort2(0), x28_something(something),
|
||||
x2c_plane(plane) {x3c_24 = b1; x3c_25 = b2;}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ struct CBooSurface
|
|||
class CBooModel
|
||||
{
|
||||
friend class CModel;
|
||||
friend class CBooRenderer;
|
||||
public:
|
||||
using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet;
|
||||
using UVAnimation = DataSpec::DNAMP1::MaterialSet::Material::UVAnimation;
|
||||
|
|
2
specter
2
specter
|
@ -1 +1 @@
|
|||
Subproject commit 096472697cbcded63e076e9a35332698f903e042
|
||||
Subproject commit 8d40a09b7ca4719cef4f54c9ce31ed48bc550b48
|
Loading…
Reference in New Issue