Search Unity

Question compute shader vs normal shader(vertex position) which is better for vertex animation?

Discussion in 'General Graphics' started by ununion, Jun 25, 2022.

  1. ununion

    ununion

    Joined:
    Dec 2, 2018
    Posts:
    275
    I have lots of agents to do same animation ,so i decide to use vertex animation tech.
    i found that i could use compute shader or normal shader with vertex texture to implement it,
    so i want to know which is better?
     
  2. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    727
    That depends on a lot of factors. Generally, I would say if you want to reuse the mesh during multiple passes, I would use a compute shader, that way you don't have to redo the work. But if you only want to use it in one pass, a vertex shader has the advantage of not having to write the data unnecessarily once you are done with it, since it just goes straight to the next render stage.
     
  3. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    I recently wrote an animation and skinned mesh rendering system for DOTS. I wrote a custom compute skinning shader that was 50% faster than Unity's Hybrid Renderer implementation due to groupshared caching of skin matrices. I benchmarked this on an AMD GPU which benefits the most from this technique.

    Late in development of this system, I added Linear Blend Skinning shader graph node support, which reads skin matrices from a buffer and does skinning in the vertex shader. Turns out computing skin matrices in a compute shader (multiplying localToRoot and bindpose matrices) and then letting the vertex shader take over from there was the fastest approach, no matter how many shadow maps were rendered. I found this to be really surprising.
     
    wetcircuit and joshuacwilde like this.