mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-12 19:31:41 +00:00
Reorg of the probe initialization/update code to streamline parts of it, and make it flow more obviously
Added some initial asset stuffs for Das Boot for building out a better testing level.
This commit is contained in:
parent
17cec11b97
commit
a552471e4e
33 changed files with 317 additions and 1821 deletions
|
|
@ -73,7 +73,8 @@ S32 QSORT_CALLBACK AscendingReflectProbeInfluence(const void* a, const void* b)
|
|||
|
||||
//
|
||||
//
|
||||
ProbeRenderInst::ProbeRenderInst() : SystemInterface(),
|
||||
ProbeRenderInst::ProbeRenderInst() :
|
||||
mIsEnabled(true),
|
||||
mTransform(true),
|
||||
mDirty(false),
|
||||
mPriority(1.0f),
|
||||
|
|
@ -85,7 +86,8 @@ ProbeRenderInst::ProbeRenderInst() : SystemInterface(),
|
|||
mProbeRefScale(1,1,1),
|
||||
mAtten(0.0),
|
||||
mCubemapIndex(0),
|
||||
mIsSkylight(false)
|
||||
mIsSkylight(false),
|
||||
mProbeIdx(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -267,12 +269,12 @@ bool RenderProbeMgr::onAdd()
|
|||
return false;
|
||||
}
|
||||
|
||||
/*String brdfTexturePath = GFXTextureManager::getBRDFTexturePath();
|
||||
String brdfTexturePath = GFXTextureManager::getBRDFTexturePath();
|
||||
if (!mBRDFTexture.set(brdfTexturePath, &GFXTexturePersistentSRGBProfile, "BRDFTexture"))
|
||||
{
|
||||
Con::errorf("RenderProbeMgr::onAdd: Failed to load BRDF Texture");
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -312,21 +314,21 @@ void RenderProbeMgr::addElement(RenderInst *inst)
|
|||
}*/
|
||||
}
|
||||
|
||||
void RenderProbeMgr::registerProbe(U32 probeIdx)
|
||||
ProbeRenderInst* RenderProbeMgr::registerProbe(const bool &isSkylight)
|
||||
{
|
||||
//Mostly for consolidation, but also lets us sanity check or prep any other data we need for rendering this in one place at time of flagging for render
|
||||
if (probeIdx >= ProbeRenderInst::all.size())
|
||||
return;
|
||||
ProbeRenderInst newProbe;
|
||||
newProbe.mIsSkylight = isSkylight;
|
||||
|
||||
mRegisteredProbes.push_back_unique(probeIdx);
|
||||
mRegisteredProbes.push_back(newProbe);
|
||||
newProbe.mProbeIdx = mRegisteredProbes.size();
|
||||
|
||||
if (!ProbeRenderInst::all[probeIdx]->mIsSkylight)
|
||||
if (!newProbe.mIsSkylight)
|
||||
{
|
||||
const U32 cubeIndex = _findNextEmptyCubeSlot();
|
||||
if (cubeIndex == INVALID_CUBE_SLOT)
|
||||
{
|
||||
Con::warnf("RenderProbeMgr::addProbe: Invalid cubemap slot.");
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//check if we need to resize the cubemap array
|
||||
|
|
@ -349,33 +351,34 @@ void RenderProbeMgr::registerProbe(U32 probeIdx)
|
|||
mCubeSlotCount += PROBE_ARRAY_SLOT_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
ProbeRenderInst::all[probeIdx]->mCubemapIndex = cubeIndex;
|
||||
newProbe.mCubemapIndex = cubeIndex;
|
||||
//mark cubemap slot as taken
|
||||
mCubeMapSlots[cubeIndex] = true;
|
||||
mCubeMapCount++;
|
||||
|
||||
Con::warnf("RenderProbeMgr::registerProbe: Registered probe %u to cubeIndex %u", probeIdx, cubeIndex);
|
||||
Con::warnf("RenderProbeMgr::registerProbe: Registered probe %u to cubeIndex %u", newProbe.mProbeIdx, cubeIndex);
|
||||
}
|
||||
|
||||
//rebuild our probe data
|
||||
_setupStaticParameters();
|
||||
mProbesDirty = true;
|
||||
|
||||
return &mRegisteredProbes.last();
|
||||
}
|
||||
|
||||
void RenderProbeMgr::unregisterProbe(U32 probeIdx)
|
||||
{
|
||||
//Mostly for consolidation, but also lets us sanity check or prep any other data we need for rendering this in one place at time of flagging for render
|
||||
if (probeIdx >= ProbeRenderInst::all.size())
|
||||
if (probeIdx >= mRegisteredProbes.size())
|
||||
return;
|
||||
|
||||
mRegisteredProbes.remove(probeIdx);
|
||||
|
||||
if (ProbeRenderInst::all[probeIdx]->mCubemapIndex == INVALID_CUBE_SLOT)
|
||||
if (mRegisteredProbes[probeIdx].mCubemapIndex == INVALID_CUBE_SLOT)
|
||||
return;
|
||||
|
||||
//mark cubemap slot as available now
|
||||
mCubeMapSlots[ProbeRenderInst::all[probeIdx]->mCubemapIndex] = false;
|
||||
mCubeMapSlots[mRegisteredProbes[probeIdx].mCubemapIndex] = false;
|
||||
mCubeMapCount--;
|
||||
|
||||
mRegisteredProbes.erase(probeIdx);
|
||||
|
||||
//rebuild our probe data
|
||||
_setupStaticParameters();
|
||||
}
|
||||
|
|
@ -407,7 +410,7 @@ void RenderProbeMgr::updateProbes()
|
|||
void RenderProbeMgr::_setupStaticParameters()
|
||||
{
|
||||
//Array rendering
|
||||
U32 probeCount = ProbeRenderInst::all.size();
|
||||
U32 probeCount = mRegisteredProbes.size();
|
||||
|
||||
mEffectiveProbeCount = 0;
|
||||
mMipCount = 0;
|
||||
|
|
@ -433,10 +436,10 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
irradMaps.clear();
|
||||
Vector<U32> cubemapIdxes;
|
||||
|
||||
if (probeCount != 0 && ProbeRenderInst::all[0]->mPrefilterCubemap != nullptr)
|
||||
if (probeCount != 0 && mRegisteredProbes[0].mPrefilterCubemap != nullptr)
|
||||
{
|
||||
//Get our mipCount
|
||||
mMipCount = ProbeRenderInst::all[0]->mPrefilterCubemap.getPointer()->getMipMapLevels();
|
||||
mMipCount = mRegisteredProbes[0].mPrefilterCubemap.getPointer()->getMipMapLevels();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -448,7 +451,7 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
if (mEffectiveProbeCount >= MAXPROBECOUNT)
|
||||
break;
|
||||
|
||||
const ProbeRenderInst& curEntry = *ProbeRenderInst::all[i];
|
||||
const ProbeRenderInst& curEntry = mRegisteredProbes[i];
|
||||
if (!curEntry.mIsEnabled)
|
||||
continue;
|
||||
|
||||
|
|
@ -489,29 +492,21 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
mProbesDirty = false;
|
||||
}
|
||||
|
||||
void RenderProbeMgr::updateProbeTexture(ProbeRenderInst* probe)
|
||||
{
|
||||
//We don't stuff skylights into the array, so we can just skip out on this if it's a skylight
|
||||
if (probe->mIsSkylight)
|
||||
return;
|
||||
|
||||
S32 probeIdx = ProbeRenderInst::all.find_next(probe);
|
||||
|
||||
if (probeIdx != -1) //i mean, the opposite shouldn't even be possible
|
||||
updateProbeTexture(probeIdx);
|
||||
}
|
||||
|
||||
void RenderProbeMgr::updateProbeTexture(U32 probeIdx)
|
||||
{
|
||||
if (probeIdx >= ProbeRenderInst::all.size())
|
||||
if (probeIdx >= mRegisteredProbes.size())
|
||||
return;
|
||||
|
||||
const U32 cubeIndex = ProbeRenderInst::all[probeIdx]->mCubemapIndex;
|
||||
mIrradianceArray->updateTexture(ProbeRenderInst::all[probeIdx]->mIrradianceCubemap, cubeIndex);
|
||||
mPrefilterArray->updateTexture(ProbeRenderInst::all[probeIdx]->mPrefilterCubemap, cubeIndex);
|
||||
//We don't stuff skylights into the array, so we can just skip out on this if it's a skylight
|
||||
if (mRegisteredProbes[probeIdx].mIsSkylight)
|
||||
return;
|
||||
|
||||
const U32 cubeIndex = mRegisteredProbes[probeIdx].mCubemapIndex;
|
||||
mIrradianceArray->updateTexture(mRegisteredProbes[probeIdx].mIrradianceCubemap, cubeIndex);
|
||||
mPrefilterArray->updateTexture(mRegisteredProbes[probeIdx].mPrefilterCubemap, cubeIndex);
|
||||
|
||||
Con::warnf("UpdatedProbeTexture - probeIdx: %u on cubeIndex %u, Irrad validity: %d, Prefilter validity: %d", probeIdx, cubeIndex,
|
||||
ProbeRenderInst::all[probeIdx]->mIrradianceCubemap->isInitialized(), ProbeRenderInst::all[probeIdx]->mPrefilterCubemap->isInitialized());
|
||||
mRegisteredProbes[probeIdx].mIrradianceCubemap->isInitialized(), mRegisteredProbes[probeIdx].mPrefilterCubemap->isInitialized());
|
||||
}
|
||||
|
||||
void RenderProbeMgr::_setupPerFrameParameters(const SceneRenderState *state)
|
||||
|
|
@ -593,7 +588,7 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
|
|||
matSet.restoreSceneViewProjection();
|
||||
|
||||
//Array rendering
|
||||
U32 probeCount = ProbeRenderInst::all.size();
|
||||
U32 probeCount = mRegisteredProbes.size();
|
||||
|
||||
S8 bestPickProbes[4] = { -1,-1,-1,-1 };
|
||||
|
||||
|
|
@ -603,7 +598,7 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
|
|||
//if (effectiveProbeCount >= MAX_FORWARD_PROBES)
|
||||
// break;
|
||||
|
||||
const ProbeRenderInst& curEntry = *ProbeRenderInst::all[i];
|
||||
const ProbeRenderInst& curEntry = mRegisteredProbes[i];
|
||||
if (!curEntry.mIsEnabled)
|
||||
continue;
|
||||
|
||||
|
|
@ -614,13 +609,13 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
|
|||
if (dist > curEntry.mRadius || dist > curEntry.mExtents.len())
|
||||
continue;
|
||||
|
||||
if(bestPickProbes[0] == -1 || (Point3F(sgData.objTrans->getPosition() - ProbeRenderInst::all[bestPickProbes[0]]->mPosition).len() > dist))
|
||||
if(bestPickProbes[0] == -1 || (Point3F(sgData.objTrans->getPosition() - mRegisteredProbes[bestPickProbes[0]].mPosition).len() > dist))
|
||||
bestPickProbes[0] = i;
|
||||
else if (bestPickProbes[1] == -1 || (Point3F(sgData.objTrans->getPosition() - ProbeRenderInst::all[bestPickProbes[1]]->mPosition).len() > dist))
|
||||
else if (bestPickProbes[1] == -1 || (Point3F(sgData.objTrans->getPosition() - mRegisteredProbes[bestPickProbes[1]].mPosition).len() > dist))
|
||||
bestPickProbes[1] = i;
|
||||
else if (bestPickProbes[2] == -1 || (Point3F(sgData.objTrans->getPosition() - ProbeRenderInst::all[bestPickProbes[2]]->mPosition).len() > dist))
|
||||
else if (bestPickProbes[2] == -1 || (Point3F(sgData.objTrans->getPosition() - mRegisteredProbes[bestPickProbes[2]].mPosition).len() > dist))
|
||||
bestPickProbes[2] = i;
|
||||
else if (bestPickProbes[3] == -1 || (Point3F(sgData.objTrans->getPosition() - ProbeRenderInst::all[bestPickProbes[3]]->mPosition).len() > dist))
|
||||
else if (bestPickProbes[3] == -1 || (Point3F(sgData.objTrans->getPosition() - mRegisteredProbes[bestPickProbes[3]].mPosition).len() > dist))
|
||||
bestPickProbes[3] = i;
|
||||
}
|
||||
}
|
||||
|
|
@ -631,7 +626,7 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
|
|||
if (bestPickProbes[i] == -1)
|
||||
continue;
|
||||
|
||||
const ProbeRenderInst& curEntry = *ProbeRenderInst::all[bestPickProbes[i]];
|
||||
const ProbeRenderInst& curEntry = mRegisteredProbes[bestPickProbes[i]];
|
||||
|
||||
probePositionArray[effectiveProbeCount] = curEntry.getPosition();
|
||||
probeRefPositionArray[effectiveProbeCount] = curEntry.mProbeRefOffset;
|
||||
|
|
@ -666,8 +661,8 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
|
|||
shaderConsts->setSafe(probeShaderConsts->mProbeBoxMaxSC, probeBoxMaxArray);
|
||||
shaderConsts->setSafe(probeShaderConsts->mProbeConfigDataSC, probeConfigArray);
|
||||
|
||||
//if (mBRDFTexture.isValid())
|
||||
// GFX->setTexture(3, mBRDFTexture);
|
||||
if (mBRDFTexture.isValid())
|
||||
GFX->setTexture(3, mBRDFTexture);
|
||||
|
||||
if(probeShaderConsts->mProbeSpecularCubemapSC->getSamplerRegister() != -1)
|
||||
GFX->setCubeArrayTexture(probeShaderConsts->mProbeSpecularCubemapSC->getSamplerRegister(), mPrefilterArray);
|
||||
|
|
@ -680,12 +675,12 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
|
|||
&& probeShaderConsts->mSkylightSpecularMap->isValid())
|
||||
{
|
||||
//Array rendering
|
||||
U32 probeCount = ProbeRenderInst::all.size();
|
||||
U32 probeCount = mRegisteredProbes.size();
|
||||
|
||||
bool hasSkylight = false;
|
||||
for (U32 i = 0; i < probeCount; i++)
|
||||
{
|
||||
const ProbeRenderInst& curEntry = *ProbeRenderInst::all[i];
|
||||
const ProbeRenderInst& curEntry = mRegisteredProbes[i];
|
||||
if (!curEntry.mIsEnabled)
|
||||
continue;
|
||||
|
||||
|
|
@ -754,8 +749,6 @@ void RenderProbeMgr::setProbeInfo(ProcessedMaterial *pmat,
|
|||
//-----------------------------------------------------------------------------
|
||||
void RenderProbeMgr::render( SceneRenderState *state )
|
||||
{
|
||||
return;
|
||||
//PROFILE_SCOPE(RenderProbeMgr_render);
|
||||
if (getProbeArrayEffect() == nullptr)
|
||||
return;
|
||||
|
||||
|
|
@ -763,7 +756,7 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
_setupStaticParameters();
|
||||
|
||||
// Early out if nothing to draw.
|
||||
if (!RenderProbeMgr::smRenderReflectionProbes || !state->isDiffusePass() || (!ProbeRenderInst::all.size() || mEffectiveProbeCount == 0 || mCubeMapCount != 0 ) && !mHasSkylight)
|
||||
if (!RenderProbeMgr::smRenderReflectionProbes || !state->isDiffusePass() || (!mRegisteredProbes.size() || mEffectiveProbeCount == 0 || mCubeMapCount != 0 ) && !mHasSkylight)
|
||||
{
|
||||
getProbeArrayEffect()->setSkip(true);
|
||||
return;
|
||||
|
|
@ -791,7 +784,7 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_CONTRIB", useDebugContrib);
|
||||
|
||||
//Array rendering
|
||||
//U32 probeCount = ProbeRenderInst::all.size();
|
||||
//U32 probeCount = mRegisteredProbes.size();
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$hasSkylight", (float)mHasSkylight);
|
||||
if (mHasSkylight)
|
||||
|
|
@ -805,7 +798,7 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
mProbeArrayEffect->setShaderConst("$cubeMips", (float)mMipCount);
|
||||
if (mEffectiveProbeCount != 0)
|
||||
{
|
||||
//mProbeArrayEffect->setTexture(3, mBRDFTexture);
|
||||
mProbeArrayEffect->setTexture(3, mBRDFTexture);
|
||||
mProbeArrayEffect->setCubemapArrayTexture(4, mPrefilterArray);
|
||||
mProbeArrayEffect->setCubemapArrayTexture(5, mIrradianceArray);
|
||||
|
||||
|
|
|
|||
|
|
@ -57,8 +57,10 @@ static U32 MAXPROBECOUNT = 50;
|
|||
class PostEffect;
|
||||
class ReflectionProbe;
|
||||
|
||||
struct ProbeRenderInst : public SystemInterface<ProbeRenderInst>
|
||||
struct ProbeRenderInst
|
||||
{
|
||||
bool mIsEnabled;
|
||||
|
||||
MatrixF mTransform;
|
||||
|
||||
F32 mRadius;
|
||||
|
|
@ -99,6 +101,8 @@ struct ProbeRenderInst : public SystemInterface<ProbeRenderInst>
|
|||
|
||||
U32 mCubemapIndex;
|
||||
|
||||
U32 mProbeIdx;
|
||||
|
||||
public:
|
||||
|
||||
ProbeRenderInst();
|
||||
|
|
@ -124,6 +128,11 @@ public:
|
|||
F32 getScore() const { return mScore; }
|
||||
|
||||
void clear();
|
||||
|
||||
inline bool ProbeRenderInst::operator ==(const ProbeRenderInst& b) const
|
||||
{
|
||||
return mProbeIdx == b.mProbeIdx;
|
||||
}
|
||||
};
|
||||
|
||||
struct ProbeShaderConstants
|
||||
|
|
@ -168,7 +177,7 @@ class RenderProbeMgr : public RenderBinManager
|
|||
{
|
||||
typedef RenderBinManager Parent;
|
||||
|
||||
Vector<U32> mRegisteredProbes;
|
||||
Vector<ProbeRenderInst> mRegisteredProbes;
|
||||
|
||||
bool mProbesDirty;
|
||||
|
||||
|
|
@ -254,7 +263,6 @@ protected:
|
|||
GFXShaderConstBuffer *shaderConsts);
|
||||
|
||||
void _setupStaticParameters();
|
||||
void updateProbeTexture(U32 probeIdx);
|
||||
void _setupPerFrameParameters(const SceneRenderState *state);
|
||||
virtual void addElement(RenderInst *inst);
|
||||
virtual void render(SceneRenderState * state);
|
||||
|
|
@ -263,29 +271,6 @@ protected:
|
|||
|
||||
PostEffect* getProbeArrayEffect();
|
||||
|
||||
public:
|
||||
// RenderBinMgr
|
||||
void updateProbes();
|
||||
void updateProbeTexture(ProbeRenderInst* probe);
|
||||
|
||||
/// Returns the active LM.
|
||||
static inline RenderProbeMgr* getProbeManager();
|
||||
|
||||
void registerProbe(U32 probeIdx);
|
||||
void unregisterProbe(U32 probeIdx);
|
||||
|
||||
virtual void setProbeInfo(ProcessedMaterial *pmat,
|
||||
const Material *mat,
|
||||
const SceneData &sgData,
|
||||
const SceneRenderState *state,
|
||||
U32 pass,
|
||||
GFXShaderConstBuffer *shaderConsts);
|
||||
|
||||
/// Debug rendering
|
||||
static bool smRenderReflectionProbes;
|
||||
|
||||
void bakeProbe(ReflectionProbe *probeInfo);
|
||||
void bakeProbes();
|
||||
|
||||
U32 _findNextEmptyCubeSlot()
|
||||
{
|
||||
|
|
@ -296,6 +281,31 @@ public:
|
|||
}
|
||||
return INVALID_CUBE_SLOT;
|
||||
}
|
||||
|
||||
public:
|
||||
// RenderBinMgr
|
||||
void updateProbes();
|
||||
|
||||
/// Returns the active LM.
|
||||
static inline RenderProbeMgr* getProbeManager();
|
||||
|
||||
ProbeRenderInst* registerProbe(const bool& isSkylight);
|
||||
void unregisterProbe(U32 probeIdx);
|
||||
|
||||
virtual void setProbeInfo(ProcessedMaterial *pmat,
|
||||
const Material *mat,
|
||||
const SceneData &sgData,
|
||||
const SceneRenderState *state,
|
||||
U32 pass,
|
||||
GFXShaderConstBuffer *shaderConsts);
|
||||
|
||||
void updateProbeTexture(U32 probeIdx);
|
||||
|
||||
/// Debug rendering
|
||||
static bool smRenderReflectionProbes;
|
||||
|
||||
void bakeProbe(ReflectionProbe *probeInfo);
|
||||
void bakeProbes();
|
||||
};
|
||||
|
||||
RenderProbeMgr* RenderProbeMgr::getProbeManager()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue