Material Layers
How it worksLayerShaders

What are LayerShaders

Every LayerShader is a gdshader with the additions that connect it to the layer chain above and below.

A LayerShader is a normal gdshader with three additions that turn it from a regular shader to a shader that can connect to the layer below and the layer above it. See the Architecture Overview for where they fit.

LayerShaders are used in LayerMaterials. There are 4 types of LayerShaders, each one for a LayerMaterial type - SurfaceShader, MaskShader, OverlayShader and DataShader. See What are LayerMaterials.

The three parts that make it work:

  1. An include at the top: #include "res://addons/material_layers/shaders/layer_lib.gdshaderinc" - enables the layer variables and macros the rest of the system depends on. A LayerShader can't work without it.

  2. A setup macro per function: SETUP_*_VERTEX; as the first line of vertex(), SETUP_*_FRAGMENT as the first line of fragment(). This enables the layer variables used to output and reference layers.

    For example in a SurfaceShader, SETUP_SURFACE_VERTEX at the top of vertex(), SETUP_SURFACE_FRAGMENT at the top of fragment().

  3. LayerShader-type specific layer variables: Each LayerShader type has its own set of layer variables. These are used to output material properties, read previous layers and blend layers together. See Layer Variables.

    LAYER_OUT_*, LAYER_BELOW_*, LAYER_BLEND_*, LAYER_BASE_* etc.

That's it. Nothing else about writing gdshader changes. You still write triplanar projections, sample textures, use vertex colors - whatever you want. Just make sure to use the correct layer variables when outputting and reading layers and material properties.

See the shader type pages for each type: SurfaceShader, MaskShader, OverlayShader, DataShader.

YoutubePatreonDocsAssetsTwitter

©2026 Foyezes