Skip to content

MSL : Translated shader texture bake fails with binding error #2699

@kwokcb

Description

@kwokcb

Issue

If you use try to back with a shader translation node with the MSL backend then it will fail with

 MSL bind attribute error.

Steps:

  1. Input file Aluminum.mtlx (from PhysicallyBased)
<?xml version="1.0"?>
<materialx version="1.38" colorspace="lin_rec709">
  <standard_surface name="SR_Aluminum" type="surfaceshader">
    <input name="base_color" type="color3" value="0.912, 0.914, 0.92" />
    <input name="specular_color" type="color3" value="0.97, 0.979, 0.988" />
    <input name="specular_roughness" type="float" value="0" />
    <input name="metalness" type="float" value="1" />
  </standard_surface>
  <surfacematerial name="Aluminum" type="material">
    <input name="surfaceshader" type="surfaceshader" nodename="SR_Aluminum" />
  </surfacematerial>
</materialx>
  1. Passes with GLSL backend
python translateshader.py --glsl 1 Aluminum.mtlx x.mtlx gltf_pbr
Processing material: Aluminum
Wrote baked document: x.mtlx
  1. Fails with MSL backend (no --glsl flag set)
python translateshader.py Aluminum.mtlx x.mtlx gltf_pbr             
Processing material: Aluminum
Traceback (most recent call last):
  File "/Users/bernardkwok/work/bernard_MaterialX_2/python/Scripts/translateshader.py", line 101, in <module>
    main()
  File "/Users/bernardkwok/work/bernard_MaterialX_2/python/Scripts/translateshader.py", line 98, in main
    baker.bakeAllMaterials(doc, searchPath, opts.outputFilename)
LookupError: MSL bind attribute error.

Alternative is

  1. Translate first to get (translated.mtlx)
<?xml version="1.0"?>
<materialx version="1.39" colorspace="lin_rec709">
  <gltf_pbr name="SR_Aluminum" type="surfaceshader">
    <input name="base_color" type="color3" output="base_color_out" nodegraph="nodegraph1" />
    <input name="metallic" type="float" output="metallic_out" nodegraph="nodegraph1" />
    <input name="roughness" type="float" output="roughness_out" nodegraph="nodegraph1" />
    <input name="specular" type="float" output="specular_out" nodegraph="nodegraph1" />
    <input name="specular_color" type="color3" output="specular_color_out" nodegraph="nodegraph1" />
    <input name="ior" type="float" output="ior_out" nodegraph="nodegraph1" />
    <input name="anisotropy_strength" type="float" output="anisotropy_strength_out" nodegraph="nodegraph1" />
    <input name="anisotropy_rotation" type="float" output="anisotropy_rotation_out" nodegraph="nodegraph1" />
    <input name="transmission" type="float" output="transmission_out" nodegraph="nodegraph1" />
    <input name="thickness" type="float" output="thickness_out" nodegraph="nodegraph1" />
    <input name="attenuation_color" type="color3" output="attenuation_color_out" nodegraph="nodegraph1" />
    <input name="attenuation_distance" type="float" output="attenuation_distance_out" nodegraph="nodegraph1" />
    <input name="sheen_color" type="color3" output="sheen_color_out" nodegraph="nodegraph1" />
    <input name="sheen_roughness" type="float" output="sheen_roughness_out" nodegraph="nodegraph1" />
    <input name="clearcoat" type="float" output="clearcoat_out" nodegraph="nodegraph1" />
    <input name="clearcoat_roughness" type="float" output="clearcoat_roughness_out" nodegraph="nodegraph1" />
    <input name="dispersion" type="float" output="dispersion_out" nodegraph="nodegraph1" />
    <input name="emissive" type="color3" output="emissive_out" nodegraph="nodegraph1" />
    <input name="emissive_strength" type="float" output="emissive_strength_out" nodegraph="nodegraph1" />
    <input name="normal" type="vector3" output="normal_out" nodegraph="nodegraph1" />
    <input name="tangent" type="vector3" output="tangent_out" nodegraph="nodegraph1" />
    <input name="alpha" type="float" output="alpha_out" nodegraph="nodegraph1" />
    <input name="alpha_mode" type="integer" output="alpha_mode_out" nodegraph="nodegraph1" />
  </gltf_pbr>
  <surfacematerial name="Aluminum" type="material">
    <input name="surfaceshader" type="surfaceshader" nodename="SR_Aluminum" />
  </surfacematerial>
  <nodegraph name="nodegraph1">
    <standard_surface_to_gltf_pbr name="node1" type="multioutput" nodedef="ND_standard_surface_to_gltf_pbr">
      <input name="base_color" type="color3" value="0.912, 0.914, 0.92" colorspace="lin_rec709" />
      <input name="specular_color" type="color3" value="0.97, 0.979, 0.988" colorspace="lin_rec709" />
      <input name="specular_roughness" type="float" value="0" colorspace="lin_rec709" />
      <input name="metalness" type="float" value="1" 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="specular_out" type="float" nodename="node1" output="specular_out" />
    <output name="specular_color_out" type="color3" nodename="node1" output="specular_color_out" />
    <output name="ior_out" type="float" nodename="node1" output="ior_out" />
    <output name="anisotropy_strength_out" type="float" nodename="node1" output="anisotropy_strength_out" />
    <output name="anisotropy_rotation_out" type="float" nodename="node1" output="anisotropy_rotation_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="attenuation_distance_out" type="float" nodename="node1" output="attenuation_distance_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="dispersion_out" type="float" nodename="node1" output="dispersion_out" />
    <output name="emissive_out" type="color3" nodename="node1" output="emissive_out" />
    <output name="emissive_strength_out" type="float" nodename="node1" output="emissive_strength_out" />
    <output name="normal_out" type="vector3" nodename="node1" output="normal_out" />
    <output name="tangent_out" type="vector3" nodename="node1" output="tangent_out" />
    <output name="alpha_out" type="float" nodename="node1" output="alpha_out" />
    <output name="alpha_mode_out" type="integer" nodename="node1" output="alpha_mode_out" />
  </nodegraph>
</materialx>
  1. Run bake:
python baketextures.py ./translated.mtlx x.mtlx          
Processing material: Aluminum
Traceback (most recent call last):
  File "/Users/bernardkwok/work/bernard_MaterialX_2/python/Scripts/baketextures.py", line 73, in <module>
    main()
  File "/Users/bernardkwok/work/bernard_MaterialX_2/python/Scripts/baketextures.py", line 70, in main
    baker.bakeAllMaterials(doc, searchPath, opts.outputFilename)
LookupError: MSL bind attribute error.

(You can also load this into MaterialXViewer and interactively translate to gltf_pbr then bake, but this will crash the program:

Processing material: Aluminum
Error in texture baking: MSL bind attribute error.
-[_MTLCommandEncoder dealloc]:134: failed assertion `Command encoder released without endEncoding'
zsh: abort      ./bin/MaterialXView

This is with head of main at SHA: e9cefcc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions