MCPcopy Create free account
hub / github.com/NVIDIA-RTX/RTXNTC / LoadMaterialsForScene

Method LoadMaterialsForScene

samples/renderer/NtcMaterialLoader.cpp:1313–1450  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1311}
1312
1313bool NtcMaterialLoader::LoadMaterialsForScene(donut::engine::Scene& scene, std::filesystem::path const& materialDir,
1314 bool enableInferenceOnLoad, bool enableBlockCompression, bool enableInferenceOnSample,
1315 bool enableInferenceOnFeedback, std::shared_ptr<nvfeedback::FeedbackManager> feedbackManager)
1316{
1317 using namespace std::chrono;
1318 time_point start = steady_clock::now();
1319
1320 uint64_t totalFileSize = 0;
1321 uint64_t totalPixels = 0;
1322 int materialCount = 0;
1323 m_weightTypeHistogram.fill(0);
1324
1325 std::vector<std::shared_ptr<engine::Material>> materials;
1326 for (std::shared_ptr<engine::Material> const& material : scene.GetSceneGraph()->GetMaterials())
1327 materials.push_back(material);
1328
1329 std::unordered_map<std::string, std::shared_ptr<NtcMaterial>> ntcMaterialCache; // ntcData.ToString() -> NtcMaterial
1330
1331 for (std::shared_ptr<engine::Material> const& material : materials)
1332 {
1333 std::shared_ptr<NtcMaterial> ntcMaterial = std::static_pointer_cast<NtcMaterial>(material);
1334
1335 fs::path modelFileName = material->modelFileName;
1336 fs::path currentMaterialDir = materialDir.empty() ? modelFileName.parent_path() : materialDir;
1337
1338 // Find a single NTC file that contains channels for all textures for this material.
1339 // In a general case, there may be multiple different files used in a single material,
1340 // but our GLTF preparation script only uses one, and we only support one in this renderer.
1341 // Also derive the channel mapping: where to source the channels for albedo, roughness, etc.
1342 donut::engine::FilePathOrInlineData ntcData;
1343 MaterialChannelMap channelMap;
1344 GetNtcDataSourceAndChannelMap(*ntcMaterial, ntcData, channelMap);
1345
1346 // No NTC data found, skip the material
1347 if (!ntcData)
1348 continue;
1349
1350 auto cacheIterator = ntcMaterialCache.find(ntcData.ToString());
1351 if (cacheIterator != ntcMaterialCache.end())
1352 {
1353 auto previouslyLoadedMaterial = cacheIterator->second;
1354
1355 // Copy over all the properties that we touch when decoding NTC materials,
1356 // but not the entire material: some flags or parameters might be different.
1357 ntcMaterial->ntcConstantBuffer = previouslyLoadedMaterial->ntcConstantBuffer;
1358 ntcMaterial->ntcWeightsBuffer = previouslyLoadedMaterial->ntcWeightsBuffer;
1359 ntcMaterial->ntcLatentsTexture = previouslyLoadedMaterial->ntcLatentsTexture;
1360 ntcMaterial->weightType = previouslyLoadedMaterial->weightType;
1361 ntcMaterial->baseOrDiffuseTexture = previouslyLoadedMaterial->baseOrDiffuseTexture;
1362 ntcMaterial->metalRoughOrSpecularTexture = previouslyLoadedMaterial->metalRoughOrSpecularTexture;
1363 ntcMaterial->normalTexture = previouslyLoadedMaterial->normalTexture;
1364 ntcMaterial->emissiveTexture = previouslyLoadedMaterial->emissiveTexture;
1365 ntcMaterial->occlusionTexture = previouslyLoadedMaterial->occlusionTexture;
1366 ntcMaterial->transmissionTexture = previouslyLoadedMaterial->transmissionTexture;
1367 ntcMaterial->opacityTexture = previouslyLoadedMaterial->opacityTexture;
1368 ntcMaterial->metalnessInRedChannel = previouslyLoadedMaterial->metalnessInRedChannel;
1369 ntcMaterial->baseOrDiffuseTextureFeedback = previouslyLoadedMaterial->baseOrDiffuseTextureFeedback;
1370 ntcMaterial->metalRoughOrSpecularTextureFeedback = previouslyLoadedMaterial->metalRoughOrSpecularTextureFeedback;

Callers 1

LoadSceneMethod · 0.80

Calls 4

LoadMaterialFileFunction · 0.85
GetMethod · 0.80

Tested by

no test coverage detected