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

Update to MaterialX v1.38.3 #1792

Conversation

seando-adsk
Copy link
Contributor

Description of Change(s)

  • Use CMake config directly from MaterialX install
  • Update for API and library changes in v1.38.3
  • Strengthen NodeDef discovery

This is the last update that is not version tagged in the C++ code.
Future updates will be bracketed using MATERIALX_MINOR_VERSION defines introduced in v1.38.3.

Notes:

  • I have submitted a signed Contributor License Agreement

- Use CMake config directly from MaterialX install
- Update for API and library changes in v1.38.3
- Strenghten NodeDef discovery

This is the last update that is not version tagged in the C++ code.
Future updates will be bracketed using MATERIALX_MINOR_VERSION defines
introduced in v1.38.3.
@jilliene
Copy link

jilliene commented Mar 7, 2022

Filed as internal issue #USD-7254

@pablode
Copy link
Contributor

pablode commented Apr 14, 2022

Hi!
I made some efforts to port this PR to MaterialX 1.38.4. You can find the diff here:
autodesk-forks/USD@adsk/update_to_materialx_1.38.3...pablode:mtlx-1.38.4

Commit 93aed43 contains a change which was presumably missed in the transition to 1.38.3.

@spiffmon
Copy link
Member

If Autodesk's preference is to jump right to 1.38.4, that would be good to know ASAP, and we'd ask that this PR be updated with additional changes? (And others following along please advise if you think that would not be desirable)

@JGamache-autodesk
Copy link
Contributor

Hi @spiffmon , I will update to 1.38.4 and generate a patch for @seando-adsk . The code @pablode wrote is very good, but there is a subtle bug in mx::loadLibraries when passing { "libraries" } that I prefer not triggering. I will try to complete this ASAP.

@seando-adsk
Copy link
Contributor Author

@JGamache-autodesk Thanks for the patch Jerry. I have applied it and uploaded the commit to this PR.
@spiffmon The update to v1.38.4 should be ready now.

@spiffmon
Copy link
Member

spiffmon commented Apr 19, 2022 via email

@JGamache-autodesk
Copy link
Contributor

@spiffmon sorry, this was 1.38.4 only. I will generate a code patch to stay backward compatible to 1.38.3.

@seando-adsk
Copy link
Contributor Author

@JGamache-autodesk / @spiffmon Support for v1.38.3 added back in (patch from Jerry).

@spiffmon
Copy link
Member

spiffmon commented Apr 19, 2022 via email

@seando-adsk
Copy link
Contributor Author

Is there a chance this can make it into 22.05?

@spiffmon
Copy link
Member

Sorry, @seando-adsk , 22.05 is basically cooked and nearly out the door. We can commit to getting this into our (next) summer release, though.

@sunyab
Copy link
Contributor

sunyab commented Apr 25, 2022

I am reviewing this change now. One question I had: is the change to use the CMake module out of the MaterialX install necessary for upgrading to 1.38.3, or was it a nice-to-have? I've noticed that this causes the build to fail when building against 1.38.3 when the Python module is not installed -- this looks like a bug that was fixed in 1.38.4.

@JGamache-autodesk
Copy link
Contributor

Hi @sunyab, using the CMake generated by MaterialX:

  • Fixes dynamic library issues on the Windows platform
  • Allows using a custom prefix in the library names

These are changes that are very hard to retrofit into FindMaterialX.cmake. Also fixes the issue of all those slightly incompatible FindMaterialX.cmake found in various projects that can now all be deleted.

If you look in the original 1.38.3 commit, you will see that build_usd.py had workarounds for these issues. Feel free to bring them back if you want to allow using build_usd.py with that MaterialX version.

@marktucker
Copy link
Contributor

I recently used this PR to build 22.05 against Mtls 1.38.4. I just wanted to point out that pxr/usdImaging/bin/usdBakeMtlx also needs modifications similar to other included in this PR to be able to build.

I also had to add back the MATERIALX_INCLUDE_DIR to get any of the Mtlx-consuming libraries to build. I'm not sure where in this PR the Mtlx include dir is supposed to be added to the compiler command line. And I had to leave the old FindMaterialX.cmake file in place, and revert to using MATERIALX_LIBRARIES to get linking to work. But I'm on Windows, and building USD in a very unique environment, not using build_usd.py. Basically I didn't end up using most (any?) of the CMakeLists changes. So these problems/comments may not be valid for anyone else.

Copy link
Contributor

@sunyab sunyab left a comment

Choose a reason for hiding this comment

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

I'm continuing to test this change internally but ran into one issue that I'd love some help with.

usdImaging/usdImagingGL/CMakeLists.txt guards the MaterialX imaging tests with a check for MATERIALX_FOUND, which no longer exists with the removal of the CMake module. I don't think that check was really necessary, so could that please be removed?

Once that's removed, if you run the testUsdImagingGLMaterialX* tests, they will all claim to pass but the results for testUsdImagingGLMaterialX_usdPreviewSurface and testUsdImagingGLMaterialX_mxPreviewSurfaceVsNative_Gold are noticeably different. I've attached images below -- baseline on the left, result with these changes on the right. Are you able to reproduce this on your side? If so, I'd love some help understanding what's happening here and whether this is expected.

image

(missing highlight on the upper-left ball)

image

(brighter gold ball in the lower right)

@seando-adsk
Copy link
Contributor Author

@marktucker You mention that this PR will require changes to pxr/usdImaging/bin/usdBakeMtlx to build. There are already changes in that folder. I have built 22.05 locally on Windows with these changes from this PR without any problems. We are using the build_usd.py script.

Sean

@marktucker
Copy link
Contributor

My apologies, you are correct. I must have done something wrong when I brought your changes into my baseline. Please ignore that part of my comment. And as I said my build environment is... unique... so obviously feel free to ignore my comments about the CMake process. Which I guess means you can ignore everything I said. Sorry for the noise.

@JGamache-autodesk
Copy link
Contributor

Hi @sunyab. Sorry for missing that MATERIALX_FOUND. Modern CMake stopped capitalizing library names, so I should have replaced it with MaterialX_FOUND.
As for the image differences.

  • The smoother specular on the green sphere is expected since the default value for roughness was properly updated from 0.2 to 0.5 in 1.38.2 to match the UsdPreviewSurface standard.
  • I can not directly explain the brighter prefiltered specular on the gold in the second scene. Might be due to changes in GGX computations between 1.38.1 and 1.38.4. I would recommend you try the recent FIS code though. It has improved a lot and stopped requiring an external texture for the albedo table. The code changes to enable this are minimal:
diff --git a/pxr/imaging/hdSt/materialXFilter.cpp b/pxr/imaging/hdSt/materialXFilter.cpp
index b0bf3c33f..54a9dc33e 100644
--- a/pxr/imaging/hdSt/materialXFilter.cpp
+++ b/pxr/imaging/hdSt/materialXFilter.cpp
@@ -79,7 +79,7 @@ _GenMaterialXShader(mx::GenContext & mxContext, mx::ElementPtr const& mxElem)

     // Use the domeLightPrefilter texture instead of sampling the Environment Map
     materialContext.getOptions().hwSpecularEnvironmentMethod =
-        mx::HwSpecularEnvironmentMethod::SPECULAR_ENVIRONMENT_PREFILTER;
+        mx::HwSpecularEnvironmentMethod::SPECULAR_ENVIRONMENT_FIS;

     return mx::createShader("Shader", materialContext, mxElem);
 }
diff --git a/pxr/imaging/hdSt/materialXShaderGen.cpp b/pxr/imaging/hdSt/materialXShaderGen.cpp
index 69f3abf8f..f0fc1e4a4 100644
--- a/pxr/imaging/hdSt/materialXShaderGen.cpp
+++ b/pxr/imaging/hdSt/materialXShaderGen.cpp
@@ -600,6 +600,8 @@ HdStMaterialXShaderGen::_EmitMxInitFunction(
         emitLine("u_envRadiance = HdGetSampler_domeLightPrefilter()", mxStage);
     }
     emitLine("u_envRadianceMips = textureQueryLevels(u_envRadiance)", mxStage);
+    emitLine("u_envRadianceSamples = 64", mxStage);
     emitLine("#endif", mxStage, false);
     emitLineBreak(mxStage);

This would generate a much improved specular experience for that test scene:
image

@seando-adsk
Copy link
Contributor Author

@sunyab I added another patch from Jerry to Enable FIS lighting for MaterialX 1.38.3 and later. I had to merge in latest dev first.

@sunyab
Copy link
Contributor

sunyab commented May 4, 2022

@JGamache-autodesk Thank you for the comments on those test cases, that was super helpful!

@seando-adsk Could I ask you to revert that FIS patch and file another PR for that so we can evaluate that separately?

Otherwise I think we're all set to land this PR once that last commit is reverted.

@seando-adsk
Copy link
Contributor Author

@sunyab Sure I can revert the last commit. Question though, do you want the MaterialX_FOUND cmake change in this PR or with the new PR?

@sunyab
Copy link
Contributor

sunyab commented May 4, 2022

@seando-adsk Ah please leave the MaterialX_FOUND change in this PR since it keeps tests running. Thanks!

@seando-adsk seando-adsk force-pushed the adsk/update_to_materialx_1.38.3 branch from 0a83b69 to e6edb7e Compare May 4, 2022 17:23
@seando-adsk
Copy link
Contributor Author

@sunyab Done, I've corrected the last commit to be just the cmake change.

@pixar-oss pixar-oss merged commit 02a9843 into PixarAnimationStudios:dev May 16, 2022
@seando-adsk seando-adsk deleted the adsk/update_to_materialx_1.38.3 branch June 7, 2022 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants