Skip to content

Commit

Permalink
Update to MaterialX v1.38.5 (PixarAnimationStudios#148)
Browse files Browse the repository at this point in the history
USD 22.08 required MaterialX 1.38.4 minimum. At Autodesk we want to align on 1.38.5.
The changes are based on an open Pixar PR PixarAnimationStudios#1965
(cherry picked from commit d9b3c81)
Co-authored-by: Pablo Delgado Krämer <[email protected]>
  • Loading branch information
ashwinbhat authored and GitHub Enterprise committed Oct 15, 2022
1 parent 9b9d9fe commit 6c7b639
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ def InstallDraco(context, force, buildArgs):
############################################################
# MaterialX

MATERIALX_URL = "https://github.com/materialx/MaterialX/archive/v1.38.4.zip"
MATERIALX_URL = "https://github.com/materialx/MaterialX/archive/v1.38.5.zip"

def InstallMaterialX(context, force, buildArgs):
with CurrentWorkingDirectory(DownloadURL(MATERIALX_URL, context, force)):
Expand Down
44 changes: 35 additions & 9 deletions pxr/imaging/hdSt/materialXShaderGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ HdStMaterialXShaderGen::HdStMaterialXShaderGen(
"st" : mxHdInfo.defaultTexcoordName;

// Register the customized version of the Surface node generator
registerImplementation("IM_surface_" + GlslShaderGenerator::TARGET,
HdStMaterialXSurfaceNodeGen::create);
registerImplementation("IM_surface_genglsl", HdStMaterialXSurfaceNodeGen::create);
}

// Based on GlslShaderGenerator::generate()
Expand Down Expand Up @@ -273,8 +272,7 @@ HdStMaterialXShaderGen::_EmitMxFunctions(
mx::ShaderStage& mxStage) const
{
// Add global constants and type definitions
emitLibraryInclude("stdlib/" + mx::GlslShaderGenerator::TARGET
+ "/lib/mx_math.glsl", mxContext, mxStage);
emitLibraryInclude("stdlib/genglsl/lib/mx_math.glsl", mxContext, mxStage);
emitLine("#if NUM_LIGHTS > 0", mxStage, false);
emitLine("#define MAX_LIGHT_SOURCES NUM_LIGHTS", mxStage, false);
emitLine("#else", mxStage, false);
Expand Down Expand Up @@ -394,16 +392,24 @@ HdStMaterialXShaderGen::_EmitMxFunctions(
emitSpecularEnvironment(mxContext, mxStage);
}
if (shadowing) {
emitLibraryInclude("pbrlib/" + mx::GlslShaderGenerator::TARGET
+ "/lib/mx_shadow.glsl", mxContext, mxStage);
emitLibraryInclude("pbrlib/genglsl/lib/mx_shadow.glsl", mxContext, mxStage);
}

#if MATERIALX_MAJOR_VERSION > 1 || \
(MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION > 38) || \
(MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION == 38 && MATERIALX_BUILD_VERSION > 4)
// MaterialX 1.38.5 changes the default transmission method to "refraction".
mxContext.getOptions().hwTransmissionRenderMethod = mx::TRANSMISSION_OPACITY;

// Emit transmission code
emitTransmissionRender(mxContext, mxStage);
#endif

// Emit directional albedo table code.
if (mxContext.getOptions().hwDirectionalAlbedoMethod ==
mx::HwDirectionalAlbedoMethod::DIRECTIONAL_ALBEDO_TABLE ||
mxContext.getOptions().hwWriteAlbedoTable) {
emitLibraryInclude("pbrlib/" + mx::GlslShaderGenerator::TARGET
+ "/lib/mx_table.glsl", mxContext, mxStage);
emitLibraryInclude("pbrlib/genglsl/lib/mx_table.glsl", mxContext, mxStage);
emitLineBreak(mxStage);
}

Expand All @@ -421,7 +427,7 @@ HdStMaterialXShaderGen::_EmitMxFunctions(
// Emit uv transform code globally if needed.
if (mxContext.getOptions().hwAmbientOcclusion) {
emitLibraryInclude(
"stdlib/" + mx::GlslShaderGenerator::TARGET + "/lib/" +
"stdlib/genglsl/lib/" +
_tokenSubstitutions[ShaderGenerator::T_FILE_TRANSFORM_UV],
mxContext, mxStage);
}
Expand Down Expand Up @@ -490,10 +496,30 @@ HdStMaterialXShaderGen::_EmitMxSurfaceShader(
// closure/shader nodes and need to be emitted first.
emitFunctionCalls(mxGraph, mxContext, mxStage, mx::ShaderNode::Classification::TEXTURE);

#if MATERIALX_MAJOR_VERSION == 1 && \
MATERIALX_MINOR_VERSION == 38 && \
MATERIALX_BUILD_VERSION <= 4
// Emit function calls for all surface shader nodes.
// These will internally emit their closure function calls.
emitFunctionCalls(mxGraph, mxContext, mxStage, mx::ShaderNode::Classification::SHADER |
mx::ShaderNode::Classification::SURFACE);
#else
// Emit function calls for "root" closure/shader nodes.
// These will internally emit function calls for any dependent closure nodes upstream.
for (mx::ShaderGraphOutputSocket* socket : mxGraph.getOutputSockets())
{
if (socket->getConnection())
{
const mx::ShaderNode* upstream = socket->getConnection()->getNode();
if (upstream->getParent() == &mxGraph &&
(upstream->hasClassification(mx::ShaderNode::Classification::CLOSURE) ||
upstream->hasClassification(mx::ShaderNode::Classification::SHADER)))
{
emitFunctionCall(*upstream, mxContext, mxStage);
}
}
}
#endif
}
else
{
Expand Down

0 comments on commit 6c7b639

Please sign in to comment.