ongoing WIP to sort out init'ing issues as well as correcting values so the probes actually correctly update data into the arrays

Additional sanity checks on the updateTexture calls added by timmy
This commit is contained in:
Areloch 2019-03-25 00:06:08 -05:00
parent 26471aaa77
commit 1627cbabe6
6 changed files with 116 additions and 114 deletions

View file

@ -109,7 +109,6 @@ ReflectionProbe::ReflectionProbe()
mObjScale = Point3F::One * 10;
mProbeRefScale = Point3F::One*10;
mUseCubemap = false;
mUseHDRCaptures = true;
mStaticCubemap = NULL;
@ -436,7 +435,6 @@ U32 ReflectionProbe::packUpdate(NetConnection *conn, U32 mask, BitStream *stream
if (stream->writeFlag(mask & CubemapMask))
{
stream->writeFlag(mUseCubemap);
stream->write(mCubemapName);
}
@ -497,12 +495,8 @@ void ReflectionProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
isMaterialDirty = true;
}
updateProbeParams();
if (stream->readFlag()) // CubemapMask
{
mUseCubemap = stream->readFlag();
String newCubemapName;
stream->read(&mCubemapName);
@ -514,29 +508,9 @@ void ReflectionProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
isMaterialDirty = true;
}
if (isMaterialDirty)
if (mDirty)
{
updateMaterial();
}
PROBEMGR->updateProbes();
}
void ReflectionProbe::createGeometry()
{
// Clean up our previous shape
if (mEditorShapeInst)
SAFE_DELETE(mEditorShapeInst);
mEditorShape = NULL;
String shapeFile = "tools/resources/ReflectProbeSphere.dae";
// Attempt to get the resource from the ResourceManager
mEditorShape = ResourceManager::get().load(shapeFile);
if (mEditorShape)
{
mEditorShapeInst = new TSShapeInstance(mEditorShape, isClientObject());
updateProbeParams();
}
}
@ -552,13 +526,11 @@ void ReflectionProbe::updateProbeParams()
mProbeInfo->mIsEnabled = false;
}
updateMaterial();
updateCubemaps();
mProbeInfo->mProbeShapeType = mProbeShapeType;
MatrixF transform = getTransform();
mProbeInfo->mPosition = getPosition();
if (mProbeShapeType == ProbeRenderInst::Sphere)
@ -633,9 +605,12 @@ void ReflectionProbe::processStaticCubemap()
mProbeInfo->mPrefilterCubemap = mPrefilterMap->mCubemap;
mProbeInfo->mIrradianceCubemap = mIrridianceMap->mCubemap;
//Update the probe manager with our new texture!
//PROBEMGR->updateProbeTexture(mProbeInfo);
}
void ReflectionProbe::updateMaterial()
void ReflectionProbe::updateCubemaps()
{
createClientResources();
@ -685,8 +660,8 @@ void ReflectionProbe::updateMaterial()
PROBEMGR->updateProbes();
if (mProbeInfo->mPrefilterCubemap->isInitialized() && mProbeInfo->mIrradianceCubemap->isInitialized())
PROBEMGR->updateProbeTexture(mProbeInfo);
//if (mProbeInfo->mPrefilterCubemap->isInitialized() && mProbeInfo->mIrradianceCubemap->isInitialized())
// PROBEMGR->updateProbeTexture(mProbeInfo);
}
bool ReflectionProbe::createClientResources()
@ -734,8 +709,66 @@ bool ReflectionProbe::createClientResources()
return true;
}
void ReflectionProbe::generateTextures()
String ReflectionProbe::getPrefilterMapPath()
{
if (mProbeUniqueID.isEmpty())
{
Con::errorf("ReflectionProbe::getPrefilterMapPath() - We don't have a set output path or persistant id, so no valid path can be provided!");
return "";
}
String path = Con::getVariable("$pref::ReflectionProbes::CurrentLevelPath", "levels/");
char fileName[256];
dSprintf(fileName, 256, "%s%s_Prefilter.dds", path.c_str(), mProbeUniqueID.c_str());
return fileName;
}
String ReflectionProbe::getIrradianceMapPath()
{
if (mProbeUniqueID.isEmpty())
{
Con::errorf("ReflectionProbe::getIrradianceMapPath() - We don't have a set output path or persistant id, so no valid path can be provided!");
return "";
}
String path = Con::getVariable("$pref::ReflectionProbes::CurrentLevelPath", "levels/");
char fileName[256];
dSprintf(fileName, 256, "%s%s_Irradiance.dds", path.c_str(), mProbeUniqueID.c_str());
return fileName;
}
void ReflectionProbe::bake()
{
if (mReflectionModeType == DynamicCubemap)
return;
PROBEMGR->bakeProbe(this);
setMaskBits(CubemapMask);
}
//-----------------------------------------------------------------------------
//Rendering of editing/debug stuff
//-----------------------------------------------------------------------------
void ReflectionProbe::createGeometry()
{
// Clean up our previous shape
if (mEditorShapeInst)
SAFE_DELETE(mEditorShapeInst);
mEditorShape = NULL;
String shapeFile = "tools/resources/ReflectProbeSphere.dae";
// Attempt to get the resource from the ResourceManager
mEditorShape = ResourceManager::get().load(shapeFile);
if (mEditorShape)
{
mEditorShapeInst = new TSShapeInstance(mEditorShape, isClientObject());
}
}
void ReflectionProbe::prepRenderImage(SceneRenderState *state)
@ -918,48 +951,6 @@ DefineEngineMethod(ReflectionProbe, postApply, void, (), ,
object->inspectPostApply();
}
String ReflectionProbe::getPrefilterMapPath()
{
if (mProbeUniqueID.isEmpty())
{
Con::errorf("ReflectionProbe::getPrefilterMapPath() - We don't have a set output path or persistant id, so no valid path can be provided!");
return "";
}
String path = Con::getVariable("$pref::ReflectionProbes::CurrentLevelPath", "levels/");
char fileName[256];
dSprintf(fileName, 256, "%s%s_Prefilter.dds", path.c_str(), mProbeUniqueID.c_str());
return fileName;
}
String ReflectionProbe::getIrradianceMapPath()
{
if (mProbeUniqueID.isEmpty())
{
Con::errorf("ReflectionProbe::getIrradianceMapPath() - We don't have a set output path or persistant id, so no valid path can be provided!");
return "";
}
String path = Con::getVariable("$pref::ReflectionProbes::CurrentLevelPath", "levels/");
char fileName[256];
dSprintf(fileName, 256, "%s%s_Irradiance.dds", path.c_str(), mProbeUniqueID.c_str());
return fileName;
}
void ReflectionProbe::bake()
{
if (mReflectionModeType == DynamicCubemap)
return;
PROBEMGR->bakeProbe(this);
setMaskBits(CubemapMask);
}
DefineEngineMethod(ReflectionProbe, Bake, void, (), ,
"@brief returns true if control object is inside the fog\n\n.")
{

View file

@ -118,7 +118,6 @@ protected:
String mCubemapName;
CubemapData *mStaticCubemap;
GFXCubemapHandle mDynamicCubemap;
bool mUseCubemap;
String cubeDescName;
U32 cubeDescId;
@ -223,12 +222,11 @@ public:
void createGeometry();
// Get the Material instance
void updateMaterial();
void updateCubemaps();
virtual void updateProbeParams();
bool createClientResources();
void generateTextures();
void processStaticCubemap();

View file

@ -513,6 +513,9 @@ void GFXD3D11CubemapArray::init(const U32 cubemapCount, const U32 cubemapFaceSiz
void GFXD3D11CubemapArray::updateTexture(const GFXCubemapHandle &cubemap, const U32 slot)
{
AssertFatal(slot <= mNumCubemaps, "GFXD3D11CubemapArray::updateTexture - trying to update a cubemap texture that is out of bounds!");
AssertFatal(mFormat == cubemap->getFormat(), "GFXD3D11CubemapArray::updateTexture - Destination format doesn't match");
AssertFatal(mSize == cubemap->getSize(), "GFXD3D11CubemapArray::updateTexture - Destination size doesn't match");
AssertFatal(mMipMapLevels == cubemap->getMipMapLevels(), "GFXD3D11CubemapArray::updateTexture - Destination mip levels doesn't match");
GFXD3D11Cubemap *pCubeObj = static_cast<GFXD3D11Cubemap*>((GFXCubemap*)cubemap);
ID3D11Resource *pDstRes = pCubeObj->get2DTex();
@ -531,16 +534,10 @@ void GFXD3D11CubemapArray::updateTexture(const GFXCubemapHandle &cubemap, const
void GFXD3D11CubemapArray::copyTo(GFXCubemapArray *pDstCubemap)
{
AssertFatal(pDstCubemap, "GFXD3D11CubemapArray::copyTo - Got null GFXCubemapArray");
const U32 dstCount = pDstCubemap->getNumCubemaps();
const GFXFormat dstFmt = pDstCubemap->getFormat();
const U32 dstSize = pDstCubemap->getSize();
const U32 dstMips = pDstCubemap->getMipMapLevels();
AssertFatal(dstCount > mNumCubemaps, "GFXD3D11CubemapArray::copyTo - Destination too small");
AssertFatal(dstFmt == mFormat, "GFXD3D11CubemapArray::copyTo - Destination format doesn't match");
AssertFatal(dstSize == mSize, "GFXD3D11CubemapArray::copyTo - Destination size doesn't match");
AssertFatal(dstMips == mMipMapLevels, "GFXD3D11CubemapArray::copyTo - Destination mip levels doesn't match");
AssertFatal(pDstCubemap->getNumCubemaps() > mNumCubemaps, "GFXD3D11CubemapArray::copyTo - Destination too small");
AssertFatal(pDstCubemap->getFormat() == mFormat, "GFXD3D11CubemapArray::copyTo - Destination format doesn't match");
AssertFatal(pDstCubemap->getSize() == mSize, "GFXD3D11CubemapArray::copyTo - Destination size doesn't match");
AssertFatal(pDstCubemap->getMipMapLevels() == mMipMapLevels, "GFXD3D11CubemapArray::copyTo - Destination mip levels doesn't match");
GFXD3D11CubemapArray *pDstCube = static_cast<GFXD3D11CubemapArray*>(pDstCubemap);
ID3D11Resource *pDstRes = pDstCube->get2DTex();
@ -556,7 +553,6 @@ void GFXD3D11CubemapArray::copyTo(GFXCubemapArray *pDstCubemap)
}
}
}
}
void GFXD3D11CubemapArray::setToTexUnit(U32 tuNum)

View file

@ -391,6 +391,7 @@ void RenderProbeMgr::_setupStaticParameters()
cubeMaps.clear();
irradMaps.clear();
Vector<U32> cubemapIdxes;
if (probeCount != 0 && ProbeRenderInst::all[0]->mPrefilterCubemap != nullptr)
{
@ -420,15 +421,6 @@ void RenderProbeMgr::_setupStaticParameters()
continue;
}
//if (curEntry.mCubemap.isNull() || curEntry.mIrradianceCubemap.isNull())
// continue;
//if (!curEntry.mCubemap->isInitialized())
// continue;
//if (!curEntry.mIrradianceCubemap->isInitialized())
// continue;
//Setup
Point3F probePos = curEntry.getPosition();
Point3F refPos = curEntry.getPosition() +curEntry.mProbeRefOffset;
@ -444,21 +436,40 @@ void RenderProbeMgr::_setupStaticParameters()
probeConfigData[mEffectiveProbeCount] = Point4F(curEntry.mProbeShapeType,
curEntry.mRadius,
curEntry.mAtten,
1);
curEntry.mCubemapIndex);
//cubeMaps.push_back(curEntry.mCubemap);
//irradMaps.push_back(curEntry.mIrradianceCubemap);
cubeMaps.push_back(curEntry.mPrefilterCubemap);
irradMaps.push_back(curEntry.mIrradianceCubemap);
cubemapIdxes.push_back(i);
mEffectiveProbeCount++;
}
if (mEffectiveProbeCount != 0)
{
//mPrefilterArray = GFXCubemapArrayHandle(GFX->createCubemapArray());
//mIrradianceArray = GFXCubemapArrayHandle(GFX->createCubemapArray());
bool useOldWay = false;
if (useOldWay)
{
//old static way
mPrefilterArray = GFXCubemapArrayHandle(GFX->createCubemapArray());
mIrradianceArray = GFXCubemapArrayHandle(GFX->createCubemapArray());
//mPrefilterArray->initStatic(cubeMaps.address(), cubeMaps.size());
//mIrradianceArray->initStatic(irradMaps.address(), irradMaps.size());
mPrefilterArray->init(cubeMaps.address(), cubeMaps.size());
mIrradianceArray->init(irradMaps.address(), irradMaps.size());
}
else
{
//faked static way by doing it via update
for (U32 i = 0; i < cubemapIdxes.size(); i++)
{
U32 probeIdx = cubemapIdxes[i];
const U32 cubeIndex = ProbeRenderInst::all[probeIdx]->mCubemapIndex;
mIrradianceArray->updateTexture(irradMaps[i], cubeIndex);
mPrefilterArray->updateTexture(cubeMaps[i], cubeIndex);
}
}
}
}
@ -740,7 +751,6 @@ void RenderProbeMgr::render( SceneRenderState *state )
{
mProbeArrayEffect->setCubemapTexture(6, skylightPrefilterMap);
mProbeArrayEffect->setCubemapTexture(7, skylightIrradMap);
}
if (mEffectiveProbeCount != 0)
@ -909,6 +919,11 @@ void RenderProbeMgr::bakeProbe(ReflectionProbe *probe)
IBLUtilities::GenerateIrradianceMap(renderTarget, cubeRefl.getCubemap(), clientProbe->mIrridianceMap->mCubemap);
IBLUtilities::GeneratePrefilterMap(renderTarget, cubeRefl.getCubemap(), prefilterMipLevels, clientProbe->mPrefilterMap->mCubemap);
U32 endMSTime = Platform::getRealMilliseconds();
F32 diffTime = F32(endMSTime - startMSTime);
Con::warnf("RenderProbeMgr::bake() - Finished Capture! Took %g milliseconds", diffTime);
Con::warnf("RenderProbeMgr::bake() - Beginning save now!");
IBLUtilities::SaveCubeMap(clientProbe->getIrradianceMapPath(), clientProbe->mIrridianceMap->mCubemap);
IBLUtilities::SaveCubeMap(clientProbe->getPrefilterMapPath(), clientProbe->mPrefilterMap->mCubemap);
}

View file

@ -170,9 +170,9 @@ class RenderProbeMgr : public RenderBinManager
//number of slots to allocate at once in the cubemap array
static const U32 PROBE_ARRAY_SLOT_BUFFER_SIZE = 10;
static const U32 PROBE_IRRAD_SIZE = 32;
static const U32 PROBE_PREFILTER_SIZE = 128;
static const GFXFormat PROBE_FORMAT = GFXFormatR8G8B8A8;// when hdr fixed GFXFormatR16G16B16A16F; look into bc6h compression
static const U32 PROBE_IRRAD_SIZE = 64;
static const U32 PROBE_PREFILTER_SIZE = 64;
static const GFXFormat PROBE_FORMAT = GFXFormatR16G16B16A16F;// GFXFormatR8G8B8A8;// when hdr fixed GFXFormatR16G16B16A16F; look into bc6h compression
static const U32 INVALID_CUBE_SLOT = U32_MAX;
//Array rendering

View file

@ -49,7 +49,8 @@ struct ProbeData
uint type; //box = 0, sphere = 1
float contribution;
float3 refPosition;
float3 pad;
float cubemapIdx;
float2 pad;
};
float defineSkylightInfluence(Surface surface, ProbeData probe, float3 wsEyeRay)
@ -104,7 +105,7 @@ float3 iblBoxDiffuse(Surface surface, ProbeData probe)
{
float3 dir = boxProject(surface, probe);
float3 color = TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, dir, probe.probeIdx, 0).xyz;
float3 color = TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, dir, probe.cubemapIdx, 0).xyz;
if (probe.contribution>0)
return color*probe.contribution;
else
@ -125,7 +126,7 @@ float3 iblBoxSpecular(Surface surface, ProbeData probe)
float lod = 0;
#endif
float3 color = TORQUE_TEXCUBEARRAYLOD(cubeMapAR, dir, probe.probeIdx, lod).xyz * (brdf.x + brdf.y);
float3 color = TORQUE_TEXCUBEARRAYLOD(cubeMapAR, dir, probe.cubemapIdx, lod).xyz * (brdf.x + brdf.y);
if (probe.contribution>0)
return color*probe.contribution;
@ -197,6 +198,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
probes[i].attenuation = probeConfigData[i].b;
probes[i].worldToLocal = worldToObjArray[i];
probes[i].probeIdx = i;
probes[i].cubemapIdx = probeConfigData[i].a;
probes[i].type = probeConfigData[i].r;
probes[i].contribution = 0;