Skip to content

Commit

Permalink
Author unassigned shaders under the mtl scope Autodesk#2174
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienblor committed Jan 9, 2025
1 parent e6d2038 commit 6df1444
Show file tree
Hide file tree
Showing 5 changed files with 731 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

- [usd#2159](https://github.com/Autodesk/arnold-usd/issues/2159) - User data errors with deformed meshes and subdivision
- [usd#2160](https://github.com/Autodesk/arnold-usd/issues/2160) - Support OSL code generated from image shaders in MaterialX 1.38.10
- [usd#2174](https://github.com/Autodesk/arnold-usd/issues/2174) - Author unassigned shaders under the mtl scope when writing to USD

## Pending Feature release (7.2.6.0)

Expand Down
17 changes: 16 additions & 1 deletion libs/translator/writer/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,21 @@ void UsdArnoldWriter::Write(const AtUniverse *universe)
}
AiNodeIteratorDestroy(iter);

std::string prevScope = _scope;
std::string mtlScope = _scope + GetMtlScope();
// Then, do a second loop only through shaders in the arnold universe.
// Those that weren't exported yet in the previous step, and that aren't
// therefore assigned to any geometry, will be exported here.
// Some of these shaders might have been marked as being "required" because other nodes
// are pointing at them (operators, etc...). For these shaders to show up in hydra, we need
// an ArnoldNodeGraph primitive to point at them.
std::string unassignedShadersStr = GetMtlScope() + std::string("/ArnoldUnassignedShaders");
std::string unassignedShadersStr = mtlScope + std::string("/ArnoldUnassignedShaders");
SdfPath unassignedShadersPath(unassignedShadersStr);
UsdPrim unassignedShaders;
int unassignedShadersIndex = 1;

if (_mask & shadersMask) {
bool createdScope = false;
iter = AiUniverseGetNodeIterator(_universe, shadersMask & _mask);
while (!AiNodeIteratorFinished(iter)) {
AtNode *node = AiNodeIteratorGetNext(iter);
Expand All @@ -178,7 +181,19 @@ void UsdArnoldWriter::Write(const AtUniverse *universe)
if (_exportedShaders.find(node) != _exportedShaders.end())
continue;

bool isArnoldShader = AiNodeEntryGetType(AiNodeGetNodeEntry(node)) == AI_NODE_SHADER;
if (isArnoldShader) {
_scope = mtlScope;
if (!createdScope) {
// Ensure the mtl scope will be created as a Scope
CreateScopeHierarchy(SdfPath(mtlScope));
createdScope = true;
}
}
WritePrimitive(node);
if (isArnoldShader) {
_scope = prevScope;
}

if (_requiredShaders.find(node) != _requiredShaders.end()) {
unassignedShaders = _stage->GetPrimAtPath(unassignedShadersPath);
Expand Down
5 changes: 5 additions & 0 deletions testsuite/test_2174/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Author unassigned shaders under the mtl scope

see #2174

author: sebastien ortega
Loading

0 comments on commit 6df1444

Please sign in to comment.