Error importing mdl shaders generated from materialx

Hi, I have MaterialX materials I want to import, and since we don’t have that direct support for materialx yet (right??) I’m converting them to mdl shaders to import instead. A such generated mdl shader could look omething like this:

mdl 1.6;

using mx = materialx;
import ::df::*;
import ::base::*;
import ::math::*;
import ::state::*;
import ::anno::*;
import ::tex::*;
import ::mx::swizzle::*;
import ::mx::cm::*;
using ::mx::core import *;
using ::mx::stdlib import *;
using ::mx::pbrlib import *;
using ::mx::sampling import *;

material NG_standard_surface_surfaceshader_100
(
    float base = 0.8,
    color base_color = color(1, 1, 1),
    float diffuse_roughness = 0,
    float metalness = 0,
    float specular = 1,
    color specular_color = color(1, 1, 1),
    float specular_roughness = 0.2,
    uniform float specular_IOR = 1.5,
    float specular_anisotropy = 0,
    float specular_rotation = 0,
    float transmission = 0,
    color transmission_color = color(1, 1, 1),
    float transmission_depth = 0,
    color transmission_scatter = color(0, 0, 0),
    float transmission_scatter_anisotropy = 0,
    float transmission_dispersion = 0,
    float transmission_extra_roughness = 0,
    float subsurface = 0,
    color subsurface_color = color(1, 1, 1),
    color subsurface_radius = color(1, 1, 1),
    float subsurface_scale = 1,
    float subsurface_anisotropy = 0,
    float sheen = 0,
    color sheen_color = color(1, 1, 1),
    float sheen_roughness = 0.3,
    float coat = 0,
    color coat_color = color(1, 1, 1),
    float coat_roughness = 0.1,
    float coat_anisotropy = 0,
    float coat_rotation = 0,
    uniform float coat_IOR = 1.5,
    float3 coat_normal = float3(0.0),
    float coat_affect_color = 0,
    float coat_affect_roughness = 0,
    float thin_film_thickness = 0,
    float thin_film_IOR = 1.5,
    float emission = 0,
    color emission_color = color(1, 1, 1),
    color opacity = color(1, 1, 1),
    bool thin_walled = false,
    float3 normal = float3(0.0),
    float3 tangent = float3(0.0)
)
 = let
{
    float2 coat_roughness_vector_out = mx::pbrlib::mx_roughness_anisotropy(mxp_roughness:coat_roughness, mxp_anisotropy:coat_anisotropy);
    float coat_tangent_rotate_degree_out = coat_rotation * 360;
    color metal_reflectivity_out = base_color * base;
    color metal_edgecolor_out = specular_color * specular;
    float coat_affect_roughness_multiply1_out = coat_affect_roughness * coat;
    float tangent_rotate_degree_out = specular_rotation * 360;
    float coat_clamped_out = math::clamp(coat, 0, 1);
    float3 subsurface_radius_vector_out = float3(float3(subsurface_radius).x, float3(subsurface_radius).y, float3(subsurface_radius).z);
    float subsurface_selector_out = float(thin_walled);
    color coat_attenuation_out = math::lerp(color(1, 1, 1), coat_color, coat);
    color emission_weight_out = emission_color * emission;
    color coat_emission_attenuation_out = math::lerp(color(1, 1, 1), coat_color, coat);
    color opacity_luminance_out = mx::stdlib::mx_luminance_color3(opacity);
    float3 coat_tangent_rotate_out = mx::stdlib::mx_rotate3d_vector3(mxp_in:tangent, mxp_amount:coat_tangent_rotate_degree_out, mxp_axis:coat_normal);
    mx::pbrlib::mx_artistic_ior__result artistic_ior_result = mx::pbrlib::mx_artistic_ior(mxp_reflectivity:metal_reflectivity_out, mxp_edge_color:metal_edgecolor_out);
    float coat_affect_roughness_multiply2_out = coat_affect_roughness_multiply1_out * coat_roughness;
    float3 tangent_rotate_out = mx::stdlib::mx_rotate3d_vector3(mxp_in:tangent, mxp_amount:tangent_rotate_degree_out, mxp_axis:normal);
    float coat_gamma_multiply_out = coat_clamped_out * coat_affect_color;
    float3 subsurface_radius_scaled_out = subsurface_radius_vector_out * subsurface_scale;
    color emission_weight_attenuated_out = emission_weight_out * coat_emission_attenuation_out;
    float3 coat_tangent_rotate_normalize_out = math::normalize(coat_tangent_rotate_out);
    float coat_affected_roughness_out = math::lerp(specular_roughness, 1, coat_affect_roughness_multiply2_out);
    float3 tangent_rotate_normalize_out = math::normalize(tangent_rotate_out);
    float coat_gamma_out = coat_gamma_multiply_out + 1;
    float3 coat_tangent_out = mx::stdlib::mx_ifgreater_vector3(coat_anisotropy, 0, coat_tangent_rotate_normalize_out, tangent);
    float2 main_roughness_out = mx::pbrlib::mx_roughness_anisotropy(mxp_roughness:coat_affected_roughness_out, mxp_anisotropy:specular_anisotropy);
    float3 main_tangent_out = mx::stdlib::mx_ifgreater_vector3(specular_anisotropy, 0, tangent_rotate_normalize_out, tangent);
    color coat_affected_subsurface_color_out = math::pow(subsurface_color, coat_gamma_out);
    color coat_affected_diffuse_color_out = math::pow(base_color, coat_gamma_out);
    material metal_bsdf_out = mx::pbrlib::mx_conductor_bsdf(mxp_weight:1, mxp_ior:artistic_ior_result.mxp_ior, mxp_extinction:artistic_ior_result.mxp_extinction, mxp_roughness:main_roughness_out, mxp_normal:normal, mxp_tangent:main_tangent_out);
    material transmission_bsdf_out = mx::pbrlib::mx_dielectric_bsdf(mxp_weight:1, mxp_tint:transmission_color, mxp_ior:specular_IOR, mxp_roughness:main_roughness_out, mxp_normal:normal, mxp_tangent:main_tangent_out, mxp_scatter_mode:mx_scatter_mode_T, mxp_base:material());
    material translucent_bsdf_out = mx::pbrlib::mx_translucent_bsdf(mxp_weight:1, mxp_color:coat_affected_subsurface_color_out, mxp_normal:normal);
    material subsurface_bsdf_out = mx::pbrlib::mx_subsurface_bsdf(mxp_weight:1, mxp_color:coat_affected_subsurface_color_out, mxp_radius:subsurface_radius_scaled_out, mxp_anisotropy:subsurface_anisotropy, mxp_normal:normal);
    material selected_subsurface_bsdf_out = mx::pbrlib::mx_mix_bsdf(mxp_fg:translucent_bsdf_out, mxp_bg:subsurface_bsdf_out, mxp_mix:subsurface_selector_out);
    material diffuse_bsdf_out = mx::pbrlib::mx_oren_nayar_diffuse_bsdf(mxp_weight:base, mxp_color:coat_affected_diffuse_color_out, mxp_roughness:diffuse_roughness, mxp_normal:normal);
    material subsurface_mix_out = mx::pbrlib::mx_mix_bsdf(mxp_fg:selected_subsurface_bsdf_out, mxp_bg:diffuse_bsdf_out, mxp_mix:subsurface);
    material sheen_layer_out = mx::pbrlib::mx_sheen_bsdf(mxp_weight:sheen, mxp_color:sheen_color, mxp_roughness:sheen_roughness, mxp_normal:normal, mxp_base:subsurface_mix_out);
    material transmission_mix_out = mx::pbrlib::mx_mix_bsdf(mxp_fg:transmission_bsdf_out, mxp_bg:sheen_layer_out, mxp_mix:transmission);
    material specular_layer_out = mx::pbrlib::mx_dielectric_bsdf(mxp_weight:specular, mxp_tint:specular_color, mxp_ior:specular_IOR, mxp_roughness:main_roughness_out, mxp_normal:normal, mxp_tangent:main_tangent_out, mxp_scatter_mode:mx_scatter_mode_R, mxp_base:transmission_mix_out);
    material specular_layer_with_thin_film_out = mx::pbrlib::mx_thin_film_bsdf(mxp_thickness:thin_film_thickness, mxp_ior:thin_film_IOR, mxp_base:specular_layer_out);
    material metalness_mix_out = mx::pbrlib::mx_mix_bsdf(mxp_fg:metal_bsdf_out, mxp_bg:specular_layer_with_thin_film_out, mxp_mix:metalness);
    material metalness_mix_attenuated_out = mx::pbrlib::mx_multiply_bsdf_color3(mxp_in1:metalness_mix_out, mxp_in2:coat_attenuation_out);
    material coat_layer_out = mx::pbrlib::mx_dielectric_bsdf(mxp_weight:coat, mxp_tint:color(1, 1, 1), mxp_ior:coat_IOR, mxp_roughness:coat_roughness_vector_out, mxp_normal:coat_normal, mxp_tangent:coat_tangent_out, mxp_scatter_mode:mx_scatter_mode_R, mxp_base:metalness_mix_attenuated_out);
    material emission_edf_out = mx::pbrlib::mx_uniform_edf(mxp_color:emission_weight_attenuated_out);
    material shader_constructor_out = mx::pbrlib::mx_surface(coat_layer_out, emission_edf_out, float3(opacity_luminance_out).x, specular_IOR);
}
in material(shader_constructor_out);

export material BakingShaderMDL
(
    float base = 1,
    float diffuse_roughness = 0,
    float metalness = 0,
    float specular = 1,
    color specular_color = color(1, 1, 1),
    float specular_roughness = 0.2,
    uniform float specular_IOR = 1.5,
    float specular_anisotropy = 0,
    float specular_rotation = 0,
    float transmission = 0,
    color transmission_color = color(1, 1, 1),
    float transmission_depth = 0,
    color transmission_scatter = color(0, 0, 0),
    float transmission_scatter_anisotropy = 0,
    float transmission_dispersion = 0,
    float transmission_extra_roughness = 0,
    float subsurface = 0,
    color subsurface_color = color(1, 1, 1),
    color subsurface_radius = color(1, 1, 1),
    float subsurface_scale = 1,
    float subsurface_anisotropy = 0,
    float sheen = 0,
    color sheen_color = color(1, 1, 1),
    float sheen_roughness = 0.3,
    float coat = 0,
    color coat_color = color(1, 1, 1),
    float coat_roughness = 0.1,
    float coat_anisotropy = 0,
    float coat_rotation = 0,
    uniform float coat_IOR = 1.5,
    float coat_affect_color = 0,
    float coat_affect_roughness = 0,
    float thin_film_thickness = 0,
    float thin_film_IOR = 1.5,
    float emission = 0,
    color emission_color = color(1, 1, 1),
    color opacity = color(1, 1, 1),
    bool thin_walled = false,
    uniform mx_coordinatespace_type geomprop_Nworld_space = mx_coordinatespace_type_world,
    uniform mx_coordinatespace_type geomprop_Tworld_space = mx_coordinatespace_type_world,
    uniform int geomprop_Tworld_index = 0,
    color SR_untitled_base_color = color(0, 0.12, 0)
)
= let
{
    float3 geomprop_Nworld_out = mx::stdlib::mx_normal_vector3(mxp_space:geomprop_Nworld_space);
    float3 geomprop_Tworld_out = mx::stdlib::mx_tangent_vector3(mxp_space:geomprop_Tworld_space, mxp_index:geomprop_Tworld_index);
    material SR_untitled_out = NG_standard_surface_surfaceshader_100(base, SR_untitled_base_color, diffuse_roughness, metalness, specular, specular_color, specular_roughness, specular_IOR, specular_anisotropy, specular_rotation, transmission, transmission_color, transmission_depth, transmission_scatter, transmission_scatter_anisotropy, transmission_dispersion, transmission_extra_roughness, subsurface, subsurface_color, subsurface_radius, subsurface_scale, subsurface_anisotropy, sheen, sheen_color, sheen_roughness, coat, coat_color, coat_roughness, coat_anisotropy, coat_rotation, coat_IOR, geomprop_Nworld_out, coat_affect_color, coat_affect_roughness, thin_film_thickness, thin_film_IOR, emission, emission_color, opacity, thin_walled, geomprop_Nworld_out, geomprop_Tworld_out);
    material finalOutput__ = SR_untitled_out;
}
in material(finalOutput__);

As you can see it imports the materialx library.

When trying to import this mdl shader in Create I get the error “SR_untitled.mdl doesn’t contain any usable materials” and in the console it says

2022-05-02 14:51:19  [Error] [rtx.neuraylib.plugin] [MDLC:COMPILER]   1.0   MDLC   comp error: U:\dev\Tests\SR_untitled.mdl(159,64): C152 'mx_normal_vector3' : cannot convert argument 'mxp_space' from 'enum ::materialx::core::mx_coordinatespace_type' to 'enum ::Z73file_3A::Z37d_3A::omniverse::ov::pkg::Z1Ecreate_2D2022_2E1_2E2::kit::mdl::core::mdl::materialx::core::mx_coordinatespace_type'
2022-05-02 14:51:19  [Error] [rtx.neuraylib.plugin] [MDLC:COMPILER]   1.0   MDLC   comp error: U:\dev\Tests\SR_untitled.mdl(160,65): C152 'mx_tangent_vector3' : cannot convert argument 'mxp_space' from 'enum ::materialx::core::mx_coordinatespace_type' to 'enum ::Z73file_3A::Z37d_3A::omniverse::ov::pkg::Z1Ecreate_2D2022_2E1_2E2::kit::mdl::core::mdl::materialx::core::mx_coordinatespace_type'
2022-05-02 14:51:19  [Error] [rtx.neuraylib.plugin] Compiler Core: U:\dev\Tests\SR_untitled.mdl(159,64): C152 'mx_normal_vector3' : cannot convert argument 'mxp_space' from 'enum ::materialx::core::mx_coordinatespace_type' to 'enum ::Z73file_3A::Z37d_3A::omniverse::ov::pkg::Z1Ecreate_2D2022_2E1_2E2::kit::mdl::core::mdl::materialx::core::mx_coordinatespace_type'
2022-05-02 14:51:19  [Error] [rtx.neuraylib.plugin] Compiler Core: U:\dev\Tests\SR_untitled.mdl(160,65): C152 'mx_tangent_vector3' : cannot convert argument 'mxp_space' from 'enum ::materialx::core::mx_coordinatespace_type' to 'enum ::Z73file_3A::Z37d_3A::omniverse::ov::pkg::Z1Ecreate_2D2022_2E1_2E2::kit::mdl::core::mdl::materialx::core::mx_coordinatespace_type'

So there seem to be some problems with namespaces/the path to the materialx library.

Any tips on how to solve this?
Thanks

Hey Niklas,
Any new findings on that? I have exactly the same problem. Converting float and color values only from mtlx to mdl at least opens in substance designer for me (while still crashing in ue4 with mdl importer and producing same error as yours on omniverse).
Using tiled image nodes in the mtlx also does not open in substance designer though.
Of course also added the mx modules to the global mdl path location.

Any help would be appreciated :)
Kr
Ralf

Hello , @user161674 , @niklas.lundstrom
I got a similar error that you reported, is there any update?

@user161674
If you have time, Could you let me know the detail of
Of course also added the mx modules to the global mdl path location. ?
To import mdl that material X script generated, Do we have to add some path to Omniverse?