Buckets::Sort implementation

This commit is contained in:
Jack Andersen 2016-07-25 16:43:55 -10:00
parent 6aead5a6e7
commit e3c8e5a7be
4 changed files with 69 additions and 14 deletions

View File

@ -30,6 +30,7 @@ float Buckets::sMinMaxDistance[2];
void Buckets::Clear()
{
sData->clear();
sBucketIndex.clear();
sPlaneObjectData->clear();
sPlaneObjectBucket->clear();
for (rstl::reserved_vector<CDrawable*, 128>& bucket : *sBuckets)
@ -40,6 +41,65 @@ void Buckets::Clear()
void Buckets::Sort()
{
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;
sBucketIndex.push_back(bucketIdx);
rstl::reserved_vector<CDrawable*, 128>& bucket = *it;
if (bucket.size())
{
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);
}
}
void Buckets::InsertPlaneObject(float dist, float something, const zeus::CAABox& aabb, bool b1,
@ -92,15 +152,14 @@ void CBooRenderer::RenderBucketItems(const std::vector<CLight>& lights)
static_cast<CParticleGen*>((void*)drawable->GetData())->Render();
break;
}
case EDrawableType::World:
case EDrawableType::Surface:
{
CBooSurface* surf = static_cast<CBooSurface*>((void*)drawable->GetData());
CBooModel* model = surf->m_parent;
if (model)
{
model->ActivateLights(lights);
CModelFlags flags;
model->DrawSurface(*surf, flags);
model->DrawSurface(*surf, CModelFlags{});
}
break;
}

View File

@ -8,10 +8,10 @@ namespace urde
{
enum class EDrawableType : u16
{
World,
Surface,
Particle,
UnsortedDrawable,
SortedDrawable
UnsortedCallback,
SortedCallback
};
class CDrawable

View File

@ -8,7 +8,8 @@ namespace urde
{
class CDrawablePlaneObject : public CDrawable
{
u16 x24_extraSort2;
friend class Buckets;
u16 x24_targetBucket;
float x28_something;
zeus::CPlane x2c_plane;
bool x3c_24 : 1;
@ -16,7 +17,7 @@ class CDrawablePlaneObject : public CDrawable
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),
: CDrawable(dtype, 0, dist, aabb, data), x24_targetBucket(0), x28_something(something),
x2c_plane(plane) {x3c_24 = b1; x3c_25 = b2;}
};
}

View File

@ -70,12 +70,7 @@ BOO_GLSL_BINDING_HEAD
" float shiftScene1 = dot(texture(sceneTex, shiftCoord + vec2(vtf.shiftScale.x / 8.0, 0.0)), kRGBToYPrime);\n"
" vec2 indCoord = (vtf.indMtx * vec3(shiftScene0 - 0.5, shiftScene1 - 0.5, 1.0)).xy;\n"
" float indScene = dot(texture(sceneTex, vtf.sceneUv + indCoord), kRGBToYPrime);\n"
" colorOut = vtf.colorReg0 * indScene * vec4(0.00001) + vtf.colorReg1 * shiftScene0 * vec4(0.00001) + vtf.colorReg2 * vec4(0.00001);\n"
" float blue = 0.0;\n"
" float green = 0.0;\n"
" if (indCoord.y < 0.0) blue = -indCoord.y * 10.0;\n"
" else green = indCoord.y * 10.0;\n"
" colorOut += vec4(0.0, green, blue, 1.0);\n"
" colorOut = vtf.colorReg0 * indScene + vtf.colorReg1 * shiftScene0 + vtf.colorReg2;\n"
"}\n";
URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter)