Vertex painting on Instanced Meshes

Hello there,

I’ve placed several rocks on my landscape using the foliage tool. Now the simple question: Can I apply vertex painting on these rocks?

Simply selecting them while in the vertex paint mode doesn’t seem to work.

Thanks in advance.

1 Like

Hello, Braindrain85,

The way the foliage system works is: You have a lot of identical meshes with the same material, and then they are rendered as instances by the gpu (a single mesh with a lot of transformations) so that all the matching objects will be only one draw call instead of thousands.

The variations that you can get happen at the level of the GPU: Giving different transformations to them, for example, doesn’t change the fact that they are identical instances, so still a single draw call.

If you start adding specific variations that imply that the objects are not identical, you will start to negate the benefits of the system. Vertex painting is one of those things, so it doesn’t make sense to be able to use it. Also think of it this way: Those objects don’t exist at a logical level, they are clones that are generated as the gpu is rendering the scene. So you can’t click on them because they don’t exist, there is nothing to paint to.

Now, if you want variations within your instances, it is possible. You could make a material that gets something like the world location, or some other parameter that is different between your instances, and makes the shader calculate a different result. This is still the same material to the same objects, so still a single draw call, but the results you will get will have variations from instance to instance. There is also a material node that gives you a random integer seeded by your instance ID, so you can drive your variation out of that.

If you see the material of a foliage element like grass, you will see that the animation is being driven by the vertex shader with a world position offset. That is happening at GPU level, so it doesn’t need the CPU to give special instructions about each object and it is counting as a single draw call overall. But every instance looks different, thanks to the shader.

So, if your shader gives you different variations (both at a pixel shader and a vertex shader level), you get a more complex result. If you drive this for example with a map, and check it against your world location, you can also get some manual control for this, similar to painting areas. But any particular control that you want for a particular instance (like it having a different material or vertex parameters) defeats the purpose of the instancing system altogether.

I hope this helps. All the best.

4 Likes

That is a very detailed answer. So I guess I will duplicate the rock and give it a different shader setup to paint it onto my landscape as instances or place a few of them by hand to use vertex painting.

Thank you very much. That helped a lot!