Search Unity

Paint textures on plane in-game

Discussion in 'Scripting' started by unikum, Aug 26, 2019.

  1. unikum


    Oct 14, 2009
    I have found several solutions for painting color on meshes, but I need to be able to pick textures and paint out. Similar to how they do it in Garden Flipper. I can't use vertex painting because I need to be able to use a lot of textures. No need for normal maps or super high resolution. Only need to be able to paint textures with a brush on a base texture that a plane uses in its material. This feels like it shouldn't be that complicated.

    There is an asset that has this functionality, Mesh Painter, but it's a dll-file where all the magic happens so I can't easily figure out how that person did it.

    Anyone knows how to do this? Basically paint textures with a brush in real time, no complicated mesh, just plain 2D basically.

    Image from Garden Flipper where you can see the circular brush and different textures that has been painted out.
  2. Kurt-Dekker


    Mar 16, 2013
    The general solution to this isn't easy.

    If you pick a resolution, supply pre-made geometry textured uniformly and matched to a series of textures, you can use the barycentric coordinate from a raycast hit to draw stuff on the textures, and this will at least provide an initial approximation of the process.

    To get started, put a quad in front of your camera, put a write-enabled texture on it, and look into Physics.Raycast() to cast the mouse at the quad, and if you hit it, find where on the texture (barycentric coordinates) and set some pixels, and you can quickly get a feel for what you're up against.