Skip to content

Commit

Permalink
Add support for MDL 1.10 (#2214)
Browse files Browse the repository at this point in the history
Update the MDL code generator to make use of MDL 1.10 features that. This includes:
- taking the color82 of the generalized Schlick BSDF into account
- implement the Zeltner mode for the Sheen BSDF
- add energy conservation to the Oren-Nayar diffuse BSDF
  • Loading branch information
krohmerNV authored Feb 13, 2025
1 parent ce08d4f commit 7fc041d
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 14 deletions.
2 changes: 1 addition & 1 deletion libraries/pbrlib/genmdl/pbrlib_genmdl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<implementation name="IM_subsurface_bsdf_genmdl" nodedef="ND_subsurface_bsdf" sourcecode="materialx::pbrlib_{{MDL_VERSION_SUFFIX}}::mx_subsurface_bsdf(mxp_weight:{{weight}}, mxp_color:{{color}}, mxp_radius:{{radius}}, mxp_anisotropy:{{anisotropy}}, mxp_normal:{{normal}})" target="genmdl" />

<!-- <sheen_bsdf> -->
<implementation name="IM_sheen_bsdf_genmdl" nodedef="ND_sheen_bsdf" sourcecode="materialx::pbrlib_{{MDL_VERSION_SUFFIX}}::mx_sheen_bsdf(mxp_weight:{{weight}}, mxp_color:{{color}}, mxp_roughness:{{roughness}}, mxp_normal:{{normal}}, mxp_base:{{base}})" target="genmdl" />
<implementation name="IM_sheen_bsdf_genmdl" nodedef="ND_sheen_bsdf" sourcecode="materialx::pbrlib_{{MDL_VERSION_SUFFIX}}::mx_sheen_bsdf(mxp_weight:{{weight}}, mxp_color:{{color}}, mxp_roughness:{{roughness}}, mxp_normal:{{normal}}, mxp_mode:{{mode}}, mxp_base:{{base}})" target="genmdl" />

<!-- <chiang_hair_bsdf> -->
<implementation name="IM_chiang_hair_bsdf_genmdl" nodedef="ND_chiang_hair_bsdf" sourcecode="materialx::pbrlib_{{MDL_VERSION_SUFFIX}}::mx_chiang_hair_bsdf(mxp_tint_R:{{tint_R}}, mxp_tint_TT:{{tint_TT}}, mxp_tint_TRT:{{tint_TRT}}, mxp_ior:{{ior}}, mxp_roughness_R:{{roughness_R}}, mxp_roughness_TT:{{roughness_TT}}, mxp_roughness_TRT:{{roughness_TRT}}, mxp_cuticle_angle:{{cuticle_angle}}, mxp_absorption_coefficient:{{absorption_coefficient}}, mxp_curve_direction:{{curve_direction}})" target="genmdl" />
Expand Down
30 changes: 30 additions & 0 deletions resources/Materials/TestSuite/pbrlib/bsdf/sheen_bsdf.mtlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<materialx version="1.39">
<nodegraph name="conty_kulla_sheen">
<sheen_bsdf name="conty_kulla_sheen_bsdf1" type="BSDF">
<input name="weight" type="float" value="1.0" />
<input name="color" type="color3" value="0.516, 0.524, 0.778" />
<input name="roughness" type="float" value="0.3" />
<input name="mode" type="string" value="conty_kulla" />
</sheen_bsdf>
<surface name="surface1" type="surfaceshader">
<input name="bsdf" type="BSDF" nodename="conty_kulla_sheen_bsdf1" />
<input name="opacity" type="float" value="1.0" />
</surface>
<output name="out" type="surfaceshader" nodename="surface1" />
</nodegraph>

<nodegraph name="zeltner_sheen">
<sheen_bsdf name="zeltner_sheen_bsdf2" type="BSDF">
<input name="weight" type="float" value="1.0" />
<input name="color" type="color3" value="0.516, 0.524, 0.778" />
<input name="roughness" type="float" value="0.3" />
<input name="mode" type="string" value="zeltner" />
</sheen_bsdf>
<surface name="surface2" type="surfaceshader">
<input name="bsdf" type="BSDF" nodename="zeltner_sheen_bsdf2" />
<input name="opacity" type="float" value="1.0" />
</surface>
<output name="out" type="surfaceshader" nodename="surface2" />
</nodegraph>
</materialx>
17 changes: 13 additions & 4 deletions source/MaterialXGenMdl/MdlShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ const string MDL_VERSION_1_6 = "1.6";
const string MDL_VERSION_1_7 = "1.7";
const string MDL_VERSION_1_8 = "1.8";
const string MDL_VERSION_1_9 = "1.9";
const string MDL_VERSION_1_10 = "1.10";
const string MDL_VERSION_SUFFIX_1_6 = "1_6";
const string MDL_VERSION_SUFFIX_1_7 = "1_7";
const string MDL_VERSION_SUFFIX_1_8 = "1_8";
const string MDL_VERSION_SUFFIX_1_9 = "1_9";
const string MDL_VERSION_SUFFIX_1_10 = "1_10";

} // anonymous namespace

Expand Down Expand Up @@ -281,6 +283,8 @@ ShaderPtr MdlShaderGenerator::generate(const string& name, ElementPtr element, G
finalOutput = "mk_color3(" + result + ".x, " + result + ".y, 0.0)";
else if (outputType == Type::VECTOR3)
finalOutput = "mk_color3(" + result + ")";
else if (outputType == Type::VECTOR4)
finalOutput = "mk_color3(" + result + ".x, " + result + ".y, " + result + ".z)";
else if (outputType == Type::COLOR3)
finalOutput = result;
else if (outputType == Type::COLOR4)
Expand Down Expand Up @@ -765,10 +769,13 @@ void MdlShaderGenerator::emitMdlVersionNumber(GenContext& context, ShaderStage&
case GenMdlOptions::MdlVersion::MDL_1_8:
emitString(MDL_VERSION_1_8, stage);
break;
case GenMdlOptions::MdlVersion::MDL_1_9:
emitString(MDL_VERSION_1_9, stage);
break;
default:
// GenMdlOptions::MdlVersion::MDL_1_9
// GenMdlOptions::MdlVersion::MDL_1_10
// GenMdlOptions::MdlVersion::MDL_LATEST
emitString(MDL_VERSION_1_9, stage);
emitString(MDL_VERSION_1_10, stage);
break;
}
emitLineEnd(stage, true);
Expand All @@ -787,10 +794,12 @@ const string& MdlShaderGenerator::getMdlVersionFilenameSuffix(GenContext& contex
return MDL_VERSION_SUFFIX_1_7;
case GenMdlOptions::MdlVersion::MDL_1_8:
return MDL_VERSION_SUFFIX_1_8;
case GenMdlOptions::MdlVersion::MDL_1_9:
return MDL_VERSION_SUFFIX_1_9;
default:
// GenMdlOptions::MdlVersion::MDL_1_9
// GenMdlOptions::MdlVersion::MDL_1_10
// GenMdlOptions::MdlVersion::MDL_LATEST
return MDL_VERSION_SUFFIX_1_9;
return MDL_VERSION_SUFFIX_1_10;
}
}

Expand Down
3 changes: 2 additions & 1 deletion source/MaterialXGenMdl/MdlShaderGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class MX_GENMDL_API GenMdlOptions : public GenUserData
MDL_1_7,
MDL_1_8,
MDL_1_9,
MDL_LATEST = MDL_1_9
MDL_1_10,
MDL_LATEST = MDL_1_10
};

/// Create MDL code generator options with default values.
Expand Down
10 changes: 10 additions & 0 deletions source/MaterialXGenMdl/MdlSyntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ TYPEDESC_REGISTER_TYPE(MDL_FILTERLOOKUPMODE, "filterlookup")
TYPEDESC_REGISTER_TYPE(MDL_FILTERTYPE, "filtertype")
TYPEDESC_REGISTER_TYPE(MDL_DISTRIBUTIONTYPE, "distributiontype")
TYPEDESC_REGISTER_TYPE(MDL_SCATTER_MODE, "scatter_mode")
TYPEDESC_REGISTER_TYPE(MDL_SHEEN_MODE, "mode")

} // namespace Type

Expand Down Expand Up @@ -196,6 +197,7 @@ const StringVec MdlSyntax::FILTERLOOKUPMODE_MEMBERS = { "closest", "linear", "cu
const StringVec MdlSyntax::FILTERTYPE_MEMBERS = { "box", "gaussian" };
const StringVec MdlSyntax::DISTRIBUTIONTYPE_MEMBERS = { "ggx" };
const StringVec MdlSyntax::SCATTER_MODE_MEMBERS = { "R", "T", "RT" };
const StringVec MdlSyntax::SHEEN_MODE_MEMBERS = { "conty_kulla", "zeltner" };

const string MdlSyntax::PORT_NAME_PREFIX = "mxp_";

Expand Down Expand Up @@ -453,6 +455,14 @@ MdlSyntax::MdlSyntax()
"mx_scatter_mode_R",
"mx_scatter_mode_R",
SCATTER_MODE_MEMBERS));

registerTypeSyntax(
Type::MDL_SHEEN_MODE,
std::make_shared<MdlEnumSyntax>(
"mx_sheen_mode",
"mx_sheen_mode_conty_kulla",
"mx_sheen_mode_conty_kulla",
SHEEN_MODE_MEMBERS));
}

TypeDesc MdlSyntax::getEnumeratedType(const string& value) const
Expand Down
2 changes: 2 additions & 0 deletions source/MaterialXGenMdl/MdlSyntax.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class MX_GENMDL_API MdlSyntax : public Syntax
static const StringVec FILTERTYPE_MEMBERS;
static const StringVec DISTRIBUTIONTYPE_MEMBERS;
static const StringVec SCATTER_MODE_MEMBERS;
static const StringVec SHEEN_MODE_MEMBERS;
static const string PORT_NAME_PREFIX; // Applied to input and output names to avoid collisions with reserved words in MDL

/// Get an type description for an enumeration based on member value
Expand Down Expand Up @@ -85,6 +86,7 @@ TYPEDESC_DEFINE_TYPE(MDL_FILTERLOOKUPMODE, "filterlookup", TypeDesc::BASETYPE_NO
TYPEDESC_DEFINE_TYPE(MDL_FILTERTYPE, "filtertype", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
TYPEDESC_DEFINE_TYPE(MDL_DISTRIBUTIONTYPE, "distributiontype", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
TYPEDESC_DEFINE_TYPE(MDL_SCATTER_MODE, "scatter_mode", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
TYPEDESC_DEFINE_TYPE(MDL_SHEEN_MODE, "mode", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)

} // namespace Type

Expand Down
8 changes: 4 additions & 4 deletions source/MaterialXGenMdl/mdl/materialx/pbrlib.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
// Document version 1.39, June 29, 2024
// see www.materialx.org
// in
// NVIDIA Material Definition Language 1.9
// NVIDIA Material Definition Language 1.10
// Language Specification
// Document version 1.9.2, September 16, 2024
// Document version 1.10.1, November 04, 2024
// www.nvidia.com/mdl

mdl 1.9;
mdl 1.10;

// forward the latest version
export using .::pbrlib_1_9 import *;
export using .::pbrlib_1_10 import *;
Loading

0 comments on commit 7fc041d

Please sign in to comment.