I have around 200 small spheres that are a part of a 3D data plot and I want to color them based on their z position. The way this is done is by making a material that uses a color ramp based on the z coordinate of the object, and applying the material to every sphere.
The problem is that I want to export this to a glb/glTF and the color ramp node doesn’t function when exported. How can I convert my 1 material into a simple base color for every sphere? It is ok if every single sphere has a different material, its just that doing this by hand is very time consuming.
I’m not sure how to generate 200x materials from the node graph, and it might be a bit slow to load in other software if you go that route. But two other options would be (a) bake to diffuse map, or (b) bake to vertex colors. I think I’d suggest (a) here, doing something like:
… the diffuse texture can probably be kept very small, since it’s just a texture equivalent of your color ramp.
Unfortunately both (a) and (b) will increase your file size as the number of spheres goes up, since the spheres have different vertex data… if that’s a problem I can try to suggest ways to reduce that size.
How would I make the material show different on different spheres? When I bake an image of a gradient and apply it to all my spheres, each sphere just shows the full color range.
You may want to start with longer a tutorial on Blender’s baking workflow and UV editor. The important thing to note here is that each sphere’s UVs determine how the texture mapped onto the sphere. If every sphere has the same UVs, they’ll all have the texture applied in the same way. If you select any one sphere and collapse its UVs to a small part of the texture (say in the purple region) then the entire sphere will be purple.
Vertex color baking is similar, but without the UVs and the texture. In the screenshot below I’ve connected “Object Location” to the color socket, but your gradient node would work the same way. Neither node can be exported, but they still work fine for baking.
Once you’ve selected all the objects and baked to their vertex colors, you can just disconnect that non-exportable node and connect the Vertex Color node instead. You should then get the same visual result, but stored in vertex colors that can be exported correctly.