Accessing a Custom Vertex Attribute in a Shader

Godot Version



I have a blender model that was generated with geometry nodes and has a custom vertex attribute that describes modified vertex normals.

Is there a way in gdshader or visual shading to access that custom attribute from a GLB export and apply it to the vertex normals?

This isn’t my area of expertise, so take this answer with a grain of salt. And, it would be nice if someone with more knowledge in this area could comment.

Currently it seems that custom vertex attributes (i.e. GLB attributes named with a starting _) are not imported.

However, additional TEXCOORD attributes (UV maps in blender) are imported as custom attributes, but it’s a bit strange.

In spatial shaders, the vertex shader is provided the variables CUSTOM0 through CUSTOM3, which seem to correspond to the imported GLTF attributes TEXCOORD_2 through TEXCOORD_9 (joined pairwise, e.g. TEXCOORD_2 and TEXCOORD_3 become CUSTOM0).

So, currently, it seems that to get custom vertex attributes from Blender, you’d need to store the data in additional UV maps. One issue I ran into while testing this is that Blender didn’t seem to export the UV maps in the order they were listed in, so it took a bit of experimentation to figure out the order of elements in the CUSTOM0 variable.

One easy alternative would be to just use vertex colors instead. These aren’t actually used as albedo color by default, so you could do whatever you want with the color in your shader, and they’re exported/imported in a reasonable manner.

Thank you for the reply. Thanks for linking to the code confirming that additional attributes aren’t imported, and for explaining how CUSTOM0-3 work. Vertex Colors is a good idea, I’ll see if I can pack my custom data into colors and then modify it from there.

I also came across this Blender technique which will apply my custom vertex normals to the geometry directly, and that seems to work as well for my use case. Although doing it in the shader would be more flexible and would allow for some more complicated shading techniques