Skip to content
/ MDL-SDK Public

NVIDIA Material Definition Language SDK

License

Notifications You must be signed in to change notification settings

NVIDIA/MDL-SDK

Repository files navigation

An introduction to the NVIDIA MDL SDK

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.

Preface

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.

Related information:

Audience

Software developers responsible for integrating MDL into applications with 2D or 3D graphics capabilities.

Prerequisite skills:

  • A working knowledge of C++
  • Familiarity with fundamental 3D graphics concepts

What is MDL?

Material definition language

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.

Figure 1. MDL example material renderings

MDL materials

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 generic_diffuse_material defines a single material parameter diffuse_color. This parameter is used to define the color for the diffuse reflection BSDF diffuse_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 tiles function 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 tiles function to define a checkerboard material with eight times eight tiles per uv unit square.

      export material checker() = diffuse( tiles( 8));
    

    Refer to 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.

What is the MDL SDK?

The following sections describe the purpose of the MDL SDK, an example workflow supported by the SDK, and a link to the installation instructions.

Purpose

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.

Example usage

The following figure illustrates an example workflow for material creation:

Figure 2. Example of a material workflow supported by the MDL SDK

The callouts in the figure are described below. Each callout describes how a specific SDK component supports this material workflow:

  1. MDL modules: You use the module mechanism to package materials and functions for re-use. 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.

  2. Internal database: The internal database provides access to all material and function definitions.

  3. 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.

  4. 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.

  5. Distilling and texture baking: Distilling is a process for mapping or simplifying compiled MDL materials to more limited material models used by specific renderers.

  6. Texture baking: Baking textures ensures optimal rendering performance for game engines.

  7. Back ends: A compiled material is the basis for code generation. The SDK provides the following backends for code generation:

    • CUDA PTX
    • LLVM 12 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: A detailed MDL specification, as well as conceptual, user, and reference API documentation is included with the MDL SDK. You can also access this documentation set from the NVIDIA Ray Tracing Documentation website.

Installing the SDK

Installations for the MDL SDK are provided for Linux, Windows, and macOS. See "Building the MDL SDK from Source" for system requirements and installation instructions.

Getting started using the SDK

To help you get up to speed quickly, 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 are organized under "The basics", which covers concepts and implementation details that all software developers need to understand, followed by concepts and implementation details concerning the integration of MDL into a renderer.

The basics

The example programs listed in this section take you through the following steps:

  • Loading, instantiating, and compiling materials
  • Generating target code for a compiled material

Examples:

Integrating MDL into a renderer

The example programs listed in this section take you through the following steps:

  • Compiling and executing functions and materials
  • Distilling and baking, which is intended for game engines and renderers with limited capabilities

Compiling and executing functions

The example programs listed in this section describe the execution of code generated for various backends and execution of material expressions:

Examples:

Compiling and executing materials

The example programs listed in this section take you through the following steps:

  • Compiling and executing code for various backends
  • Compiling and executing distribution functions
  • Rendering with simple path tracers

Examples:

Distilling and baking

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.

Examples:

Other topics

The following examples cover topics and use cases that may be important to your particular MDL integration.

Examples:

Additional resources