Texture painting with UV

Okay so this is quite a strage question. i had a game idea in mind, but im not quite sure if it could be done. so, the idea was that you are traveling around and recoloring the world. for example by touching something, it will become colored. the problem is that i want the object you can color to be UV-mapped, and only part you’re touching (for example by touching a building, it wont become fully colored, but rather colored in a small radius).

But to simplify the question, i want a kind of texture painting system where i could paint on any 3D object. but instead of just painting with one color, i could use a texture, wich would automaticly map to the premade UV-map

Thanks in Advance
//Gaffa

So you want to do something like [Tag: The power of Paint][1]? [1]: https://www.youtube.com/watch?v=QnE--7Zq5K0

I mentioned that i don't know much about JS so variable declaration could be wrong. The OP didn't even mentioned he is new to programming. So yeah, you ARE being mean. Edit : Ok, so i now get it why the syntax is wrong, i've corrected it. But, the other points remains valid.

2 Answers

2

Don’t do it with textures.
I have done something similar (technically, not ‘painting’ but damaging stuff) and painting textures is hard. The best thing you can do is to paint mesh vertex colors instead, and use a shader which utilizes those colors in any way you want (tint, change hue, draw holes or whatever). This will require your meshes to follow some rules for the result to look nice, i think it’s called Manifold mesh (connected surface without ‘breaks’). Also some extra tessellation in the mesh (unrelated to GPU tessellation) to alloy you paint the middle of a big plane etc.
To find which vertices to paint, you may or may not choose to use some lookup algorithm, such as an octree, but it won’t be necessary with low-vertex meshes. Try simple approach and see if it’s a bottleneck.

If for some reason you can’t use vertex coloring (non-manifold or too complex / too simple meshes), you can use a 3D texture instead. Simply create a 3D texture that you will map onto the bounds of your mesh / object in shader. Paint to this 3D texture, then read it in a shader. It seems like you would need a very high volume resolution, but with some smart techniques similar to distance field mapping and some extra offset (to make the edges look less regular) you can get very good results.

Both approaches (vertex abd 3D texture) worked for me very well

You can see it running here http://interactive.mandategame.com/mandateshipbuilder/shipbuilder.html Just wait for the scene to load, then switch to interactive mode (the rightmost button that resembles 'play' arrow). Then you can blow holes to both the shield and armor of the ship. This is the mesh painting approach, however, because of reasons mentioned above, I switched to the texture approach

Can you give a little more information on how you did it?

Hmm, yeah. Hey habfans7, please read answers to your questions, and accept them.

Sounds like De Blob then :slight_smile:

Shouldn’t be too hard - you’d have all your meshes UV mapped and textured already, but the strength of the texture should be multiplied by vertex colour/alpha.

Initialise all your meshes with a fully opaque vertex colour, say . Then, when you collide with a mesh, find the nearest vertex to the touched point (here and here if you need help), and reduce its opacity. In your shader, you’d use a lerp that blended between the “unpainted” and the “painted” texture based on the value of the vertex alpha to reveal more of the texture the longer it had been touched.

Ah thanks man :)

I just have a problem. I've managed to find the nearest Vector3 vertex point. the next step is the vertex color, but i dont really understand how that works. i want to color all the verticies white at start, but where i touch (the closest vertex) will become the standard texture as if it was uncolored.

You can easily infer the OP doesn't have a lot of experience, at least with Unity (may or may not be new), by the question itself. Not a thing wrong with that. Seriously not being mean, just pointing out facts here. (But c'mon, the code still wouldn't compile, surely that's kind of a mean thing to do in an answer. ;) )