mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
WIP of shifting the skylight cubemap to be packed into the cubemap array
This commit is contained in:
parent
27b304eec3
commit
b40d33a663
4 changed files with 63 additions and 90 deletions
|
|
@ -638,8 +638,7 @@ void ReflectionProbe::processBakedCubemap()
|
||||||
mProbeInfo->mIsEnabled = true;
|
mProbeInfo->mIsEnabled = true;
|
||||||
|
|
||||||
//Update the probe manager with our new texture!
|
//Update the probe manager with our new texture!
|
||||||
if (!mProbeInfo->mIsSkylight)
|
PROBEMGR->updateProbeTexture(mProbeInfo->mProbeIdx);
|
||||||
PROBEMGR->updateProbeTexture(mProbeInfo->mProbeIdx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -730,8 +729,7 @@ void ReflectionProbe::processStaticCubemap()
|
||||||
mProbeInfo->mIsEnabled = true;
|
mProbeInfo->mIsEnabled = true;
|
||||||
|
|
||||||
//Update the probe manager with our new texture!
|
//Update the probe manager with our new texture!
|
||||||
if (!mProbeInfo->mIsSkylight)
|
PROBEMGR->updateProbeTexture(mProbeInfo->mProbeIdx);
|
||||||
PROBEMGR->updateProbeTexture(mProbeInfo->mProbeIdx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -739,7 +737,7 @@ bool ReflectionProbe::createClientResources()
|
||||||
{
|
{
|
||||||
if (mProbeInfo == nullptr)
|
if (mProbeInfo == nullptr)
|
||||||
{
|
{
|
||||||
mProbeInfo = PROBEMGR->registerProbe(mProbeShapeType == ProbeRenderInst::Skylight);
|
mProbeInfo = PROBEMGR->registerProbe();
|
||||||
if (!mProbeInfo)
|
if (!mProbeInfo)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -314,51 +314,47 @@ void RenderProbeMgr::addElement(RenderInst *inst)
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
ProbeRenderInst* RenderProbeMgr::registerProbe(const bool &isSkylight)
|
ProbeRenderInst* RenderProbeMgr::registerProbe()
|
||||||
{
|
{
|
||||||
ProbeRenderInst newProbe;
|
ProbeRenderInst newProbe;
|
||||||
newProbe.mIsSkylight = isSkylight;
|
|
||||||
|
|
||||||
mRegisteredProbes.push_back(newProbe);
|
mRegisteredProbes.push_back(newProbe);
|
||||||
newProbe.mProbeIdx = mRegisteredProbes.size();
|
newProbe.mProbeIdx = mRegisteredProbes.size();
|
||||||
|
|
||||||
if (!newProbe.mIsSkylight)
|
const U32 cubeIndex = _findNextEmptyCubeSlot();
|
||||||
|
if (cubeIndex == INVALID_CUBE_SLOT)
|
||||||
{
|
{
|
||||||
const U32 cubeIndex = _findNextEmptyCubeSlot();
|
Con::warnf("RenderProbeMgr::addProbe: Invalid cubemap slot.");
|
||||||
if (cubeIndex == INVALID_CUBE_SLOT)
|
return nullptr;
|
||||||
{
|
|
||||||
Con::warnf("RenderProbeMgr::addProbe: Invalid cubemap slot.");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
//check if we need to resize the cubemap array
|
|
||||||
if (cubeIndex >= mCubeSlotCount)
|
|
||||||
{
|
|
||||||
//alloc temp array handles
|
|
||||||
GFXCubemapArrayHandle irr = GFXCubemapArrayHandle(GFX->createCubemapArray());
|
|
||||||
GFXCubemapArrayHandle prefilter = GFXCubemapArrayHandle(GFX->createCubemapArray());
|
|
||||||
|
|
||||||
irr->init(mCubeSlotCount + PROBE_ARRAY_SLOT_BUFFER_SIZE, PROBE_IRRAD_SIZE, PROBE_FORMAT);
|
|
||||||
prefilter->init(mCubeSlotCount + PROBE_ARRAY_SLOT_BUFFER_SIZE, PROBE_PREFILTER_SIZE, PROBE_FORMAT);
|
|
||||||
|
|
||||||
mIrradianceArray->copyTo(irr);
|
|
||||||
mPrefilterArray->copyTo(prefilter);
|
|
||||||
|
|
||||||
//assign the temp handles to the new ones, this will destroy the old ones as well
|
|
||||||
mIrradianceArray = irr;
|
|
||||||
mPrefilterArray = prefilter;
|
|
||||||
|
|
||||||
mCubeSlotCount += PROBE_ARRAY_SLOT_BUFFER_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
newProbe.mCubemapIndex = cubeIndex;
|
|
||||||
//mark cubemap slot as taken
|
|
||||||
mCubeMapSlots[cubeIndex] = true;
|
|
||||||
mCubeMapCount++;
|
|
||||||
|
|
||||||
Con::warnf("RenderProbeMgr::registerProbe: Registered probe %u to cubeIndex %u", newProbe.mProbeIdx, cubeIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check if we need to resize the cubemap array
|
||||||
|
if (cubeIndex >= mCubeSlotCount)
|
||||||
|
{
|
||||||
|
//alloc temp array handles
|
||||||
|
GFXCubemapArrayHandle irr = GFXCubemapArrayHandle(GFX->createCubemapArray());
|
||||||
|
GFXCubemapArrayHandle prefilter = GFXCubemapArrayHandle(GFX->createCubemapArray());
|
||||||
|
|
||||||
|
irr->init(mCubeSlotCount + PROBE_ARRAY_SLOT_BUFFER_SIZE, PROBE_IRRAD_SIZE, PROBE_FORMAT);
|
||||||
|
prefilter->init(mCubeSlotCount + PROBE_ARRAY_SLOT_BUFFER_SIZE, PROBE_PREFILTER_SIZE, PROBE_FORMAT);
|
||||||
|
|
||||||
|
mIrradianceArray->copyTo(irr);
|
||||||
|
mPrefilterArray->copyTo(prefilter);
|
||||||
|
|
||||||
|
//assign the temp handles to the new ones, this will destroy the old ones as well
|
||||||
|
mIrradianceArray = irr;
|
||||||
|
mPrefilterArray = prefilter;
|
||||||
|
|
||||||
|
mCubeSlotCount += PROBE_ARRAY_SLOT_BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
newProbe.mCubemapIndex = cubeIndex;
|
||||||
|
//mark cubemap slot as taken
|
||||||
|
mCubeMapSlots[cubeIndex] = true;
|
||||||
|
mCubeMapCount++;
|
||||||
|
|
||||||
|
Con::warnf("RenderProbeMgr::registerProbe: Registered probe %u to cubeIndex %u", newProbe.mProbeIdx, cubeIndex);
|
||||||
|
|
||||||
mProbesDirty = true;
|
mProbesDirty = true;
|
||||||
|
|
||||||
return &mRegisteredProbes.last();
|
return &mRegisteredProbes.last();
|
||||||
|
|
@ -416,6 +412,7 @@ void RenderProbeMgr::_setupStaticParameters()
|
||||||
mMipCount = 0;
|
mMipCount = 0;
|
||||||
|
|
||||||
mHasSkylight = false;
|
mHasSkylight = false;
|
||||||
|
mSkylightCubemapIdx = -1;
|
||||||
|
|
||||||
if (probePositionsData.size() != MAXPROBECOUNT)
|
if (probePositionsData.size() != MAXPROBECOUNT)
|
||||||
{
|
{
|
||||||
|
|
@ -434,19 +431,9 @@ void RenderProbeMgr::_setupStaticParameters()
|
||||||
probeBBMaxData.fill(Point4F::Zero);
|
probeBBMaxData.fill(Point4F::Zero);
|
||||||
probeConfigData.fill(Point4F::Zero);
|
probeConfigData.fill(Point4F::Zero);
|
||||||
|
|
||||||
cubeMaps.clear();
|
|
||||||
irradMaps.clear();
|
|
||||||
Vector<U32> cubemapIdxes;
|
Vector<U32> cubemapIdxes;
|
||||||
|
|
||||||
if (probeCount != 0 && mRegisteredProbes[0].mPrefilterCubemap != nullptr)
|
mMipCount = 1;
|
||||||
{
|
|
||||||
//Get our mipCount
|
|
||||||
mMipCount = mRegisteredProbes[0].mPrefilterCubemap.getPointer()->getMipMapLevels();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mMipCount = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (U32 i = 0; i < probeCount; i++)
|
for (U32 i = 0; i < probeCount; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -457,11 +444,12 @@ void RenderProbeMgr::_setupStaticParameters()
|
||||||
if (!curEntry.mIsEnabled)
|
if (!curEntry.mIsEnabled)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
U32 mips = mRegisteredProbes[0].mPrefilterCubemap.getPointer()->getMipMapLevels();
|
||||||
|
mMipCount = mips != 0 && mips > mMipCount ? mips : 0;
|
||||||
|
|
||||||
if (curEntry.mProbeShapeType == ProbeRenderInst::ProbeShapeType::Skylight || curEntry.mIsSkylight)
|
if (curEntry.mProbeShapeType == ProbeRenderInst::ProbeShapeType::Skylight || curEntry.mIsSkylight)
|
||||||
{
|
{
|
||||||
skylightPos = curEntry.getPosition();
|
mSkylightCubemapIdx = curEntry.mCubemapIndex;
|
||||||
skylightPrefilterMap = curEntry.mPrefilterCubemap;
|
|
||||||
skylightIrradMap = curEntry.mIrradianceCubemap;
|
|
||||||
mHasSkylight = true;
|
mHasSkylight = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -483,9 +471,6 @@ void RenderProbeMgr::_setupStaticParameters()
|
||||||
curEntry.mAtten,
|
curEntry.mAtten,
|
||||||
curEntry.mCubemapIndex);
|
curEntry.mCubemapIndex);
|
||||||
|
|
||||||
cubeMaps.push_back(curEntry.mPrefilterCubemap);
|
|
||||||
irradMaps.push_back(curEntry.mIrradianceCubemap);
|
|
||||||
|
|
||||||
cubemapIdxes.push_back(i);
|
cubemapIdxes.push_back(i);
|
||||||
|
|
||||||
mEffectiveProbeCount++;
|
mEffectiveProbeCount++;
|
||||||
|
|
@ -499,10 +484,6 @@ void RenderProbeMgr::updateProbeTexture(U32 probeIdx)
|
||||||
if (probeIdx >= mRegisteredProbes.size())
|
if (probeIdx >= mRegisteredProbes.size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//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;
|
const U32 cubeIndex = mRegisteredProbes[probeIdx].mCubemapIndex;
|
||||||
mIrradianceArray->updateTexture(mRegisteredProbes[probeIdx].mIrradianceCubemap, cubeIndex);
|
mIrradianceArray->updateTexture(mRegisteredProbes[probeIdx].mIrradianceCubemap, cubeIndex);
|
||||||
mPrefilterArray->updateTexture(mRegisteredProbes[probeIdx].mPrefilterCubemap, cubeIndex);
|
mPrefilterArray->updateTexture(mRegisteredProbes[probeIdx].mPrefilterCubemap, cubeIndex);
|
||||||
|
|
@ -758,7 +739,7 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
||||||
_setupStaticParameters();
|
_setupStaticParameters();
|
||||||
|
|
||||||
// Early out if nothing to draw.
|
// Early out if nothing to draw.
|
||||||
if (!RenderProbeMgr::smRenderReflectionProbes || !state->isDiffusePass() || (!mRegisteredProbes.size() || mEffectiveProbeCount == 0 || mCubeMapCount != 0 ) && !mHasSkylight)
|
if (!RenderProbeMgr::smRenderReflectionProbes || !state->isDiffusePass() || (mRegisteredProbes.size() == 0 || (mEffectiveProbeCount == 0 && !mHasSkylight)))
|
||||||
{
|
{
|
||||||
getProbeArrayEffect()->setSkip(true);
|
getProbeArrayEffect()->setSkip(true);
|
||||||
return;
|
return;
|
||||||
|
|
@ -772,7 +753,7 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
||||||
// the vector light material as we use lazy creation.
|
// the vector light material as we use lazy creation.
|
||||||
//_setupPerFrameParameters(state);
|
//_setupPerFrameParameters(state);
|
||||||
|
|
||||||
//Visualization
|
//Visualization
|
||||||
String useDebugAtten = Con::getVariable("$Probes::showAttenuation", "0");
|
String useDebugAtten = Con::getVariable("$Probes::showAttenuation", "0");
|
||||||
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_ATTENUATION", useDebugAtten);
|
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_ATTENUATION", useDebugAtten);
|
||||||
|
|
||||||
|
|
@ -785,14 +766,17 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
||||||
String useDebugContrib = Con::getVariable("$Probes::showProbeContrib", "0");
|
String useDebugContrib = Con::getVariable("$Probes::showProbeContrib", "0");
|
||||||
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_CONTRIB", useDebugContrib);
|
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_CONTRIB", useDebugContrib);
|
||||||
|
|
||||||
//Array rendering
|
if (mHasSkylight || mEffectiveProbeCount != 0)
|
||||||
//U32 probeCount = mRegisteredProbes.size();
|
{
|
||||||
|
mProbeArrayEffect->setTexture(3, mBRDFTexture);
|
||||||
|
mProbeArrayEffect->setCubemapArrayTexture(4, mPrefilterArray);
|
||||||
|
mProbeArrayEffect->setCubemapArrayTexture(5, mIrradianceArray);
|
||||||
|
}
|
||||||
|
|
||||||
mProbeArrayEffect->setShaderConst("$hasSkylight", (float)mHasSkylight);
|
mProbeArrayEffect->setShaderConst("$hasSkylight", (float)mHasSkylight);
|
||||||
if (mHasSkylight)
|
if (mHasSkylight)
|
||||||
{
|
{
|
||||||
mProbeArrayEffect->setCubemapTexture(6, skylightPrefilterMap);
|
mProbeArrayEffect->setShaderConst("$skylightCubemapIdx", mSkylightCubemapIdx);
|
||||||
mProbeArrayEffect->setCubemapTexture(7, skylightIrradMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mProbeArrayEffect->setShaderConst("$numProbes", (float)mEffectiveProbeCount);
|
mProbeArrayEffect->setShaderConst("$numProbes", (float)mEffectiveProbeCount);
|
||||||
|
|
@ -800,10 +784,6 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
||||||
mProbeArrayEffect->setShaderConst("$cubeMips", (float)mMipCount);
|
mProbeArrayEffect->setShaderConst("$cubeMips", (float)mMipCount);
|
||||||
if (mEffectiveProbeCount != 0)
|
if (mEffectiveProbeCount != 0)
|
||||||
{
|
{
|
||||||
mProbeArrayEffect->setTexture(3, mBRDFTexture);
|
|
||||||
mProbeArrayEffect->setCubemapArrayTexture(4, mPrefilterArray);
|
|
||||||
mProbeArrayEffect->setCubemapArrayTexture(5, mIrradianceArray);
|
|
||||||
|
|
||||||
if (useDebugContrib == String("1"))
|
if (useDebugContrib == String("1"))
|
||||||
{
|
{
|
||||||
MRandomLCG RandomGen;
|
MRandomLCG RandomGen;
|
||||||
|
|
@ -829,14 +809,14 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
||||||
|
|
||||||
mProbeArrayEffect->setShaderConst("$probeContribColors", contribColors);
|
mProbeArrayEffect->setShaderConst("$probeContribColors", contribColors);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mProbeArrayEffect->setShaderConst("$inProbePosArray", probePositionsData);
|
mProbeArrayEffect->setShaderConst("$inProbePosArray", probePositionsData);
|
||||||
mProbeArrayEffect->setShaderConst("$inRefPosArray", probeRefPositionsData);
|
mProbeArrayEffect->setShaderConst("$inRefPosArray", probeRefPositionsData);
|
||||||
mProbeArrayEffect->setShaderConst("$worldToObjArray", probeWorldToObjData);
|
mProbeArrayEffect->setShaderConst("$worldToObjArray", probeWorldToObjData);
|
||||||
mProbeArrayEffect->setShaderConst("$bbMinArray", probeBBMinData);
|
mProbeArrayEffect->setShaderConst("$bbMinArray", probeBBMinData);
|
||||||
mProbeArrayEffect->setShaderConst("$bbMaxArray", probeBBMaxData);
|
mProbeArrayEffect->setShaderConst("$bbMaxArray", probeBBMaxData);
|
||||||
mProbeArrayEffect->setShaderConst("$probeConfigData", probeConfigData);
|
mProbeArrayEffect->setShaderConst("$probeConfigData", probeConfigData);
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure the effect is gonna render.
|
// Make sure the effect is gonna render.
|
||||||
getProbeArrayEffect()->setSkip(false);
|
getProbeArrayEffect()->setSkip(false);
|
||||||
|
|
|
||||||
|
|
@ -199,13 +199,9 @@ class RenderProbeMgr : public RenderBinManager
|
||||||
Vector<Point4F> probeBBMinData;
|
Vector<Point4F> probeBBMinData;
|
||||||
Vector<Point4F> probeBBMaxData;
|
Vector<Point4F> probeBBMaxData;
|
||||||
Vector<Point4F> probeConfigData;
|
Vector<Point4F> probeConfigData;
|
||||||
Vector<GFXCubemapHandle> cubeMaps;
|
|
||||||
Vector<GFXCubemapHandle> irradMaps;
|
|
||||||
|
|
||||||
bool mHasSkylight;
|
bool mHasSkylight;
|
||||||
GFXCubemapHandle skylightIrradMap;
|
S32 mSkylightCubemapIdx;
|
||||||
GFXCubemapHandle skylightPrefilterMap;
|
|
||||||
Point4F skylightPos;
|
|
||||||
|
|
||||||
AlignedArray<Point4F> mProbePositions;
|
AlignedArray<Point4F> mProbePositions;
|
||||||
AlignedArray<Point4F> mProbeBBMin;
|
AlignedArray<Point4F> mProbeBBMin;
|
||||||
|
|
@ -286,7 +282,7 @@ public:
|
||||||
/// Returns the active LM.
|
/// Returns the active LM.
|
||||||
static inline RenderProbeMgr* getProbeManager();
|
static inline RenderProbeMgr* getProbeManager();
|
||||||
|
|
||||||
ProbeRenderInst* registerProbe(const bool& isSkylight);
|
ProbeRenderInst* registerProbe();
|
||||||
void unregisterProbe(U32 probeIdx);
|
void unregisterProbe(U32 probeIdx);
|
||||||
|
|
||||||
virtual void setProbeInfo(ProcessedMaterial *pmat,
|
virtual void setProbeInfo(ProcessedMaterial *pmat,
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,8 @@ uniform float4 probeConfigData[MAX_PROBES]; //r,g,b/mode,radius,atten
|
||||||
uniform float4 probeContribColors[MAX_PROBES];
|
uniform float4 probeContribColors[MAX_PROBES];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TORQUE_UNIFORM_SAMPLERCUBE(skylightSpecularMap, 6);
|
|
||||||
TORQUE_UNIFORM_SAMPLERCUBE(skylightIrradMap, 7);
|
|
||||||
uniform float hasSkylight;
|
uniform float hasSkylight;
|
||||||
|
uniform float skylightCubemapIdx;
|
||||||
|
|
||||||
float4 main(PFXVertToPix IN) : SV_TARGET
|
float4 main(PFXVertToPix IN) : SV_TARGET
|
||||||
{
|
{
|
||||||
|
|
@ -173,8 +172,8 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
||||||
|
|
||||||
if (hasSkylight && alpha > 0.001)
|
if (hasSkylight && alpha > 0.001)
|
||||||
{
|
{
|
||||||
irradiance += TORQUE_TEXCUBELOD(skylightIrradMap, float4(surface.R, 0)).xyz * alpha;
|
irradiance += TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, surface.R, skylightCubemapIdx, 0).xyz * alpha;
|
||||||
specular += TORQUE_TEXCUBELOD(skylightSpecularMap, float4(surface.R, lod)).xyz * alpha;
|
specular += TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, surface.R, skylightCubemapIdx, lod).xyz * alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUGVIZ_SPECCUBEMAP == 1 && DEBUGVIZ_DIFFCUBEMAP == 0
|
#if DEBUGVIZ_SPECCUBEMAP == 1 && DEBUGVIZ_DIFFCUBEMAP == 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue