Browse Source

Skybox texture filtering now uses renderer tasks
Removed light probe cache since both refl. probes and skybox now use renderer tasks and internal storage

BearishSun 8 years ago
parent
commit
88f7cd4031

+ 0 - 7
Source/BansheeCore/Include/BsRenderer.h

@@ -175,13 +175,6 @@ namespace bs
 		 */
 		virtual void notifySkyboxAdded(Skybox* skybox) { }
 
-		/**
-		 * Called whenever the texture assigned to a skybox is changed.
-		 *
-		 * @note	Core thread.
-		 */
-		virtual void notifySkyboxTextureChanged(Skybox* skybox) { }
-
 		/**
 		 * Called whenever a skybox is destroyed.
 		 *

+ 31 - 2
Source/BansheeCore/Include/BsSkybox.h

@@ -8,6 +8,11 @@
 
 namespace bs
 {
+	namespace ct
+	{
+		class RendererTask;
+	}
+
 	/** @addtogroup Implementation
 	 *  @{
 	 */
@@ -99,6 +104,12 @@ namespace bs
 	protected:
 		Skybox();
 
+		/** 
+		 * Filters the skybox radiance texture, generating filtered radiance (for reflections) and irradiance. Should be 
+		 * called any time the skybox texture changes. 
+		 */
+		void filterTexture();
+
 		/** @copydoc CoreObject::createCore */
 		SPtr<ct::CoreObject> createCore() const override;
 
@@ -108,6 +119,10 @@ namespace bs
 		/** @copydoc CoreObject::syncToCore */
 		CoreSyncData syncToCore(FrameAlloc* allocator) override;
 
+		SPtr<Texture> mFilteredRadiance;
+		SPtr<Texture> mIrradiance;
+		SPtr<ct::RendererTask> mRendererTask;
+
 		/************************************************************************/
 		/* 								RTTI		                     		*/
 		/************************************************************************/
@@ -125,18 +140,32 @@ namespace bs
 		public:
 			~Skybox();
 
+			/** 
+			 * Returns a texture containing filtered version of the radiance texture used for reflections. This might not
+			 * be available if it hasn't been generated yet.
+			 */
+			SPtr<Texture> getFilteredRadiance() const { return mFilteredRadiance; }
+
+			/**
+			 * Returns a texture containing sky irradiance. This might not be available if it hasn't been generated yet.
+			 */
+			SPtr<Texture> getIrradiance() const { return mIrradiance; }
+
 		protected:
 			friend class bs::Skybox;
 
-			Skybox();
+			Skybox(const SPtr<Texture>& filteredRadiance, const SPtr<Texture>& irradiance);
 
 			/** @copydoc CoreObject::initialize */
 			void initialize() override;
 
 			/** @copydoc CoreObject::syncToCore */
 			void syncToCore(const CoreSyncData& data) override;
+
+			SPtr<Texture> mFilteredRadiance;
+			SPtr<Texture> mIrradiance;
 		};
 	}
 
 	/** @} */
-}
+}

+ 14 - 2
Source/BansheeCore/Include/BsSkyboxRTTI.h

@@ -5,6 +5,7 @@
 #include "BsCorePrerequisites.h"
 #include "BsRTTIType.h"
 #include "BsSkybox.h"
+#include "BsRenderer.h"
 
 namespace bs
 {
@@ -20,12 +21,23 @@ namespace bs
 			BS_RTTI_MEMBER_REFL(mTexture, 0)
 			BS_RTTI_MEMBER_PLAIN(mUUID, 1)
 			BS_RTTI_MEMBER_PLAIN(mBrightness, 2)
+			BS_RTTI_MEMBER_REFLPTR(mFilteredRadiance, 3)
+			BS_RTTI_MEMBER_REFLPTR(mIrradiance, 4)
 		BS_END_RTTI_MEMBERS
 	public:
-        SkyboxRTTI()
+		SkyboxRTTI()
 			:mInitMembers(this)
 		{ }
 
+		void onSerializationStarted(IReflectable* obj, const UnorderedMap<String, UINT64>& params) override
+		{
+			Skybox* skybox = static_cast<Skybox*>(obj);
+
+			// Make sure that the renderer finishes generating filtered radiance and irradiance before saving
+			if (skybox->mRendererTask)
+				skybox->mRendererTask->wait();
+		}
+
 		void onDeserializationEnded(IReflectable* obj, const UnorderedMap<String, UINT64>& params) override
 		{
 			// Note: Since this is a CoreObject I should call initialize() right after deserialization,
@@ -53,4 +65,4 @@ namespace bs
 
 	/** @} */
 	/** @endcond */
-}
+}

+ 85 - 6
Source/BansheeCore/Source/BsSkybox.cpp

@@ -7,6 +7,7 @@
 #include "BsTexture.h"
 #include "BsRenderer.h"
 #include "BsUUID.h"
+#include "BsIBLUtility.h"
 
 namespace bs
 {
@@ -23,7 +24,75 @@ namespace bs
 	template class TSkybox<false>;
 
 	Skybox::Skybox()
-	{ }
+	{
+		// This shouldn't normally happen, as filtered textures are generated when a radiance texture is assigned, but
+		// we check for it anyway (something could have gone wrong).
+		if(mTexture.isLoaded())
+		{
+			if (mFilteredRadiance == nullptr || mIrradiance == nullptr)
+				filterTexture();
+		}
+	}
+
+	void Skybox::filterTexture()
+	{
+		// If previous rendering task exists, cancel it
+		if (mRendererTask != nullptr)
+			mRendererTask->cancel();
+
+		{
+			TEXTURE_DESC cubemapDesc;
+			cubemapDesc.type = TEX_TYPE_CUBE_MAP;
+			cubemapDesc.format = PF_FLOAT_R11G11B10;
+			cubemapDesc.width = ct::IBLUtility::REFLECTION_CUBEMAP_SIZE;
+			cubemapDesc.height = ct::IBLUtility::REFLECTION_CUBEMAP_SIZE;
+			cubemapDesc.numMips = PixelUtil::getMaxMipmaps(cubemapDesc.width, cubemapDesc.height, 1, cubemapDesc.format);
+			cubemapDesc.usage = TU_STATIC | TU_RENDERTARGET;
+
+			mFilteredRadiance = Texture::_createPtr(cubemapDesc);
+		}
+
+		{
+			TEXTURE_DESC irradianceCubemapDesc;
+			irradianceCubemapDesc.type = TEX_TYPE_CUBE_MAP;
+			irradianceCubemapDesc.format = PF_FLOAT_R11G11B10;
+			irradianceCubemapDesc.width = ct::IBLUtility::IRRADIANCE_CUBEMAP_SIZE;
+			irradianceCubemapDesc.height = ct::IBLUtility::IRRADIANCE_CUBEMAP_SIZE;
+			irradianceCubemapDesc.numMips = 0;
+			irradianceCubemapDesc.usage = TU_STATIC | TU_RENDERTARGET;
+
+			mIrradiance = Texture::_createPtr(irradianceCubemapDesc);
+		}
+
+		auto renderComplete = [this]()
+		{
+			mRendererTask = nullptr;
+		};
+
+		SPtr<ct::Skybox> coreSkybox = getCore();
+		SPtr<ct::Texture> coreFilteredRadiance = mFilteredRadiance->getCore();
+		SPtr<ct::Texture> coreIrradiance = mIrradiance->getCore();
+
+		auto filterSkybox = [coreFilteredRadiance, coreIrradiance, coreSkybox]()
+		{
+			// Filter radiance
+			ct::gIBLUtility().scaleCubemap(coreSkybox->getTexture(), 0, coreFilteredRadiance, 0);
+			ct::gIBLUtility().filterCubemapForSpecular(coreFilteredRadiance, nullptr);
+
+			coreSkybox->mFilteredRadiance = coreFilteredRadiance;
+
+			// Generate irradiance
+			ct::gIBLUtility().filterCubemapForIrradiance(coreFilteredRadiance, coreIrradiance);
+			coreSkybox->mIrradiance = coreIrradiance;
+
+			return true;
+		};
+
+		mRendererTask = ct::RendererTask::create("SkyboxFilter", filterSkybox);
+
+		mRendererTask->onComplete.connect(renderComplete);
+		ct::gRenderer()->addTask(mRendererTask);
+	}
 
 	SPtr<ct::Skybox> Skybox::getCore() const
 	{
@@ -43,7 +112,15 @@ namespace bs
 
 	SPtr<ct::CoreObject> Skybox::createCore() const
 	{
-		ct::Skybox* skybox = new (bs_alloc<ct::Skybox>()) ct::Skybox();
+		SPtr<ct::Texture> filteredRadiance;
+		if (mFilteredRadiance)
+			filteredRadiance = mFilteredRadiance->getCore();
+
+		SPtr<ct::Texture> irradiance;
+		if (mIrradiance)
+			irradiance = mIrradiance->getCore();
+
+		ct::Skybox* skybox = new (bs_alloc<ct::Skybox>()) ct::Skybox(filteredRadiance, irradiance);
 		SPtr<ct::Skybox> skyboxPtr = bs_shared_ptr<ct::Skybox>(skybox);
 		skyboxPtr->mUUID = mUUID;
 		skyboxPtr->_setThisPtr(skyboxPtr);
@@ -81,6 +158,9 @@ namespace bs
 
 	void Skybox::_markCoreDirty(SkyboxDirtyFlag flags)
 	{
+		if(flags == SkyboxDirtyFlag::Texture)
+			filterTexture();
+
 		markCoreDirty((UINT32)flags);
 	}
 
@@ -96,7 +176,8 @@ namespace bs
 
 	namespace ct
 	{
-		Skybox::Skybox()
+		Skybox::Skybox(const SPtr<Texture>& filteredRadiance, const SPtr<Texture>& irradiance)
+			:mFilteredRadiance(filteredRadiance), mIrradiance(irradiance)
 		{ }
 
 		Skybox::~Skybox()
@@ -138,9 +219,7 @@ namespace bs
 			}
 			else
 			{
-				if (dirtyFlags == SkyboxDirtyFlag::Texture)
-					gRenderer()->notifySkyboxTextureChanged(this);
-				else
+				if (dirtyFlags != SkyboxDirtyFlag::Texture)
 				{
 					gRenderer()->notifySkyboxRemoved(this);
 					gRenderer()->notifySkyboxAdded(this);

+ 0 - 2
Source/BansheeEngine/CMakeSources.cmake

@@ -87,7 +87,6 @@ set(BS_BANSHEEENGINE_INC_RENDERER
 	"Include/BsRendererMaterialManager.h"
 	"Include/BsRenderQueue.h"
 	"Include/BsRendererUtility.h"
-	"Include/BsLightProbeCache.h"
 )
 
 set(BS_BANSHEEENGINE_SRC_RTTI
@@ -173,7 +172,6 @@ set(BS_BANSHEEENGINE_SRC_RENDERER
 	"Source/BsRendererMaterialManager.cpp"
 	"Source/BsRenderQueue.cpp"
 	"Source/BsRendererUtility.cpp"
-	"Source/BsLightProbeCache.cpp"
 )
 
 set(BS_BANSHEEENGINE_SRC_INPUT

+ 0 - 94
Source/BansheeEngine/Include/BsLightProbeCache.h

@@ -1,94 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsPrerequisites.h"
-#include "BsParamBlocks.h"
-#include "BsRendererMaterial.h"
-#include "BsModule.h"
-
-namespace bs { namespace ct
-{
-	/** @addtogroup Renderer-Engine-Internal
-	 *  @{
-	 */
-
-	/** 
-	 * Keeps a cache of all textures used by light probes so they may be generated during development time, and then just
-	 * loaded during runtime.
-	 */
-	class BS_EXPORT LightProbeCache : public Module<LightProbeCache>
-	{
-	public:
-		~LightProbeCache();
-
-		/** Initializes the cache with a path at which it can find the saved textures. */
-		void initCache(const Path& path);
-
-		/** Notifies the manager that the probe with the provided UUID is dirty and needs to be re-created. */
-		void notifyDirty(const String& uuid);
-
-		/** 
-		 * Checks if the radiance texture for the probe with the specified UUID is marked as dirty, or if it hasn't been
-		 * cached yet at all. 
-		 */
-		bool isRadianceDirty(const String& uuid) const;
-
-		/** 
-		 * Checks if the radiance texture for the probe with the specified UUID is marked as dirty, or if it hasn't been
-		 * cached yet at all. 
-		 */
-		bool isIrradianceDirty(const String& uuid) const;
-
-		/** Sets a cached radiance texture and associates it with the provided UUID. */
-		void setCachedRadianceTexture(const String& uuid, const SPtr<Texture>& texture);
-
-		/** Sets a cached irradiance texture and associates it with the provided UUID. */
-		void setCachedIrradianceTexture(const String& uuid, const SPtr<Texture>& texture);
-
-		/** 
-		 * Returns an radiance texture that was assigned to the specified UUID with setCachedRadianceTexture() was
-		 * called. 
-		 */
-		SPtr<Texture> getCachedRadianceTexture(const String& uuid) const;
-
-		/** 
-		 * Returns an irradiance texture that was assigned to the specified UUID with setCachedIrradianceTexture() was
-		 * called. 
-		 */
-		SPtr<Texture> getCachedIrradianceTexture(const String& uuid) const;
-
-		/** Unloads in-memory data for a probe with the specified UUID. */
-		void unloadCachedTexture(const String& uuid);
-
-		/** Saves all cached textures in a folder at the provided path. */
-		void saveCache(const Path& path);
-
-	private:
-		/** Information about a single light probe texture. */
-		struct TextureInfo
-		{
-			SPtr<Texture> texture = nullptr;
-			bool dirty = false;
-			bool needsSaving = false;
-		};
-
-		/** Information about textures for a single light probe. */
-		struct ProbeInfo
-		{
-			TextureInfo radiance;
-			TextureInfo irradiance;
-		};
-
-		/** Loads a saved cached texture at the specified path. */
-		SPtr<Texture> loadCachedTexture(const Path& path) const;
-
-		/** Saves cached texture data at the specified path. */
-		void saveCachedTexture(const TextureInfo& texInfo, const Path& path);
-
-		Path mDataPath;
-		mutable UnorderedMap<String, ProbeInfo> mProbeInfos;
-	};
-
-	/** @} */
-}}

+ 0 - 3
Source/BansheeEngine/Source/BsApplication.cpp

@@ -21,7 +21,6 @@
 #include "BsPlatform.h"
 #include "BsEngineShaderIncludeHandler.h"
 #include "BsEngineConfig.h"
-#include "BsLightProbeCache.h"
 
 namespace bs
 {
@@ -43,7 +42,6 @@ namespace bs
 		ShortcutManager::shutDown();
 		GUIManager::shutDown();
 		SpriteManager::shutDown();
-		ct::LightProbeCache::shutDown();
 		BuiltinResources::shutDown();
 		RendererMaterialManager::shutDown();
 		VirtualInput::shutDown();
@@ -58,7 +56,6 @@ namespace bs
 
 		VirtualInput::startUp();
 		BuiltinResources::startUp();
-		ct::LightProbeCache::startUp();
 		RendererMaterialManager::startUp();
 		RendererManager::instance().initialize();
 		SpriteManager::startUp();

+ 0 - 277
Source/BansheeEngine/Source/BsLightProbeCache.cpp

@@ -1,277 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsLightProbeCache.h"
-#include "BsFileSystem.h"
-#include "BsIReflectable.h"
-#include "BsRTTIType.h"
-#include "BsFileSerializer.h"
-
-namespace bs { namespace ct
-{
-	struct CachedTextureData : IReflectable
-	{
-		TextureType type;
-		UINT32 numFaces;
-		UINT32 numMips;
-		Vector<SPtr<PixelData>> pixelData;
-
-		/************************************************************************/
-		/* 								RTTI		                     		*/
-		/************************************************************************/
-	public:
-		friend class CachedTextureDataRTTI;
-		static RTTITypeBase* getRTTIStatic();
-		RTTITypeBase* getRTTI() const override;
-	};
-
-	class CachedTextureDataRTTI : public RTTIType <CachedTextureData, IReflectable, CachedTextureDataRTTI>
-	{
-	private:
-		BS_BEGIN_RTTI_MEMBERS
-			BS_RTTI_MEMBER_PLAIN(type, 0)
-			BS_RTTI_MEMBER_PLAIN(numFaces, 1)
-			BS_RTTI_MEMBER_PLAIN(numMips, 2)
-			BS_RTTI_MEMBER_REFLPTR_ARRAY(pixelData, 3)
-		BS_END_RTTI_MEMBERS
-	public:
-		CachedTextureDataRTTI()
-			:mInitMembers(this)
-		{ }
-
-		const String& getRTTIName() override
-		{
-			static String name = "CachedTextureData";
-			return name;
-		}
-
-		UINT32 getRTTIId() override
-		{
-			return TID_CachedTextureData;
-		}
-
-		SPtr<IReflectable> newRTTIObject() override
-		{
-			return bs_shared_ptr_new<CachedTextureData>();
-		}
-	};
-
-	RTTITypeBase* CachedTextureData::getRTTIStatic()
-	{
-		return CachedTextureDataRTTI::instance();
-	}
-
-	RTTITypeBase* CachedTextureData::getRTTI() const
-	{
-		return getRTTIStatic();
-	}
-
-	LightProbeCache::~LightProbeCache()
-	{
-		for (auto& entry : mProbeInfos)
-		{
-			if(entry.second.radiance.needsSaving || entry.second.irradiance.needsSaving)
-			{
-				LOGWRN("Shutting down reflection cubemap cache manager but not all textures were saved on disk before "
-					   "shutdown.");
-				break;
-			}
-		}
-	}
-
-	void LightProbeCache::initCache(const Path& path)
-	{
-		mDataPath = path;
-
-		auto visitFile = [&](const Path& filePath) -> bool
-		{
-			String uuid = filePath.getFilename(false);
-			mProbeInfos.insert(std::make_pair(uuid, ProbeInfo()));
-
-			return true;
-		};
-
-		FileSystem::iterate(path, visitFile, nullptr, false);
-	}
-
-	void LightProbeCache::notifyDirty(const String& uuid)
-	{
-		auto iterFind = mProbeInfos.find(uuid);
-		if (iterFind != mProbeInfos.end())
-		{
-			iterFind->second.radiance.dirty = true;
-			iterFind->second.irradiance.dirty = true;
-		}
-	}
-
-	bool LightProbeCache::isRadianceDirty(const String& uuid) const
-	{
-		auto iterFind = mProbeInfos.find(uuid);
-		if (iterFind != mProbeInfos.end())
-		{
-			if(iterFind->second.radiance.texture != nullptr)
-				return iterFind->second.radiance.dirty;
-		}
-
-		return true;
-	}
-
-	bool LightProbeCache::isIrradianceDirty(const String& uuid) const
-	{
-		auto iterFind = mProbeInfos.find(uuid);
-		if (iterFind != mProbeInfos.end())
-		{
-			if(iterFind->second.irradiance.texture != nullptr)
-				return iterFind->second.irradiance.dirty;
-		}
-
-		return true;
-	}
-
-	void LightProbeCache::setCachedRadianceTexture(const String& uuid, const SPtr<Texture>& texture)
-	{
-		ProbeInfo& probeInfo = mProbeInfos[uuid];
-		TextureInfo& texInfo = probeInfo.radiance;
-		texInfo.texture = texture;
-		texInfo.needsSaving = true;
-		texInfo.dirty = false;
-	}
-
-	void LightProbeCache::setCachedIrradianceTexture(const String& uuid, const SPtr<Texture>& texture)
-	{
-		ProbeInfo& probeInfo = mProbeInfos[uuid];
-		TextureInfo& texInfo = probeInfo.irradiance;
-		texInfo.texture = texture;
-		texInfo.needsSaving = true;
-		texInfo.dirty = false;
-	}
-
-	SPtr<Texture> LightProbeCache::getCachedRadianceTexture(const String& uuid) const
-	{
-		auto iterFind = mProbeInfos.find(uuid);
-		if (iterFind == mProbeInfos.end())
-			return nullptr;
-
-		TextureInfo& texInfo = iterFind->second.radiance;
-		if (texInfo.texture != nullptr)
-			return texInfo.texture;
-
-		Path filePath = mDataPath + "R_" + uuid + ".asset";
-		texInfo.texture = loadCachedTexture(filePath);
-		
-		return texInfo.texture;
-	}
-
-	SPtr<Texture> LightProbeCache::getCachedIrradianceTexture(const String& uuid) const
-	{
-		auto iterFind = mProbeInfos.find(uuid);
-		if (iterFind == mProbeInfos.end())
-			return nullptr;
-
-		TextureInfo& texInfo = iterFind->second.irradiance;
-		if (texInfo.texture != nullptr)
-			return texInfo.texture;
-
-		Path filePath = mDataPath + "IRR_" + uuid + ".asset";
-		texInfo.texture = loadCachedTexture(filePath);
-
-		return texInfo.texture;
-	}
-
-	void LightProbeCache::unloadCachedTexture(const String& uuid)
-	{
-		auto iterFind = mProbeInfos.find(uuid);
-		if (iterFind != mProbeInfos.end())
-		{
-			// Not allowed to unload if it requires saving (should only happen during development time)
-			if (!iterFind->second.radiance.needsSaving)
-				iterFind->second.radiance.texture = nullptr;
-
-			if (!iterFind->second.irradiance.needsSaving)
-				iterFind->second.irradiance.texture = nullptr;
-		}
-	}
-
-	void LightProbeCache::saveCache(const Path& path)
-	{
-		for(auto& entry : mProbeInfos)
-		{
-			ProbeInfo& probeInfo = entry.second;
-
-			Path radiancePath = path + "R_" + entry.first + ".asset";
-			saveCachedTexture(probeInfo.radiance, radiancePath);
-			probeInfo.radiance.needsSaving = false;
-
-			Path irradiancePath = path + "IRRR_" + entry.first + ".asset";
-			saveCachedTexture(probeInfo.irradiance, irradiancePath);
-			probeInfo.irradiance.needsSaving = false;
-		}
-	}
-
-	SPtr<Texture> LightProbeCache::loadCachedTexture(const Path& path) const
-	{
-		if (!FileSystem::exists(path))
-			return nullptr;
-
-		FileDecoder fd(path);
-		SPtr<CachedTextureData> textureData = std::static_pointer_cast<CachedTextureData>(fd.decode());
-
-		if (textureData == nullptr || textureData->pixelData.size() == 0 || textureData->pixelData[0] == nullptr)
-			return nullptr;
-
-		TEXTURE_DESC desc;
-		desc.type = textureData->type;
-		desc.format = textureData->pixelData[0]->getFormat();
-		desc.width = textureData->pixelData[0]->getWidth();
-		desc.height = textureData->pixelData[0]->getHeight();
-		desc.depth = textureData->pixelData[0]->getDepth();
-
-		if (desc.type == TEX_TYPE_CUBE_MAP)
-			desc.numArraySlices = textureData->numFaces / 6;
-		else
-			desc.numArraySlices = textureData->numFaces;
-
-		desc.numMips = textureData->numMips;
-
-		SPtr<Texture> texture = Texture::create(desc);
-		for (UINT32 face = 0; face < textureData->numFaces; face++)
-		{
-			for (UINT32 mip = 0; mip < textureData->numMips; mip++)
-			{
-				UINT32 srcIdx = face * textureData->numMips + mip;
-				if (srcIdx >= textureData->pixelData.size())
-					continue;
-
-				texture->writeData(*textureData->pixelData[srcIdx], mip, face, true);
-			}
-		}
-
-		return texture;
-	}
-
-	void LightProbeCache::saveCachedTexture(const TextureInfo& texInfo, const Path& path)
-	{
-		if (!texInfo.needsSaving)
-			return;
-
-		auto& texProps = texInfo.texture->getProperties();
-
-		SPtr<CachedTextureData> textureData = bs_shared_ptr_new<CachedTextureData>();
-		textureData->type = texProps.getTextureType();
-		textureData->numFaces = texProps.getNumFaces();
-		textureData->numMips = texProps.getNumMipmaps() + 1;
-
-		for (UINT32 face = 0; face < textureData->numFaces; face++)
-		{
-			for (UINT32 mip = 0; mip < textureData->numMips; mip++)
-			{
-				SPtr<PixelData> pixelData = texProps.allocBuffer(face, mip);
-				texInfo.texture->readData(*pixelData, mip, face);
-
-				textureData->pixelData.push_back(pixelData);
-			}
-		}
-;
-		FileEncoder fe(path);
-		fe.encode(textureData.get());
-	}
-}}

+ 1 - 1
Source/RenderBeast/Include/BsImageBasedLighting.h

@@ -119,7 +119,7 @@ namespace bs { namespace ct
 		ReflProbeParamBuffer();
 
 		/** Updates the parameter buffer contents with require refl. probe data. */
-		void populate(const SkyInfo& sky, const VisibleReflProbeData& probeData, 
+		void populate(const Skybox* sky, const VisibleReflProbeData& probeData, 
 			const SPtr<Texture>& reflectionCubemaps, bool capturingReflections);
 
 		SPtr<GpuParamBlockBuffer> buffer;

+ 2 - 8
Source/RenderBeast/Include/BsRenderBeast.h

@@ -121,9 +121,6 @@ namespace bs
 		/** @copydoc Renderer::notifySkyboxAdded */
 		void notifySkyboxAdded(Skybox* skybox) override;
 
-		/** @copydoc Renderer::notifySkyboxTextureChanged */
-		void notifySkyboxTextureChanged(Skybox* skybox) override;
-
 		/** @copydoc Renderer::notifySkyboxRemoved */
 		void notifySkyboxRemoved(Skybox* skybox) override;
 
@@ -171,11 +168,8 @@ namespace bs
 		/**	Destroys data used by the renderer on the core thread. */
 		void destroyCore();
 
-		/** Updates light probes, rendering & filtering ones that are dirty and updating the global probe cubemap array. */
-		void renderReflectionProbes(const FrameInfo& frameInfo);
-
-		/** Renders the skybox filtered reflections and irradiance cubemap, if they require updating. */
-		void updateSkybox();
+		/** Updates the global reflection probe cubemap array with changed probe textures. */
+		void updateReflProbeArray();
 
 		// Core thread only fields
 

+ 1 - 14
Source/RenderBeast/Include/BsRendererScene.h

@@ -24,16 +24,6 @@ namespace bs
 	// Limited by max number of array elements in texture for DX11 hardware
 	constexpr UINT32 MaxReflectionCubemaps = 2048 / 6;
 
-	/** Contains information about the skybox in the current scene. */
-	struct SkyInfo
-	{
-		Skybox* skybox = nullptr;
-
-		SPtr<Texture> radiance;
-		SPtr<Texture> filteredReflections;
-		SPtr<Texture> irradiance;
-	};
-
 	/** Contains most scene objects relevant to the renderer. */
 	struct SceneInfo
 	{
@@ -60,7 +50,7 @@ namespace bs
 		SPtr<Texture> reflProbeCubemapsTex;
 
 		// Sky
-		SkyInfo sky;
+		Skybox* skybox = nullptr;
 
 		// Buffers for various transient data that gets rebuilt every frame
 		//// Rebuilt every frame
@@ -116,9 +106,6 @@ namespace bs
 		/** Registers a new sky texture in the scene. */
 		void registerSkybox(Skybox* skybox);
 
-		/** Updates information about the previously registered skybox. */
-		void updateSkybox(Skybox* skybox);
-
 		/** Removes a skybox from the scene. */
 		void unregisterSkybox(Skybox* skybox);
 

+ 23 - 12
Source/RenderBeast/Source/BsImageBasedLighting.cpp

@@ -6,7 +6,6 @@
 #include "BsGpuBuffer.h"
 #include "BsGpuParamsSet.h"
 #include "BsReflectionProbe.h"
-#include "BsLightProbeCache.h"
 #include "BsGpuParamsSet.h"
 #include "BsRenderBeast.h"
 #include "BsRendererUtility.h"
@@ -138,21 +137,25 @@ namespace bs { namespace ct
 		buffer = gReflProbeParamsParamDef.createBuffer();
 	}
 
-	void ReflProbeParamBuffer::populate(const SkyInfo& sky, const VisibleReflProbeData& probeData, 
+	void ReflProbeParamBuffer::populate(const Skybox* sky, const VisibleReflProbeData& probeData, 
 		const SPtr<Texture>& reflectionCubemaps, bool capturingReflections)
 	{
+		float brightness = 1.0f;
 		UINT32 skyReflectionsAvailable = 0;
 		UINT32 numSkyMips = 0;
-		if (sky.filteredReflections != nullptr)
+
+		if(sky != nullptr)
 		{
-			numSkyMips = sky.filteredReflections->getProperties().getNumMipmaps() + 1;
-			skyReflectionsAvailable = 1;
+			SPtr<Texture> filteredReflections = sky->getFilteredRadiance();
+			if (filteredReflections)
+			{
+				numSkyMips = filteredReflections->getProperties().getNumMipmaps() + 1;
+				skyReflectionsAvailable = 1;
+			}
+
+			brightness = sky->getBrightness();
 		}
 
-		float brightness = 1.0f;
-		if (sky.skybox != nullptr)
-			brightness = sky.skybox->getBrightness();
-
 		gReflProbeParamsParamDef.gSkyCubemapNumMips.set(buffer, numSkyMips);
 		gReflProbeParamsParamDef.gSkyCubemapAvailable.set(buffer, skyReflectionsAvailable);
 		gReflProbeParamsParamDef.gSkyBrightness.set(buffer, brightness);
@@ -236,7 +239,7 @@ namespace bs { namespace ct
 		framebufferSize[1] = height;
 		gTiledImageBasedLightingParamDef.gFramebufferSize.set(mParamBuffer, framebufferSize);
 
-		mReflProbeParamBuffer.populate(sceneInfo.sky, probeData, sceneInfo.reflProbeCubemapsTex, 
+		mReflProbeParamBuffer.populate(sceneInfo.skybox, probeData, sceneInfo.reflProbeCubemapsTex, 
 			viewProps.renderingReflections);
 
 		mParamBuffer->flushToGPU();
@@ -247,11 +250,19 @@ namespace bs { namespace ct
 		mGBufferC.set(inputs.gbuffer.roughMetal);
 		mGBufferDepth.set(inputs.gbuffer.depth);
 
+		SPtr<Texture> skyFilteredRadiance;
+		SPtr<Texture> skyIrradiance;
+		if(sceneInfo.skybox)
+		{
+			skyFilteredRadiance = sceneInfo.skybox->getFilteredRadiance();
+			skyIrradiance = sceneInfo.skybox->getIrradiance();
+		}
+
 		mImageBasedParams.preintegratedEnvBRDFParam.set(inputs.preIntegratedGF);
 		mImageBasedParams.reflectionProbesParam.set(probeData.getProbeBuffer());
 		mImageBasedParams.reflectionProbeCubemapsTexParam.set(sceneInfo.reflProbeCubemapsTex);
-		mImageBasedParams.skyReflectionsTexParam.set(sceneInfo.sky.filteredReflections);
-		mImageBasedParams.skyIrradianceTexParam.set(sceneInfo.sky.irradiance);
+		mImageBasedParams.skyReflectionsTexParam.set(skyFilteredRadiance);
+		mImageBasedParams.skyIrradianceTexParam.set(skyIrradiance);
 
 		mParamsSet->setParamBlockBuffer("PerCamera", view.getPerViewBuffer(), true);
 

+ 4 - 74
Source/RenderBeast/Source/BsRenderBeast.cpp

@@ -14,7 +14,6 @@
 #include "BsShader.h"
 #include "BsGpuParamBlockBuffer.h"
 #include "BsTime.h"
-#include "BsRenderableElement.h"
 #include "BsCoreObjectManager.h"
 #include "BsRenderBeastOptions.h"
 #include "BsLight.h"
@@ -22,18 +21,13 @@
 #include "BsRendererUtility.h"
 #include "BsAnimationManager.h"
 #include "BsSkeleton.h"
-#include "BsGpuBuffer.h"
-#include "BsGpuParamsSet.h"
 #include "BsRendererExtension.h"
-#include "BsLightProbeCache.h"
 #include "BsReflectionProbe.h"
 #include "BsIBLUtility.h"
-#include "BsLightGrid.h"
 #include "BsSkybox.h"
-#include "BsShadowRendering.h"
 #include "BsStandardDeferredLighting.h"
+#include "BsShadowRendering.h"
 #include "BsRenderCompositor.h"
-#include "BsMesh.h"
 #include "BsRendererTextures.h"
 #include "BsRenderBeastIBLUtility.h"
 
@@ -211,11 +205,6 @@ namespace bs { namespace ct
 		mScene->registerSkybox(skybox);
 	}
 
-	void RenderBeast::notifySkyboxTextureChanged(Skybox* skybox)
-	{
-		mScene->updateSkybox(skybox);
-	}
-
 	void RenderBeast::notifySkyboxRemoved(Skybox* skybox)
 	{
 		mScene->unregisterSkybox(skybox);
@@ -314,9 +303,8 @@ namespace bs { namespace ct
 		ShadowRendering& shadowRenderer = mMainViewGroup->getShadowRenderer();
 		shadowRenderer.renderShadowMaps(*mScene, *mMainViewGroup, frameInfo);
 
-		// Update reflection probe and skybox textures, if required
-		renderReflectionProbes(frameInfo);
-		updateSkybox();
+		// Update reflection probe array if required
+		updateReflProbeArray();
 
 		// Render everything
 		renderViews(*mMainViewGroup, frameInfo);
@@ -462,7 +450,7 @@ namespace bs { namespace ct
 		gProfilerCPU().endSample("RenderOverlay");
 	}
 	
-	void RenderBeast::renderReflectionProbes(const FrameInfo& frameInfo)
+	void RenderBeast::updateReflProbeArray()
 	{
 		SceneInfo& sceneInfo = mScene->_getSceneInfo();
 		UINT32 numProbes = (UINT32)sceneInfo.reflProbes.size();
@@ -540,64 +528,6 @@ namespace bs { namespace ct
 		bs_frame_clear();
 	}
 
-	void RenderBeast::updateSkybox()
-	{
-		SkyInfo& sky = mScene->_getSceneInfo().sky;
-
-		// Get skybox image-based lighting textures if needed/available
-		if (sky.skybox != nullptr && sky.radiance != nullptr)
-		{
-			// If haven't assigned them already, do it now
-			if (sky.filteredReflections == nullptr)
-			{
-				if (!LightProbeCache::instance().isRadianceDirty(sky.skybox->getUUID()))
-					sky.filteredReflections = LightProbeCache::instance().getCachedRadianceTexture(sky.skybox->getUUID());
-				else
-				{
-					TEXTURE_DESC cubemapDesc;
-					cubemapDesc.type = TEX_TYPE_CUBE_MAP;
-					cubemapDesc.format = PF_FLOAT_R11G11B10;
-					cubemapDesc.width = IBLUtility::REFLECTION_CUBEMAP_SIZE;
-					cubemapDesc.height = IBLUtility::REFLECTION_CUBEMAP_SIZE;
-					cubemapDesc.numMips = PixelUtil::getMaxMipmaps(cubemapDesc.width, cubemapDesc.height, 1, cubemapDesc.format);
-					cubemapDesc.usage = TU_STATIC | TU_RENDERTARGET;
-
-					sky.filteredReflections = Texture::create(cubemapDesc);
-
-					gIBLUtility().scaleCubemap(sky.radiance, 0, sky.filteredReflections, 0);
-					gIBLUtility().filterCubemapForSpecular(sky.filteredReflections, nullptr);
-					LightProbeCache::instance().setCachedRadianceTexture(sky.skybox->getUUID(), sky.filteredReflections);
-				}
-			}
-
-			if(sky.irradiance == nullptr)
-			{
-				if (!LightProbeCache::instance().isIrradianceDirty(sky.skybox->getUUID()))
-					sky.irradiance = LightProbeCache::instance().getCachedIrradianceTexture(sky.skybox->getUUID());
-				else
-				{
-					TEXTURE_DESC irradianceCubemapDesc;
-					irradianceCubemapDesc.type = TEX_TYPE_CUBE_MAP;
-					irradianceCubemapDesc.format = PF_FLOAT_R11G11B10;
-					irradianceCubemapDesc.width = IBLUtility::IRRADIANCE_CUBEMAP_SIZE;
-					irradianceCubemapDesc.height = IBLUtility::IRRADIANCE_CUBEMAP_SIZE;
-					irradianceCubemapDesc.numMips = 0;
-					irradianceCubemapDesc.usage = TU_STATIC | TU_RENDERTARGET;
-
-					sky.irradiance = Texture::create(irradianceCubemapDesc);
-
-					gIBLUtility().filterCubemapForIrradiance(sky.filteredReflections, sky.irradiance);
-					LightProbeCache::instance().setCachedIrradianceTexture(sky.skybox->getUUID(), sky.filteredReflections);
-				}
-			}
-		}
-		else
-		{
-			sky.filteredReflections = nullptr;
-			sky.irradiance = nullptr;
-		}
-	}
-
 	void RenderBeast::captureSceneCubeMap(const SPtr<Texture>& cubemap, const Vector3& position, bool hdr)
 	{
 		const SceneInfo& sceneInfo = mScene->getSceneInfo();

+ 16 - 6
Source/RenderBeast/Source/BsRenderCompositor.cpp

@@ -17,6 +17,7 @@
 #include "BsObjectRendering.h"
 #include "BsGpuParamsSet.h"
 #include "BsRendererExtension.h"
+#include "BsSkybox.h"
 
 namespace bs { namespace ct
 {
@@ -729,9 +730,17 @@ namespace bs { namespace ct
 
 		// Prepare refl. probe param buffer
 		ReflProbeParamBuffer reflProbeParamBuffer;
-		reflProbeParamBuffer.populate(sceneInfo.sky, visibleReflProbeData, sceneInfo.reflProbeCubemapsTex, 
+		reflProbeParamBuffer.populate(sceneInfo.skybox, visibleReflProbeData, sceneInfo.reflProbeCubemapsTex, 
 			viewProps.renderingReflections);
 
+		SPtr<Texture> skyFilteredRadiance;
+		SPtr<Texture> skyIrradiance;
+		if(sceneInfo.skybox)
+		{
+			skyFilteredRadiance = sceneInfo.skybox->getFilteredRadiance();
+			skyIrradiance = sceneInfo.skybox->getIrradiance();
+		}
+
 		// Prepare objects for rendering
 		const VisibilityInfo& visibility = inputs.view.getVisibilityMasks();
 		UINT32 numRenderables = (UINT32)sceneInfo.renderables.size();
@@ -766,8 +775,8 @@ namespace bs { namespace ct
 				iblParams.reflectionProbeIndicesParam.set(gridProbeIndices);
 				iblParams.reflectionProbesParam.set(visibleReflProbeData.getProbeBuffer());
 
-				iblParams.skyReflectionsTexParam.set(sceneInfo.sky.filteredReflections);
-				iblParams.skyIrradianceTexParam.set(sceneInfo.sky.irradiance);
+				iblParams.skyReflectionsTexParam.set(skyFilteredRadiance);
+				iblParams.skyIrradianceTexParam.set(skyIrradiance);
 
 				iblParams.reflectionProbeCubemapsTexParam.set(sceneInfo.reflProbeCubemapsTex);
 				iblParams.preintegratedEnvBRDFParam.set(RendererTextures::preintegratedEnvGF);
@@ -824,13 +833,14 @@ namespace bs { namespace ct
 
 	void RCNodeSkybox::render(const RenderCompositorNodeInputs& inputs)
 	{
-		const SkyInfo& sky = inputs.scene.sky;
+		Skybox* skybox = inputs.scene.skybox;
+		SPtr<Texture> radiance = skybox ? skybox->getTexture() : nullptr;
 
-		if (sky.radiance != nullptr)
+		if (radiance != nullptr)
 		{
 			SkyboxMat* material = SkyboxMat::getVariation(false);
 			material->bind(inputs.view.getPerViewBuffer());
-			material->setParams(sky.radiance, Color::White);
+			material->setParams(radiance, Color::White);
 		}
 		else
 		{

+ 3 - 31
Source/RenderBeast/Source/BsRendererScene.cpp

@@ -3,7 +3,6 @@
 #include "BsRendererScene.h"
 #include "BsCamera.h"
 #include "BsLight.h"
-#include "BsLightProbeCache.h"
 #include "BsReflectionProbe.h"
 #include "BsMesh.h"
 #include "BsRenderer.h"
@@ -460,8 +459,6 @@ namespace bs {	namespace ct
 		// Last element is the one we want to erase
 		mInfo.radialLights.erase(mInfo.radialLights.end() - 1);
 		mInfo.radialLightWorldBounds.erase(mInfo.radialLightWorldBounds.end() - 1);
-
-		LightProbeCache::instance().unloadCachedTexture(probe->getUUID());
 	}
 
 	void RendererScene::setReflectionProbeArrayIndex(UINT32 probeIdx, UINT32 arrayIdx, bool markAsClean)
@@ -475,38 +472,13 @@ namespace bs {	namespace ct
 
 	void RendererScene::registerSkybox(Skybox* skybox)
 	{
-		mInfo.sky.skybox = skybox;
-
-		SPtr<Texture> skyTex = skybox->getTexture();
-		if (skyTex != nullptr && skyTex->getProperties().getTextureType() == TEX_TYPE_CUBE_MAP)
-			mInfo.sky.radiance = skyTex;
-
-		mInfo.sky.filteredReflections = nullptr;
-		mInfo.sky.irradiance = nullptr;
-	}
-
-	void RendererScene::updateSkybox(Skybox* skybox)
-	{
-		LightProbeCache::instance().notifyDirty(skybox->getUUID());
-
-		if (mInfo.sky.skybox == skybox)
-		{
-			mInfo.sky.radiance = skybox->getTexture();
-			mInfo.sky.filteredReflections = nullptr;
-			mInfo.sky.irradiance = nullptr;
-		}
+		mInfo.skybox = skybox;
 	}
 
 	void RendererScene::unregisterSkybox(Skybox* skybox)
 	{
-		LightProbeCache::instance().unloadCachedTexture(skybox->getUUID());
-
-		if (mInfo.sky.skybox == skybox)
-		{
-			mInfo.sky.radiance = nullptr;
-			mInfo.sky.filteredReflections = nullptr;
-			mInfo.sky.irradiance = nullptr;
-		}
+		if (mInfo.skybox == skybox)
+			mInfo.skybox = nullptr;
 	}
 
 	void RendererScene::setOptions(const SPtr<RenderBeastOptions>& options)