Skip to content

How to use MaterialX shaders

Tugcga edited this page Aug 15, 2026 · 2 revisions

Consider, as example, the following robot model.

image_001

This is model from the game. We will recreate from scratch the simple shader, which use textures for this model.

Before we start, some prepare steps. At first, switch shading model to OSL. It's because MaterialX shader nodes translated into osl-shaders and in fact Cycles render this osl-shader.

image_002

At second, you need the addon MaterialXSI. It contains all built-in MaterialX nodes.

Ok, we a redy to construct the shader tree. This tree should use only MaterialX nodes, no other are not allowed. It's bacause to convert the shader tree into osl-shader it use built-in MaterialX functionallity. So, it understand only what it understand, nothing more.

Start by adding Surfacematerial node. It's the root node, where the MaterialX shader is start. And connect it to the material port of the root material node. Does not delete DiffuseBSDF node. It will used for fallbacks, if something go wrong and MaterialX will be fail to compile osl-shader.

image_003

The shader may start either from this Surfacematerial node or from Lama Surface. But Lama Surface is a part of special Lama family of nodes. Skip it, for simplicity.

Next add Surface node, and connect it to the Surfaceshader port. This node geather different aspect of the surface shader: how the surface looks (Bsdf), how it illuminate the light (Edf) and transparency (Opacity).

image_004

Next define the main diffuse layer of the shader. Add Oren Nayar Diffuse Bsdf node and connect it to Bsdf port of the Surface node.

image_005

For now it at least works. Not interesting, but wait a time.

image_006

Next we should assign an image texture to this diffuse layer. Add Image Color3 node and select the albedo texture.

image_007

But before it works, we should define UV-coordinates. And here is a terminolofy problem. In MaterialX there is a node Textcoord Vector2, which get required uv-channel. But it works for non-osl shaders. In OSL u and v channels are not texture coordinates, it,s baricentric coordinates of each triangle. S, for OSL we need another approach. We can get uv-coordinates by using geometry bproperties. So, add Geompropvalue Vector3 node, and define property name geom:uv. We need vector3 version, instead of Vector2, because in Cycles uv-coordinates stored in this form.

image_008

Next convert it to Vector2 by using Convert Vector3 Vector2 node. Connect it to Texture Coordinates port of the Image Color3 node.

image_009

And now the texture is visible.

image_011

Clone this wiki locally