To help you get up to speed quickly, the the MDL SDK provides many example programs that you can use as a starting point for the integration of MDL into your application.
The example programs presented in The Basics cover concepts and implementation details that all software developers need to understand. The example programs presented in Integrating MDL into a Renderer cover important concepts and implementation details to consider for this task.
Note: For a description of how the example programs can be compiled, see Getting Started.
The programs listed in this section illustrate standard workflow tasks: loading, instantiating, and compiling materials, and generating target code for a compiled material.
Basic SDK concepts:
Example for Starting and Shutting Down the MDL SDK API shows how to start and shutdown the MDL SDK API
Loading a module and inspecting materials and functions exported from the module:
Example for MDL Modules shows how to load an MDL module and inspect its contents
Example for Instantiation of MDL Definitions shows hot to instantiate material and function definitions
Creating call graphs and attaching functions to material parameters:
Example for Function Calls shows how to create a textured material by using a series of function calls
Compiled materials -- creating a compact and optimized representation of your material instance:
Example for Compilation of MDL Materials shows how to perform class and instance compilation of material instances
Overview of target code generation -- common steps for all renderers:
Example for Generating Shader Code for an MDL Material shows how to generate HLSL, GLSL, or PTX code for a compiled material
The example programs listed in the following sections take you through the following steps:
The example programs listed in this section describe the execution of code generated for various backends and execution of material expressions:
CPU baking:
Example for Execution of Compiled MDL Materials (CPU) shows how to execute material sub-expressions of a compiled MDL material for the native (CPU) backend
CUDA baking:
Example for Execution of Compiled MDL Materials (PTX) shows how to execute material sub-expressions of a compiled MDL material for the PTX backend with CUDA
OpenGL baking:
Example for Execution of Compiled MDL Materials (GLSL) shows how to execute material sub-expressions of a compiled MDL material for the GLSL backend with OpenGL
Vulcan baking:
Example for Execution of Compiled MDL Materials (GLSL Vulkan) shows how to execute material sub-expressions of a compiled MDL material for the GLSL backend with Vulkan
The example programs listed in this section take you through the following steps:
CUDA renderer -- using compiled BSDFs:
Example for Compiled Distribution Functions (PTX) shows how to use compiled material distribution functions in a CUDA based renderer
CPU renderer:
Example for Integrating MDL into a Renderer by Using the Native Backend (CPU) shows how to use compiled materials and an MDL native backend in a CPU-based renderer
Vulcan renderer:
Example for Compiled Distribution Functions (GLSL) shows how to use compiled materials and the GLSL backend in a Vulkan-based renderer
CUDA renderer -- enabling automatic derivatives:
Example for Texture Filtering with Automatic Derivatives shows how to enable automatic derivatives for texture filtering. Note: This example is useful for all renderers.
DirectX renderer:
Example for a Microsoft DXR-based MDL-enabled Path Tracer shows how to use MDL materials to render glTF scenes. Note: This is the most complete rendering example and it illustrates how to interface with MaterialX and glTF.
OptiX framework:
Example for Inlining MDL Code into Shaders (OptiX 7) shows how to optimize the evaluation of MDL materials for OptiX 7. OptiX is a scalable framework for building ray tracing based applications. (It is not a renderer.)
Distilling and baking enable you to optimize MDL materials for game engines and renderers with limited capabilities. The following examples provide an introduction to the MDL distilling mechanism and how to use it.
General introduction to distilling and baking:
Example for Material Distilling and Baking Distilling of compiled materials and baking of material sub-expressions.
Unity game engine -- distilling and baking:
Example for Material Distilling and Baking for Unity shows how to distill compiled materials and bake material sub-expressions for Unity
Simple GLSL rasterizer -- using baked textures or GLSL code generation:
Example for Using Distilled Materials in OpenGL shows how to map distilled materials to a GLSL shader
Example for custom Distiller plugin shows how to implement a custom distiller target
The following examples cover topics and use cases that may be important to your particular MDL integration.
Traversing a compiled material:
Example for Traversing Compiled Materials shows how to traverse compiled MDL materials to reconstruct compilable MDL code
Building a new MDL module:
Example for building of new MDL Modules shows how to build a new MDL module
Exploring the MDL module namespace:
Example for the Discovery of MDL Modules shows how to discover MDL modules in specified search paths and list them
Presenting discovered modules to a user:
Example Implementation of an MDL Browser shows how to implement a material selection dialog for a material library
Encapsulating an MDL material in MDLE:
Example for Integrating the MDL Encapsulated Format shows how to export and load materials or functions using the MDL encapsulated format. Note: MDLE enables you to inline all external MDL dependencies. All textures and resources are stored in the package.
Converting an AxF file to MDL:
Example for converting from X-Rite AxF to MDL material formats shows how to convert an X-Rite AxF file to MDL