BH3D Logo
The Hidden Costs of Material Graphs

The Hidden Costs of Material Graphs

By Ben Houston, 2023-05-30

The growing popularity of graph-based materials, particularly MaterialX, is a testament to the industry's push for innovation. Earlier this year, industry giants like Adobe, Autodesk, and Epic Games pledged to standardize MaterialX within USD files to streamline the exchange of high-quality 3D assets. Rumors also suggest that Apple may standardize MaterialX in USD files for their upcoming VR headset. While material graphs are indeed flexible, expressive, and powerful, they come with substantial costs when used for run-time dynamic loading in Web and Games. This article examines these hidden costs and proposes potential alternatives.

Identifying the Major Consumers of Interoperable 3D Content

Interoperable 3D content consumers can be broadly classified into two distinct segments, each with unique needs and characteristics:

Offline Consumers

Typically encompassing:

  • 3D Content Creation Editors & Renderers (VFX)
  • Game Content Creation Editors (Traditional Game Content)

Their primary requirements are:

  • Limited constraints on time & space, as they generally operate on high-end machines.
  • High flexibility, expressiveness, and the ability to re-edit or tweak the content.

Real-time Consumers

This segment usually includes:

  • Web 3D
  • Game Engine Runtime Imports (Custom Content)

Their fundamental needs are:

  • Efficient operation on consumer-grade hardware, including mid-range mobile phones, while keeping file sizes small and visuals impressive.

Realtime Shader Compilation has Been Costly

My personal journey took me from the "Offline" segment, where I worked in the VFX industry creating software tools, to the "Real-time" segment in 2013. Despite my appreciation for material graphs, the need to optimize real-time dynamic experiences on consumer-grade hardware led me away from them.

The primary reason? Compiling shaders at run-time is either incredibly time-consuming or not an option at all.

Consider these specifics:

  • WebGL shader compilation takes approximately 100ms for a typical PBR shader.
  • Unreal Engine and Unity do not support unique runtime shader compilation, perhaps due to the risk of poor user experiences or larger game downloads.

So, what's the alternative?

A Solution: Flat Opinionated Material Models

n my experience, the most effective strategy is to choose a material model and then pre-compile a shader for that. As you load materials at run-time, you can fit them into the pre-existing shader. For additional efficiency, you can pre-compile common subsets of the material model.

This approach requires selecting a flat material model that varies only in its factors, textures, and flags. Any graph component is likely to be unique, which makes it impossible to pre-compile or reuse.

Interestingly, this strategy aligns well with the Khronos glTF PBR model—a flat, opinionated material model that can be pre-compiled

Unveiling the Cost of Material Graphs

Using Opinionated Flat Material Models: < 0.2 seconds

By using a single flat material and reusing pre-compiled shaders, we can achieve a load time of less than 200ms. This efficiency results from initiating shader compilation before the model loading. As more models and materials are loaded, there is no need to compile new shaders, making the shader compilation overhead constant.

Using Unique Graphs Per Material Models: > 1.2 seconds

On the other hand, using unique materials for each node (12 + 1 materials) would result in a load time of at least 1.2 seconds on my M2 Mac Mini—and even worse on a low-end mobile phone. The shader compilation overhead grows linearly with the number of unique material graphs loaded.

Additional Use Cases for Flat Materials

Three GPU Pathtracer

The Three-GPU-Pathtracer project leverages flat materials to create a single shader capable of representing all materials in the scene. This approach allows each different material in the scene to drive the shader using just textures, factors, and flags, accessible via simple data textures. The shader is pre-compiled and optimized for the scene, resulting in a fast and efficient rendering pipeline.

Scalable 3D Preview Viewports

Visualizing thousands of models with materials simultaneously can be challenging if they all have unique shading models. The USD Preview Material addresses this issue to some extent. Its fixed functionality allows the pre-compilation strategy, which I described earlier, to optimize the scene.