| 90 | } |
| 91 | |
| 92 | void ShadowsOfMordor::Builder::SceneBuildCache::UpdateLightmaps() |
| 93 | { |
| 94 | Texture* lightmaps[3]; |
| 95 | for (int32 lightmapIndex = 0; lightmapIndex < Lightmaps.Count(); lightmapIndex++) |
| 96 | { |
| 97 | // Cache data |
| 98 | auto& lightmapEntry = Lightmaps[lightmapIndex]; |
| 99 | auto lightmap = Scene->LightmapsData.GetLightmap(lightmapIndex); |
| 100 | ASSERT(lightmap); |
| 101 | lightmap->GetTextures(lightmaps); |
| 102 | |
| 103 | // Download buffer data |
| 104 | if (lightmapEntry.LightmapData->DownloadData(ImportLightmapTextureData)) |
| 105 | { |
| 106 | LOG(Error, "Cannot download LightmapData."); |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | // Import all textures but don't use file proxy to improve performance |
| 111 | for (int32 textureIndex = 0; textureIndex < NUM_SH_TARGETS; textureIndex++) |
| 112 | { |
| 113 | // Get asset name |
| 114 | String assetPath; |
| 115 | if (lightmaps[textureIndex]) |
| 116 | assetPath = lightmaps[textureIndex]->GetPath(); |
| 117 | else |
| 118 | Scene->LightmapsData.GetCachedLightmapPath(&assetPath, lightmapIndex, textureIndex); |
| 119 | |
| 120 | // Import texture with custom options |
| 121 | #if COMPILE_WITH_ASSETS_IMPORTER |
| 122 | Guid id = Guid::Empty; |
| 123 | ImportTexture::Options options; |
| 124 | options.Type = TextureFormatType::HdrRGBA; |
| 125 | options.IndependentChannels = true; |
| 126 | #if PLATFORM_WINDOWS |
| 127 | options.Compress = Scene->GetLightmapSettings().CompressLightmaps; |
| 128 | #else |
| 129 | options.Compress = false; // TODO: use better BC7 compressor that would handle alpha more precisely (otherwise lightmaps have artifacts, see TextureTool.stb.cpp) |
| 130 | #endif |
| 131 | options.GenerateMipMaps = true; |
| 132 | options.IsAtlas = false; |
| 133 | options.sRGB = false; |
| 134 | options.NeverStream = false; |
| 135 | ImportLightmapIndex = lightmapIndex; |
| 136 | ImportLightmapTextureIndex = textureIndex; |
| 137 | options.InternalLoad.Bind<SceneBuildCache, &SceneBuildCache::onImportLightmap>(this); |
| 138 | if (AssetsImportingManager::Create(AssetsImportingManager::CreateTextureTag, assetPath, id, &options)) |
| 139 | { |
| 140 | LOG(Error, "Cannot create new lightmap {0}:{1}", lightmapIndex, textureIndex); |
| 141 | return; |
| 142 | } |
| 143 | const auto result = Content::LoadAsync<Texture>(id); |
| 144 | if (result == nullptr) |
| 145 | #else |
| 146 | #error "Cannot import lightmaps. Assets importer module iss missing." |
| 147 | auto result = nullptr; |
| 148 | #endif |
| 149 | { |
no test coverage detected