MDL Distill and Bake

Overview

Distill and Bake Extension

MDL distilling refers to the process of simplifying and converting full-fidelity MDL materials to UsdPreviewSurface for improved portability and rendering performance. The selected MDL materials are distilled, input textures are baked, and a corresponding UsdPreviewSurface UsdShade Graph is created. When working with complex materials, especially those with many interconnected functions and procedural elements, the evaluation and computation required during rendering can be resource-intensive.

To address this, distilling involves analyzing the structure and behavior of the material and identifying opportunities to simplify or optimize the calculations without significantly affecting the visual appearance. This process aims to reduce the overall complexity of the material, resulting in faster rendering times, improved performance, and portability to other USD-compliant software.

The current release supports the following mappings:

  • diffuseColor

  • emissiveColor

  • clearCoatRoughness

  • normal

The extension adds a “Distill and Bake” option to the right-click context menu in the stage window. You can select multiple USD materials at once to be distilled. The selected materials’ textures are baked, and a UsdPreviewSurface shader is created. The output of the UsdPreviewSurface shader is connected to the surface input of the material.

Installation

  1. To enable the extension, go to Window > Extensions to open the extension panel.

  2. In the search box, enter “distill” (1), and select the “Refresh” menu item from the hamburger menu (2)(3) .

  3. Install and enable the MDL Distill and Bake Extension.

Distill and Bake Extension Menu

Usage

To use the extension:

  1. Set the resolution and sampling preferences from Edit > Preferences under the “Materials” tab (1)(2).

Distill and Bake Prefs
  1. Select an MDL material in the scene from the stage property window.

  2. Right-click on the material and choose “Distill and Bake” from the dropdown menu (1).

  3. Select a directory to store the baked texture maps in the file browser that appears.

  4. To verify the distilled material, right-click on the material that went through the distillation process and choose “Open in MDL Material Graph” from the dropdown menu. This will open the material graph editor (2).

Distill and Bake Menu
  1. The material graph will display the distilled UsdPreviewSurface shader and the original MDL material.

  2. To see the results, disconnect the mdl:surface port from the “Shader” node and connect the UsdPreviewSurface material to the now-empty port (1)(2). This step is not necessary when using this representation in other USD-compliant software, as the MDL context will be ignored, and only the surface context will be used.

Distill and Bake Graph

Scripting

You can invoke the extension via Python. The following are function descriptions and examples.

class MdlDistillAndBake

Constructor

  • usd_prim (Usd.Prim): The prim to distill and bake to UsdPreviewSurface (default: None).

  • output_folder (str): The output folder for texture maps. If not set, a temporary folder is created and deleted when the extension is unloaded (default: None).

  • output_samples (int): The number of samples for baking (default: 1).

  • output_resolution (int): The baking resolution (default: 128).

Distill and Bake

  • distill()

Get parameter ranges and defaults

  • get_baking_resolution_min()

  • get_baking_resolution_max()

  • get_baking_resolution_default()

  • get_baking_samples_min()

  • get_baking_samples_max()

  • get_baking_samples_default()

Examples

Distill and bake a given material and choose the destination folder for texture maps

Assuming an OmniGlass is attached to a USD Prim:

import omni.mdl.distill_and_bake
import omni.usd

stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath('/World/Looks/OmniGlass')
distiller = omni.mdl.distill_and_bake.MdlDistillAndBake(prim, output_folder='D:/temp')
distiller.distill()

Distill and bake all materials in a stage

from pxr import UsdShade
import omni.mdl.distill_and_bake

stage = omni.usd.get_context().get_stage()
for prim in stage.Traverse():
    if UsdShade.Material(prim):
        matname = prim.GetPath()
        print(matname)
        distiller = omni.mdl.distill_and_bake.MdlDistillAndBake(prim)
        distiller.distill()

Known Limitations

  • A material needs to be bound to a USD Prim in order to be distilled and baked.

  • UDIMs are not currently supported.

  • Some things such as Subsurface Scattering do not translate to the UsdPreviewSurface.

  • Textures that have procedural components do not always transfer as expected, including some vMaterials.