void Skybox::InitializePresets(Renderer* pRenderer, const Settings::Rendering& renderSettings) { EnvironmentMap::Initialize(pRenderer); EnvironmentMap::LoadShaders(); const std::string extension = ".hdr"; const std::string BRDFLUTTextureFileName = "BRDFIntegrationLUT"; const std::string BRDFLUTTextureFilePath = EnvironmentMap::sTextureCacheDirectory + BRDFLUTTextureFileName + extension; const bool bUseCache = Engine::GetSettings().bCacheEnvironmentMapsOnDisk && DirectoryUtil::FileExists(BRDFLUTTextureFilePath); if(bUseCache) { EnvironmentMap::sBRDFIntegrationLUTTexture = pRenderer->CreateHDRTexture(BRDFLUTTextureFileName + extension, EnvironmentMap::sTextureCacheDirectory); } else { Texture LUTTexture = EnvironmentMap::CreateBRDFIntegralLUTTexture(); EnvironmentMap::sBRDFIntegrationLUTTexture = LUTTexture._id; if (Engine::GetSettings().bCacheEnvironmentMapsOnDisk) { pRenderer->SaveTextureToDisk(EnvironmentMap::sBRDFIntegrationLUTTexture, BRDFLUTTextureFilePath, false); } // todo: we can unload shaders / render targets here } // Cubemap Skyboxes //------------------------------------------------------------------------------------------------------------------------------------ { // NIGHTSKY // #AsyncLoad: Mutex DEVICE const bool bEquirectangular = false; const auto offsetIter = s_filePaths.begin() + ECubeMapPresets::NIGHT_SKY; const FilePaths filePaths = FilePaths(offsetIter, offsetIter + 6); TextureID skydomeTex = pRenderer->CreateCubemapFromFaceTextures(filePaths, false); //Skybox::SetPreset(ECubeMapPresets::NIGHT_SKY, std::move(Skybox(pRenderer, skydomeTex, bEquirectangular))); s_Presets[ECubeMapPresets::NIGHT_SKY] = Skybox(pRenderer, skydomeTex, bEquirectangular); } if (renderSettings.bEnableEnvironmentLighting) { // HDR / IBL - Equirectangular Skyboxes //------------------------------------------------------------------------------------------------------------------------------------ //EnvironmentMap::Initialize(pRenderer); const bool bEquirectangular = true; EnvironmentMapFileNames files; const std::vector<EEnvironmentMapPresets> presets = { EEnvironmentMapPresets::BARCELONA , EEnvironmentMapPresets::TROPICAL_BEACH, EEnvironmentMapPresets::MILKYWAY , EEnvironmentMapPresets::TROPICAL_RUINS, EEnvironmentMapPresets::WALK_OF_FAME }; std::for_each(RANGE(presets), [&](auto preset) { const auto rootAndFilesPair = GetsIBLFiles(preset); s_Presets[preset] = Skybox(pRenderer, bEquirectangular); s_Presets[preset].Initialize(rootAndFilesPair.second, rootAndFilesPair.first); }); } }
void Skybox::InitializePresets_Async(Renderer* pRenderer, const Settings::Rendering& renderSettings) { EnvironmentMap::Initialize(pRenderer); { std::unique_lock<std::mutex> lck(Engine::mLoadRenderingMutex); EnvironmentMap::LoadShaders(); } { std::unique_lock<std::mutex> lck(Engine::mLoadRenderingMutex); Texture LUTTexture = EnvironmentMap::CreateBRDFIntegralLUTTexture(); EnvironmentMap::sBRDFIntegrationLUTTexture = LUTTexture._id; } // Cubemap Skyboxes //------------------------------------------------------------------------------------------------------------------------------------ { // NIGHTSKY // #AsyncLoad: Mutex DEVICE const bool bEquirectangular = false; const auto offsetIter = s_filePaths.begin() + ECubeMapPresets::NIGHT_SKY; const FilePaths filePaths = FilePaths(offsetIter, offsetIter + 6); TextureID skydomeTex = -1; { std::unique_lock<std::mutex> lck(Engine::mLoadRenderingMutex); skydomeTex = pRenderer->CreateCubemapFromFaceTextures(filePaths, false); } s_Presets[ECubeMapPresets::NIGHT_SKY] = Skybox(pRenderer, skydomeTex, bEquirectangular); } if (renderSettings.bEnableEnvironmentLighting) { // HDR / IBL - Equirectangular Skyboxes //------------------------------------------------------------------------------------------------------------------------------------ //EnvironmentMap::Initialize(pRenderer); const std::string sIBLDirectory = Renderer::sHDRTextureRoot + std::string("sIBL/"); const bool bEquirectangular = true; EnvironmentMapFileNames files; const std::vector<EEnvironmentMapPresets> presets = { EEnvironmentMapPresets::BARCELONA , EEnvironmentMapPresets::TROPICAL_BEACH, EEnvironmentMapPresets::MILKYWAY , EEnvironmentMapPresets::TROPICAL_RUINS, EEnvironmentMapPresets::WALK_OF_FAME }; if (renderSettings.bPreLoadEnvironmentMaps) { std::for_each(RANGE(presets), [&](auto preset) { const auto rootAndFilesPair = GetsIBLFiles(preset); { s_Presets[preset] = Skybox(pRenderer, bEquirectangular); s_Presets[preset].Initialize(rootAndFilesPair.second, rootAndFilesPair.first); } }); } else { auto& preset = presets.back(); const auto rootAndFilesPair = GetsIBLFiles(preset); { s_Presets[preset] = Skybox(pRenderer, bEquirectangular); s_Presets[preset].Initialize(rootAndFilesPair.second, rootAndFilesPair.first); } } } }