Some notes about the 2-pass hair material system.Recreating a multi-pass hair shader In
URP brings with it a number of problems, Other than being much more complex than the surface shaders of the built-in pipeline, multi-pass shaders would also break the scripted render pipeline (SRP) batching for those materials as
URP only allows for a single pass in it's shaders.
But there is an alternative answer. Instead of trying to render mulitple passes in a single shader, it is possible to assign multiple materials to a single mesh. Each additional material assigned to the mesh renderer will cause the last sub-mesh in the list to be redrawn with that material and shader. Thus creating multi-pass rendering that is fully compliant with the SRP batcher.
The trick is that some hair objects have multiple sub-meshes, which are not necessarily hair materials, so the hair material sub-meshes must be isolated into their own objects and mesh renderers so they can be easily assigned multiple materials.
So that's what the system does, it extracts, if needed, any hair sub-meshes from the character objects so they can be rendered with multiple material passes, and assigned the two pass materials to them. The package for three pipelines can do this, but the built-in pipeline really doesn't need it as the the hair shader already renders in two passes, though it might be useful if you want to assign your own shaders to it.
76% of original size (was 666x19) - Click to enlarge
I've added this as an optional button. Also note that it is only possible to change mesh and object data on a prefab variant of the character fbx, so this function operates on the prefabs (found in the Prefabs sub-folder of the character.)
A comparison of the opaque dithered default shader with the two material pass alpha clip + alpha blend method.
76% of original size (was 666x19) - Click to enlarge
There is noticeable dithering in the opaque dithered shader, as expected, which is not present in the two pass rendering. Also as the hair is first rendered opaque to the z-buffer, the second alpha blend pass has much smaller performance impact as it does not overdraw the opaque areas.
But what's interesting about this method is that it also works in HDRP. As the two pass rendering does not need to manipulate the alpha channel for a depth pre-pass (the opaque pass effectively
is the pre-pass), it means the hair can be rendered much more accurately and in higher quality.
Putting it all together I recreated a Cycles render I did recently to see what kind of quality I could push out of HDRP and I'm quite happy with the result:
76% of original size (was 666x19) - Click to enlarge