Search Unity

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

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

  1. Automoda

    Automoda

    Joined:
    Apr 27, 2017
    Posts:
    154
    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:
    6,441
    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 Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,434
    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. Automoda

    Automoda

    Joined:
    Apr 27, 2017
    Posts:
    154
    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 Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,434
    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. Automoda

    Automoda

    Joined:
    Apr 27, 2017
    Posts:
    154
    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.
     
unityunity