Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multioutput upstream node input references #35

Merged
merged 11 commits into from
Dec 6, 2024

Conversation

kwokcb
Copy link
Contributor

@kwokcb kwokcb commented Dec 6, 2024

Changes

  • Fix up gltf to mtlx conversion of input lookups to upstream nodes with multiple outputs. Was setting the output number versus the output name.
  • As part of this all nodes with multiple outputs will have their outputs explicit created on the MTLX node.

Tests

  • Add in a new example with renderings.
    gltf_multioutput_node
<?xml version="1.0"?>
<materialx version="1.38">
  <nodegraph name="Nodegraph" xpos="0.9137658957355556" ypos="5.011704275726809">
    <checkerboard name="Checkerboard" type="color3" xpos="2.6484388609576195" ypos="2.0402610775419423">
      <input name="color1" type="color3" value="0.14902, 1, 0.945098" />
      <input name="color2" type="color3" value="0.858824, 0.152941, 0.011765" />
      <input name="uvtiling" type="vector2" value="10, 2" />
      <input name="uvoffset" type="vector2" value="0, 0" />
      <input name="texcoord" type="vector2" nodename="Texcoord" />
    </checkerboard>
    <texcoord name="Texcoord" type="vector2" xpos="-0.8397642640423806" ypos="-0.09473892245805758">
      <input name="index" type="integer" value="0" />
    </texcoord>
    <ramplr name="Ramplr" type="color3" xpos="2.6484388609576195" ypos="-0.09473892245805758">
      <input name="valuel" type="color3" output="outcolor" nodename="Gltf_colorimage" />
      <input name="valuer" type="color3" value="0.929412, 0.898039, 0.937255" />
      <input name="texcoord" type="vector2" nodename="Texcoord" />
    </ramplr>
    <multiply name="Multiply" type="color3" xpos="6.04843886095762" ypos="-0.09473892245805758">
      <input name="in1" type="color3" nodename="Ramplr" />
      <input name="in2" type="color3" nodename="Checkerboard" />
    </multiply>
    <gltf_colorimage name="Gltf_colorimage" type="multioutput" xpos="-0.8220400471923701" ypos="3.8882610775419426">
      <input name="file" type="filename" value="grid.png" colorspace="srgb_texture" />
      <input name="default" type="color4" value="0, 0, 0, 0" />
      <input name="pivot" type="vector2" value="0, 1" />
      <input name="scale" type="vector2" value="1, 1" />
      <input name="rotate" type="float" value="0" />
      <input name="offset" type="vector2" value="0, 0" />
      <input name="operationorder" type="integer" value="1" />
      <input name="uaddressmode" type="string" value="periodic" />
      <input name="vaddressmode" type="string" value="periodic" />
      <input name="filtertype" type="string" value="linear" />
      <input name="color" type="color4" value="1, 1, 1, 1" />
      <input name="geomcolor" type="color4" value="1, 1, 1, 1" />
      <output name="outcolor" type="color3" />
      <output name="outa" type="float" />
    </gltf_colorimage>
    <output name="out_Multiply_1" type="color3" nodename="Multiply" />
  </nodegraph>
  <gltf_pbr name="Gltf_pbr" type="surfaceshader" xpos="4.685284074783164" ypos="3.143475303472994">
    <input name="base_color" type="color3" nodegraph="Nodegraph" />
  </gltf_pbr>
  <surfacematerial name="USD_Default" type="material" xpos="7.619874613318136" ypos="3.193034733981979">
    <input name="surfaceshader" type="surfaceshader" nodename="Gltf_pbr" />
  </surfacematerial>
</materialx>
{
  "images": [
    {
      "uri": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVQI12P4z/AfAAQAAf/zKSWvAAAAAElFTkSuQmCC",
      "name": "KHR_texture_procedural_fallback"
    },
    {
      "name": "nodegraph1/image_color4/file",
      "uri": "grid.png"
    },
    {
      "name": "nodegraph1/image_color3/file",
      "uri": "grid.png"
    }
  ],
  "textures": [
    {
      "source": 0
    },
    {
      "name": "nodegraph1/image_color4/file",
      "source": 1
    },
    {
      "name": "nodegraph1/image_color3/file",
      "source": 2
    }
  ],
  "extensions": {
    "KHR_texture_procedurals": {
      "procedurals": [
        {
          "name": "nodegraph1",
          "nodetype": "nodegraph",
          "type": "color3",
          "inputs": [],
          "outputs": [
            {
              "name": "output_color3",
              "nodetype": "output",
              "type": "color3",
              "node": 2
            }
          ],
          "nodes": [
            {
              "name": "texcoord_vector2",
              "nodetype": "texcoord",
              "type": "vector2",
              "inputs": [
                {
                  "name": "index",
                  "nodetype": "input",
                  "type": "integer",
                  "value": 0
                }
              ],
              "outputs": [
                {
                  "nodetype": "output",
                  "name": "out",
                  "type": "vector2"
                }
              ]
            },
            {
              "name": "place2d_vector3",
              "nodetype": "place2d",
              "type": "vector2",
              "inputs": [
                {
                  "name": "texcoord",
                  "nodetype": "input",
                  "type": "vector2",
                  "node": 0
                },
                {
                  "name": "pivot",
                  "nodetype": "input",
                  "type": "vector2",
                  "value": [
                    0.0,
                    0.0
                  ]
                },
                {
                  "name": "scale",
                  "nodetype": "input",
                  "type": "vector2",
                  "value": [
                    1.0,
                    1.0
                  ]
                },
                {
                  "name": "rotate",
                  "nodetype": "input",
                  "unit": "degree",
                  "unittype": "angle",
                  "type": "float",
                  "value": 0.0
                },
                {
                  "name": "offset",
                  "nodetype": "input",
                  "type": "vector2",
                  "value": [
                    0.0,
                    0.0
                  ]
                },
                {
                  "name": "operationorder",
                  "nodetype": "input",
                  "type": "integer",
                  "value": 1
                }
              ],
              "outputs": [
                {
                  "nodetype": "output",
                  "name": "out",
                  "type": "vector2"
                }
              ]
            },
            {
              "name": "multiply_color4",
              "nodetype": "multiply",
              "type": "color3",
              "inputs": [
                {
                  "name": "in1",
                  "nodetype": "input",
                  "type": "color3",
                  "node": 4
                },
                {
                  "name": "in2",
                  "nodetype": "input",
                  "type": "color3",
                  "node": 3
                }
              ],
              "outputs": [
                {
                  "nodetype": "output",
                  "name": "out",
                  "type": "color3"
                }
              ]
            },
            {
              "name": "image_color4",
              "nodetype": "image",
              "type": "color3",
              "inputs": [
                {
                  "name": "file",
                  "nodetype": "input",
                  "colorspace": "none",
                  "type": "filename",
                  "texture": 1
                },
                {
                  "name": "layer",
                  "nodetype": "input",
                  "type": "string",
                  "value": "0"
                },
                {
                  "name": "default",
                  "nodetype": "input",
                  "type": "color3",
                  "value": [
                    0.9511,
                    0.0255797,
                    0.0255797
                  ]
                },
                {
                  "name": "texcoord",
                  "nodetype": "input",
                  "type": "vector2",
                  "node": 1
                },
                {
                  "name": "uaddressmode",
                  "nodetype": "input",
                  "type": "string",
                  "value": "periodic"
                },
                {
                  "name": "vaddressmode",
                  "nodetype": "input",
                  "type": "string",
                  "value": "periodic"
                },
                {
                  "name": "filtertype",
                  "nodetype": "input",
                  "type": "string",
                  "value": "linear"
                },
                {
                  "name": "framerange",
                  "nodetype": "input",
                  "type": "string",
                  "value": "100"
                },
                {
                  "name": "frameoffset",
                  "nodetype": "input",
                  "type": "integer",
                  "value": 1
                },
                {
                  "name": "frameendaction",
                  "nodetype": "input",
                  "type": "string",
                  "value": "constant"
                }
              ],
              "outputs": [
                {
                  "nodetype": "output",
                  "name": "out",
                  "type": "color3"
                }
              ]
            },
            {
              "name": "image_color3",
              "nodetype": "image",
              "type": "color3",
              "inputs": [
                {
                  "name": "file",
                  "nodetype": "input",
                  "colorspace": "srgb_texture",
                  "type": "filename",
                  "texture": 2
                },
                {
                  "name": "layer",
                  "nodetype": "input",
                  "type": "string",
                  "value": "0"
                },
                {
                  "name": "default",
                  "nodetype": "input",
                  "type": "color3",
                  "value": [
                    0.9511,
                    0.0255797,
                    0.0255797
                  ]
                },
                {
                  "name": "texcoord",
                  "nodetype": "input",
                  "type": "vector2",
                  "node": 5
                },
                {
                  "name": "uaddressmode",
                  "nodetype": "input",
                  "type": "string",
                  "value": "periodic"
                },
                {
                  "name": "vaddressmode",
                  "nodetype": "input",
                  "type": "string",
                  "value": "periodic"
                },
                {
                  "name": "filtertype",
                  "nodetype": "input",
                  "type": "string",
                  "value": "linear"
                },
                {
                  "name": "framerange",
                  "nodetype": "input",
                  "type": "string",
                  "value": "100"
                },
                {
                  "name": "frameoffset",
                  "nodetype": "input",
                  "type": "integer",
                  "value": 1
                },
                {
                  "name": "frameendaction",
                  "nodetype": "input",
                  "type": "string",
                  "value": "constant"
                }
              ],
              "outputs": [
                {
                  "nodetype": "output",
                  "name": "out",
                  "type": "color3"
                }
              ]
            },
            {
              "name": "place2d_vector2",
              "nodetype": "place2d",
              "type": "vector2",
              "inputs": [
                {
                  "name": "texcoord",
                  "nodetype": "input",
                  "type": "vector2",
                  "node": 0
                },
                {
                  "name": "pivot",
                  "nodetype": "input",
                  "type": "vector2",
                  "value": [
                    0.5,
                    0.5
                  ]
                },
                {
                  "name": "scale",
                  "nodetype": "input",
                  "type": "vector2",
                  "value": [
                    1.0,
                    1.0
                  ]
                },
                {
                  "name": "rotate",
                  "nodetype": "input",
                  "unit": "degree",
                  "unittype": "angle",
                  "type": "float",
                  "value": 45.0
                },
                {
                  "name": "offset",
                  "nodetype": "input",
                  "type": "vector2",
                  "value": [
                    0.0,
                    0.0
                  ]
                },
                {
                  "name": "operationorder",
                  "nodetype": "input",
                  "type": "integer",
                  "value": 1
                }
              ],
              "outputs": [
                {
                  "nodetype": "output",
                  "name": "out",
                  "type": "vector2"
                }
              ]
            }
          ]
        }
      ]
    }
  },
  "materials": [
    {
      "name": "gltf_pbr_surfaceshader",
      "pbrMetallicRoughness": {
        "baseColorTexture": {
          "index": 0,
          "extensions": {
            "KHR_texture_procedurals": {
              "index": 0,
              "output": 0
            }
          }
        }
      }
    }
  ],
  "asset": {
    "version": "2.0",
    "generator": "MaterialX 1.39 / glTF 2.0 Texture Procedural Converter"
  },
  "extensionsUsed": [
    "KHR_texture_procedurals",
    "EXT_texture_procedurals_mx_1_39"
  ]
}
  • Fix the comparison tests to ignore additional metadata on shaders all the time.
  • Update boombox and shader translation node tests to have outputs explicit for multioutput nodes.

@kwokcb kwokcb merged commit fa9caef into KhronosGroup:main Dec 6, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant