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

MaterialX v1.38.3 and MayaUSD 0.16.0 updates #2062

Merged
merged 1 commit into from
Feb 3, 2022
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
42 changes: 24 additions & 18 deletions doc/MaterialX.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ We currently support exporting to MaterialX-compatible UsdShade networks:

### To enable:

- Rebuild the MayaUsd plugin for Maya 2022.1 or PR126 using tip of the dev branch or any commit that includes [PR 1478](https://github.com/Autodesk/maya-usd/pull/1478)
- Look for a new "MaterialX shading" option in the `Materials` dropdown of the export options
Two options:
- Install MayaUSD v0.16.0
- Rebuild tip of MayaUSD repo using a MaterialX-enabled build of USD

## Import

Expand All @@ -43,8 +44,9 @@ We can import MaterialX networks.

### To enable:

- Rebuild the MayaUsd plugin for Maya 2022.1 or PR126 using tip of the dev branch or any commit that includes [PR 1478](https://github.com/Autodesk/maya-usd/pull/1478)
- The import code will discover MaterialX shading networks and attempt to import them automatically
Two options:
- Install MayaUSD v0.16.0
- Rebuild tip of MayaUSD repo using a MaterialX-enabled build of USD

## USD stage support in viewport

Expand All @@ -67,20 +69,24 @@ The same spheres exported with MaterialX shading and loaded as a USD stage: ![al

### To enable:

This one is more complex and requires knowledge of how to build USD.
Two options:
- Install MayaUSD v0.16.0 on top of Maya 2022.3 or PR132
- Rebuild tip of MayaUSD repo using a MaterialX-enabled build of USD and a supported Maya version

**Requires Maya 2022.1 or PR126**
Once the updated plugin is in use, the viewport will automatically select MaterialX shading over UsdPreviewSurface shading if the referenced USD stage contains MaterialX shading networks.

1. Build MaterialX using the [Autodesk fork of MaterialX](https://github.com/autodesk-forks/MaterialX)
- Requires a version later than [PR 1285](https://github.com/autodesk-forks/MaterialX/pull/1285) for proper transparency support.
- Requires at minimum MATERIALX_BUILD_CONTRIB, MATERIALX_BUILD_GEN_OGSXML, and MATERIALX_BUILD_SHARED_LIBS options to be enabled
- We only require the OGS XML shadergen part (and USD requires the GLSL shadergen), so you can turn off all complex options like Viewer, OIIO, OSL, or Python support
2. Install that freshly built MaterialX in the `install` location where you intend to build USD next
3. Build a recent USD from the tip of the dev branch into the `install` location that has the updated MaterialX from step 1 (assuming you will use the build_usd.py script)
- There is an API change in the Autodesk branch of MaterialX that requires updating `pxr/imaging/hdSt/materialXFilter.cpp` at line 71 to remove second parameter on the `isTransparentSurface()` function call
4. Rebuild MayaUSD plugin from the tip of the dev branch or any commit that includes both [PR 1478](https://github.com/Autodesk/maya-usd/pull/1478) and [PR 1433](https://github.com/Autodesk/maya-usd/pull/1433)
- Requires enabling the CMAKE_WANT_MATERIALX_BUILD option
- MaterialX_DIR should point to the one built in step 1
- PXR_USD_LOCATION should point to one built in step 3
### Building a MaterialX-enabled USD compatible with MayaUSD

Once the updated plugin is in use, the viewport will automatically select MaterialX shading over UsdPreviewSurface shading if the referenced USD stage contains MaterialX shading networks.
We currently use MaterialX 1.38.3 and USD 20.11. Combining these two together requires patching USD:

```
git checkout tags/v21.11
# Fetch updates selected for next USD release
git cherry-pick 08a5644770d063fe355aff1a2069b22b84d8402a
git cherry-pick adfc04eea92b91965b0da68503539b079a5d30d9
git cherry-pick 4ac8a7e9a440695f0392a94e27db1683773fce76
```

Then you need to merge the pending MaterialX v1.38.3 update submitted as [pull request 1738](https://github.com/PixarAnimationStudios/USD/pull/1738)

Then you build USD using the `build_usd.py` script and the `--materialx` option.
17 changes: 15 additions & 2 deletions lib/mayaUsd/render/vp2RenderDelegate/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ const std::set<std::string> _mtlxTopoNodeSet = {
// Swizzles are inlined into the codegen and affect topology.
"swizzle",
// Conversion nodes:
"convert"
"convert",
// Constants: they get inlined in the source.
"constant"

};

// clang-format on
Expand Down Expand Up @@ -386,6 +389,9 @@ void _AddMissingTexcoordReaders(mx::DocumentPtr& mtlxDoc)
{
// We expect only one node graph, but fixing them all is not an issue:
for (mx::NodeGraphPtr nodeGraph : mtlxDoc->getNodeGraphs()) {
if (nodeGraph->hasSourceUri()) {
continue;
}
// This will hold the emergency "ST" reader if one was necessary
mx::NodePtr stReader;
// Store nodes to delete when loop iteration is complete
Expand Down Expand Up @@ -422,7 +428,7 @@ void _AddMissingTexcoordReaders(mx::DocumentPtr& mtlxDoc)
}
}
// Check if it is an explicit texcoord reader:
if (nodeDef->getCategory() == "texcoord") {
if (nodeDef->getNodeString() == "texcoord") {
// Switch it with a geompropvalue of the same name:
std::string nodeName = node->getName();
std::string oldName = nodeName + "_toDelete";
Expand Down Expand Up @@ -2167,6 +2173,13 @@ void HdVP2Material::_UpdateShaderInstance(const HdMaterialNetwork& mat)
#ifdef WANT_MATERIALX_BUILD
const bool isMaterialXNode = _IsMaterialX(node);
if (isMaterialXNode) {
mx::NodeDefPtr nodeDef
= _GetMaterialXData()._mtlxLibrary->getNodeDef(node.identifier.GetString());
if (nodeDef
&& _mtlxTopoNodeSet.find(nodeDef->getNodeString()) != _mtlxTopoNodeSet.cend()) {
// A topo node does not emit editable parameters:
continue;
}
nodeName += _nodePathMap[node.path].GetName().c_str();
if (node.path == _surfaceShaderId) {
nodeName = "";
Expand Down