Skip to content

Commit

Permalink
Merge branch 'main' into fix-swizzle-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jstone-lucasfilm authored Aug 3, 2024
2 parents 51bf7bd + e98d05f commit 8633690
Show file tree
Hide file tree
Showing 17 changed files with 545 additions and 276 deletions.
19 changes: 16 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,23 @@ if (MATERIALX_BUILD_USE_CCACHE)
endif()
endif()

# Attempt to configure OSL testing if it can be found by cmake.
# This will not override any explicitly provided oslc and testrender
if(MATERIALX_BUILD_RENDER AND MATERIALX_BUILD_GEN_OSL AND MATERIALX_BUILD_TESTS)
# We currently only need the actual OSL binaries if we're running tests with Render and GenOSL enabled.
find_package(OSL QUIET)
if(OSL_FOUND)
if(NOT MATERIALX_OSL_BINARY_OSLC)
set(MATERIALX_OSL_BINARY_OSLC $<TARGET_FILE:OSL::oslc>)
endif()
if(NOT MATERIALX_OSL_BINARY_TESTRENDER)
# currently OSL does not export a cmake target for testrender, but once that's added this can be simplified.
set(MATERIALX_OSL_BINARY_TESTRENDER $<TARGET_FILE_DIR:OSL::oslc>/testrender)
endif()
endif()
endif()

# Add global definitions
add_definitions(-DMATERIALX_OSL_BINARY_OSLC=\"${MATERIALX_OSL_BINARY_OSLC}\")
add_definitions(-DMATERIALX_OSL_BINARY_TESTRENDER=\"${MATERIALX_OSL_BINARY_TESTRENDER}\")
add_definitions(-DMATERIALX_OSL_INCLUDE_PATH=\"${MATERIALX_OSL_INCLUDE_PATH}\")
if (MATERIALX_OSL_LEGACY_CLOSURES)
add_definitions(-DMATERIALX_OSL_LEGACY_CLOSURES)
endif()
Expand Down
2 changes: 2 additions & 0 deletions documents/Specification/MaterialX.PBRSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ This document describes a number of shader-semantic nodes implementing widely-us
**[Shading Model Examples](#shading-model-examples)**
[Autodesk Standard Surface](#autodesk-standard-surface)
[UsdPreviewSurface](#usdpreviewsurface)
[Khronos glTF PBR](#khronos-gltf-pbr)
[OpenPBR Surface](#openpbr-surface)

**[References](#references)**

Expand Down
331 changes: 331 additions & 0 deletions documents/Specification/MaterialX.Proposals.md

Large diffs are not rendered by default.

245 changes: 4 additions & 241 deletions documents/Specification/MaterialX.Specification.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions documents/Specification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The documents in this folder comprise the complete MaterialX Specification, vers
* [**MaterialX NPR Shading Nodes**](./MaterialX.NPRSpec.md) - specifies shading nodes that are designed for use in non-photorealistic and stylized rendering
* [**MaterialX Geometry Extensions**](./MaterialX.GeomExts.md) - additional MaterialX elements to define geometry-related information such as collections, properties and material assignments
* [**MaterialX Supplemental Notes**](./MaterialX.Supplement.md) - describes recommended naming and structuring conventions for libraries of custom node definitions
* [**MaterialX: Proposed Additions and Changes**](./MaterialX.Proposals.md) - describes proposed future updates to various components of the Specification

<p>

Expand Down
4 changes: 2 additions & 2 deletions libraries/bxdf/open_pbr_surface.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
doc="Index of refraction of the dielectric base." />
<input name="specular_roughness_anisotropy" type="float" value="0.0" uimin="0.0" uimax="1.0" uiname="Specular Anisotropy" uifolder="Specular" uiadvanced="true"
doc="The directional bias of the roughness of the metal/dielectric base, resulting in increasingly stretched highlights along the tangent direction." />
<input name="transmission_weight" type="float" value="0.0" uimin="0.0" uimax="1.0" uiname="Transmission Weight" uifolder="Transmission" uiadvanced="true"
<input name="transmission_weight" type="float" value="0.0" uimin="0.0" uimax="1.0" uiname="Transmission Weight" uifolder="Transmission" uiadvanced="true" hint="transparency"
doc="Mixture weight between the transparent and opaque dielectric base. The greater the value the more transparent the material." />
<input name="transmission_color" type="color3" value="1, 1, 1" uimin="0,0,0" uimax="1,1,1" uiname="Transmission Color" uifolder="Transmission" uiadvanced="true"
doc="Controls color of the transparent base due to Beer's law volumetric absorption under the surface (reverts to a non-physical tint when transmission_depth is zero)." />
Expand Down Expand Up @@ -75,7 +75,7 @@
doc="The amount of emitted light, as a luminance in nits." />
<input name="emission_color" type="color3" value="1, 1, 1" uimin="0,0,0" uimax="1,1,1" uiname="Emission Color" uifolder="Emission"
doc="The color of the emitted light." />
<input name="geometry_opacity" type="float" value="1" uimin="0" uimax="1" uiname="Opacity" uifolder="Geometry"
<input name="geometry_opacity" type="float" value="1" uimin="0" uimax="1" uiname="Opacity" uifolder="Geometry" hint="opacity"
doc="The opacity of the entire material." />
<input name="geometry_thin_walled" type="boolean" value="false" uiname="Thin Walled" uifolder="Geometry" uiadvanced="true"
doc="If true the surface is double-sided and represents an infinitesimally thin shell. Suitable for extremely geometrically thin objects such as leaves or paper." />
Expand Down
106 changes: 92 additions & 14 deletions libraries/bxdf/translation/open_pbr_to_standard_surface.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
<output name="coat_roughness_out" type="float" />
<output name="coat_anisotropy_out" type="float" />
<output name="coat_IOR_out" type="float" />
<output name="coat_affect_color_out" type="float" />
<output name="coat_affect_roughness_out" type="float" />

<output name="thin_film_thickness_out" type="float" />
Expand All @@ -96,19 +95,101 @@

<nodegraph name="NG_open_pbr_surface_to_standard_surface" nodedef="ND_open_pbr_surface_to_standard_surface">

<!-- Coat Darkening -->
<subtract name="coat_ior_minus_one" type="float">
<input name="in1" type="float" interfacename="coat_ior" />
<input name="in2" type="float" value="1.0" />
</subtract>
<add name="coat_ior_plus_one" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in2" type="float" interfacename="coat_ior" />
</add>
<divide name="coat_ior_to_F0_sqrt" type="float">
<input name="in1" type="float" nodename="coat_ior_minus_one" />
<input name="in2" type="float" nodename="coat_ior_plus_one" />
</divide>
<multiply name="coat_ior_to_F0" type="float">
<input name="in1" type="float" nodename="coat_ior_to_F0_sqrt" />
<input name="in2" type="float" nodename="coat_ior_to_F0_sqrt" />
</multiply>
<!-- approximate Kcoat, "internal diffuse reflection coefficient" of coat -->
<subtract name="one_minus_coat_F0" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in2" type="float" nodename="coat_ior_to_F0" />
</subtract>
<multiply name="coat_ior_sqr" type="float">
<input name="in1" type="float" interfacename="coat_ior" />
<input name="in2" type="float" interfacename="coat_ior" />
</multiply>
<divide name="one_minus_coat_F0_over_eta2" type="float">
<input name="in1" type="float" nodename="one_minus_coat_F0" />
<input name="in2" type="float" nodename="coat_ior_sqr" />
</divide>
<subtract name="Kcoat" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in2" type="float" nodename="one_minus_coat_F0_over_eta2" />
</subtract>
<!-- approximate base metal albedo estimate, Emetal -->
<multiply name="Emetal" type="color3">
<input name="in1" type="color3" interfacename="base_color" />
<input name="in2" type="float" interfacename="specular_weight" />
</multiply>
<!-- approximate base dielectric albedo estimate, Edielectric -->
<mix name="Edielectric" type="color3">
<input name="fg" type="color3" interfacename="subsurface_color" />
<input name="bg" type="color3" interfacename="base_color" />
<input name="mix" type="float" interfacename="subsurface_weight" />
</mix>
<!-- thus calculate overall base albedo estimate approximation, Ebase -->
<mix name="Ebase" type="color3">
<input name="fg" type="color3" nodename="Emetal" />
<input name="bg" type="color3" nodename="Edielectric" />
<input name="mix" type="float" interfacename="base_metalness" />
</mix>
<!-- final base darkening factor due to coat: base_darkening = (1 - Kcoat) / (1 - Ebase*Kcoat) -->
<multiply name="Ebase_Kcoat" type="color3">
<input name="in1" type="color3" nodename="Ebase" />
<input name="in2" type="float" nodename="Kcoat" />
</multiply>
<subtract name="one_minus_Kcoat" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in2" type="float" nodename="Kcoat" />
</subtract>
<subtract name="one_minus_Ebase_Kcoat" type="color3">
<input name="in1" type="color3" value="1.0, 1.0, 1.0" />
<input name="in2" type="color3" nodename="Ebase_Kcoat" />
</subtract>
<convert name="one_minus_Kcoat_color" type="color3">
<input name="in" type="float" nodename="one_minus_Kcoat" />
</convert>
<divide name="base_darkening" type="color3">
<input name="in1" type="color3" nodename="one_minus_Kcoat_color" />
<input name="in2" type="color3" nodename="one_minus_Ebase_Kcoat" />
</divide>
<multiply name="coat_weight_times_coat_darkening" type="float">
<input name="in1" type="float" interfacename="coat_weight" />
<input name="in2" type="float" interfacename="coat_darkening" />
</multiply>
<mix name="modulated_base_darkening" type="color3">
<input name="fg" type="color3" nodename="base_darkening" />
<input name="bg" type="color3" value="1.0, 1.0, 1.0" />
<input name="mix" type="float" nodename="coat_weight_times_coat_darkening" />
</mix>

<!--Base-->
<dot name="base" type="float">
<input name="in" type="float" interfacename="base_weight" />
</dot>
<dot name="baseColor" type="color3">
<input name="in" type="color3" interfacename="base_color" />
</dot>
<dot name="diffuseRoughness" type="float">
<input name="in" type="float" interfacename="base_diffuse_roughness" />
</dot>
<dot name="metalness" type="float">
<input name="in" type="float" interfacename="base_metalness" />
</dot>
<multiply name="baseColor" type="color3">
<input name="in1" type="color3" interfacename="base_color" />
<input name="in2" type="color3" nodename="modulated_base_darkening" />
</multiply>

<!--Specular-->
<dot name="spec" type="float">
Expand Down Expand Up @@ -154,9 +235,10 @@
<dot name="subsurface" type="float">
<input name="in" type="float" interfacename="subsurface_weight" />
</dot>
<dot name="subsurfaceColor" type="color3">
<input name="in" type="color3" interfacename="subsurface_color" />
</dot>
<multiply name="subsurfaceColor" type="color3">
<input name="in1" type="color3" interfacename="subsurface_color" />
<input name="in2" type="color3" nodename="modulated_base_darkening" />
</multiply>
<dot name="subsurfaceScale" type="float">
<input name="in" type="float" interfacename="subsurface_radius" />
</dot>
Expand Down Expand Up @@ -195,12 +277,9 @@
<dot name="coatIOR" type="float">
<input name="in" type="float" interfacename="coat_ior" />
</dot>
<dot name="coatAffectColor" type="float">
<input name="in" type="float" interfacename="coat_darkening" />
</dot>
<dot name="coatAffectRoughness" type="float">
<input name="in" type="float" interfacename="coat_darkening" />
</dot>
<constant name="coatAffectRoughness" type="float">
<input name="value" type="float" value="1.0" />
</constant>

<!--ThinFilm-->
<multiply name="thinFilmThicknessConversion" type="float">
Expand Down Expand Up @@ -267,7 +346,6 @@
<output name="coat_roughness_out" type="float" nodename="coatRoughness" />
<output name="coat_anisotropy_out" type="float" nodename="coatAnisotropy" />
<output name="coat_IOR_out" type="float" nodename="coatIOR" />
<output name="coat_affect_color_out" type="float" nodename="coatAffectColor" />
<output name="coat_affect_roughness_out" type="float" nodename="coatAffectRoughness" />

<output name="thin_film_thickness_out" type="float" nodename="thinFilmThickness" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<materialx version="1.39" colorspace="lin_rec709">
<surfacematerial name="geom_hint" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="geometric_opacity_hint" />
</surfacematerial>
<open_pbr_surface name="geometric_opacity_hint" type="surfaceshader">
<input name="geometry_opacity" type="float" value="0.5" />
</open_pbr_surface>
<surfacematerial name="transp_hint" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="transparency_weight_hint" />
</surfacematerial>
<open_pbr_surface name="transparency_weight_hint" type="surfaceshader">
<input name="transmission_weight" type="float" value="0.8" />
</open_pbr_surface>
</materialx>
13 changes: 13 additions & 0 deletions source/MaterialXCore/Definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ InterfaceElementPtr NodeDef::getImplementation(const string& target) const
return InterfaceElementPtr();
}

const StringMap NodeDef::getInputHints() const
{
StringMap hints;
for (InputPtr input : getActiveInputs())
{
if (input->hasHint())
{
hints[input->getName()] = input->getHint();
}
}
return hints;
}

bool NodeDef::validate(string* message) const
{
bool res = true;
Expand Down
7 changes: 7 additions & 0 deletions source/MaterialXCore/Definition.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ class MX_CORE_API NodeDef : public InterfaceElement
/// an Implementation element or a NodeGraph element.
InterfaceElementPtr getImplementation(const string& target = EMPTY_STRING) const;

/// @}
/// @name Hints
/// @{

/// Return list of input hint pairs of the form { input_name, hint_string }
const StringMap getInputHints() const;

/// @}
/// @name Validation
/// @{
Expand Down
4 changes: 4 additions & 0 deletions source/MaterialXCore/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const string InterfaceElement::TARGET_ATTRIBUTE = "target";
const string InterfaceElement::VERSION_ATTRIBUTE = "version";
const string InterfaceElement::DEFAULT_VERSION_ATTRIBUTE = "isdefaultversion";
const string Input::DEFAULT_GEOM_PROP_ATTRIBUTE = "defaultgeomprop";
const string Input::HINT_ATTRIBUTE = "hint";
const string Input::TRANSPARENCY_HINT = "transparency";
const string Input::OPACITY_HINT = "opacity";
const string Input::ANISOTROPY_HINT = "anisotropy";
const string Output::DEFAULT_INPUT_ATTRIBUTE = "defaultinput";

//
Expand Down
26 changes: 26 additions & 0 deletions source/MaterialXCore/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ class MX_CORE_API Input : public PortElement
/// for this input.
InputPtr getInterfaceInput() const;

/// @}
/// @name Hints
/// @{

/// Return true if the input has a hint
bool hasHint() const
{
return hasAttribute(HINT_ATTRIBUTE);
}

/// Return the code generation hint
const string& getHint() const
{
return getAttribute(HINT_ATTRIBUTE);
}

// Set the code generation hint
void setHint(const string& hint)
{
setAttribute(HINT_ATTRIBUTE, hint);
}

/// @}
/// @name Validation
/// @{
Expand All @@ -232,6 +254,10 @@ class MX_CORE_API Input : public PortElement
public:
static const string CATEGORY;
static const string DEFAULT_GEOM_PROP_ATTRIBUTE;
static const string HINT_ATTRIBUTE;
static const string TRANSPARENCY_HINT;
static const string OPACITY_HINT;
static const string ANISOTROPY_HINT;
};

/// @class Output
Expand Down
29 changes: 23 additions & 6 deletions source/MaterialXGenShader/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ using OpaqueTestPair = std::pair<string, float>;
using OpaqueTestPairList = vector<OpaqueTestPair>;

// Inputs on a surface shader which are checked for transparency
const OpaqueTestPairList inputPairList = { { "opacity", 1.0f },
{ "existence", 1.0f },
{ "alpha", 1.0f },
{ "transmission", 0.0f } };
const OpaqueTestPairList DEFAULT_INPUT_PAIR_LIST = { { "opacity", 1.0f },
{ "existence", 1.0f },
{ "alpha", 1.0f },
{ "transmission", 0.0f } };

const string MIX_CATEGORY("mix");
const string MIX_FG_INPUT("fg");
Expand Down Expand Up @@ -116,6 +116,23 @@ bool isTransparentShaderNode(NodePtr node, NodePtr interfaceNode)
return false;
}

// Check against nodedef input hints
OpaqueTestPairList inputPairList = DEFAULT_INPUT_PAIR_LIST;
NodeDefPtr nodeDef = node->getNodeDef();
StringMap nodeDefList = nodeDef ? nodeDef->getInputHints() : StringMap();
for (auto &item : nodeDefList)
{
string inputName = item.first;
if (item.second == Input::TRANSPARENCY_HINT)
{
inputPairList.push_back(std::make_pair(inputName, 0.0f) );
}
else if (item.second == Input::OPACITY_HINT)
{
inputPairList.push_back(std::make_pair(inputName, 1.0f));
}
}

// Check against the interface if a node is passed in to check against
OpaqueTestPairList interfaceNames;
if (interfaceNode)
Expand Down Expand Up @@ -167,8 +184,8 @@ bool isTransparentShaderNode(NodePtr node, NodePtr interfaceNode)
NodePtr inputNode = checkInput->getConnectedNode();
if (inputNode)
{
NodeDefPtr nodeDef = inputNode->getNodeDef();
string nodeGroup = nodeDef ? nodeDef->getAttribute(NodeDef::NODE_GROUP_ATTRIBUTE) : EMPTY_STRING;
NodeDefPtr inputNodeDef = inputNode->getNodeDef();
string nodeGroup = inputNodeDef ? inputNodeDef->getAttribute(NodeDef::NODE_GROUP_ATTRIBUTE) : EMPTY_STRING;
if (nodeGroup != NodeDef::ADJUSTMENT_NODE_GROUP &&
nodeGroup != NodeDef::CHANNEL_NODE_GROUP)
{
Expand Down
Loading

0 comments on commit 8633690

Please sign in to comment.