Search Unity

Question Does anyone know how to convert this smear shader to work on a skinned mesh renderer?

Discussion in 'Shaders' started by Renegade_Wolf, Jul 30, 2022.

  1. Renegade_Wolf

    Renegade_Wolf

    Joined:
    Jan 17, 2022
    Posts:
    38
    Link to shader and effect in question: https://github.com/cjacobwade/HelpfulScripts/tree/master/SmearEffect

    So, I'd like to achieve a "smearing" effect on some components of my models that use a skinned mesh. The shader I linked achieves a look I'm going for:
    https://www.reddit.com/r/Unity3D/comments/4r1bgh/someone_made_a_smear_effect_shader_for_unity/

    However, it uses "renderer.material", which was automatically upgraded to GetComponent<Renderer>() for me, which I manually updated to search for a SkinnedMeshRenderer as that's what I have on my object.

    Skinned mesh renderers don't really work the same, vertex-wise, though, because they aren't moving the object through physical space. So in the code, I figured I needed to grab the vertex buffer and queue that up for the current and previous "positions".

    The problem I'm having now is, I have no idea how to use that information. I figure I'll probably need to run it through the code in his custom shader (as that introduces some noise I'd like to see), but I also don't want his shader overriding the one on my object, which is already highly customized.

    Perhaps there's a way I can achieve the same effect using shader graphs? How could I go about doing that? I attempted to add some smear, but I haven't figured out how to get the noise to work (and it was a smear constant, not positional smear).
     
  2. Renegade_Wolf

    Renegade_Wolf

    Joined:
    Jan 17, 2022
    Posts:
    38
    Just bumping this - unfortunately, shaders are not my strong suit, and I need to simultaneously keep my artstyle consistent while adding new things like this. Would appreciate any help. Thanks
     
  3. Renegade_Wolf

    Renegade_Wolf

    Joined:
    Jan 17, 2022
    Posts:
    38
    I hope it's alright to continue bumping this as long as it's unanswered
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    The skinned mesh’s per vertex previous frame position is stored in the mesh’s TEXCOORD4 if you have motion vectors enabled for the skinned mesh renderer. Unfortunately you can’t access TEXCOORD4 in Shader Graph if that’s what you’re currently using.
     
  5. Renegade_Wolf

    Renegade_Wolf

    Joined:
    Jan 17, 2022
    Posts:
    38
    Hmm, while I do have shadergraph as my main material, I am just trying to figure out how to either modify my shadergraph to achieve the smearing effect - or modify the smearing effect so that it can use a skinned mesh rather than the default, which relies on a normal renderer.

    It sounds like going through shadergraph isn't an option. Which means I have to modify the code to work for a skinned mesh renderer... I think maybe the TEXCOORD4 might be a starting point, although I don't know how useful it will be in converting the effect over because it currently relies on world position of the object and applies a noise curve to the vertices. Now I'd need to access all the vertices and apply the noise in the right way which I'm not sure how to do.

    Maybe a better question would be, has anyone created a working alternative of this smear effect but for skinned meshes, rather than for moving meshes through space?
     
  6. Renegade_Wolf

    Renegade_Wolf

    Joined:
    Jan 17, 2022
    Posts:
    38
    Bumping again.
     
  7. Renegade_Wolf

    Renegade_Wolf

    Joined:
    Jan 17, 2022
    Posts:
    38
    Trying again.