How to paint textures onto objects (2D or 3D) and calculate percentage covered?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Will Nations
:warning: Old Version Published before Godot 3 was released.

Wanting to make a mechanic like Splatoon has.

  • 2D or 3D objects
  • can manipulate fluids in the environment that have their own texture (they would have a shader perhaps? idk)
  • if the fluids overlap with an object, it’s possible to “paint” the fluids texture over the underlying 2D/3D texture.
  • There is a way to calculate how much of the object’s area/surface area is covered by the fluid.
  • The functionality can account for multiple types of fluids and compare the results (top-most fluids win-out).

I’m not sure how you would actually program the “fluid sticking to object” and “calculate surface area covered” parts. Obviously you should be able to create a fluid dynamics simulation with Bullet or something (though I haven’t learned how you would do that either)…

I think I’ve found something that might be useful: Reddit - Dive into anything

It’s not a complete answer, but at least it shows where you should start.

henriquelalves | 2017-11-30 15:44

Thanks, I’ll look into this.

Will Nations | 2017-11-30 16:22

:bust_in_silhouette: Reply From: Will Nations

Quotes from reduz/Juan in the FB group:

“I would probably add something that maps triangles to UV and then have a manually unwrapped unique texture for the whole level where you paint. A 3D App can probably do such unwrap. You may need to do this in C++ for performance (using GDNative).”

“I think this needs to be done mostly in CPU and, at most, upload a texture to a shader to show different inks”

"You probably need to create a custom data structure for this on CPU, since you will need to splat around triangles and stuff.

I would use a BVH with triangles, and would store UVs for each triangle (you can search for how to build a BVH in a lot of articles).

you can raycast into the BVH to obtain a collision with a triangle, and then you can splat ink around by checking neighobouring triangles.

In the end all this works to splat on a texture where you store who owns the ink.

You can use the same when checking collision against the floor, to check who owns the ink."

“You will probably need to generate a secondary UV map (like, UV2) that covers all your paintable area in the scene and unwrap all your scene together. Blender can do this easily (just select all objects, press space and search for unwrap, it will unwrap all together to a single texture).”


So my understanding from that was that I have a texture broken up into tons of tiny transparent triangles. This texture is on all of the paintable materials wrapping the objects to make them paintable.

I could shoot a projectile of paint, have it “explode” a bit when it hits something, pop out a few smaller projectile CollisionObjects (bits of paint), all hidden within a particle effect. Then, when the bits of paint hit objects with a paintable material, I could grab the collision point, fetch which triangle it is on the paintable texture, and then color it and some neighboring triangles to simulate paint sticking onto the object.

This will do as an answer until a more detailed implementation can be made by someone down the line.