Hair cards shader for unity universal render pipeline
This shader has been an experimental project for me and will likely not receive any further development. It is by no means a finished product and can be improved upon in many areas. Nervertheless I decided to share it for anyone to use. This may be a good starting point if you wish to create your own hair shader.
--> See shader in action: https://www.youtube.com/watch?v=EmU62lWMhSU
Download all files inside the FulcrumHairShader directory and put them in a folder in your project.
MAKE SURE that all accompanying .hlsl files are inside the same folder as the main hair shader, otherwise it will not find them.
Universal Render Pipeline has to be installed of course.
The shader has been developed and tested only on unity version 2021.3.22f1
This hair shader is not phisically arccurate and may not look correct in every lighting scenario. In my testing it looked fine most of the times but when lightsources get too bright the reflections might look a bit too bright.
It looks best if you use a normal map.
To get correct looking results, you may have to play around with Smoothness and Specular color values. In most cases it would look more accurate if I had used Albedo color for reflections but that would've meant that black hair woulnd't have reflections so I went with a hybrid approach.
The Fake SSS (subsurface scattering) property visually brightends the diffuse lighting of the hair but also reduces the amount of metallness to actually get that effect.
The shader makes use of the mesh tangents. In the Import settings of your mesh make sure tangents are generated by unity or be sure that they are properly exported from your 3D software if you checked Import. I haven't done mush investigating but blender seems not to export tangents or unity doesn't import them correctly. By default unity has it set to generate in this version, so it should be fine.
== perfomance optimisations
If you want to develop this shader further on your own, feel free to do so and correct my mistakes. For the most part I'm following the same structure as the other lit shaders in the urp pipeline and my shader still depends on some of the urp shader files. A lot of things have also been striped out. Performance can probably be improved a number of ways. Firstly the specular lighting function is called twice per lightsource to produce the two highlights. Removing one will speed things up.. Im using custom fresnel function with tangent insead of normal to produce the anisotropic effect. The formula for fresnel comes from blenders implmentation, you might be able to simplify it and still get the nice reflecion results. I don't see a reason why deffered rendering would not work I didn't bother porting everything to GBuffer pass but it should probably work fine. I'm also not super happy with how the hashing looks, there is probably a smarter hash function to use. The shader takes some things from the kajiya kay hair shading model however my specular function is very different.