To enable materialx, build USD with --materialx
option
python build_scripts\build_usd.py --materialx
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
usd_preview_surface_plastic.mtlx defines a material called USD_Plastic
using the UsdPreviewSurface
MaterialX node.
Flattening can be performed by using usdcat
usdcat --flatten basic.usda -o basic_flatten.usda
Example 2: BasicTextured with variants
basicTextured.usda - Teapot referring two MaterialX files
USD_Plastic
using the UsdPreviewSurface
MaterialX node.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).
#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>
}