all  /  test_assets  / MaterialXTest  / basic_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

basic_flatten.usda

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

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 "Shaders"
    {
        def Shader "ND_UsdPreviewSurface_surfaceshader"
        {
            uniform token info:id = "ND_UsdPreviewSurface_surfaceshader"
            token outputs:surface
        }
    }
}

def Sphere "sphere" (
    prepend apiSchemas = ["MaterialBindingAPI"]
)
{
    rel material:binding = </MaterialX/Materials/USD_Plastic>
}