Changing a mask on material dynamically based on per pixel collision

I recall seeing this feature done and tutorialized, but I can’t seem to pinpoint it with the right words.

What i’m looking forward is the path to make a material, that has a mask that changes its textures (like painting on) based on a per pixel mesh collision. For instance, here i’m making a paint gun. How do I have the material receive the hit and change the mask on the material (based on UV space) a pixel from 0 to 1. Like a splatter on a characters body.

I saw also saw an alternative technique with decals in this video, but I’m unsure of the basics to capturing the hit detection. My past experience with decals is the fact that they don’t follow the body like they should when the character mvoes.
Is it this possible or am I just crazy?


This is possible, but not trivial.

Normal decals are not very suitable for this kind of situation as they have a bit of overhead per decal, slowing your game down when you want to do Splatoon or Portal 2 amounts of paint. Additionally they don’t really handle deforming geometry such as characters well.

The most common technique to achieve this is to instead have a dynamic mask inside your materials that blends between the base material and the paint material. Every time you add new paint, you update this mask texture instead of adding a new decal. You could still use a decal texture if you want, but you would have to transform it into the UV space of the mask texture.

This way you have a fixed render cost regardless of the amount of paint. This also has the added benefit of allowing you more control over the way the paint is blended between splats.

I think the Dynamic Mask is exactly what I want. Never really prefered decals in any way since it gave me less control over how it blends with the material its displayed onto.

So I’m thinking of going with that, is there any documentation regarding dynamic masks and how it tracks a hit and change it on the material? I swore I saw something but nothing comes up, just random stuff with the words I search for.

Thanks Arnage

That’s the reason why I said it’s not trivial: I’m afraid there is no standard hit tracking mask that you can simply activate. You’ll have to build that yourself.

That makes sense. I’ll probably have to push that feature to a later date so I can put in some more effort in coming up with my own system. Thanks for all the help though.