Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Question Dots Animation Skinning

Discussion in 'DOTS Animation' started by deus0, Jan 16, 2021.

  1. deus0

    deus0

    Joined:
    May 12, 2015
    Posts:
    256
    Hi, I have been looking around but cannot work out how to transform my bone skinning code into GPU code with the new DOTS hybrid rendering v2.

    Currently my system on the CPU will do a simple calculation to transform each mesh vertex:

    var position = vert.position;
    var currentMatrix = skeletonAnimationLink.boneMatrixes[boneIndex];
    var originalMatrix = skeletonAnimationLink.originalMatrixes[boneIndex];
    position = math.transform(math.mul(currentMatrix, math.inverse(originalMatrix)), position);
    vert.position = position;
    chunkMeshAnimation.vertices[i] = vert;

    It will take the current bone matrix, the original, and simply transform the position by the difference.

    I tried to convert this code into a shader at first, but had significant problems getting a written shader to work in the new systems. So my next attempted solution was a shadergraph. I recall we used to be able to write a custom shader graph node, I might possibly need to do that again (if anyone has a suggestion).


    My latest try was to set it up so the matrix, or a series of them per bone, (original and latest) are set as variables that I can then update with my CPU systems. This would still be a significant speedup as it would move the vertex processing to the GPU. However the shader graph nodes didn't have any inputs for Vertex Position, so this stopped my progress.

    Does anyone have any ideas at how to solve this (the most performant way)? I am fine with writing a shader or a shadergraph, I just need to be able to send the bone data into the GPU and do the processing of vertexes there.

    Edit: Something like this might be possible I mean as a shadergraph. It just does not seem like a good solution. I'm not sure how to pass in the Bone Index, and then chose a property based on it.


    I think shadergraph is limited so it's probaly best to write a shader. But it seems very difficult to write shaders for shadergraph, possibly impossible? If there's any examples, please let me know.
     
    Last edited: Jan 16, 2021
  2. kite3h

    kite3h

    Joined:
    Aug 27, 2012
    Posts:
    197


    Use Custom function node.
     
    deus0 likes this.
  3. deus0

    deus0

    Joined:
    May 12, 2015
    Posts:
    256
    Thanks! I ended up writing a custom shader instead and used compute buffers to set data in them.
     
  4. kite3h

    kite3h

    Joined:
    Aug 27, 2012
    Posts:
    197
    I also use same way.
     
    deus0 likes this.