Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Author unassigned shaders under the mtl scope #2175

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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