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

T gamaj/update to materialx 1 38 5 #2528

Merged
merged 3 commits into from
Aug 5, 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
33 changes: 26 additions & 7 deletions lib/mayaUsd/render/MaterialXGenOgsXml/GlslFragmentGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,22 @@ ShaderPtr GlslFragmentGenerator::generate(

const bool lighting = requiresLighting(graph);

#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION == 38 && MATERIALX_BUILD_VERSION == 3
#if MX_COMBINED_VERSION == 13804
// 1.38.4 is the only version requiring "libraries" in the path
std::string libRoot = "libraries/";
#else
// No libRoot for other versions:
std::string libRoot;
#endif

#if MX_COMBINED_VERSION <= 13804
#define MX_EMIT_INCLUDE emitInclude
#else
std::string libRoot = "libraries/";
#define MX_EMIT_INCLUDE emitLibraryInclude
#endif

// Emit common math functions
emitInclude(libRoot + "stdlib/genglsl/lib/mx_math.glsl", context, pixelStage);
MX_EMIT_INCLUDE(libRoot + "stdlib/genglsl/lib/mx_math.glsl", context, pixelStage);
emitLineBreak(pixelStage);

int specularMethod = context.getOptions().hwSpecularEnvironmentMethod;
Expand All @@ -202,18 +210,18 @@ ShaderPtr GlslFragmentGenerator::generate(
emitLine("#define MX_NUM_FIS_SAMPLES 64", pixelStage, false);
}
emitLineBreak(pixelStage);
emitInclude(
MX_EMIT_INCLUDE(
libRoot + "pbrlib/genglsl/ogsxml/mx_lighting_maya_v3.glsl", context, pixelStage);
} else if (specularMethod == SPECULAR_ENVIRONMENT_PREFILTER) {
if (OgsXmlGenerator::useLightAPI() < 2) {
emitInclude(
MX_EMIT_INCLUDE(
libRoot + "pbrlib/genglsl/ogsxml/mx_lighting_maya_v1.glsl", context, pixelStage);
} else {
emitInclude(
MX_EMIT_INCLUDE(
libRoot + "pbrlib/genglsl/ogsxml/mx_lighting_maya_v2.glsl", context, pixelStage);
}
} else if (specularMethod == SPECULAR_ENVIRONMENT_NONE) {
emitInclude(
MX_EMIT_INCLUDE(
libRoot + "pbrlib/genglsl/ogsxml/mx_lighting_maya_none.glsl", context, pixelStage);
} else {
throw ExceptionShaderGenError(
Expand All @@ -222,11 +230,22 @@ ShaderPtr GlslFragmentGenerator::generate(
}
emitLineBreak(pixelStage);

#if MX_COMBINED_VERSION >= 13805
emitTransmissionRender(context, pixelStage);
#endif

// Set the include file to use for uv transformations,
// depending on the vertical flip flag.
#if MX_COMBINED_VERSION <= 13804
_tokenSubstitutions[ShaderGenerator::T_FILE_TRANSFORM_UV] = string(libRoot + "stdlib/genglsl")
+ (context.getOptions().fileTextureVerticalFlip ? "/lib/mx_transform_uv_vflip.glsl"
: "/lib/mx_transform_uv.glsl");
#else
_tokenSubstitutions[ShaderGenerator::T_FILE_TRANSFORM_UV]
= (context.getOptions().fileTextureVerticalFlip ? "mx_transform_uv_vflip.glsl"
: "mx_transform_uv.glsl");
_tokenSubstitutions[HW::T_REFRACTION_ENV] = MX_REFRACTION_SUBSTITUTION;
#endif

// Add all functions for node implementations
emitFunctionDefinitions(graph, context, pixelStage);
Expand Down
12 changes: 12 additions & 0 deletions lib/mayaUsd/render/MaterialXGenOgsXml/GlslFragmentGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@

MATERIALX_NAMESPACE_BEGIN

#if !defined(MATERIALX_NAMESPACE_BEGIN)
JGamache-autodesk marked this conversation as resolved.
Show resolved Hide resolved
// The above define was introduced in MaterialX 1.38.3. If it does not exist, we know we are on an
// earlier 1.38 MaterialX version that can use the same code we use for 1.38.3
#define MX_COMBINED_VERSION 13803
#else
#define MX_COMBINED_VERSION \
((MATERIALX_MAJOR_VERSION * 100 * 100) + (MATERIALX_MINOR_VERSION * 100) \
+ MATERIALX_BUILD_VERSION)
#endif

#define MX_REFRACTION_SUBSTITUTION "(mayaGetSpecularEnvironmentNumLOD() > 0)"

namespace Stage {
/// A special stage for private uniform definitions that are not included
/// in the GLSL fragment but need to be known to the GLSL-to-HLSL
Expand Down
8 changes: 8 additions & 0 deletions lib/mayaUsd/render/MaterialXGenOgsXml/OgsFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ class GlslGeneratorWrapperBase
}
}

#if MX_COMBINED_VERSION >= 13805
// MaterialX has a new implementation of transmission as refraction in version 1.38.5, but
// does not work out of the box in Maya (probably because we only output a color).
// We will deactivate until we have time to upgrade the MaterialX output to a Maya surface
// struct where we can expose transmission values.
genOptions.hwTransmissionRenderMethod = mx::TRANSMISSION_OPACITY;
#endif

// Set to use no direct lighting
if (mx::OgsXmlGenerator::useLightAPI() >= 2) {
genOptions.hwMaxActiveLightSources = 0;
Expand Down
4 changes: 3 additions & 1 deletion lib/mayaUsd/render/MaterialXGenOgsXml/OgsXmlGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const pugi::char_t* DIFFUSEI("diffuseI");
const pugi::char_t* ENVMATRIX("u_envMatrix");
const pugi::char_t* ENVRADIANCEMIPS("u_envRadianceMips");
const pugi::char_t* ENVRADIANCESAMPLES("u_envRadianceSamples");
const pugi::char_t* ENVREFRACTION(MX_REFRACTION_SUBSTITUTION);
const pugi::char_t* FEATURE_LEVEL("feature_level");
const pugi::char_t* FLAGS("flags");
const pugi::char_t* FRAGMENT("fragment");
Expand Down Expand Up @@ -141,7 +142,8 @@ const pugi::char_t* VERSION("version");
// here:
bool isUnusedUniform(const std::string& name)
{
return name == ENVMATRIX || name == ENVRADIANCEMIPS || name == ENVRADIANCESAMPLES;
return name == ENVMATRIX || name == ENVRADIANCEMIPS || name == ENVRADIANCESAMPLES
|| name == ENVREFRACTION;
}

std::string DOT_COMBINE(const pugi::char_t* frag, const pugi::char_t* attr)
Expand Down