The NVIDIA® Material Definition Language (MDL) SDK is an open-source set of tools that enable the integration of physically-based materials into rendering applications.
This README introduces the MDL SDK. It describes the target audience, the purpose of the SDK, an example workflow, and running example programs that illustrate the implementation of core MDL concepts.
For additional information:
- For installation instructions, see "Building the MDL SDK from Source"
- For a brief introduction to MDL, see "What is MDL"
Software developers integrating MDL into applications with 2D or 3D graphics capabilities.
Prerequisite skills:
- A working knowledge of C++
- Familiarity with fundamental 3D graphics concepts
NVIDIA Material Definition Language (MDL) is a domain-specific programming language that you use to define physically-based materials and lights for rendering. It is designed for the definition of the highest quality materials, fast rendering, and serves as an industry standard for material exchange.
Materials consist of two parts: a material definition and functions:
-
The material definition is declarative and based on a robust material model.
Example: The following code snippet is a simple declarative material definition. In the example, the material
diffusedefines a single material parameterdiffuse_color. This parameter is used to define the color for the diffuse reflection BSDFdiffuse_reflection_bsdf.export material diffuse( color diffuse_color = color(0.7)) = material( surface: material_surface ( scattering: df::diffuse_reflection_bsdf ( tint: diffuse_color ) ) ); -
The functions, which are written in a procedural programming language, compute parameter values for the material model.
Example: In the following code snippet, the
tilesfunction computes the color for a tile at a particular texture coordinate to define a checkerboard. The parameters define the number of tiles in one direction and the two colors for the black and white tiles. The computation uses math functions from the MDL standard math library.export color tiles( int no_tiles, color black = color(0.1), color white = color(0.8)) { float3 uvw = step(0.5, frac( no_tiles/2 * state::texture_coordinate(0))); float black_or_white = frac((uvw.x + uvw.y)*0.5)*2.0; return lerp( black, white, black_or_white); }The following code snippet uses the
tilesfunction to define a checkerboard material with eight times eight tiles per UV unit square.export material checker() = diffuse( tiles( 8));Refer to the Material Definition Language Handbook for more details on the MDL language.
Related information: For detailed information about MDL, the underlying concepts, and creating MDL materials, see the MDL documentation.
The following sections describe the purpose of the MDL SDK, an example workflow supported by the SDK, and a link to the installation instructions.
The MDL SDK is a toolkit delivered as an open-source C++ library. It is designed to support a wide range of material workflows in new or existing applications.
The following figure illustrates an example workflow for material creation:
The callouts in the figure are described below. Each callout describes how a specific SDK component supports this material workflow:
-
MDL modules: You use the module mechanism to package materials and functions for reuse. An MDL module contains one or more material and function definitions. When you load a module, it is parsed and validated by the MDL compiler and its content is stored in an internal database.
-
Internal database: The internal database provides access to all material and function definitions.
-
Transactions and call graphs: You create, edit, and store material instances and function calls using transactions. The results are stored in the internal database. From database entities, you can connect functions to material parameters and build call graphs that express complex materials.
-
Compiled materials: You can compile these graphs into a compact optimized representation, which is referred to as a compiled material. The compilation step includes inlining of call expressions, constant folding, and the elimination of common subexpressions.
-
Distilling: Distilling is a process for mapping or simplifying compiled MDL materials to more limited material models used by specific renderers.
-
Texture baking: Baking textures ensures optimal rendering performance for game engines.
-
Backends: A compiled material is the basis for code generation. The SDK provides the following backends for code generation:
- CUDA PTX
- LLVM IR
- HLSL and GLSL
- Native code generation for the CPU
The SDK also provides:
-
Example programs: To help you get started using the MDL SDK, working example programs are provided. See "Getting started using the SDK" for an introduction to these example programs.
-
Documentation: The MDL SDK includes a detailed MDL specification and conceptual, user, and API reference documentation. You can also access this documentation set from the NVIDIA Ray Tracing Documentation website.
Prebuilt MDL SDK packages for Linux, Windows, and macOS are available from the releases page.
See "Building the MDL SDK from Source" for system requirements and build instructions.
The MDL SDK includes example programs that cover the complete integration
workflow, from loading a module to rendering complete scenes. The example
sources are located in examples/mdl_sdk.
These examples form a practical introduction to the core SDK concepts.
| Goal | Example | What it demonstrates |
|---|---|---|
| Initialize the SDK | start_shutdown |
Loading, starting, and shutting down the SDK |
| Inspect a module | modules |
Loading a module and inspecting its exported definitions |
| Instantiate definitions | instantiation |
Creating material and function instances |
| Build call graphs | calls |
Connecting functions to material parameters |
| Compile materials | compilation |
Class and instance compilation |
| Generate target code | code_gen |
Generating HLSL, GLSL, PTX, or native code |
These focused examples show how to execute compiled material expressions with different backends and graphics APIs.
| Runtime | Example | Backend | Requirements |
|---|---|---|---|
| CPU | execution_native |
Native CPU | Basic SDK |
| CUDA | execution_cuda |
PTX | CUDA |
| OpenGL | execution_glsl |
GLSL | OpenGL |
| Vulkan | execution_glsl_vk |
GLSL | Vulkan |
The dxr
example is the most comprehensive renderer included with the MDL SDK. It
demonstrates end-to-end MDL integration in a DirectX Raytracing path tracer,
including loading and rendering complete glTF scenes.
| Example | Scene support | Backend | Requirements |
|---|---|---|---|
dxr |
Complete glTF and GLB scenes with MDL materials | HLSL, DirectX Raytracing | Windows, DirectX 12 |
These examples concentrate on individual backend and renderer integration techniques using simple procedural geometry.
| Example | Focus | Geometry | Backend |
|---|---|---|---|
df_native |
CPU execution of compiled distribution functions | Sphere or hair | Native CPU |
df_cuda |
GPU execution of compiled distribution functions | Sphere or hair | PTX |
df_vulkan |
Distribution functions in a Vulkan path tracer | Sphere | GLSL |
optix7 |
Inlining generated MDL code into OptiX shaders | Sphere or cube | PTX, OptiX 7 |
Several renderers also support automatic derivatives for texture filtering.
The spectral rendering guide explains how to integrate spectral rendering into an application using the
extended df_native example as its primary reference. The df_cuda,
df_vulkan, and dxr examples also demonstrate spectral rendering.
| Goal | Example | What it demonstrates |
|---|---|---|
| Bake material expressions | baking |
Baking material sub-expressions to textures or constants without distilling |
| Distill and bake materials | distilling |
Distilling compiled materials and baking material expressions |
| Prepare materials for Unity | distilling_unity |
Distilling and baking for the Unity material model |
| Render distilled materials | distilling_glsl |
Mapping distilled materials to GLSL shaders |
| Implement a distiller target | distilling_target |
Creating a custom distiller target plugin |
| Package materials | mdle |
Exporting and loading self-contained MDLE packages |
| Convert measured materials | axf_to_mdl |
Converting X-Rite AxF files to MDL |
| Goal | Example | What it demonstrates |
|---|---|---|
| Traverse a compiled material | traversal |
Reconstructing compilable MDL code |
| Build an MDL module | create_module |
Creating modules programmatically |
| Discover modules and packages | discovery |
Exploring configured MDL search paths |
| Present a material library | mdl_browser |
Implementing a material selection interface |
| Inspect module dependencies | dependency_inspector |
Listing imports and resource dependencies |
| Resolve MDL resources | entity_resolver |
Implementing a custom entity resolver |

