mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 00:24:40 +00:00
Added deletion tracking so when we delete a probe, it'll delete the prefilter/irrad bakes if they exist.
WIP of static cubemap bake(not working).
This commit is contained in:
parent
1766e291ba
commit
1fc38d496f
5 changed files with 106 additions and 78 deletions
|
|
@ -301,6 +301,26 @@ void ReflectionProbe::onRemove()
|
||||||
Parent::onRemove();
|
Parent::onRemove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReflectionProbe::deleteObject()
|
||||||
|
{
|
||||||
|
//we're deleting it?
|
||||||
|
//Then we need to clear out the processed cubemaps(if we have them)
|
||||||
|
|
||||||
|
String prefilPath = getPrefilterMapPath();
|
||||||
|
if (Platform::isFile(prefilPath))
|
||||||
|
{
|
||||||
|
Platform::fileDelete(prefilPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String irrPath = getIrradianceMapPath();
|
||||||
|
if (Platform::isFile(irrPath))
|
||||||
|
{
|
||||||
|
Platform::fileDelete(irrPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
Parent::deleteObject();
|
||||||
|
}
|
||||||
|
|
||||||
void ReflectionProbe::setTransform(const MatrixF & mat)
|
void ReflectionProbe::setTransform(const MatrixF & mat)
|
||||||
{
|
{
|
||||||
// Let SceneObject handle all of the matrix manipulation
|
// Let SceneObject handle all of the matrix manipulation
|
||||||
|
|
@ -424,8 +444,14 @@ void ReflectionProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
|
||||||
{
|
{
|
||||||
mUseCubemap = stream->readFlag();
|
mUseCubemap = stream->readFlag();
|
||||||
|
|
||||||
|
String newCubemapName;
|
||||||
stream->read(&mCubemapName);
|
stream->read(&mCubemapName);
|
||||||
|
|
||||||
|
//if (newCubemapName != mCubemapName)
|
||||||
|
{
|
||||||
|
processStaticCubemap();
|
||||||
|
}
|
||||||
|
|
||||||
isMaterialDirty = true;
|
isMaterialDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -502,6 +528,42 @@ void ReflectionProbe::updateProbeParams()
|
||||||
mProbeInfo->mScore = mMaxDrawDistance;
|
mProbeInfo->mScore = mMaxDrawDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReflectionProbe::processStaticCubemap()
|
||||||
|
{
|
||||||
|
createClientResources();
|
||||||
|
|
||||||
|
Sim::findObject(mCubemapName, mStaticCubemap);
|
||||||
|
|
||||||
|
if (!mStaticCubemap)
|
||||||
|
{
|
||||||
|
Con::errorf("ReflectionProbe::updateMaterial() - unable to find static cubemap file!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mStaticCubemap->mCubemap == nullptr)
|
||||||
|
{
|
||||||
|
mStaticCubemap->createMap();
|
||||||
|
mStaticCubemap->updateFaces();
|
||||||
|
}
|
||||||
|
|
||||||
|
String prefilPath = getPrefilterMapPath();
|
||||||
|
String irrPath = getIrradianceMapPath();
|
||||||
|
|
||||||
|
//if (!Platform::isFile(irrPath) || !Platform::isFile(prefilPath))
|
||||||
|
{
|
||||||
|
GFXTextureTargetRef renderTarget = GFX->allocRenderToTextureTarget(false);
|
||||||
|
|
||||||
|
/*IBLUtilities::GenerateIrradianceMap(renderTarget, mStaticCubemap->mCubemap, mIrridianceMap->mCubemap);
|
||||||
|
IBLUtilities::GeneratePrefilterMap(renderTarget, mStaticCubemap->mCubemap, mPrefilterMipLevels, mPrefilterMap->mCubemap);
|
||||||
|
|
||||||
|
IBLUtilities::SaveCubeMap(getIrradianceMapPath(), mIrridianceMap->mCubemap);
|
||||||
|
IBLUtilities::SaveCubeMap(getPrefilterMapPath(), mPrefilterMap->mCubemap);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
mProbeInfo->mCubemap = &mPrefilterMap->mCubemap;
|
||||||
|
mProbeInfo->mIrradianceCubemap = &mIrridianceMap->mCubemap;
|
||||||
|
}
|
||||||
|
|
||||||
void ReflectionProbe::updateMaterial()
|
void ReflectionProbe::updateMaterial()
|
||||||
{
|
{
|
||||||
createClientResources();
|
createClientResources();
|
||||||
|
|
@ -518,47 +580,6 @@ void ReflectionProbe::updateMaterial()
|
||||||
{
|
{
|
||||||
mProbeInfo->mIrradianceCubemap = &mIrridianceMap->mCubemap;
|
mProbeInfo->mIrradianceCubemap = &mIrridianceMap->mCubemap;
|
||||||
}
|
}
|
||||||
if (mBrdfTexture.isValid())
|
|
||||||
{
|
|
||||||
mProbeInfo->mBRDFTexture = &mBrdfTexture;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (mReflectionModeType == StaticCubemap && !mCubemapName.isEmpty())
|
|
||||||
{
|
|
||||||
Sim::findObject(mCubemapName, mStaticCubemap);
|
|
||||||
|
|
||||||
if (!mStaticCubemap)
|
|
||||||
{
|
|
||||||
Con::errorf("ReflectionProbe::updateMaterial() - unable to find static cubemap file!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mStaticCubemap->mCubemap == nullptr)
|
|
||||||
{
|
|
||||||
mStaticCubemap->createMap();
|
|
||||||
mStaticCubemap->updateFaces();
|
|
||||||
}
|
|
||||||
|
|
||||||
//GFXTextureTargetRef renderTarget = GFX->allocRenderToTextureTarget(false);
|
|
||||||
|
|
||||||
//IBLUtilities::GenerateIrradianceMap(renderTarget, mStaticCubemap->mCubemap, mIrridianceMap->mCubemap);
|
|
||||||
//IBLUtilities::GeneratePrefilterMap(renderTarget, mStaticCubemap->mCubemap, mPrefilterMipLevels, mPrefilterMap->mCubemap);
|
|
||||||
|
|
||||||
mProbeInfo->mCubemap = &mStaticCubemap->mCubemap;
|
|
||||||
mProbeInfo->mIrradianceCubemap = &mStaticCubemap->mCubemap;
|
|
||||||
|
|
||||||
/*if (mPrefilterMap != nullptr && mPrefilterMap->mCubemap.isValid())
|
|
||||||
{
|
|
||||||
mProbeInfo->mCubemap = &mPrefilterMap->mCubemap;
|
|
||||||
}
|
|
||||||
if (mIrridianceMap != nullptr && mIrridianceMap->mCubemap.isValid())
|
|
||||||
{
|
|
||||||
mProbeInfo->mIrradianceCubemap = &mIrridianceMap->mCubemap;
|
|
||||||
}*/
|
|
||||||
if (mBrdfTexture.isValid())
|
|
||||||
{
|
|
||||||
mProbeInfo->mBRDFTexture = &mBrdfTexture;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mReflectionModeType == DynamicCubemap && !mDynamicCubemap.isNull())
|
else if (mReflectionModeType == DynamicCubemap && !mDynamicCubemap.isNull())
|
||||||
|
|
@ -566,6 +587,11 @@ void ReflectionProbe::updateMaterial()
|
||||||
mProbeInfo->mCubemap = &mDynamicCubemap;
|
mProbeInfo->mCubemap = &mDynamicCubemap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mBrdfTexture.isValid())
|
||||||
|
{
|
||||||
|
mProbeInfo->mBRDFTexture = &mBrdfTexture;
|
||||||
|
}
|
||||||
|
|
||||||
//Make us ready to render
|
//Make us ready to render
|
||||||
if (mEnabled)
|
if (mEnabled)
|
||||||
mProbeInfo->mIsEnabled = true;
|
mProbeInfo->mIsEnabled = true;
|
||||||
|
|
@ -584,7 +610,6 @@ bool ReflectionProbe::createClientResources()
|
||||||
mIrridianceMap->createMap();
|
mIrridianceMap->createMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String irrPath = getIrradianceMapPath();
|
String irrPath = getIrradianceMapPath();
|
||||||
if (Platform::isFile(irrPath))
|
if (Platform::isFile(irrPath))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -200,6 +200,8 @@ public:
|
||||||
bool onAdd();
|
bool onAdd();
|
||||||
void onRemove();
|
void onRemove();
|
||||||
|
|
||||||
|
virtual void deleteObject();
|
||||||
|
|
||||||
// Override this so that we can dirty the network flag when it is called
|
// Override this so that we can dirty the network flag when it is called
|
||||||
void setTransform(const MatrixF &mat);
|
void setTransform(const MatrixF &mat);
|
||||||
|
|
||||||
|
|
@ -230,6 +232,8 @@ public:
|
||||||
bool createClientResources();
|
bool createClientResources();
|
||||||
void generateTextures();
|
void generateTextures();
|
||||||
|
|
||||||
|
void processStaticCubemap();
|
||||||
|
|
||||||
// This is the function that allows this object to submit itself for rendering
|
// This is the function that allows this object to submit itself for rendering
|
||||||
void prepRenderImage(SceneRenderState *state);
|
void prepRenderImage(SceneRenderState *state);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -744,7 +744,7 @@ class SimObject: public ConsoleObject, public TamlCallbacks
|
||||||
void unregisterObject();
|
void unregisterObject();
|
||||||
|
|
||||||
/// Unregister, mark as deleted, and free the object.
|
/// Unregister, mark as deleted, and free the object.
|
||||||
void deleteObject();
|
virtual void deleteObject();
|
||||||
|
|
||||||
/// Performs a safe delayed delete of the object using a sim event.
|
/// Performs a safe delayed delete of the object using a sim event.
|
||||||
void safeDeleteObject();
|
void safeDeleteObject();
|
||||||
|
|
|
||||||
|
|
@ -225,18 +225,20 @@ void LightManager::registerGlobalLights( const Frustum *frustum, bool staticLigh
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Cull the lights using the frustum.
|
// Cull the lights using the frustum.
|
||||||
getSceneManager()->getContainer()->findObjectList( *frustum, lightMask, &activeLights );
|
getSceneManager()->getContainer()->findObjectList(*frustum, lightMask, &activeLights);
|
||||||
if (enableZoneLightCulling)
|
|
||||||
{
|
if (enableZoneLightCulling)
|
||||||
for (U32 i = 0; i < activeLights.size(); ++i)
|
{
|
||||||
{
|
for (U32 i = 0; i < activeLights.size(); ++i)
|
||||||
if (!getSceneManager()->mRenderedObjectsList.contains(activeLights[i]))
|
{
|
||||||
{
|
if (!getSceneManager()->mRenderedObjectsList.contains(activeLights[i]))
|
||||||
activeLights.erase(i);
|
{
|
||||||
--i;
|
activeLights.erase(i);
|
||||||
}
|
--i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Store the culling position for sun placement
|
// Store the culling position for sun placement
|
||||||
// later... see setSpecialLight.
|
// later... see setSpecialLight.
|
||||||
mCullPos = frustum->getPosition();
|
mCullPos = frustum->getPosition();
|
||||||
|
|
@ -246,10 +248,10 @@ void LightManager::registerGlobalLights( const Frustum *frustum, bool staticLigh
|
||||||
// the shape bounds and can often get culled.
|
// the shape bounds and can often get culled.
|
||||||
|
|
||||||
GameConnection *conn = GameConnection::getConnectionToServer();
|
GameConnection *conn = GameConnection::getConnectionToServer();
|
||||||
if ( conn->getControlObject() )
|
if (conn->getControlObject())
|
||||||
{
|
{
|
||||||
GameBase *conObject = conn->getControlObject();
|
GameBase *conObject = conn->getControlObject();
|
||||||
activeLights.push_back_unique( conObject );
|
activeLights.push_back_unique(conObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -941,34 +941,31 @@ void ProbeManager::ReflectProbeMaterialInfo::setProbeParameters(const ProbeRende
|
||||||
GFX->setTexture(0, deferredTexTarget->getTexture());
|
GFX->setTexture(0, deferredTexTarget->getTexture());
|
||||||
GFX->setTexture(1, matInfoTexTarget->getTexture());
|
GFX->setTexture(1, matInfoTexTarget->getTexture());
|
||||||
GFX->setTexture(2, colorTexTarget->getTexture());
|
GFX->setTexture(2, colorTexTarget->getTexture());
|
||||||
GFX->setCubeTexture(3, probeInfo->mCubemap->getPointer());
|
|
||||||
GFX->setCubeTexture(4, probeInfo->mIrradianceCubemap->getPointer());
|
//Add some safety catches in the event the cubemaps aren't fully initialized yet
|
||||||
|
if (probeInfo->mCubemap == nullptr || probeInfo->mCubemap->isNull())
|
||||||
|
{
|
||||||
|
GFX->setCubeTexture(3, nullptr);
|
||||||
|
matParams->setSafe(cubeMips, 2.0f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GFX->setCubeTexture(3, probeInfo->mCubemap->getPointer());
|
||||||
|
matParams->setSafe(cubeMips, mPow(probeInfo->mCubemap->getPointer()->getMipMapLevels(), 2.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (probeInfo->mIrradianceCubemap == nullptr || probeInfo->mIrradianceCubemap->isNull())
|
||||||
|
GFX->setCubeTexture(4, nullptr);
|
||||||
|
else
|
||||||
|
GFX->setCubeTexture(4, probeInfo->mIrradianceCubemap->getPointer());
|
||||||
|
|
||||||
GFX->setTexture(5, probeInfo->mBRDFTexture->getPointer());
|
GFX->setTexture(5, probeInfo->mBRDFTexture->getPointer());
|
||||||
|
|
||||||
//set material params
|
//set material params
|
||||||
matParams->setSafe(cubeMips, mPow(probeInfo->mCubemap->getPointer()->getMipMapLevels(), 2.0f));
|
|
||||||
matParams->setSafe(eyePosWorld, renderState->getCameraPosition());
|
matParams->setSafe(eyePosWorld, renderState->getCameraPosition());
|
||||||
matParams->setSafe(bbMin, probeInfo->mBounds.minExtents);
|
matParams->setSafe(bbMin, probeInfo->mBounds.minExtents);
|
||||||
matParams->setSafe(bbMax, probeInfo->mBounds.maxExtents);
|
matParams->setSafe(bbMax, probeInfo->mBounds.maxExtents);
|
||||||
matParams->setSafe(useSphereMode, probeInfo->mProbeShapeType == ProbeRenderInst::Sphere ? 1.0f : 0.0f);
|
matParams->setSafe(useSphereMode, probeInfo->mProbeShapeType == ProbeRenderInst::Sphere ? 1.0f : 0.0f);
|
||||||
|
|
||||||
//SH Terms
|
|
||||||
//static AlignedArray<Point3F> shTermsArray(9, sizeof(Point3F));
|
|
||||||
//dMemset(shTermsArray.getBuffer(), 0, shTermsArray.getBufferSize());
|
|
||||||
|
|
||||||
/*for (U32 i = 0; i < 9; i++)
|
|
||||||
{
|
|
||||||
matParams->setSafe(shTerms[i], probeInfo->mSHTerms[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (U32 i = 0; i < 5; i++)
|
|
||||||
{
|
|
||||||
matParams->setSafe(shConsts[i], probeInfo->mSHConstants[i]);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//const MatrixF worldToObjectXfm = probeInfo->mTransform;
|
|
||||||
//MaterialParameterHandle *worldToObjMat = matInstance->getMaterialParameterHandle("$worldToObj");
|
|
||||||
//matParams->setSafe(worldToObjMat, worldToObjectXfm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue