How to get a material as input using Nodes?

I’ve just created my basic own shader using nodes.
It’s reading two texture inputs and combining the color of both masked by using the alpha of the first texture.

But I was thinking I should move the scope of this, so instead of using a TextureNode as input I want to use the resulting color of a material. There doesn’t seem to be a way to convert MeshStandardMaterial to MeshStandardNodeMaterial or am I missing something?

How can I use materials as inputs for a node, for example new MathNode(materialNodeA, materialNodeB, maskNode, MathNode.MIX);?

What are you hoping to achieve by using a material as an input to another material? I think that’s probably not the right way to think about it… a material is an entire shader program, and you want to compose the inputs to that shader program – not multiple shader programs.

MeshStandardMaterial has no relationship to the node material system; use StandardNodeMaterial instead. See this introduction.

Rather than combining entire materials, try to combine specific channels. For example, if you have two textures masked by alpha:

var material = new StandardNodeMaterial();
material.color = new MathNode(
  new TextureNode(...),
  new TextureNode(...),

Basically I’m trying to achieve a blend material node, where the blending is controlled by a texture mask.
I want two MeshStandardMaterials (not the Node version, because this is how they’re loaded by GLTFLoader) materials and all their properties to be blended by the mask, not just the textures.
See this example in Blender:

I don’t believe that is supported. You can individually mask each of the inputs to the material as shown above, or you can render the object twice with two different materials, each masked as needed.

Thank you for your response.
That’s unfortunate to hear, as I quite like the flexibility of the Material Node system :slight_smile:

I guess I could work around this limitation by creating a function to convert MeshStandardMaterial to MeshStandardNodeMaterial and blend the nodes like that.

Nothing that ends in -Material can be used as an input to another node, I think you’ve misunderstood.

The final effect you show in the Blender screenshot is possible, you just need to do it in a different way as mentioned above. It’s not a functional limitation, but you need to structure it with the understanding that the material builds a complete shader. Think of StandardNodeMaterial as more like the MaterialOutput, it is the last step of a very flexible chain.

Hmm you’re right, as I was starting with my idea I came to the same conclusion.

This problem can be solved in two ways (pictures are examples from Blender):

  1. Create a node that can take a shader as input, and create a Color and Alpha output

  2. Create a node that can take two shaders and a blend factor (value or texture) and outputs a new shader.

I unfortunately can’t contribute as I have no idea how to code that.
So for now I will use texture nodes as input.