all  /  test_assets  / MaterialXTest  / basicTextured_flatten .usda

USD assets with MaterialX

Enabling MaterialX in USD

To enable materialx, build USD with --materialx option

python build_scripts\build_usd.py --materialx

Sample USD and MaterialX files

The MaterialX files are TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.

All rights reserved, and covered by the Apache 2.0 license.

Example 1: Basic

  • basic.usda - Sphere referring a MaterialX usd_preview_surface_plastic.mtlx

usd_preview_surface_plastic.mtlx defines a material called USD_Plastic using the UsdPreviewSurface MaterialX node.

  • basic_flatten.usda - flattened version of basic.usda

Flattening can be performed by using usdcat

usdcat --flatten basic.usda -o basic_flatten.usda

screenshot

Example 2: BasicTextured with variants

  • basicTextured.usda - Teapot referring two MaterialX files

    1. usd_preview_surface_plastic.mtlx defines a material called USD_Plastic using the UsdPreviewSurface MaterialX node.
    2. standard_surface_brass_tiled.mtlx defines a material called Tiled_Brass using the standard_surface MaterialX node. This MaterialX file also uses a texture for coat_color and coat_rougness

    Both of these materials are accessible as materialvariants. To switch between variants in USDView, open the Interpreter and run the following commands:

         sbPrim = usdviewApi.stage.GetPrimAtPath("/Teapot")
         vs = sbPrim.GetVariantSet("materialvariants")
         vs.SetVariantSelection("Plastic")
         vs.SetVariantSelection("BrassTiled")
    
- basicTextured_flatten.usda - flattened version of basicTextured.usda 

![screenshot](screenshots/basicTextured_brasstiled.png)  
![screenshot](screenshots/basicTextured_plastic.png)  

 *Known limitations and MaterialX notes*: 
 - variants are lost when Usd is flattened 
 - Since the `fileprefix="./textures/"` is ignored by usdMtlx, our mtlx duplicates the fileprefix in the value input `value="./textures/`

### References
- MaterialX in USD:  ASWF Open Source 2021 [slides](https://materialx.org/assets/ASWF_OSD2021_MaterialX_slides_final.pdf).
- MaterialX examples: [MaterialX ASWF repository](https://github.com/AcademySoftwareFoundation/MaterialX/tree/main/resources/Materials/Examples).

Edit this page

basicTextured_flatten.usda

#usda 1.0
(
    doc = "Generated from Composed Stage of root layer basicTextured.usda"
    upAxis = "Y"
    metersPerUnit = 0.01
    defaultPrim = "Teapot"
)

def Scope "MaterialX"
{
    def "Materials"
    {
        def Material "USD_Plastic"
        {
            float inputs:clearcoat
            float inputs:clearcoatRoughness
            color3f inputs:diffuseColor = (0.10470402, 0.24188282, 0.818)
            float inputs:displacement
            color3f inputs:emissiveColor
            float inputs:ior = 1.5
            float inputs:metallic
            float3 inputs:normal
            float inputs:occlusion
            float inputs:opacity
            float inputs:opacityThreshold
            float inputs:roughness = 0.32467532
            color3f inputs:specularColor
            int inputs:useSpecularWorkflow
            token outputs:mtlx:surface.connect = </MaterialX/Materials/USD_Plastic/ND_UsdPreviewSurface_surfaceshader.outputs:surface>

            def Shader "ND_UsdPreviewSurface_surfaceshader"
            {
                uniform token info:id = "ND_UsdPreviewSurface_surfaceshader"
                float inputs:clearcoat.connect = </MaterialX/Materials/USD_Plastic.inputs:clearcoat>
                float inputs:clearcoatRoughness.connect = </MaterialX/Materials/USD_Plastic.inputs:clearcoatRoughness>
                color3f inputs:diffuseColor.connect = </MaterialX/Materials/USD_Plastic.inputs:diffuseColor>
                float inputs:displacement.connect = </MaterialX/Materials/USD_Plastic.inputs:displacement>
                color3f inputs:emissiveColor.connect = </MaterialX/Materials/USD_Plastic.inputs:emissiveColor>
                float inputs:ior.connect = </MaterialX/Materials/USD_Plastic.inputs:ior>
                float inputs:metallic.connect = </MaterialX/Materials/USD_Plastic.inputs:metallic>
                float3 inputs:normal.connect = </MaterialX/Materials/USD_Plastic.inputs:normal>
                float inputs:occlusion.connect = </MaterialX/Materials/USD_Plastic.inputs:occlusion>
                float inputs:opacity.connect = </MaterialX/Materials/USD_Plastic.inputs:opacity>
                float inputs:opacityThreshold.connect = </MaterialX/Materials/USD_Plastic.inputs:opacityThreshold>
                float inputs:roughness.connect = </MaterialX/Materials/USD_Plastic.inputs:roughness>
                color3f inputs:specularColor.connect = </MaterialX/Materials/USD_Plastic.inputs:specularColor>
                int inputs:useSpecularWorkflow.connect = </MaterialX/Materials/USD_Plastic.inputs:useSpecularWorkflow>
                token outputs:surface
            }
        }

        def Material "Tiled_Brass"
        {
            float inputs:base = 1
            color3f inputs:base_color = (1, 1, 1)
            float inputs:coat = 1
            float inputs:coat_affect_color
            float inputs:coat_affect_roughness
            float inputs:coat_anisotropy
            color3f inputs:coat_color
            float inputs:coat_IOR
            float3 inputs:coat_normal
            float inputs:coat_rotation
            float inputs:coat_roughness
            float inputs:diffuse_roughness
            float inputs:emission
            color3f inputs:emission_color
            float inputs:metalness = 1
            float3 inputs:normal
            color3f inputs:opacity
            float inputs:sheen
            color3f inputs:sheen_color
            float inputs:sheen_roughness
            float inputs:specular = 0
            float inputs:specular_anisotropy
            color3f inputs:specular_color
            float inputs:specular_IOR
            float inputs:specular_rotation
            float inputs:specular_roughness
            float inputs:subsurface
            float inputs:subsurface_anisotropy
            color3f inputs:subsurface_color
            color3f inputs:subsurface_radius
            float inputs:subsurface_scale
            float3 inputs:tangent
            float inputs:thin_film_IOR
            float inputs:thin_film_thickness
            bool inputs:thin_walled
            float inputs:transmission
            color3f inputs:transmission_color
            float inputs:transmission_depth
            float inputs:transmission_dispersion
            float inputs:transmission_extra_roughness
            color3f inputs:transmission_scatter
            float inputs:transmission_scatter_anisotropy
            token outputs:mtlx:surface.connect = </MaterialX/Materials/Tiled_Brass/ND_standard_surface_surfaceshader.outputs:surface>

            def Shader "ND_standard_surface_surfaceshader"
            {
                uniform token info:id = "ND_standard_surface_surfaceshader"
                float inputs:base.connect = </MaterialX/Materials/Tiled_Brass.inputs:base>
                color3f inputs:base_color.connect = </MaterialX/Materials/Tiled_Brass.inputs:base_color>
                float inputs:coat.connect = </MaterialX/Materials/Tiled_Brass.inputs:coat>
                float inputs:coat_affect_color.connect = </MaterialX/Materials/Tiled_Brass.inputs:coat_affect_color>
                float inputs:coat_affect_roughness.connect = </MaterialX/Materials/Tiled_Brass.inputs:coat_affect_roughness>
                float inputs:coat_anisotropy.connect = </MaterialX/Materials/Tiled_Brass.inputs:coat_anisotropy>
                color3f inputs:coat_color.connect = </MaterialX/Materials/Tiled_Brass/NG_brass1.outputs:out_color>
                float inputs:coat_IOR.connect = </MaterialX/Materials/Tiled_Brass.inputs:coat_IOR>
                float3 inputs:coat_normal.connect = </MaterialX/Materials/Tiled_Brass.inputs:coat_normal>
                float inputs:coat_rotation.connect = </MaterialX/Materials/Tiled_Brass.inputs:coat_rotation>
                float inputs:coat_roughness.connect = </MaterialX/Materials/Tiled_Brass/NG_brass1.outputs:out_roughness>
                float inputs:diffuse_roughness.connect = </MaterialX/Materials/Tiled_Brass.inputs:diffuse_roughness>
                float inputs:emission.connect = </MaterialX/Materials/Tiled_Brass.inputs:emission>
                color3f inputs:emission_color.connect = </MaterialX/Materials/Tiled_Brass.inputs:emission_color>
                float inputs:metalness.connect = </MaterialX/Materials/Tiled_Brass.inputs:metalness>
                float3 inputs:normal.connect = </MaterialX/Materials/Tiled_Brass.inputs:normal>
                color3f inputs:opacity.connect = </MaterialX/Materials/Tiled_Brass.inputs:opacity>
                float inputs:sheen.connect = </MaterialX/Materials/Tiled_Brass.inputs:sheen>
                color3f inputs:sheen_color.connect = </MaterialX/Materials/Tiled_Brass.inputs:sheen_color>
                float inputs:sheen_roughness.connect = </MaterialX/Materials/Tiled_Brass.inputs:sheen_roughness>
                float inputs:specular.connect = </MaterialX/Materials/Tiled_Brass.inputs:specular>
                float inputs:specular_anisotropy.connect = </MaterialX/Materials/Tiled_Brass.inputs:specular_anisotropy>
                color3f inputs:specular_color.connect = </MaterialX/Materials/Tiled_Brass.inputs:specular_color>
                float inputs:specular_IOR.connect = </MaterialX/Materials/Tiled_Brass.inputs:specular_IOR>
                float inputs:specular_rotation.connect = </MaterialX/Materials/Tiled_Brass.inputs:specular_rotation>
                float inputs:specular_roughness.connect = </MaterialX/Materials/Tiled_Brass/NG_brass1.outputs:out_roughness>
                float inputs:subsurface.connect = </MaterialX/Materials/Tiled_Brass.inputs:subsurface>
                float inputs:subsurface_anisotropy.connect = </MaterialX/Materials/Tiled_Brass.inputs:subsurface_anisotropy>
                color3f inputs:subsurface_color.connect = </MaterialX/Materials/Tiled_Brass.inputs:subsurface_color>
                color3f inputs:subsurface_radius.connect = </MaterialX/Materials/Tiled_Brass.inputs:subsurface_radius>
                float inputs:subsurface_scale.connect = </MaterialX/Materials/Tiled_Brass.inputs:subsurface_scale>
                float3 inputs:tangent.connect = </MaterialX/Materials/Tiled_Brass.inputs:tangent>
                float inputs:thin_film_IOR.connect = </MaterialX/Materials/Tiled_Brass.inputs:thin_film_IOR>
                float inputs:thin_film_thickness.connect = </MaterialX/Materials/Tiled_Brass.inputs:thin_film_thickness>
                bool inputs:thin_walled.connect = </MaterialX/Materials/Tiled_Brass.inputs:thin_walled>
                float inputs:transmission.connect = </MaterialX/Materials/Tiled_Brass.inputs:transmission>
                color3f inputs:transmission_color.connect = </MaterialX/Materials/Tiled_Brass.inputs:transmission_color>
                float inputs:transmission_depth.connect = </MaterialX/Materials/Tiled_Brass.inputs:transmission_depth>
                float inputs:transmission_dispersion.connect = </MaterialX/Materials/Tiled_Brass.inputs:transmission_dispersion>
                float inputs:transmission_extra_roughness.connect = </MaterialX/Materials/Tiled_Brass.inputs:transmission_extra_roughness>
                color3f inputs:transmission_scatter.connect = </MaterialX/Materials/Tiled_Brass.inputs:transmission_scatter>
                float inputs:transmission_scatter_anisotropy.connect = </MaterialX/Materials/Tiled_Brass.inputs:transmission_scatter_anisotropy>
                token outputs:surface
            }

            def NodeGraph "NG_brass1"
            {
                color3f outputs:out_color.connect = </MaterialX/Materials/Tiled_Brass/NG_brass1/image_color.outputs:out>
                float outputs:out_roughness.connect = </MaterialX/Materials/Tiled_Brass/NG_brass1/image_roughness.outputs:out>

                def Shader "image_color"
                {
                    uniform token info:id = "ND_tiledimage_color3"
                    asset inputs:file = @textures/brass_color.jpg@ (
                        colorSpace = "srgb_texture"
                    )
                    float2 inputs:realworldimagesize = (0.5, 0.5)
                    float2 inputs:realworldtilesize = (0.5, 0.5)
                    float2 inputs:uvtiling = (1, 1)
                    color3f outputs:out
                }

                def Shader "image_roughness"
                {
                    uniform token info:id = "ND_tiledimage_float"
                    asset inputs:file = @textures/brass_roughness.jpg@
                    float2 inputs:uvtiling = (1, 1)
                    float outputs:out
                }
            }
        }
    }

    def "Shaders"
    {
        def Shader "ND_UsdPreviewSurface_surfaceshader"
        {
            uniform token info:id = "ND_UsdPreviewSurface_surfaceshader"
            token outputs:surface
        }

        def Shader "ND_standard_surface_surfaceshader"
        {
            uniform token info:id = "ND_standard_surface_surfaceshader"
            token outputs:surface
        }
    }

    def "NodeGraphs"
    {
        def NodeGraph "NG_brass1"
        {
            color3f outputs:out_color.connect = </MaterialX/NodeGraphs/NG_brass1/image_color.outputs:out>
            float outputs:out_roughness.connect = </MaterialX/NodeGraphs/NG_brass1/image_roughness.outputs:out>

            def Shader "image_color"
            {
                uniform token info:id = "ND_tiledimage_color3"
                asset inputs:file = @textures/brass_color.jpg@ (
                    colorSpace = "srgb_texture"
                )
                float2 inputs:realworldimagesize = (0.5, 0.5)
                float2 inputs:realworldtilesize = (0.5, 0.5)
                float2 inputs:uvtiling = (1, 1)
                color3f outputs:out
            }

            def Shader "image_roughness"
            {
                uniform token info:id = "ND_tiledimage_float"
                asset inputs:file = @textures/brass_roughness.jpg@
                float2 inputs:uvtiling = (1, 1)
                float outputs:out
            }
        }
    }
}

def Xform "Teapot" (
    kind = "component"
)
{
    def Mesh "teapot_MeshShape" (
        prepend apiSchemas = ["MaterialBindingAPI"]
    )
    {
        uniform bool doubleSided = 1
        float3[] extent = [(-1.176974, -0.591498, -0.808233), (0.990245, 0.874611, 0.791548)]
        int[] faceVertexCounts = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ... (truncated)]
        int[] faceVertexIndices = [0, 6000, 5971, 0, 5970, 6000, 5970, 1, 6000, 1, 5972, 6000, 6000,... (truncated)]
        rel material:binding = </MaterialX/Materials/Tiled_Brass>
        normal3f[] normals = [(0.098006964, -0.99509066, -0.013756995), (0.09332999, -0.99505883, -0... (truncated)]
            interpolation = "vertex"
        )
        uniform token orientation = "rightHanded"
        point3f[] points = [(0.007673, -0.591496, -0.00914), (0.00763, -0.591496, -0.009326), (0.007... (truncated)]
        texCoord2f[] primvars:st = [(0.016655, 0), (0.049989, 0), (0.083322, 0), (0.116655, 0), (0.1... (truncated)]
            interpolation = "vertex"
        )
        uniform token subdivisionScheme = "none"
    }
}