Browse Source

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).

Areloch 6 years ago
parent
commit
1fc38d496f

+ 66 - 41
Engine/source/T3D/lighting/reflectionProbe.cpp

@@ -301,6 +301,26 @@ void ReflectionProbe::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)
 {
    // Let SceneObject handle all of the matrix manipulation
@@ -424,8 +444,14 @@ void ReflectionProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
    {
       mUseCubemap = stream->readFlag();
 
+      String newCubemapName;
       stream->read(&mCubemapName);
 
+      //if (newCubemapName != mCubemapName)
+      {
+         processStaticCubemap();
+      }
+
       isMaterialDirty = true;
    }
 
@@ -502,62 +528,57 @@ void ReflectionProbe::updateProbeParams()
    mProbeInfo->mScore = mMaxDrawDistance;
 }
 
-void ReflectionProbe::updateMaterial()
+void ReflectionProbe::processStaticCubemap()
 {
    createClientResources();
 
-   if (mReflectionModeType != DynamicCubemap)
+   Sim::findObject(mCubemapName, mStaticCubemap);
+
+   if (!mStaticCubemap)
    {
-      if ((mReflectionModeType == BakedCubemap) && !mProbeUniqueID.isEmpty())
-      {
-         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 == StaticCubemap && !mCubemapName.isEmpty())
-      {
-         Sim::findObject(mCubemapName, mStaticCubemap);
+      Con::errorf("ReflectionProbe::updateMaterial() - unable to find static cubemap file!");
+      return;
+   }
 
-         if (!mStaticCubemap)
-         {
-            Con::errorf("ReflectionProbe::updateMaterial() - unable to find static cubemap file!");
-            return;
-         }
+   if (mStaticCubemap->mCubemap == nullptr)
+   {
+      mStaticCubemap->createMap();
+      mStaticCubemap->updateFaces();
+   }
 
-         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);
 
-         //GFXTextureTargetRef renderTarget = GFX->allocRenderToTextureTarget(false);
+      IBLUtilities::SaveCubeMap(getIrradianceMapPath(), mIrridianceMap->mCubemap);
+      IBLUtilities::SaveCubeMap(getPrefilterMapPath(), mPrefilterMap->mCubemap);*/
+   }
 
-         //IBLUtilities::GenerateIrradianceMap(renderTarget, mStaticCubemap->mCubemap, mIrridianceMap->mCubemap);
-         //IBLUtilities::GeneratePrefilterMap(renderTarget, mStaticCubemap->mCubemap, mPrefilterMipLevels, mPrefilterMap->mCubemap);
+   mProbeInfo->mCubemap = &mPrefilterMap->mCubemap;
+   mProbeInfo->mIrradianceCubemap = &mIrridianceMap->mCubemap;
+}
 
-         mProbeInfo->mCubemap = &mStaticCubemap->mCubemap;
-         mProbeInfo->mIrradianceCubemap = &mStaticCubemap->mCubemap;
+void ReflectionProbe::updateMaterial()
+{
+   createClientResources();
 
-         /*if (mPrefilterMap != nullptr && mPrefilterMap->mCubemap.isValid())
+   if (mReflectionModeType != DynamicCubemap)
+   {
+      if ((mReflectionModeType == BakedCubemap) && !mProbeUniqueID.isEmpty())
+      {
+         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;
          }
       }
    }
@@ -566,6 +587,11 @@ void ReflectionProbe::updateMaterial()
       mProbeInfo->mCubemap = &mDynamicCubemap;
    }
 
+   if (mBrdfTexture.isValid())
+   {
+      mProbeInfo->mBRDFTexture = &mBrdfTexture;
+   }
+
    //Make us ready to render
    if (mEnabled)
       mProbeInfo->mIsEnabled = true;
@@ -584,7 +610,6 @@ bool ReflectionProbe::createClientResources()
       mIrridianceMap->createMap();
    }
 
-
    String irrPath = getIrradianceMapPath();
    if (Platform::isFile(irrPath))
    {

+ 4 - 0
Engine/source/T3D/lighting/reflectionProbe.h

@@ -200,6 +200,8 @@ public:
    bool onAdd();
    void onRemove();
 
+   virtual void deleteObject();
+
    // Override this so that we can dirty the network flag when it is called
    void setTransform(const MatrixF &mat);
 
@@ -230,6 +232,8 @@ public:
    bool createClientResources();
    void generateTextures();
 
+   void processStaticCubemap();
+
    // This is the function that allows this object to submit itself for rendering
    void prepRenderImage(SceneRenderState *state);
 

+ 1 - 1
Engine/source/console/simObject.h

@@ -744,7 +744,7 @@ class SimObject: public ConsoleObject, public TamlCallbacks
       void unregisterObject();
 
       /// 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.
       void safeDeleteObject();

+ 16 - 14
Engine/source/lighting/lightManager.cpp

@@ -225,18 +225,20 @@ void LightManager::registerGlobalLights( const Frustum *frustum, bool staticLigh
    else
    {
       // Cull the lights using the frustum.
-      getSceneManager()->getContainer()->findObjectList( *frustum, lightMask, &activeLights );
-	  if (enableZoneLightCulling)
-	  {
-		  for (U32 i = 0; i < activeLights.size(); ++i)
-		  {
-			  if (!getSceneManager()->mRenderedObjectsList.contains(activeLights[i]))
-			  {
-				  activeLights.erase(i);
-				  --i;
-			  }
-		  }
-	  }
+      getSceneManager()->getContainer()->findObjectList(*frustum, lightMask, &activeLights);
+
+      if (enableZoneLightCulling)
+      {
+         for (U32 i = 0; i < activeLights.size(); ++i)
+         {
+            if (!getSceneManager()->mRenderedObjectsList.contains(activeLights[i]))
+            {
+               activeLights.erase(i);
+               --i;
+            }
+         }
+      }
+
       // Store the culling position for sun placement
       // later... see setSpecialLight.
       mCullPos = frustum->getPosition();
@@ -246,10 +248,10 @@ void LightManager::registerGlobalLights( const Frustum *frustum, bool staticLigh
       // the shape bounds and can often get culled.
 
       GameConnection *conn = GameConnection::getConnectionToServer();
-      if ( conn->getControlObject() )
+      if (conn->getControlObject())
       {
          GameBase *conObject = conn->getControlObject();
-         activeLights.push_back_unique( conObject );
+         activeLights.push_back_unique(conObject);
       }
    }
 

+ 18 - 21
Engine/source/lighting/probeManager.cpp

@@ -941,34 +941,31 @@ void ProbeManager::ReflectProbeMaterialInfo::setProbeParameters(const ProbeRende
    GFX->setTexture(0, deferredTexTarget->getTexture());
 	GFX->setTexture(1, matInfoTexTarget->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());
 
    //set material params
-   matParams->setSafe(cubeMips, mPow(probeInfo->mCubemap->getPointer()->getMipMapLevels(), 2.0f));
 	matParams->setSafe(eyePosWorld, renderState->getCameraPosition());
 	matParams->setSafe(bbMin, probeInfo->mBounds.minExtents);
 	matParams->setSafe(bbMax, probeInfo->mBounds.maxExtents);
 	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);
 }
 
 //