Skip to content

Commit

Permalink
Improvements to color space handling
Browse files Browse the repository at this point in the history
- Add support for 'none' as a colorspace attribute, specifying that the given color should not be transformed.
- Add support for colorspace attributes on multi-output nodes (e.g. UsdUvTexture), which only affect color-typed outputs.
- Update the 'usd_normal_map.mtlx' and 'usd_uv_texture.mtlx' examples to demonstrate these new capabilities.
- Remove legacy references to colorspace 'none' for physical colors, as it's more accurate in practice to interpret these values as visible colors.
  • Loading branch information
jstone-lucasfilm committed Jun 23, 2024
1 parent 537aa92 commit b26f19e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 89 deletions.
4 changes: 2 additions & 2 deletions documents/Specification/MaterialX.PBRSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ The PBS nodes also make use of the following standard MaterialX types:


* `weight` (float): Weight for this BSDF’s contribution, range [0.0, 1.0]. Defaults to 1.0.
* `ior `(color3): Index of refraction. Default is (0.18, 0.42, 1.37) with colorspace "none" (approximate IOR for gold).
* `extinction` (color3): Extinction coefficient. Default is (3.42, 2.35, 1.77) with colorspace "none" (approximate extinction coefficients for gold).
* `ior `(color3): Index of refraction. Default is (0.18, 0.42, 1.37) (approximate IOR for gold).
* `extinction` (color3): Extinction coefficient. Default is (3.42, 2.35, 1.77) (approximate extinction coefficients for gold).
* `roughness` (vector2): Surface roughness. Defaults to (0.05, 0.05).
* `thinfilm_thickness` (float): The thickness of an iridescent thin film layer applied over the base bsdf, expressed in nanometers. Defaults to 0.0, for no thin film.
* `thinfilm_ior` (float): The index of refraction of the thin film layer. Defaults to 1.5.
Expand Down
4 changes: 2 additions & 2 deletions libraries/pbrlib/pbrlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
-->
<nodedef name="ND_conductor_bsdf" node="conductor_bsdf" bsdf="R" nodegroup="pbr" doc="A reflection BSDF node based on a microfacet model and a Fresnel curve for conductors/metals.">
<input name="weight" type="float" value="1.0" uimin="0.0" uimax="1.0" />
<input name="ior" type="color3" value="0.183, 0.421, 1.373" colorspace="none" />
<input name="extinction" type="color3" value="3.424, 2.346, 1.770" colorspace="none" />
<input name="ior" type="color3" value="0.183, 0.421, 1.373" />
<input name="extinction" type="color3" value="3.424, 2.346, 1.770" />
<input name="roughness" type="vector2" value="0.05, 0.05" />
<input name="thinfilm_thickness" type="float" value="0" unittype="distance" unit="nanometer" />
<input name="thinfilm_ior" type="float" value="1.5" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
<?xml version="1.0"?>
<materialx version="1.39" colorspace="lin_rec709">
<nodegraph name="NG_usd_normal_map">
<tiledimage name="N_tiledimage" type="vector3" nodedef="ND_tiledimage_vector3">
<input name="file" type="filename" value="resources/Images/mesh_wire_norm.png" />
<input name="uvtiling" type="vector2" value="8.0, 8.0" />
</tiledimage>
<normalmap name="N_normalmap" type="vector3" nodedef="ND_normalmap_float">
<input name="in" type="vector3" nodename="N_tiledimage" />
<input name="space" type="string" value="object" />
</normalmap>
<output name="out" type="vector3" nodename="N_normalmap" />
</nodegraph>
<texcoord name="N_texcoord" type="vector2" />
<multiply name="N_multiply" type="vector2">
<input name="in1" type="vector2" nodename="N_texcoord" />
<input name="in2" type="vector2" value="8, 8" />
</multiply>
<UsdUVTexture name="N_texture_normal" type="multioutput">
<input name="file" type="filename" value="resources/Images/mesh_wire_norm.png" colorspace="none" />
<input name="st" type="vector2" nodename="N_multiply" />
</UsdUVTexture>
<convert name="N_convert" type="vector3">
<input name="in" type="color3" nodename="N_texture_normal" output="rgb" />
</convert>
<normalmap name="N_normalmap" type="vector3">
<input name="in" type="vector3" nodename="N_convert" />
<input name="space" type="string" value="object" />
</normalmap>
<UsdPreviewSurface name="N_surface" type="surfaceshader">
<input name="normal" type="vector3" output="out" nodegraph="NG_usd_normal_map" />
<input name="normal" type="vector3" nodename="N_normalmap" />
<input name="diffuseColor" type="color3" value="1, 1, 1" />
<input name="metallic" type="float" value="1" />
<input name="roughness" type="float" value="0.001" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,17 @@
<?xml version="1.0"?>
<materialx version="1.39">

<!-- UsdUVTexture: version 2.2 test -->
<UsdUVTexture name="UsdUVTexture22" type="multioutput" version="2.2">
<UsdUVTexture name="texture_base_color" type="multioutput">
<input name="file" type="filename" value="resources/Images/brass_color.jpg" colorspace="srgb_texture" />
</UsdUVTexture>
<convert name="extractColor" type="color3">
<input name="in" type="color4" nodename="UsdUVTexture22" output="rgba" />
</convert>
<UsdUVTexture name="UsdUVTexture22_rough" type="multioutput" version="2.2">
<UsdUVTexture name="texture_roughness" type="multioutput">
<input name="file" type="filename" value="resources/Images/brass_roughness.jpg" />
</UsdUVTexture>
<extract name="extractRoughness" type="float">
<input name="in" type="color4" nodename="UsdUVTexture22_rough" output="rgba" />
<input name="index" type="integer" value="0" />
</extract>

<UsdPreviewSurface name="UsdPreviewSurface22" type="surfaceshader" nodedef="ND_UsdPreviewSurface_surfaceshader" version="2.3">
<input name="diffuseColor" type="color3" nodename="extractColor" />
<input name="roughness" type="float" nodename="extractRoughness" />
<UsdPreviewSurface name="UsdPreviewSurface" type="surfaceshader" nodedef="ND_UsdPreviewSurface_surfaceshader">
<input name="diffuseColor" type="color3" nodename="texture_base_color" output="rgb" />
<input name="roughness" type="float" nodename="texture_roughness" output="r" />
<input name="metallic" type="float" value="1" />
</UsdPreviewSurface>
<surfacematerial name="USDTexture_Tiled_Brass22" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="UsdPreviewSurface22" />
<surfacematerial name="TiledBrass" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="UsdPreviewSurface" />
</surfacematerial>

<!-- UsdUVTexture: version 2.3 test. Default is currently 2.3 so no version specifier required -->
<UsdUVTexture name="UsdUVTexture23_rough" type="multioutput">
<input name="file" type="filename" value="resources/Images/brass_roughness.jpg" />
</UsdUVTexture>
<UsdUVTexture name="UsdUVTexture23" type="multioutput">
<input name="file" type="filename" value="resources/Images/brass_color.jpg" colorspace="srgb_texture" />
</UsdUVTexture>

<UsdPreviewSurface name="UsdPreviewSurface23" type="surfaceshader" nodedef="ND_UsdPreviewSurface_surfaceshader" version="2.3">
<input name="diffuseColor" type="color3" nodename="UsdUVTexture23" output="rgb" />
<input name="roughness" type="float" nodename="UsdUVTexture23_rough" output="r" />
<input name="metallic" type="float" value="1" />
</UsdPreviewSurface>
<surfacematerial name="USDTexture_Tiled_Brass23" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="UsdPreviewSurface23" />
</surfacematerial>

</materialx>

This file was deleted.

16 changes: 10 additions & 6 deletions source/MaterialXGenShader/ShaderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,14 @@ void ShaderGraph::applyInputTransforms(ConstNodePtr node, ShaderNodePtr shaderNo
if (input->hasValue() || input->hasInterfaceName())
{
string sourceColorSpace = input->getActiveColorSpace();
if (input->getType() == FILENAME_TYPE_STRING && node->isColorType())
if (input->getType() == FILENAME_TYPE_STRING && (node->isColorType() || node->isMultiOutputType()))
{
// Adjust the source color space for filename interface names.
if (input->hasInterfaceName())
{
for (ConstNodePtr parentNode : context.getParentNodes())
{
if (!parentNode->isColorType())
if (!parentNode->isColorType() && !parentNode->isMultiOutputType())
{
InputPtr interfaceInput = parentNode->getInput(input->getInterfaceName());
string interfaceColorSpace = interfaceInput ? interfaceInput->getActiveColorSpace() : EMPTY_STRING;
Expand All @@ -652,9 +652,11 @@ void ShaderGraph::applyInputTransforms(ConstNodePtr node, ShaderNodePtr shaderNo
}
}

ShaderOutput* shaderOutput = shaderNode->getOutput();
populateColorTransformMap(colorManagementSystem, shaderOutput, sourceColorSpace, targetColorSpace, false);
populateUnitTransformMap(unitSystem, shaderOutput, input, targetDistanceUnit, false);
for (ShaderOutput* shaderOutput : shaderNode->getOutputs())
{
populateColorTransformMap(colorManagementSystem, shaderOutput, sourceColorSpace, targetColorSpace, false);
populateUnitTransformMap(unitSystem, shaderOutput, input, targetDistanceUnit, false);
}
}
else
{
Expand Down Expand Up @@ -1069,7 +1071,9 @@ void ShaderGraph::populateColorTransformMap(ColorManagementSystemPtr colorManage
if (!shaderPort ||
sourceColorSpace.empty() ||
targetColorSpace.empty() ||
sourceColorSpace == targetColorSpace)
sourceColorSpace == targetColorSpace ||
sourceColorSpace == "none" ||
targetColorSpace == "none")
{
return;
}
Expand Down

0 comments on commit b26f19e

Please sign in to comment.