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

Support OSL code generated from image shaders in MaterialX 1.38.10 #2160

Merged
merged 4 commits into from
Dec 18, 2024
Merged
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 @@ -4,6 +4,7 @@
## Pending Feature release

- [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

## Pending Feature release (7.2.6.0)

Expand Down
25 changes: 23 additions & 2 deletions libs/common/materials_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ AtNode* ReadMtlxOslShader(const std::string& nodeName,
}
uint8_t paramType = AiParamGetType(paramEntry);

#if ARNOLD_VERSION_NUM < 70400
// The tiledimage / image shaders need to create
// an additional osl shader to represent the filename
if (paramType == AI_TYPE_POINTER && TfStringStartsWith(attrNameStr, "param_shader_file")) {
Expand Down Expand Up @@ -616,17 +617,37 @@ AtNode* ReadMtlxOslShader(const std::string& nodeName,
if (colorSpaceAttr != inputAttrs.end()) {
std::string colorSpaceStr = VtValueGetString(colorSpaceAttr->second.value);
AiNodeSetStr(oslSource, str::param_colorspace, AtString(colorSpaceStr.c_str()));

} else {
AiNodeSetStr(oslSource, str::param_colorspace, str::_auto);
}
// Connect the original osl shader attribute to our new osl shader
AiNodeLink(oslSource,paramName, node);
continue;
}
}
}
#else
if (paramType == AI_TYPE_STRING && TfStringStartsWith(attrNameStr, "param_shader_file")) {
std::string filename = VtValueGetString(attr.value);
// if the filename is empty, there's nothing else to do
if (!filename.empty()) {
// get the metadata "osl_struct" on the arnold attribute for "file", it should be set to "textureresource"
AtString fileStr;
// Check if this "file" attribute has a colorSpace metadata, that we have
// set as a separate parameter
std::string colorSpaceStr = std::string("colorSpace:")+ attrName.GetString();
TfToken colorSpace(colorSpaceStr);
const auto colorSpaceAttr = inputAttrs.find(colorSpace);
if (colorSpaceAttr != inputAttrs.end()) {
std::string colorSpaceStr = VtValueGetString(colorSpaceAttr->second.value);
AiNodeSetStr(node, str::param_shader_file_colorspace, AtString(colorSpaceStr.c_str()));
} else {
AiNodeSetStr(node, str::param_shader_file_colorspace, str::_auto);
}
}
}

#endif
int arrayType = AI_TYPE_NONE;
if (paramType == AI_TYPE_ARRAY) {
const AtParamValue *defaultValue = AiParamGetDefault(paramEntry);
Expand Down