MaterialX
MaterialX is an open standard for the exchange of rich material and look-development content across applications and renderers.
Top Related Projects
glTF – Runtime 3D Asset Delivery
Universal Scene Description
Mitsuba 2: A Retargetable Forward and Inverse Renderer
Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
Quick Overview
MaterialX is an open standard for representing rich material and look-development content in computer graphics. It provides a flexible and extensible system for defining materials, lights, and related data that can be used across various digital content creation tools and rendering systems.
Pros
- Cross-platform compatibility and interoperability between different 3D content creation tools
- Extensible and customizable to support various material models and rendering techniques
- Strong industry adoption and support from major studios and software vendors
- Comprehensive documentation and examples for easy integration
Cons
- Learning curve for developers new to material description languages
- Limited real-time rendering support in some implementations
- Potential performance overhead for very complex material networks
- Ongoing development may lead to occasional breaking changes in newer versions
Code Examples
- Creating a basic material:
#include <MaterialXCore/Document.h>
namespace mx = MaterialX;
// Create a document and add a material
mx::DocumentPtr doc = mx::createDocument();
mx::MaterialPtr material = doc->addMaterial("MyMaterial");
// Add a simple shader node
mx::NodePtr shaderNode = doc->addNode("standard_surface", "StandardSurface", "surfaceshader");
material->setShaderNodeDef(shaderNode);
// Set base color
shaderNode->setInputValue("base_color", mx::Color3(0.8f, 0.2f, 0.2f));
- Loading and modifying an existing MaterialX document:
#include <MaterialXFormat/XmlIo.h>
// Load a MaterialX document from file
mx::DocumentPtr doc = mx::createDocument();
mx::readFromXmlFile(doc, "example.mtlx");
// Modify a node parameter
mx::NodePtr node = doc->getNode("MyNode");
if (node)
{
node->setInputValue("roughness", 0.5f);
}
// Save the modified document
mx::writeToXmlFile(doc, "modified_example.mtlx");
- Creating a node graph:
// Create a node graph
mx::NodeGraphPtr nodeGraph = doc->addNodeGraph("MyNodeGraph");
// Add nodes to the graph
mx::NodePtr noise = nodeGraph->addNode("noise2d", "Noise", "float");
mx::NodePtr multiply = nodeGraph->addNode("multiply", "Multiply", "float");
// Connect nodes
multiply->setConnectedNode("in1", noise);
multiply->setInputValue("in2", 2.0f);
// Create an output for the node graph
mx::OutputPtr output = nodeGraph->addOutput("out", "float");
output->setConnectedNode(multiply);
Getting Started
To get started with MaterialX:
-
Clone the repository:
git clone https://github.com/AcademySoftwareFoundation/MaterialX.git
-
Build the library:
cd MaterialX mkdir build cd build cmake .. cmake --build . --config Release
-
Include MaterialX in your project:
#include <MaterialXCore/Document.h> #include <MaterialXFormat/XmlIo.h> // Your MaterialX code here
-
Link against the MaterialX libraries in your project's build system.
Competitor Comparisons
glTF – Runtime 3D Asset Delivery
Pros of glTF
- Widely adopted industry standard for 3D asset exchange
- Extensive ecosystem with numerous tools and viewers
- Efficient binary format for optimized file size and loading
Cons of glTF
- Limited support for advanced material definitions
- Less flexibility for custom extensions and properties
- Primarily focused on real-time rendering use cases
Code Comparison
glTF (JSON part):
{
"materials": [{
"name": "Material",
"pbrMetallicRoughness": {
"baseColorFactor": [1.0, 0.0, 0.0, 1.0],
"metallicFactor": 0.5,
"roughnessFactor": 0.1
}
}]
}
MaterialX:
<materialx version="1.38">
<material name="Material">
<shaderref name="SR_Material" node="StandardSurface">
<bindinput name="base_color" type="color3" value="1.0, 0.0, 0.0" />
<bindinput name="metalness" type="float" value="0.5" />
<bindinput name="specular_roughness" type="float" value="0.1" />
</shaderref>
</material>
</materialx>
This comparison highlights the different approaches to material definition between glTF and MaterialX, with glTF using a more compact JSON format and MaterialX utilizing a more extensible XML-based structure.
Universal Scene Description
Pros of OpenUSD
- More comprehensive ecosystem for 3D content creation and exchange
- Broader industry adoption and support from major studios
- Extensive documentation and examples for various use cases
Cons of OpenUSD
- Steeper learning curve due to its complexity and extensive feature set
- Larger codebase and potentially higher resource requirements
- Less focused on material representation compared to MaterialX
Code Comparison
MaterialX example:
<materialx version="1.38">
<standard_surface name="my_material">
<input name="base_color" type="color3" value="0.8, 0.2, 0.1"/>
<input name="roughness" type="float" value="0.5"/>
</standard_surface>
</materialx>
OpenUSD example:
def Xform "Sphere" (
kind = "component"
)
{
def Sphere "Geometry"
{
double radius = 1
color3f[] primvars:displayColor = [(0.8, 0.2, 0.1)]
}
}
Both repositories focus on different aspects of 3D content creation. MaterialX specializes in material definition and exchange, while OpenUSD provides a more comprehensive framework for describing entire 3D scenes, including geometry, materials, and animation. The choice between the two depends on specific project requirements and workflow integration needs.
Mitsuba 2: A Retargetable Forward and Inverse Renderer
Pros of Mitsuba2
- More focused on physically-based rendering and light transport simulation
- Supports advanced features like spectral rendering and polarized light transport
- Offers a Python-based scene description language for flexibility
Cons of Mitsuba2
- Steeper learning curve due to its specialized nature
- Less emphasis on material definition and exchange compared to MaterialX
- Smaller community and ecosystem
Code Comparison
MaterialX (Node definition):
<nodedef name="ND_plastic_surface" node="plastic_surface">
<input name="diffuse_color" type="color3" value="0.18, 0.18, 0.18"/>
<input name="specular_color" type="color3" value="1, 1, 1"/>
<input name="roughness" type="float" value="0.3"/>
<output name="out" type="surfaceshader"/>
</nodedef>
Mitsuba2 (Scene description):
scene = mi.load_dict({
'type': 'scene',
'integrator': {'type': 'path'},
'bsdf': {
'type': 'plastic',
'diffuse_reflectance': {'type': 'rgb', 'value': [0.18, 0.18, 0.18]},
'specular_reflectance': {'type': 'rgb', 'value': [1, 1, 1]},
'roughness': 0.3
}
})
Both examples define a plastic material, but Mitsuba2 uses a Python-based scene description, while MaterialX uses XML for node definitions.
Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
Pros of pbrt-v3
- More focused on physically-based rendering techniques
- Includes a comprehensive book explaining the implementation details
- Offers a wider range of rendering algorithms and techniques
Cons of pbrt-v3
- Less emphasis on material definition and exchange
- May be more complex for beginners to understand and use
- Limited integration with existing content creation tools
Code Comparison
MaterialX example (material definition):
<material name="plastic">
<shaderref name="plastic_shader" node="standard_surface">
<bindinput name="base_color" type="color3" value="0.8, 0.2, 0.2" />
<bindinput name="specular_roughness" type="float" value="0.2" />
</shaderref>
</material>
pbrt-v3 example (material definition):
Material "plastic" "color Kd" [0.8 0.2 0.2] "float roughness" [0.2]
Shape "sphere" "float radius" [1]
Both repositories serve different purposes in the computer graphics ecosystem. MaterialX focuses on standardizing material and look development across various tools and renderers, while pbrt-v3 is a physically-based renderer implementation with educational value. The code examples show how materials are defined in each system, with MaterialX using an XML-based format and pbrt-v3 using a custom scene description language.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Introduction
MaterialX is an open standard for representing rich material and look-development content in computer graphics, enabling its platform-independent description and exchange across applications and renderers. Launched at Industrial Light & Magic in 2012, MaterialX has been a key technology in their feature films and real-time experiences since Star Wars: The Force Awakens and Millennium Falcon: Smugglers Run. The project was released as open source in 2017, with companies including Sony Pictures Imageworks, Pixar, Autodesk, Adobe, and SideFX contributing to its ongoing development. In 2021, MaterialX became the seventh hosted project of the Academy Software Foundation.
Quick Start for Developers
- Download the latest version of the CMake build system.
- Point CMake to the root of the MaterialX library and generate C++ projects for your platform and compiler.
- Select the
MATERIALX_BUILD_PYTHON
option to build Python bindings. - Select the
MATERIALX_BUILD_VIEWER
option to build the MaterialX viewer.
Supported Platforms
The MaterialX codebase requires a compiler with support for C++17, and can be built with any of the following:
- Microsoft Visual Studio 2017 or newer
- GCC 8 or newer
- Clang 5 or newer
The Python bindings for MaterialX are based on PyBind11, and support Python versions 3.6 and greater.
MaterialX Viewer
The MaterialX Viewer leverages shader generation to build GLSL shaders from MaterialX graphs, rendering the results using the NanoGUI framework.
Figure 1: Procedural and uniform materials in the MaterialX viewer
Figure 2: Textured, color-space-managed materials in the MaterialX viewer
Open Chess Set
The Open Chess Set is an open reference asset, consisting of a MaterialX file in the Standard Surface shading model and a geometry file in the glTF format. It was authored by Moeen Sayed and Mujtaba Sayed, and was contributed to the MaterialX project by Side Effects.
Figure 3: The Open Chess Set, rendered in Arnold for Maya
Figure 4: The Open Chess Set, rendered in Karma XPU for Houdini
Pre-Built Binaries
The following packages contain pre-built binaries for the latest release, including the MaterialX viewer, Python libraries, and example assets:
- Microsoft Windows (Visual Studio 2022, Python 3.12)
- MacOS (Xcode 15, Python 3.12)
- Linux (GCC 14, Python 3.12)
Additional Resources
- The Developer Guide contains a developer-oriented overview of MaterialX with API documentation.
- The Python Scripts folder contains standalone examples of MaterialX Python code.
- The JavaScript folder contains details on building JavaScript bindings for MaterialX.
- Presentations at ASWF Open Source Days and the SIGGRAPH Physically Based Shading Course provide details on the roadmap for MaterialX development.
Top Related Projects
glTF – Runtime 3D Asset Delivery
Universal Scene Description
Mitsuba 2: A Retargetable Forward and Inverse Renderer
Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot