Search Unity

Resolved How to Blend Between Animation and Vertex Displacement

Discussion in 'General Graphics' started by yzhao105, Jul 6, 2021.

  1. yzhao105

    yzhao105

    Joined:
    Sep 15, 2017
    Posts:
    28
    I wrote a vertex displacement shader for our artists to use on hair and clothes so that they don't have to add extra joints and make animations. But some of our existing models already have animations for hair and clothes, and sometimes the way the models' rigged doesn't really work with my shader. Our artists do not want to go back and repaint the weights for every model, and asked me if I can make them a slider to adjust how much the mesh is affected by bones or vertex shader. Is this even possible? I can't think of a way to do this.

    Any help will be appreciated!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    Nope.


    Unity applies skinning to meshes behind the scenes either on the CPU or with a hidden shader on the GPU that you cannot modify. By the time your shader gets access to the mesh it's no longer "skinned", but just a normal mesh that has been pre-deformed, so there's no way to go back to some version of the mesh without skinning.

    Well, that's not entirely true. You could store the original mesh positions in the vertex data and lerp back to that.

    But I'm going to stop you right there because you and your artists absolutely do not want to do that because what your artists want isn't the mesh prior to skinning, you want the mesh after skinning but just without those extra bones and weighted to another bone, which is impossible because you don't know where the other bone is and don't know what the weighting should be unless you redo the weighting on the mesh which the artists would have to do themselves which is the whole thing they're trying to avoid doing because they don't want to have to repaint the weighting on the mesh.

    *deep breaths*

    TLDR, go tell your artists to repaint the weights.

    And while they're at it, have them paint some vertex colors in the places where they want the shader to do less procedural deformation animation. That you can do.
     
    yzhao105 likes this.
  3. yzhao105

    yzhao105

    Joined:
    Sep 15, 2017
    Posts:
    28
    LOL, Thanks!

    I couldn't think of any way to fulfill their request. (And thanks for confirming this!) So I went ahead and wrote a script that basically does the repainting by removing specific bone's weight and adding another bone's weight in its place on a set of vertices, so that they don't need to repaint those themselves.

    And they did paint the vertex color, so I could use those.