Skip to content

Commit

Permalink
rename interior nodes, remove translation unit test, and add translat…
Browse files Browse the repository at this point in the history
…ed mtl to render testsuite

Signed-off-by: Charlotte Manning <[email protected]>
  • Loading branch information
charo-m committed Sep 28, 2024
1 parent be8d624 commit 6d7ddd2
Show file tree
Hide file tree
Showing 3 changed files with 264 additions and 43 deletions.
12 changes: 6 additions & 6 deletions libraries/bxdf/translation/standard_surface_to_gltf_pbr.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</dotproduct>

<!-- Metallic roughness -->
<ifequal name="no_transmission_base_color" type="color3">
<ifequal name="noTransmissionBaseColor" type="color3">
<input name="value1" type="float" nodename="hasCoatColor" />
<input name="value2" type="float" value="0" />
<input name="in1" type="color3" nodename="scaledBaseColor" />
Expand All @@ -85,8 +85,8 @@
<ifgreater name="base_color" type="color3">
<input name="value1" type="float" interfacename="transmission" />
<input name="value2" type="float" value="0" />
<input name="in1" type="color3" nodename="transmission_in_effect_base_color" />
<input name="in2" type="color3" nodename="no_transmission_base_color" />
<input name="in1" type="color3" nodename="transmissionInEffectBaseColor" />
<input name="in2" type="color3" nodename="noTransmissionBaseColor" />
</ifgreater>
<dot name="metallic" type="float">
<input name="in" type="float" interfacename="metalness" />
Expand All @@ -102,7 +102,7 @@
<dot name="thickness" type="float">
<input name="in" type="float" interfacename="transmission_depth" />
</dot>
<ifgreater name="transmission_in_effect_attenuation_color" type="color3">
<ifgreater name="transmissionInEffectAttenuationColor" type="color3">
<input name="value1" type="float" interfacename="transmission_depth" />
<input name="value2" type="float" value="0" />
<input name="in1" type="color3" interfacename="transmission_color" />
Expand All @@ -111,10 +111,10 @@
<ifgreater name="attenuation_color" type="color3">
<input name="value1" type="float" interfacename="transmission" />
<input name="value2" type="float" value="0" />
<input name="in1" type="color3" nodename="transmission_in_effect_attenuation_color" />
<input name="in1" type="color3" nodename="transmissionInEffectAttenuationColor" />
<input name="in2" type="color3" value="1, 1, 1" />
</ifgreater>
<ifgreater name="transmission_in_effect_base_color" type="color3">
<ifgreater name="transmissionInEffectBaseColor" type="color3">
<input name="value1" type="float" interfacename="transmission_depth" />
<input name="value2" type="float" value="0" />
<input name="in1" type="color3" value="1, 1, 1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
<?xml version="1.0"?>
<materialx version="1.39" colorspace="lin_rec709" xmlns:xi="http://www.w3.org/2001/XInclude">
<extract name="N_extract_0" type="float">
<input name="in" type="color3" output="attenuation_color_out" nodegraph="nodegraph1" />
<input name="index" type="integer" value="0" />
</extract>
<extract name="N_extract_1" type="float">
<input name="in" type="color3" output="attenuation_color_out" nodegraph="nodegraph1" />
<input name="index" type="integer" value="1" />
</extract>
<extract name="N_extract_2" type="float">
<input name="in" type="color3" output="attenuation_color_out" nodegraph="nodegraph1" />
<input name="index" type="integer" value="2" />
</extract>
<combine3 name="combine" type="vector3">
<input name="in1" type="float" nodename="N_extract_0" output="" />
<input name="in2" type="float" nodename="N_extract_1" output="" />
<input name="in3" type="float" nodename="N_extract_2" output="" />
</combine3>
<ln name="ln_attenuation_color_vec" type="vector3">
<input name="in" type="vector3" nodename="combine" />
</ln>
<divide name="ln_attenuation_color_vec_over_distance" type="vector3">
<input name="in1" type="vector3" nodename="ln_attenuation_color_vec" />
<input name="in2" type="float" />
</divide>
<multiply name="attenuation_coeff" type="vector3">
<input name="in1" type="vector3" nodename="ln_attenuation_color_vec_over_distance" />
<input name="in2" type="float" value="-1" />
</multiply>
<anisotropic_vdf name="isotropic_volume" type="VDF">
<input name="absorption" type="vector3" nodename="attenuation_coeff" />
<input name="scattering" type="vector3" value="0, 0, 0" />
<input name="anisotropy" type="float" value="0" />
</anisotropic_vdf>
<subtract name="one_minus_ior" type="float">
<input name="in1" type="float" value="1" />
<input name="in2" type="float" value="1.5" />
</subtract>
<add name="one_plus_ior" type="float">
<input name="in1" type="float" value="1" />
<input name="in2" type="float" value="1.5" />
</add>
<divide name="ior_div" type="float">
<input name="in1" type="float" nodename="one_minus_ior" />
<input name="in2" type="float" nodename="one_plus_ior" />
</divide>
<multiply name="dielectric_f0_from_ior" type="float">
<input name="in1" type="float" nodename="ior_div" />
<input name="in2" type="float" nodename="ior_div" />
</multiply>
<multiply name="dielectric_f0_from_ior_specular_color" type="color3">
<input name="in1" type="color3" value="1, 1, 1" />
<input name="in2" type="float" nodename="dielectric_f0_from_ior" />
</multiply>
<min name="clamped_dielectric_f0_from_ior_specular_color" type="color3">
<input name="in1" type="color3" nodename="dielectric_f0_from_ior_specular_color" />
<input name="in2" type="float" value="1" />
</min>
<multiply name="dielectric_f0" type="color3">
<input name="in1" type="color3" nodename="clamped_dielectric_f0_from_ior_specular_color" />
<input name="in2" type="float" value="1" />
</multiply>
<multiply name="dielectric_f90" type="color3">
<input name="in1" type="color3" value="1, 1, 1" />
<input name="in2" type="float" value="1" />
</multiply>
<roughness_anisotropy name="roughness_uv" type="vector2">
<input name="roughness" type="float" output="roughness_out" nodegraph="nodegraph1" />
</roughness_anisotropy>
<oren_nayar_diffuse_bsdf name="diffuse_bsdf" type="BSDF">
<input name="color" type="color3" output="base_color_out" nodegraph="nodegraph1" />
<input name="normal" type="vector3" nodename="geomNode_Nworld" />
</oren_nayar_diffuse_bsdf>
<dielectric_bsdf name="transmission_bsdf" type="BSDF">
<input name="weight" type="float" value="1" />
<input name="tint" type="color3" output="base_color_out" nodegraph="nodegraph1" />
<input name="ior" type="float" value="1.5" />
<input name="roughness" type="vector2" nodename="roughness_uv" />
<input name="normal" type="vector3" nodename="geomNode_Nworld" />
<input name="tangent" type="vector3" nodename="geomNode_Tworld" />
<input name="scatter_mode" type="string" value="T" />
</dielectric_bsdf>
<generalized_schlick_bsdf name="reflection_bsdf" type="BSDF">
<input name="color0" type="color3" nodename="dielectric_f0" />
<input name="color90" type="color3" nodename="dielectric_f90" />
<input name="roughness" type="vector2" nodename="roughness_uv" />
<input name="normal" type="vector3" nodename="geomNode_Nworld" />
<input name="tangent" type="vector3" nodename="geomNode_Tworld" />
<input name="scatter_mode" type="string" value="R" />
</generalized_schlick_bsdf>
<mix name="transmission_mix" type="BSDF">
<input name="bg" type="BSDF" nodename="diffuse_bsdf" />
<input name="fg" type="BSDF" nodename="transmission_bsdf" />
<input name="mix" type="float" output="transmission_out" nodegraph="nodegraph1" />
</mix>
<layer name="dielectric_bsdf" type="BSDF">
<input name="top" type="BSDF" nodename="reflection_bsdf" />
<input name="base" type="BSDF" nodename="transmission_mix" />
</layer>
<generalized_schlick_bsdf name="tf_reflection_bsdf" type="BSDF">
<input name="color0" type="color3" nodename="dielectric_f0" />
<input name="color90" type="color3" nodename="dielectric_f90" />
<input name="roughness" type="vector2" nodename="roughness_uv" />
<input name="normal" type="vector3" nodename="geomNode_Nworld" />
<input name="tangent" type="vector3" nodename="geomNode_Tworld" />
<input name="scatter_mode" type="string" value="R" />
<input name="thinfilm_thickness" type="float" value="100" />
<input name="thinfilm_ior" type="float" value="1.3" />
</generalized_schlick_bsdf>
<layer name="tf_dielectric_bsdf" type="BSDF">
<input name="top" type="BSDF" nodename="tf_reflection_bsdf" />
<input name="base" type="BSDF" nodename="transmission_mix" />
</layer>
<mix name="mix_iridescent_dielectric_bsdf" type="BSDF">
<input name="bg" type="BSDF" nodename="dielectric_bsdf" />
<input name="fg" type="BSDF" nodename="tf_dielectric_bsdf" />
<input name="mix" type="float" value="0" />
</mix>
<generalized_schlick_bsdf name="metal_bsdf" type="BSDF">
<input name="color0" type="color3" output="base_color_out" nodegraph="nodegraph1" />
<input name="color90" type="color3" value="1, 1, 1" />
<input name="roughness" type="vector2" nodename="roughness_uv" />
<input name="normal" type="vector3" nodename="geomNode_Nworld" />
<input name="tangent" type="vector3" nodename="geomNode_Tworld" />
</generalized_schlick_bsdf>
<generalized_schlick_bsdf name="tf_metal_bsdf" type="BSDF">
<input name="color0" type="color3" output="base_color_out" nodegraph="nodegraph1" />
<input name="color90" type="color3" value="1, 1, 1" />
<input name="roughness" type="vector2" nodename="roughness_uv" />
<input name="normal" type="vector3" nodename="geomNode_Nworld" />
<input name="tangent" type="vector3" nodename="geomNode_Tworld" />
<input name="thinfilm_thickness" type="float" value="100" />
<input name="thinfilm_ior" type="float" value="1.3" />
</generalized_schlick_bsdf>
<mix name="mix_iridescent_metal_bsdf" type="BSDF">
<input name="bg" type="BSDF" nodename="metal_bsdf" />
<input name="fg" type="BSDF" nodename="tf_metal_bsdf" />
<input name="mix" type="float" value="0" />
</mix>
<mix name="base_mix" type="BSDF">
<input name="bg" type="BSDF" nodename="mix_iridescent_dielectric_bsdf" />
<input name="fg" type="BSDF" nodename="mix_iridescent_metal_bsdf" />
<input name="mix" type="float" output="metallic_out" nodegraph="nodegraph1" />
</mix>
<extract name="sheen_color_r" type="float">
<input name="in" type="color3" output="sheen_color_out" nodegraph="nodegraph1" />
<input name="index" type="integer" value="0" />
</extract>
<extract name="sheen_color_g" type="float">
<input name="in" type="color3" output="sheen_color_out" nodegraph="nodegraph1" />
<input name="index" type="integer" value="1" />
</extract>
<extract name="sheen_color_b" type="float">
<input name="in" type="color3" output="sheen_color_out" nodegraph="nodegraph1" />
<input name="index" type="integer" value="2" />
</extract>
<max name="sheen_color_max_rg" type="float">
<input name="in1" type="float" nodename="sheen_color_r" />
<input name="in2" type="float" nodename="sheen_color_g" />
</max>
<max name="sheen_intensity" type="float">
<input name="in1" type="float" nodename="sheen_color_max_rg" />
<input name="in2" type="float" nodename="sheen_color_b" />
</max>
<multiply name="sheen_roughness_sq" type="float">
<input name="in1" type="float" output="sheen_roughness_out" nodegraph="nodegraph1" />
<input name="in2" type="float" output="sheen_roughness_out" nodegraph="nodegraph1" />
</multiply>
<divide name="sheen_color_normalized" type="color3">
<input name="in1" type="color3" output="sheen_color_out" nodegraph="nodegraph1" />
<input name="in2" type="float" nodename="sheen_intensity" />
</divide>
<sheen_bsdf name="sheen_bsdf" type="BSDF">
<input name="weight" type="float" nodename="sheen_intensity" />
<input name="color" type="color3" nodename="sheen_color_normalized" />
<input name="roughness" type="float" nodename="sheen_roughness_sq" />
<input name="normal" type="vector3" nodename="geomNode_Nworld" />
</sheen_bsdf>
<layer name="sheen_layer" type="BSDF">
<input name="top" type="BSDF" nodename="sheen_bsdf" />
<input name="base" type="BSDF" nodename="base_mix" />
</layer>
<roughness_anisotropy name="clearcoat_roughness_uv" type="vector2">
<input name="roughness" type="float" output="clearcoat_roughness_out" nodegraph="nodegraph1" />
</roughness_anisotropy>
<dielectric_bsdf name="clearcoat_bsdf" type="BSDF">
<input name="weight" type="float" output="clearcoat_out" nodegraph="nodegraph1" />
<input name="roughness" type="vector2" nodename="clearcoat_roughness_uv" />
<input name="ior" type="float" value="1.5" />
<input name="normal" type="vector3" nodename="geomNode_Nworld" />
<input name="tangent" type="vector3" nodename="geomNode_Tworld" />
</dielectric_bsdf>
<layer name="clearcoat_layer" type="BSDF">
<input name="top" type="BSDF" nodename="clearcoat_bsdf" />
<input name="base" type="BSDF" nodename="sheen_layer" />
</layer>
<multiply name="emission_color" type="color3">
<input name="in1" type="color3" output="emissive_out" nodegraph="nodegraph1" />
<input name="in2" type="float" value="1" />
</multiply>
<uniform_edf name="emission" type="EDF">
<input name="color" type="color3" nodename="emission_color" />
</uniform_edf>
<ifgreatereq name="opacity_mask_cutoff" type="float">
<input name="value1" type="float" value="1" />
<input name="value2" type="float" value="0.5" />
<input name="in1" type="float" value="1" />
<input name="in2" type="float" value="0" />
</ifgreatereq>
<ifequal name="opacity_mask" type="float">
<input name="value1" type="integer" value="0" />
<input name="value2" type="integer" value="1" />
<input name="in1" type="float" nodename="opacity_mask_cutoff" />
<input name="in2" type="float" value="1" />
</ifequal>
<ifequal name="opacity" type="float">
<input name="value1" type="integer" value="0" />
<input name="value2" type="integer" value="0" />
<input name="in1" type="float" value="1" />
<input name="in2" type="float" nodename="opacity_mask" />
</ifequal>
<surface name="shader_constructor" type="surfaceshader">
<input name="bsdf" type="BSDF" nodename="clearcoat_layer" />
<input name="edf" type="EDF" nodename="emission" />
<input name="opacity" type="float" nodename="opacity" />
</surface>
<surfacematerial name="Glass" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="shader_constructor" />
</surfacematerial>
<nodegraph name="nodegraph1">
<standard_surface_to_gltf_pbr name="node1" type="multioutput" nodedef="ND_standard_surface_to_gltf_pbr">
<input name="base" type="float" value="0.0" colorspace="lin_rec709" />
<input name="specular_roughness" type="float" value="0.01" colorspace="lin_rec709" />
<input name="transmission" type="float" value="1" colorspace="lin_rec709" />
<input name="transmission_color" type="color3" value="1, 1, 1" colorspace="lin_rec709" />
<input name="transmission_depth" type="float" value="0" colorspace="lin_rec709" />
</standard_surface_to_gltf_pbr>
<output name="base_color_out" type="color3" nodename="node1" output="base_color_out" />
<output name="metallic_out" type="float" nodename="node1" output="metallic_out" />
<output name="roughness_out" type="float" nodename="node1" output="roughness_out" />
<output name="transmission_out" type="float" nodename="node1" output="transmission_out" />
<output name="thickness_out" type="float" nodename="node1" output="thickness_out" />
<output name="attenuation_color_out" type="color3" nodename="node1" output="attenuation_color_out" />
<output name="sheen_color_out" type="color3" nodename="node1" output="sheen_color_out" />
<output name="sheen_roughness_out" type="float" nodename="node1" output="sheen_roughness_out" />
<output name="clearcoat_out" type="float" nodename="node1" output="clearcoat_out" />
<output name="clearcoat_roughness_out" type="float" nodename="node1" output="clearcoat_roughness_out" />
<output name="emissive_out" type="color3" nodename="node1" output="emissive_out" />
</nodegraph>
<normal name="geomNode_Nworld" type="vector3">
<input name="space" type="string" value="world" />
</normal>
<tangent name="geomNode_Tworld" type="vector3">
<input name="space" type="string" value="world" />
<input name="index" type="integer" value="0" />
</tangent>
</materialx>
37 changes: 0 additions & 37 deletions source/MaterialXTest/MaterialXGenShader/GenShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,43 +141,6 @@ TEST_CASE("GenShader: Shader Translation", "[translate]")
}
}

TEST_CASE("GenShader: Gltf Transmission Translation", "[translate]")
{
mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath();
mx::ShaderTranslatorPtr shaderTranslator = mx::ShaderTranslator::create();

mx::FilePath testPath = searchPath.find("resources/Materials/Examples/StandardSurface");

mx::FilePath mtlxFile{"standard_surface_glass.mtlx"};
mx::DocumentPtr doc = mx::createDocument();
loadLibraries({ "libraries/targets", "libraries/stdlib", "libraries/pbrlib", "libraries/bxdf" }, searchPath, doc);

mx::readFromXmlFile(doc, testPath / mtlxFile, searchPath);
mtlxFile.removeExtension();

bool translated = false;
try
{
shaderTranslator->translateAllMaterials(doc, "gltf_pbr");
translated = true;
}
catch (mx::Exception &e)
{
std::cout << "Failed translating: " << (testPath / mtlxFile).asString() << ": " << e.what() << std::endl;
}
REQUIRE(translated);

std::string validationErrors;
bool valid = doc->validate(&validationErrors);
if (!doc->validate(&validationErrors))
{
std::cout << "Shader translation of " << (testPath / mtlxFile).asString() << " failed" << std::endl;
std::cout << "Validation errors: " << validationErrors << std::endl;
}
REQUIRE(valid);

}

TEST_CASE("GenShader: Transparency Regression Check", "[genshader]")
{
mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath();
Expand Down

0 comments on commit 6d7ddd2

Please sign in to comment.