---
title: "Material Graphs"
description: "Node-based materials for MavonEngine — made in the level editor, compiled to three.js TSL and put on primitives, with parameters, textures, noise and subgraphs."
canonical_url: "https://mavonengine.com/core-concepts/material-graphs"
---

> Index of every page on this site: [llms.txt](https://mavonengine.com/llms.txt)

A material graph is a material made of nodes. It compiles to a three.js [TSL](https://github.com/mrdoob/three.js/wiki/Three.js-Shading-Language) node material (`MeshStandardNodeMaterial`), so it runs on the WebGL 2 and the WebGPU backend of the [renderer](https://mavonengine.com/core-concepts/game-loop#renderer). You make them in the [level editor](https://mavonengine.com/core-concepts/level-editor)'s **Graphs** view, which shows a live preview of the material over the nodes.

Material graphs use the same file format, editor and [subgraphs](https://mavonengine.com/core-concepts/logic-graphs#subgraphs) as [logic graphs](https://mavonengine.com/core-concepts/logic-graphs): `graphs/<name>.graph.json` with `"kind": "material"`.

## Using one

Pick it as the **material graph** of a [primitive](https://mavonengine.com/core-concepts/scenes#built-in-types-client) in the Properties panel, or set its `materialGraph` prop in the scene file. Without one the primitive draws with its own material again.

```typescript
primitive.setMaterialGraph('lava')
primitive.setMaterialGraph(undefined) // back to its own material
```

On any mesh, through the game's library of material graphs. Every mesh using a graph shares one compiled material, and changing the graph (the editor does on every edit) swaps the new one onto all of them:

```typescript
import { materialGraphs } from '@mavonengine/core/Graph/Material/MaterialGraphs'

await materialGraphs.apply(mesh, 'lava')
materialGraphs.release(mesh) // stop following the graph, the material stays
```

## Nodes

<table>
<thead>
  <tr>
    <th>
      Category
    </th>
    
    <th>
      Nodes
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Output
    </td>
    
    <td>
      <strong>
        Material Output
      </strong>
      
      : Base Color, Opacity, Roughness, Metalness, Emissive, Normal, Position Offset. Inputs left unconnected keep the material's defaults. A graph has exactly one
    </td>
  </tr>
  
  <tr>
    <td>
      Surface
    </td>
    
    <td>
      <strong>
        UV
      </strong>
      
      , <strong>
        World Position
      </strong>
      
      , <strong>
        Local Position
      </strong>
      
      , <strong>
        World Normal
      </strong>
      
      , <strong>
        View Direction
      </strong>
    </td>
  </tr>
  
  <tr>
    <td>
      Texture
    </td>
    
    <td>
      <strong>
        Texture
      </strong>
      
      : samples a loaded texture <a href="/resources">
        resource
      </a>
      
       by name, at a UV. One that isn't loaded shows magenta
    </td>
  </tr>
  
  <tr>
    <td>
      Noise
    </td>
    
    <td>
      <strong>
        Perlin Noise
      </strong>
      
       (3D), <strong>
        Value Noise
      </strong>
      
       (2D)
    </td>
  </tr>
  
  <tr>
    <td>
      Input
    </td>
    
    <td>
      <strong>
        Float
      </strong>
      
      , <strong>
        Vec2
      </strong>
      
      , <strong>
        Vec3
      </strong>
      
      , <strong>
        Vec4
      </strong>
      
      , <strong>
        Color
      </strong>
      
      , <strong>
        Parameter
      </strong>
      
      , <strong>
        Time
      </strong>
    </td>
  </tr>
  
  <tr>
    <td>
      Math, Vector
    </td>
    
    <td>
      The same as in logic graphs: Add, Multiply, Mix, Clamp, Smoothstep, Remap, Sine, Fraction, … Combine, Split, Length, Dot, Normalize, Cross
    </td>
  </tr>
</tbody>
</table>

**Parameter** nodes read the graph's parameters, which become uniforms of the compiled material. **Comment** and **Group** nodes annotate the graph, as in logic graphs.

## Your own nodes

A material node needs a TSL implementation beside its definition. Register it with `registerNode()` and `registerTslNode()`, or from a plugin with `ctx.registerNode(definition, tsl)`, see [Plugins](https://mavonengine.com/tooling/plugins#graphs-and-nodes). A node that only works on the WebGPU backend sets `requires: 'webgpu'`, and the editor warns about it on WebGL 2.

## Compiling from code

```typescript
import { compileMaterialGraph } from '@mavonengine/core/Graph/Material/compileMaterialGraph'

const { material, parameters } = compileMaterialGraph(graph, {
  parameters: { glow: 2 },
  textures: name => game.resources.items[name],
})
parameters.glow.value = 3 // a uniform: changes without compiling again
```

A graph with problems throws a `MaterialGraphError` listing them.

## Sitemap

See the full [sitemap](https://mavonengine.com/sitemap.md) for all pages.
