usdex.rtx#

usdex.rtx provides utility functions for creating, editing, and querying UsdShade data models which represent MDL Materials and Shaders for use with the RTX Renderer.

usdex.rtx.createMdlShader(
material: pxr.UsdShade.Material,
name: str,
mdlPath: pxr.Sdf.AssetPath,
module: str,
connectMaterialOutputs: bool = True,
) pxr.UsdShade.Shader#

Create a UsdShade.Shader as a child of the UsdShade.Material argument with the specified MDL

Parameters:
  • material – Parent UsdShade.Material for the shader to be created

  • name – Name of the shader to be created

  • mdlPath – Absolute or relative path to the MDL asset

  • module – Name of the MDL module to set as source asset sub-identifier for the shader

  • connectMaterialOutputs – If true, it creates the surface, volume and displacement outputs of the material and connects them to the shader output

Returns:

the newly created UsdShade.Shader. Returns an Invalid prim on error.

usdex.rtx.createMdlShaderInput(
material: pxr.UsdShade.Material,
name: str,
value: pxr.Vt.Value,
typeName: pxr.Sdf.ValueTypeName,
colorSpace: usdex.core._usdex_core.ColorSpace | None = None,
) pxr.UsdShade.Input#

Create an MDL shader input

If the shader input already exists and is a different type, defined in the current edit target layer -> it will be removed and recreated

If the shader input already exists and has a connected source -> the source will be disconnected before being set

Note

When creating texture asset inputs (diffuse, normal, roughness, etc.) it is important to set the colorSpace parameter so that the textures are sampled correctly. Typically, diffuse is “auto”, which resolves to “sRGB”. Normal, roughness, and other textures should be “raw”.

Parameters:
  • material – The UsdShade.Material prim that contains the MDL shader

  • name – Name of the input to be created

  • value – The value assigned to the input

  • typeName – The Sdf.ValueTypeName of the input

  • colorSpace – If set, the newly created input’s colorSpace attribute

Returns:

The newly created Usd.Shade.Input input. Returns an Invalid Usd.Shade.Input on error.

usdex.rtx.computeEffectiveMdlSurfaceShader(
material: pxr.UsdShade.Material,
) pxr.UsdShade.Shader#

Get the effective surface Shader of a Material for the MDL render context.

If no valid Shader is connected to the MDL render context then the universal render context will be considered.

Parameters:

material – The Material to consider

Returns:

The connected Shader. Returns an invalid object on error.

usdex.rtx.addDiffuseTextureToPbrMaterial(
material: pxr.UsdShade.Material,
texturePath: pxr.Sdf.AssetPath,
) bool#

Add a diffuse texture to a PBR material

It is expected that the material was created by usdex.rtx.definePbrMaterial().

Note

The material prim’s “Color” input will be removed and replaced with “DiffuseTexture”. Due to the input removal this function should be used at initial authoring time rather than in a stronger layer.

Parameters:
  • material – The UsdShade.Material prim to add the texture

  • texturePath – The Sdf.AssetPath for the texture

Returns:

Whether or not the texture was added to the material

usdex.rtx.addNormalTextureToPbrMaterial(
material: pxr.UsdShade.Material,
texturePath: pxr.Sdf.AssetPath,
) bool#

Add a normal texture to a PBR material

It is expected that the material was created by usdex.rtx.definePbrMaterial().

Parameters:
  • material – The UsdShade.Material prim to add the texture

  • texturePath – The Sdf.AssetPath for the texture

Returns:

Whether or not the texture was added to the material

usdex.rtx.addOrmTextureToPbrMaterial(
material: pxr.UsdShade.Material,
texturePath: pxr.Sdf.AssetPath,
) bool#

Add an ORM texture to a PBR material

It is expected that the material was created by usdex.rtx.definePbrMaterial().

Note

The material prim’s “Roughness” and “Metallic” inputs will be removed and replaced with “ORMTexture”. Due to the input removal this function should be used at initial authoring time rather than in a stronger layer.

Parameters:
  • material – The UsdShade.Material prim to add the texture

  • texturePath – The Sdf.AssetPath for the texture

Returns:

Whether or not the texture was added to the material

usdex.rtx.addRoughnessTextureToPbrMaterial(
material: pxr.UsdShade.Material,
texturePath: pxr.Sdf.AssetPath,
) bool#

Add a roughness texture to a PBR material

It is expected that the material was created by usdex.rtx.definePbrMaterial().

Note

The material prim’s “Roughness” input will be removed and replaced with “RoughnessTexture”. Due to the input removal this function should be used at initial authoring time rather than in a stronger layer.

Parameters:
  • material – The UsdShade.Material prim to add the texture

  • texturePath – The Sdf.AssetPath for the texture

Returns:

Whether or not the texture was added to the material

usdex.rtx.addMetallicTextureToPbrMaterial(
material: pxr.UsdShade.Material,
texturePath: pxr.Sdf.AssetPath,
) bool#

Add a metallic texture to a PBR material

It is expected that the material was created by usdex.rtx.definePbrMaterial().

Note

The material prim’s “Metallic” input will be removed and replaced with “MetallicTexture”. Due to the input removal this function should be used at initial authoring time rather than in a stronger layer.

Parameters:
  • material – The UsdShade.Material prim to add the texture

  • texturePath – The Sdf.AssetPath for the texture

Returns:

Whether or not the texture was added to the material

usdex.rtx.addOpacityTextureToPbrMaterial(
material: pxr.UsdShade.Material,
texturePath: pxr.Sdf.AssetPath,
) bool#

Add an Opacity texture to a PBR material

It is expected that the material was created by usdex.rtx.definePbrMaterial().

Note

The material prim’s “Opacity” input will be removed and replaced with “OpacityTexture”. Due to the input removal this function should be used at initial authoring time rather than in a stronger layer.

These shader parameters will be set to produce better masked geometry: - MDL OmniPBR: opacity_threshold = float_epsilon (just greater than zero) - UsdPreviewSurface: ior = 1.0 - UsdPreviewSurface: opacityThreshold = float_epsilon (just greater than zero)

Parameters:
  • material – The UsdShade.Material prim to add the texture

  • texturePath – The Sdf.AssetPath for the texture

Returns:

Whether or not the texture was added to the material