Liquify and Image warping

Published June 15, 2016
Advertisement

[size=2]As a first go at a journal entry, just a simple topic:


For a feature for my little 3d painting app, I wanted to be able to warp source images to make them fit better onto 3d models. Never having done image warping before I quickly came to what I presume is the basis for how most people do it...

For a given source image, I created a corresponding sized 2d array of 2D vector floats, I'll call a 'vector map':

grid_zpsjkuagamp.png

Each vector represents a displacement (in pixel space) to find the source pixel for each destination pixel in the resulting image.

So the process to create the final image is as follows:


  1. [font=arial]Loop through all the destination pixels[/font]


  • [font=arial]For each xy, look up the corresponding vector in the vector map.[/font]


  • [font=arial]Add the vector to xy, to get a float source xy.[/font]


  • [font=arial]Look up the source pixel from the source image (using texture filtering if desired)[/font]


  • [font=arial]Copy the source pixel to the xy destination.[/font]



  • Here is an example, using a simple circle brush, with vector direction and magnitude depending on distance from the centre:


    liquify_zpsyan9p0ss.png

    And here is a more subtle brush just pushing in the direction of mouse drag:
    liquify2_zpsrb5unkrb.jpg

    It also occurs to me that it is fairly easy to extend this vector map to use systems such as a guidance mesh, or anchor and pull points. These could perhaps be done faster by other more direct methods, but as this is not CPU critical in my case it would fit the bill, and is very flexible.

    Next Entry 3D Painting App
    1 likes 1 comments

    Comments

    duckflock

    Nice! Just FYI, in mathematics a function that maps each coordinate point to a vector is called a vector field :)

    June 16, 2016 06:22 AM
    You must log in to join the conversation.
    Don't have a GameDev.net account? Sign up!
    Advertisement