Skip to content

Commit

Permalink
Fix issue with Storm and rendering custom nodes that use texture coor…
Browse files Browse the repository at this point in the history
…dinates

This issue is specific to custom nodes that use the <texcoord> node in their
defining nodegraph and either re-use that nodes output or are a multioutput
node.

This change removes the addition of the 'index' input to the network
interface, and in Storm sets the texture coordinate primvar type as
Vector2 regardless of the node's output type.

Previously, we were adding the 'index' input to the network interface which
means that the second time we come across this node we have an input
that is not a part of the nodedef. This means that when we pass it to
MaterialX for shadergen it is not able to correctly identify the node. Also,
in Storm when we gather the primvar information for the glslfx header,
we use the node's output type for the texture coordinates, which is not
likely to be a vector2 type, and for multioutput nodes specifically it
causes shadergen to completely fail.

(Internal change: 2341878)
  • Loading branch information
klucknav authored and pixar-oss committed Sep 24, 2024
1 parent 8fa5867 commit 4c94900
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
20 changes: 8 additions & 12 deletions pxr/imaging/hdMtlx/hdMtlx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ PXR_NAMESPACE_OPEN_SCOPE

TF_DEFINE_PRIVATE_TOKENS(
_tokens,
(index)
(texcoord)
(geompropvalue)
(filename)
);

static mx::FileSearchPath
Expand Down Expand Up @@ -184,12 +186,12 @@ HdMtlxConvertToString(VtValue const& hdParameterValue)
}

static bool
_ContainsTexcoordNode(mx::NodeDefPtr const& mxNodeDef)
_UsesTexcoordNode(mx::NodeDefPtr const& mxNodeDef)
{
mx::InterfaceElementPtr impl = mxNodeDef->getImplementation();
if (impl && impl->isA<mx::NodeGraph>()) {
mx::NodeGraphPtr nodegraph = impl->asA<mx::NodeGraph>();
if (nodegraph->getNodes("texcoord").size() != 0) {
if (!nodegraph->getNodes(_tokens->texcoord).empty()) {
return true;
}
}
Expand Down Expand Up @@ -275,7 +277,7 @@ _AddMaterialXNode(
// MaterialX nodes that use textures can have more than one filename input
if (mxHdData) {
for (mx::InputPtr const& mxInput : mxNodeDef->getActiveInputs()) {
if (mxInput->getType() == "filename") {
if (mxInput->getType() == _tokens->filename) {
// Save the corresponding Mx and Hydra names for ShaderGen
mxHdData->mxHdTextureMap[mxNodeName].insert(mxInput->getName());
// Save the path to adjust parameters after for ShaderGen
Expand All @@ -285,7 +287,7 @@ _AddMaterialXNode(
}

// MaterialX primvar node
if (mxNodeCategory == "geompropvalue") {
if (mxNodeCategory == _tokens->geompropvalue) {
if (mxHdData) {
// Save the path to have the primvarName declared in ShaderGen
mxHdData->hdPrimvarNodes.insert(hdNodePath);
Expand All @@ -294,14 +296,8 @@ _AddMaterialXNode(

// Stdlib MaterialX texture coordinate node or a custom node that
// uses a texture coordinate node
if (mxNodeCategory == "texcoord" || _ContainsTexcoordNode(mxNodeDef)) {
if (mxNodeCategory == _tokens->texcoord || _UsesTexcoordNode(mxNodeDef)) {
if (mxHdData) {
// Make sure it has the index parameter set.
if (std::find(hdNodeParamNames.begin(), hdNodeParamNames.end(),
_tokens->index) == hdNodeParamNames.end()) {
netInterface->SetNodeParameterValue(
hdNodeName, _tokens->index, VtValue(0));
}
// Save the path to have the textureCoord name declared in ShaderGen
mxHdData->hdPrimvarNodes.insert(hdNodePath);
}
Expand Down
14 changes: 4 additions & 10 deletions pxr/imaging/hdSt/materialXFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,9 @@ _UpdatePrimvarNodes(
(*mxHdPrimvarDefaultValueMap)[primvarName] = defaultPrimvarValue;
}

// Texcoord nodes will have an index parameter set
primvarNameIt = hdPrimvarNode.parameters.find(_tokens->index);
if (primvarNameIt != hdPrimvarNode.parameters.end()) {
// Get the sdr node for the texcoord node
else {
// Other primvar nodes will be either a texcoord node or a
// custom node that uses a texcoord node.
SdrRegistry &sdrRegistry = SdrRegistry::GetInstance();
const SdrShaderNodeConstPtr sdrTexCoordNode =
sdrRegistry.GetShaderNodeByIdentifierAndType(
Expand All @@ -511,12 +510,7 @@ _UpdatePrimvarNodes(
texCoordName = metadata[SdrNodeMetadata->Primvars];
}

// Figure out the mx typename
mx::NodeDefPtr mxNodeDef = mxDoc->getNodeDef(
hdPrimvarNode.nodeTypeId.GetString());
if (mxNodeDef) {
(*mxHdPrimvarMap)[texCoordName] = mxNodeDef->getType();
}
(*mxHdPrimvarMap)[texCoordName] = mx::Type::VECTOR2->getName();
}
}
}
Expand Down

0 comments on commit 4c94900

Please sign in to comment.