MaterialX

repository·main·Indexed 24 days ago

https://github.com/academysoftwarefoundation/materialx

An open standard for representing rich material and look-development content in computer graphics. MaterialX enables platform-independent description and exchange of shading networks, patterns, texturing, and geometric assignments. Version 1.39 introduces updates to array type handling, standardized color space names aligned with ACES 1.2 OCIO, and new procedural, geometric, and math nodes. The project also provides JavaScript bindings generated via Emscripten for loading, modifying, and generating WebGL-compatible shader code.

Tokens
84K
Snippets
122
Records
335
Agent score
78%

What's inside MaterialX

  1. Overview of MaterialX Specification v1.39

    main

    MaterialX is an open standard for representing rich material and look-development content in computer graphics. It enables platform-independent description and exchange of shading networks, patterns, texturing, complex nested materials, and geometric assignments.

    Version 1.39 introduces several key architectural changes, including the separation of Geometry Extensions into a distinct document, updates to array type handling (now uniform and static length), and standardized color space names aligned with ACES 1.2 OCIO. It also expands the standard library with new procedural, geometric, math, adjustment, conditional, and channel nodes.

  2. Overview of MaterialX Python modules

    main

    MaterialX provides several Python modules that allow for programmatic interaction with the MaterialX ecosystem. The core functionality is split into specialized modules depending on whether you need to manipulate the core graph, handle XML serialization, or generate shaders (including OSL and GLSL support).

    Available modules include:

    • PyMaterialXCore: Provides access to the MaterialX core functionality.
    • PyMaterialXFormat: Provides support for XML serialization and deserialization.
    • PyMaterialXGenShader: Handles core shader generation.
    • PyMaterialXGenOsl: Handles OSL (Open Shading Language) shader generation (conditional build).
    • PyMaterialXGenGlsl: Handles GLSL shader generation (conditional build).
  3. Overview of pugixml in MaterialX

    main

    pugixml is a C++ XML processing library used within MaterialX for handling XML data. It provides a DOM-like interface for tree traversal and modification, an extremely fast XML parser that constructs a DOM tree from files or buffers, and an XPath 1.0 implementation for complex queries. It includes full Unicode support with automatic encoding conversions during parsing and saving.

    MaterialX-specific modifications: This specific distribution includes modifications to the original pugixml source to support:

    • Tracking for new-line characters.
    • Serialization of < and > characters instead of using &lt and &gt entities.
  4. Overview of MaterialX C++ Libraries

    main

    MaterialX is a collection of C++ libraries designed for managing complex shading and look development data. The ecosystem is divided into core data management, various shader generation backends, and language bindings:

    Core Libraries

    • MaterialXCore: Provides support for core MaterialX elements and graph traversal.
    • MaterialXFormat: Handles XML serialization and provides file accessor utilities.

    Shader Generation

    MaterialX supports generating shading language code through several specialized libraries:

    • MaterialXGenShader: The core shader generation support.
    • MaterialXGenGlsl: Generates GLSL shading language code.
    • MaterialXGenMdl: Generates MDL (Material Definition Language) code.
    • MaterialXGenOsl: Generates OSL (Open Shading Language) code.

    Bindings and Tools

    • PyMaterialX: Python wrappers for the C++ modules.
    • JsMaterialX: JavaScript bindings for the C++ modules.
    • MaterialXView: The default material viewer application.
    • MaterialXTest: A suite of unit tests for all MaterialX libraries.
  5. Explore MaterialX resources

    main

    Additional resources for working with MaterialX:

    • Developer Guide: Contains build and API documentation.
    • Python Scripts: Located in python/Scripts, these are standalone examples of MaterialX Python code.
    • JavaScript Bindings: Details on building JavaScript bindings can be found in the javascript/ folder.
  6. Explore MaterialX Standard Data Libraries

    main

    MaterialX provides several standard data libraries that contain node declarations, graph definitions, and shader generator source code. These libraries are organized by functional purpose:

    • Standard Pattern Library (stdlib): Contains core node definitions (stdlib_defs.mtlx) and nodegraph definitions (stdlib_ng.mtlx). It includes language-specific support for:
      • GLSL (genglsl)
      • OSL (genosl)
      • MDL (genmdl)
      • MSL (genmsl)
    • Physically Based Shading Library (pbrlib): Provides PBR-specific node declarations and nodegraph definitions, including language-specific implementations for GLSL, OSL, MDL, and MSL.
    • BxDF Graph Library (bxdf): Contains graph definitions for specific shading models, such as:
      • standard_surface.mtlx (Autodesk Standard Surface)
      • gltf_pbr.mtlx (glTF PBR)
      • usd_preview_surface.mtlx (UsdPreviewSurface)
      • lama (MaterialX Lama node set)
    • Color Management Library (cmlib): Provides language-independent MaterialX graphs for common color space transforms (e.g., acescg, srgb_displayp3, rec709_display).
  7. Understand the Shader Generation and Render Test Suite structure

    main

    The Test Suite is used to validate MaterialX by parsing input documents to identify renderable elements. It performs two main types of validation:

    1. ShaderGen tests: Uses appropriate shader generators to produce source code from MaterialX elements.
    2. Render validation tests: Compiles and/or renders the generated code to verify correctness.

    Folder Layout

    • Library Groupings: Input files are primarily grouped by library, such as stdlib and pbrlib.
    • Element Categories: Sub-folders group documents by element type (e.g., stdlib/math contains math-related .mtlx files like math.mtlx, trig.mtlx, etc.).
    • Dependencies: The Geometry and Images folders provide the necessary stock assets used during testing.
    • Utilities: The Utilities folder contains tools for rendering with testrender and light configuration specifications for hardware rendering.

    Configuration

    Execution options for Render tests are defined in the _options.mtlx file located at the top level of the test suite. This file can be edited locally to modify test behavior.

  8. Overview of MaterialX NPR Shading Nodes

    main

    The MaterialX NPR (Non-Photorealistic Rendering) library contains nodes specifically designed for illustrative and non-photorealistic shading styles. These nodes are conceptually separated from the Standard and Physically Based (PBR) libraries. The library is organized into three categories:

    1. NPR Application Nodes: Nodes like viewdirection that provide scene-level information.
    2. NPR Utility Nodes: Nodes like facingratio that perform geometric calculations useful for NPR.
    3. NPR Shading Nodes: Nodes like gooch_shade that implement specific non-photorealistic lighting models.
  9. Understand Operator node input naming conventions

    main

    Operator nodes process input streams to form an output. The naming of input ports follows specific conventions based on the operator type:

    1. Compositing Operators: Use fg (foreground) and bg (background) as input names. For float and color3 variants, an alpha port is also used. For the mix operator, use mix.
    2. Single-input Operators: Use in if there is exactly one input.
    3. Multi-input Operators: Use in1, in2, etc., if there is more than one input.

    If an implementation does not support a specific operator, it should generally pass through the bg, in, or in1 input unchanged.

      <multiply name="n7" type="color3">
        <input name="in1" type="color3" nodename="n5"/>
        <input name="in2" type="float" value="2.0"/>
      </multiply>
      <over name="n11" type="color4">
        <input name="fg" type="color4" nodename="n8"/>
        <input name="bg" type="color4" nodename="inbg"/>
      </over>
      <add name="n2" type="color3">
        <input name="in1" type="color3" nodename="n12"/>
        <input name="in2" type="color3" nodename="img4"/>
      </add>
  10. Convert and Adjust Colors

    main

    MaterialX provides several nodes for color space conversion and manipulation:

    • rgbtohsv: Converts RGB to HSV space (H and S range 0-1). Alpha is preserved.
    • hsvtorgb: Converts HSV to RGB space. Alpha is preserved.
    • hsvadjust: Adjusts an RGB color by converting to HSV, applying offsets/scales, and converting back. amount.x is hue offset (1.0 = 360°), amount.y is saturation scale, and amount.z is value scale.
    • saturate: Adjusts saturation using an amount multiplier. Uses lumacoeffs for desaturation calculation.
    • colorcorrect: A composite node for artist-friendly color correction. It combines hue, saturation, gamma, lift, gain, contrast, contrast pivot, and exposure adjustments.
  11. Chiang Hair Model Parameters and Components

    main

    The Chiang hair model describes scattering from a hair fiber modeled as a rough dielectric cylinder with tilted cuticle scales. It is implemented via the <chiang_hair_bsdf> node.

    Input Parameters

    • ior: The index of refraction ($\eta$).
    • absorption_coefficient: The absorption coefficient ($\sigma_a$).
    • cuticle_angle: The cuticle angle ($\alpha$), remapped from the input range $[0, 1]$ to $[-\pi/2, \pi/2]$.
    • roughness_R: Longitudinal variance $v$ for the R lobe.
    • roughness_TT: Longitudinal variance $v$ for the TT lobe.
    • roughness_TRT: Longitudinal variance $v$ for the TRT lobe.
    • roughness_R (azimuthal): Azimuthal logistic scale $s$ for the R lobe.
    • roughness_TT (azimuthal): Azimuthal logistic scale $s$ for the TT lobe.
    • roughness_TRT (azimuthal): Azimuthal logistic scale $s$ for the TRT lobe.

    Scattering Lobes

    The model defines several lobes with different scattering behaviors:

    • R (Reflection): Primary specular reflection.
    • TT (Transmission-Transmission): Light passing through the fiber.
    • TRT (Transmission-Reflection-Transmission): Light reflecting off the internal back surface.
    • TRRT+: An additional lobe used for complex scattering, which features uniform azimuthal scattering ($N_{TRRT+} = 1/(2\pi)$).
  12. Translate between shading models using Shading Translation Graphs

    main

    The MaterialX PBS Library includes specific nodegraphs designed to translate input parameters from one shading model to another. This allows for approximating the same visual results across different models by mapping their parameters to the target model's inputs.

    Currently supported translation graphs:

    • Autodesk Standard Surface to UsdPreviewSurface
    • Autodesk Standard Surface to glTF