Default NodeMaterial vertex color input to white if attribute doesn't exist on mesh

At the moment it seems like it isn’t possible to make a generic NodeMaterial() that:

  • Uses vertex colors
  • And also works for meshes that don’t include vertex colors

This is because the vertex color input returns zero vector when attribute isn’t defined, so any material that uses the vertex color input will inevitably render black when applied to a mesh or mesh primitive that doesn’t inlcude vertex colors.

I think a best solution would be to make InputBlock of color type return a vec4(1.0) when the vertex color attribute isn’t present. This way color input node would behave in expected way for meshes that don’t include color data.

For now I was able to come up with a workaround by creating a custom EnsureVertexColor node, but even that required overwriting NodeMaterial _prepareDefinesForAttributes method so that it also exposes a #define for vertex color. However, this is so convoluted workaround that hopefully an official way to use vertex color input on generic meshes will be added. :slightly_smiling_face:

You can create a input that you can fill from the code. That input will be a float (0 or 1). You can set it to 1 if the mesh has vertex color and 0 else. Then it is up to you to apply a fallback if that input is 0

That wouldn’t work work because it is possible that the material is shared between mesh parts/primitives that have different attributes.