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

Autodesk: Optimize MaterialX shader generation in Storm by comparing topologies #3073

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
16 changes: 9 additions & 7 deletions pxr/imaging/hdMtlx/hdMtlx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,15 @@ _AddMaterialXNode(
}
}

// MaterialX nodes that use textures are assumed to have a filename input
if (mxNodeDef->getNodeGroup() == "texture2d") {
if (mxHdData) {
// Save the corresponding MaterialX and Hydra names for ShaderGen
mxHdData->mxHdTextureMap[mxNodeName] = connectionName;
// Save the path to adjust parameters after traversing the network
mxHdData->hdTextureNodes.insert(hdNodePath);
// MaterialX nodes that use textures can have more than one filename input
if (mxHdData) {
for (auto const& input: mxNodeDef->getActiveInputs()) {
if (input->getType() == "filename") {
// Save the corresponding MaterialX and Hydra names for ShaderGen
mxHdData->mxHdTextureMap[mxNodeName].insert(input->getName());
// Save the path to adjust parameters after traversing the network
mxHdData->hdTextureNodes.insert(hdNodePath);
}
}
}

Expand Down
12 changes: 5 additions & 7 deletions pxr/imaging/hdMtlx/hdMtlx.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ HdMtlxConvertToString(VtValue const& hdParameterValue);

// Storing MaterialX-Hydra texture and primvar information
struct HdMtlxTexturePrimvarData {
HdMtlxTexturePrimvarData()
: mxHdTextureMap(MaterialX::StringMap()), // Mx-Hd texture name mapping
hdTextureNodes(std::set<SdfPath>()), // Paths to HdTexture Nodes
hdPrimvarNodes(std::set<SdfPath>()) {} // Paths to HdPrimvar nodes
MaterialX::StringMap mxHdTextureMap;
std::set<SdfPath> hdTextureNodes;
std::set<SdfPath> hdPrimvarNodes;
HdMtlxTexturePrimvarData() = default;
using TextureMap = std::map<std::string, std::set<std::string>>;
TextureMap mxHdTextureMap; // Mx-Hd texture name mapping
std::set<SdfPath> hdTextureNodes; // Paths to HdTexture Nodes
std::set<SdfPath> hdPrimvarNodes; // Paths to HdPrimvar nodes
};

/// Creates and returns a MaterialX Document from the given HdMaterialNetwork2
Expand Down
2 changes: 1 addition & 1 deletion pxr/imaging/hdSt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2966,7 +2966,7 @@ pxr_register_test(testHdStMaterialXShaderGen_SStextured
TESTENV testHdStMaterialXShaderGen
)
pxr_register_test(testHdStMaterialXShaderGen_UsdPSglass
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStMaterialXShaderGen --filename usd_preview_surface_glass.mtlx --materialTag translucent"
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStMaterialXShaderGen --filename usd_preview_surface_glass.mtlx"
STDOUT_REDIRECT shadergen_UsdPSglass.out
EXPECTED_RETURN_CODE 0
POST_COMMAND "diff -B -b shadergen_UsdPSglass.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStMaterialXShaderGen/baseline/shadergen_UsdPSglass.out"
Expand Down
17 changes: 15 additions & 2 deletions pxr/imaging/hdSt/materialNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,21 @@ _MakeMaterialParamsForTexture(
NdrTokenVec const& assetIdentifierPropertyNames =
sdrNode->GetAssetIdentifierInputNames();

if (assetIdentifierPropertyNames.size() == 1) {
TfToken const& fileProp = assetIdentifierPropertyNames[0];
if (!assetIdentifierPropertyNames.empty()) {
TfToken fileProp = assetIdentifierPropertyNames[0];

// Some MaterialX nodes can have multiple file inputs. Take the first
// one that matches the param name. If we lookup a <trilinear> texture
// against an output named "N42_fileY", we will find the right one.
if (assetIdentifierPropertyNames.size() > 1) {
for (auto const& propName: assetIdentifierPropertyNames) {
if (TfStringEndsWith(outputName.GetString(), propName)) {
fileProp = propName;
break;
}
}
}

auto const& it = node.parameters.find(fileProp);
if (it != node.parameters.end()){
const VtValue &v = it->second;
Expand Down
Loading