autodesk-forks / MaterialX

MaterialX C++ and Python libraries
http://www.materialx.org/
Apache License 2.0
107 stars 23 forks source link

Support legacy Arnold "context" hint on shaderref upgrade #1149

Closed bernardkwok closed 3 years ago

bernardkwok commented 3 years ago

Update #1150

Add in special Arnold "context" support when upgrading "shaderrefs". Use as the type to create instead of checing the regular node, nodedef attributes.

This will only be enabled for builds with the build flag MATERIALX_BUILD_GEN_ARNOLD set.

Test case added wit this test as input:

<?xml version="1.0"?>
<materialx version="1.36">

   <material name="test_material">
      <shaderref name="simple_srf1" node="noise" context="surfaceshader">
         <bindinput name="octaves" type="int" value="12" />
         <bindinput name="distortion" type="float" value="6" />
         <bindinput name="lacunarity" type="float" value="2" />
         <bindinput name="amplitude" type="float" value="1" />
         <bindinput name="color1" type="color3" value="1, 1, 0" />
         <bindinput name="color2" type="color3" value="0.9, 0.1, 0" />
      </shaderref>

      <shaderref name="simple_disp" node="noise" context="displacementshader">
         <bindinput name="octaves" type="int" value="8" />
         <bindinput name="distortion" type="float" value="3" />
         <bindinput name="lacunarity" type="float" value="4" />
         <bindinput name="amplitude" type="float" value="1" />
         <bindinput name="color1" type="color3" value="0, 0, 0" />
         <bindinput name="color2" type="color3" value="1, 1, 1" />
      </shaderref>
   </material>

   <material name="test_material2">
      <shaderref name="simple_srf2" node="standard_surface">
         <bindinput name="base_color" type="color3" value="0, 1, 0" />
         <bindinput name="base" type="float" value="0.8" />
      </shaderref>

      <shaderref name="simple_disp" node="image" context="displacementshader">
         <bindinput name="filename" type="string" value="wheel.tx" />
      </shaderref>
   </material>

</materialx>

The expected output is:

<?xml version="1.0"?>
<materialx version="1.38">
  <noise name="simple_srf1" type="surfaceshader">
    <input name="octaves" type="int" value="12" />
    <input name="distortion" type="float" value="6" />
    <input name="lacunarity" type="float" value="2" />
    <input name="amplitude" type="float" value="1" />
    <input name="color1" type="color3" value="1, 1, 0" />
    <input name="color2" type="color3" value="0.9, 0.1, 0" />
  </noise>
   <noise name="simple_disp" type="displacementshader">
      <input name="octaves" type="int" value="8" />
      <input name="distortion" type="float" value="3" />
      <input name="lacunarity" type="float" value="4" />
      <input name="amplitude" type="float" value="1" />
      <input name="color1" type="color3" value="0, 0, 0" />
      <input name="color2" type="color3" value="1, 1, 1" />
   </noise>
   <surfacematerial name="test_material" type="material">
    <input name="surfaceshader" type="surfaceshader" nodename="simple_srf1" />
    <input name="displacementshader" type="displacementshader" nodename="simple_disp" />
  </surfacematerial>

  <standard_surface name="simple_srf2" type="surfaceshader">
    <input name="base_color" type="color3" value="0, 1, 0" />
    <input name="base" type="float" value="0.8" />
  </standard_surface>
   <image name="simple_disp2" type="displacementshader">
      <input name="filename" type="string" value="wheel.tx" />
   </image>
   <surfacematerial name="test_material2" type="material">
    <input name="surfaceshader" type="surfaceshader" nodename="simple_srf2" />
    <input name="displacementshader" type="displacementshader" nodename="simple_disp2" />
  </surfacematerial>
</materialx>