Search Unity

Anisotropic shader makes no sense -- How does it work?

Discussion in 'High Definition Render Pipeline' started by Goatogrammetry, Feb 8, 2020.

  1. Goatogrammetry

    Goatogrammetry

    Joined:
    Apr 27, 2017
    Posts:
    197
    Ok so here's what I've found by experiment:

    The anisotropic shader makes the highlight stretch to a line. The line's orientation on the model is determined by the orientation of the uv island. Negative aniso values make a vertical line as seen by the uv map, and positive values make a horizontal line. The further you move from 0 the crisper the line effect gets. Ok great.

    Now, I'm an artist. I dont code game engines. So I'd like to know what the guys that do code engines were expecting artists to do with this shader. I've been working on a horse model, and horses really benefit from aniso effects. However, there's no way to unwrap uv islands for a horse that will make the aniso's uv based shine work while still making it work with a texture. The problem is seams, and the fact that by definition you wont have the same uv island orientation at seams.

    So they introduce the 'tangent map'. I assumed I could use it to adjust the angle implied by the UV map, allowing me to flow the aniso effect along the fur's path. I was guessing it was 0-360 remapped to 0-255 and while it would be a pain, I figured I could make it work. No, thats not what it is. The map is an actual vector4 with a hint-bubble stating "BC7/BC5/DXT5(nm)". Seriously, what the flying F* am I supposed to make of this? DXT5 seems to be a compression standard, but the internet contains no data, nor does Unity's documentation.

    So, not one to be stopped by bad documentation, I wrote a shader and sent in a blank texture, but I used UV2 and mapped UV2 on the mesh to be a side-projection. In theory that might kinda work and there'd be no seams. No, it isn't using UV2. Since anisotropy is so 'uv based' one would think you could pick a 2nd uv set to base it on but they didn't seem to consider that.

    So I tried baking every known variant of every weird texture I could in xnormal. Nothing seemed to be a 'uv island compensator' so of course nothing worked.

    I'm not a mathematician, so I dont know what a BC7/BC5/DXT5(nm) tangent map IS, but I wrote another shader that let me manually enter R,G,B,A as sliders to see if I could manually guess a color for the different islands to get the sheen to line up. Of course I broke the mesh up into bits so I could test each island vs the body on its own. Fail. Turns out the tangent map is affecting the shadows, not just the anisotropic highlights?! Whats the bloody point of it all!? Its like adding a 2nd normal map. Yes, the sliders caused the sheen to wig-out, but when I got the sheen right, the shadows were munched.

    So, unity shader coders, could one of you please write a how-to document on how to use this thing? I'm not a coder, but I'm a good artist. I should be the guy you were planning on writing this shader for, and I give up.



    The brown horse is one mesh using unity's HDRP Lit with aniso. There's an island seam on the rump.

    The gray horse is 2 meshes, the back legs are separated and have a different tangent value plugged in to the tangent map. Note the shadow has been ruined. So the tangent map seems to be unusable, for if you did you'd be screwing not only with the gloss but the actual surface normals used in lighting? How was this INTENDED to be used. How would you use it to shade a horse like this?
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,789
    Yeah the intent is to have a map that explicitly shows the direction the anisotropy should have. The kinda look like normal maps. See examples here : https://wiki.unity3d.com/index.php/Anisotropic_Highlight_Shader (they are for old legacy stuff, but I think the general gist is the same).
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Your mesh is split at the rump seam.

    To fix it (assuming the horse has good normal map) is to go to unity import options, set the normals to calculate, smoothness source from angle and whack the slider up to 180.

    This will force Unity to process it as one mesh without smoothing groups. For a horse, you really don't want smoothing groups anyway, the normal map should take care of it. This will likely fix your issue.

    upload_2020-2-8_16-14-22.png
     
  4. Goatogrammetry

    Goatogrammetry

    Joined:
    Apr 27, 2017
    Posts:
    197
    Thats a UV seam, not a smoothing group (that model has zero hard edges). The UV islands' edges *cant* be oriented in an identical way as a matter of course, otherwise they wouldn't be islands.



    Could someone from Unity look at this, then explain how its supposed to work (if it ever was meant to be useful). Red Dead had it working on thier horses. But they had artists that could work with shader coders and we know Unity wont make games, so the best they're going to get is people like me whining about usability. This is the 3rd show stopper HDRP shader problem I've run into.
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Try it out to see. Often, it's not a UV island when it comes to shaders. If calculating anisotropy, it'll be because the vertex normals are *still* split on import.

    UV islands are not the problem when sampling from a correct normal map.
     
  6. Goatogrammetry

    Goatogrammetry

    Joined:
    Apr 27, 2017
    Posts:
    197
    No difference. To clarify, the gray horse has a mesh seam (I cut the horse into 2 meshes), but its purpose was to try 2 different versions of the material, one with different inputs into that tangent map. Just trying to see if I could get it to match if I twiddled some numbers, but I was horrified to see it changed the shadows along with the lighting. So. I cant imagine any data in that tangent map that wouldn't screw the render of the object. It has a normal map thats supposed to handle normals. Nobody needs another one laying on top that ...I dunno. Violates it.
     
  7. SGiygas

    SGiygas

    Joined:
    Jan 18, 2017
    Posts:
    6
    I hate to revive an old thread but this seems like the only one that has this issue (and it's still happening)
    This is with anisotropy at anything except 0
    upload_2020-6-28_16-50-24.png
    This is it off. There is no issue with smoothing or the model being split. The anisotropic shader just seems to make uv seams visible for some reason
    upload_2020-6-28_16-50-51.png
     
  8. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    IF someone paste the code, I can try to make the necessary change for it to work
     
  9. Goatogrammetry

    Goatogrammetry

    Joined:
    Apr 27, 2017
    Posts:
    197
    Public Service Announcement regarding the HDRP Anisotropic Shader: Give up now.

    What you're seeing is the thing I was whining about 6 months ago. Aniso shader doesnt just affect the highlights like you'd expect, but it screws with the shadows too. So I'm going to guess that your UV islands' edges cross where you're seeing that shading difference. Nobody wants their shadows (or essentially the normals) to change just because of a highlight treatment. But the HDRP shader does this. Its the same issue I had on the horse's butt in the images above.

    Give up. Nothing you do can fix it and Unity doesn't care to fix it-- I did days worth of testing and had many ideas including messing with Amplify Shaders and everything failed. I even provided a nice thread about it here on the forum complete with pictures and examples. HDRP does NOT have an anisotropic shader... It has a junk shader by that name though!
     
  10. Spoonfishlee

    Spoonfishlee

    Joined:
    Mar 21, 2016
    Posts:
    50
    amarcolina likes this.
  11. Matjio

    Matjio

    Unity Technologies

    Joined:
    Dec 1, 2014
    Posts:
    108
    Hi, just saw this thread, and asked internally.
    If an anisotropy direction map is authored that is seamless across the uv islands you should not have this issue.
    Without a map, anisotropy uses the uv island orientation, which will likely have seams (but is usually fine for hair cards etc).
    Re. shadows, anisotropy should not influence.
    If you find a bug, please verify that you have tested on a recent version and file a bug providing a small scene so that we can reproduce the issue on our side.
    Best, Mat
     
    joaopereira likes this.
  12. ApulecioGala

    ApulecioGala

    Joined:
    Mar 31, 2022
    Posts:
    1
    JoNax97 likes this.
  13. Inegvin

    Inegvin

    Joined:
    Apr 7, 2016
    Posts:
    3
  14. Jack_Martison

    Jack_Martison

    Joined:
    Jun 24, 2018
    Posts:
    143
    Bump. Anyone tried to apply flowmap from Substance Painter?
     
  15. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,789
    Yes.
     
    Jack_Martison likes this.