Skip to content

Implemented Part I of addExplicitTypeConversions()#2929

Open
christopher-jacobs wants to merge 7 commits into
AcademySoftwareFoundation:mainfrom
christopher-jacobs:main
Open

Implemented Part I of addExplicitTypeConversions()#2929
christopher-jacobs wants to merge 7 commits into
AcademySoftwareFoundation:mainfrom
christopher-jacobs:main

Conversation

@christopher-jacobs

Copy link
Copy Markdown

In regards to #2919 I implemented addExplicitTypeConversions() and added two tests to show a valid conversion and an invalid conversion. The valid test connects a vector3 output to a color3 output, and the invalid test attempts to connect a vector3 output to a float output. This currently loops through the entire NodeGraph to see if any conversions are possible, but I believe that this could be more easily implemented to be integrated with validate() (possibly taking the outputted message to find the questionable node and then check this connection directly).

This is my first time contributing to an open source project so let me know what can be improved and also any feedback. Looking at Parts II and III this is a very interesting and cool idea that I would love to continue if possible! Thank you!

@kwokcb kwokcb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good start on this.

However, there are additional complications and scope....

  1. You can have "interface" inputs (input nodes) connected to internal node inputs.
  2. You have have internal node outputs connected to interface "outputs" (output nodes).

The "get" / "set" connected nodes will probably not work in these cases as they are not stricty node-node connections and also they will traverse to the parent.

  1. You need to consider not just NodeGraphs but "graphs" in general which is the parent class GraphElement. This will allow include of Documents which inherit from GraphElement.

I will also add this to the issue, as this should be clarified there more succinctly. Apologies for the general language used.

@christopher-jacobs

Copy link
Copy Markdown
Author

Thank you for that feedback! I'll reiterate on this and make sure that I take these into consideration!

@kwokcb

kwokcb commented May 15, 2026

Copy link
Copy Markdown
Contributor

As mentioned in the issue, I think it might be better to use some form of the validation logic to find the problem connections and then fix them afterwards.

Comment thread source/MaterialXCore/Node.h Outdated
/// Modify the nodes that can be converted explicitly within the associated NodeGraph.
/// @param addedNodes List of added nodes that were successfully integrated (w.r.t. the connection).
/// @param invalidConnections List of connections that could not be successfully converted.
void addExplicitTypeConversions(vector<NodePtr>& addedNodes, vector<NodePtr>& invalidConnections);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kwokcb I'm curious stylistically if you think its important that this method exist on the NodeGraph class itself, or if instead we should consider it a true utility - and make it a stand-alone function.

In the back of my head I worry we start expanding the API surface of these objects, things may get harder in the future to manage API/ABI compatibility.

Also in any future world where we have the ability to feed ShaderGen with some other data model, if these "utility" functions existed stand-alone - we might be able to serve the same logic through the abstract interface, and say allow USD materials to also have conversion nodes inserted on demand.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason that it needs to be on the core classes (*). It does need an input object (GraphElement) but that could be wrapped up into some opaque wrapper.

I'd prefer if these we're not global methods but instead add a "operation stack" base class which takes one or more "operations" (wrappers) to perform. You could create a MTLX version here and USD could create their own.

Is this kind of what your thinking of? ( Std disclaimer is that I haven't followed any of the ShaderGen refactor stuff of late.)

(*) @christopher-jacobs : This is not meant to overwhelm you with longer term complications. I think for this task it can just be on the GraphElement class.

@christopher-jacobs christopher-jacobs May 15, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, if anything I like observing this conversation and learning more about the different ways this could be implemented. I'll go ahead and implement the changes within GraphElement as we discussed earlier. I'm very interested though in this conversation and to explore and learn more! Thank you both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants