Search Unity

How does Unity skinned animation affect the precision of vertex data

Discussion in 'General Graphics' started by hong1991, Mar 4, 2019.

  1. hong1991

    hong1991

    Joined:
    Sep 16, 2017
    Posts:
    14
    I am writing a outline shader. For a better result, i used a second normal, and pack it with tangent.
    how i packed:
    tangent = (tangent + 1)*0.5;
    secondNormal = (secondNormal + 1)*0.5;
    packed = (floor(tangent*100) + secondNormal)*0.01;

    It works fine when i am using it with a Mesh Renderer, But wrong with a Skinned Mesh Renderer. I speculate that it was a precision issue. I turn off all the vertex compression and mesh compression. It doesn't help. What can it be?

    Or is there any way that i can use a second normal in shader?
     
    Last edited: Mar 5, 2019
  2. hong1991

    hong1991

    Joined:
    Sep 16, 2017
    Posts:
    14
    solved
     
  3. CUCinimod

    CUCinimod

    Joined:
    Feb 12, 2019
    Posts:
    1
    How?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,349
    I'd be curious what the op did as well. The problem they were experiencing wasn't one of precision, it was because the tangent is transformed by the skinning when using a skinned mesh renderer which doesn't know about the packing so the resulting value you get in the shader wouldn't be valid for unpacking.

    The solution I know of to this is to store the outline normal in the tangent straight, then reconstruct the normal mapping tangent in the shader using derivatives.

    https://forum.unity.com/threads/normal-mapping-particles-only-shows-on-half.349304/#post-2546395

    One word of caution, these two techniques combined along with a Surface Shader will produce terrible results. You will have to use a custom vertex fragment shader.
     
  5. hong1991

    hong1991

    Joined:
    Sep 16, 2017
    Posts:
    14
    Just convert the smoothed normal to tangent space and remap the range of each component form [-1, 1] to [0, 1], then save it in vertex color. It just like what we do with normalmap.
    And thanks @bgolus, your solution is inspiring.
     
    bgolus likes this.
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,349
    That’s a nice solution! Gets around the whole issue of custom vectors not getting transformed by skinning, and doesn’t break Surface Shaders, I like it.