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
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
Sounds like De Blob then 
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.
So you want to do something like [Tag: The power of Paint][1]? [1]: https://www.youtube.com/watch?v=QnE--7Zq5K0
– Bunny83I 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.
– aditya007