Autodesk / maya-usd

A common USD (Universal Scene Description) plugin for Autodesk Maya

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow for 1-to-1 shader translation

BramStout opened this issue · comments

Is your feature request related to a problem? Please describe.
Maya-USD has a few different shading modes that supports multiple portable material definitions, but there are times where you don't care about portability. Maybe you want to use USD, but you keep everything in Maya anyways, maybe you have an external program that generates a scene and you want to use USD to get it into Maya and need Maya materials, or maybe you have a render engine where Maya-USD doesn't have a shading mode for it, but the node types do match.

In any case, sometimes you just want Maya-USD to do a 1-to-1 translation of materials.

Describe the solution you'd like
Looking at the source code trying to figure out if a 1-to-1 translation is possible, I noticed that the pxrRIS shading node already does a 1-to-1 translation, except for swapping out the node type names. So, I propose to duplicate the pxrRIS shading node, rename it the relevant parts from "pxrRIS" to "maya", and then make the following adjustments in the code:

  • _GetShadingPlugs(): Have it just return the Maya plugs (Link)
  • _GetShaderTypeName(const MFnDependencyNode& depNode): Directly return the maya type name (Link)
  • _ExportShadingNodeHelper: Get rid of the check that makes it only export out Pxr* nodes (Link)
  • Export: Have it bind the exported shading mode to the normal interface and not the "ri" interface (Link)
  • _GetMayaTypeNameForShaderId: Directly return the shader id, regardless of the value of defaultToMayaNodes (best to remove that attribute as well, since it would be unnecessary) (Link)
  • _GetOrCreateShaderObject: Remove check causing it to only import in Pxr* nodes (Link)

And that should be it to get a minimally viable shading mode that does 1-to-1 translation. Of course there are a few other places that might need to have a few changes.

I would say that this 1-to-1 shading mode should not be enabled by default for export, but I do think it can be enabled by default for import.

It would be nice if we could have a simple 1-to-1 shading mode right now, while a more permanent solution can be worked on. I think the biggest hurdle for materials is that the different shading modes have to be written in C++, which makes it impractical for most users to be able to export out materials for render engines unsupported by Maya-USD. A shading mode where the translation can be specified by a JSON file could be nice.

Additional context
I'm aware that this sort of backseat-programming isn't always appreciated, and I do apologise for that. Normally I would add in it myself and send in a pull request, but I currently don't have the time to clone Maya-USD, get it to compile, figure out the important details related to adding this feature in, then actually add in the feature, test it, and send it in. So, I'm putting it in here, in the hopes that somebody else does have the time, and to see if others also have ideas regarding this feature.

Hello @BramStout, Thank you for logging this issue with us. I was talking with one of our Dev's in regards to this to see if this is a possibility and he let me know that what you are describing are basically the UsdMayaSymmetricShaderWriter and UsdMayaSymmetricShaderReader classes.

We currently have a plugin that does what you want in our testing section: https://github.com/Autodesk/maya-usd/blob/dev/test/lib/usd/plugin/mayaShaderTranslation.cpp

If it somehow fits in your production pipeline. It only needs to be configured as either a Maya or a USD plugin and loaded alongside MayaUSD. This will add a "Maya Shaders" option to the material sections of the import and export to USD dialogs.

I hope that is helpful. Let me know if you have any further questions.