working on the port of the lux hair shader for unity 5 i had another look into real time shadows and shaders using alpha blending and – le voila – after having done some testing i found a quite promising solution.
right now i have managed to render real time shadows on top of alpha blended geometry by using 2 materials on the same mesh:
mat1 using alpha testing to fill the z-buffer and render all fully opaque parts (using the built in shadow receiver functions)
mat2 using alpha blending and a “custom” shadow receiver function.
i still have to work on the hair brdf and the implementation of spherical harmonics (gi does not really make sense here as hair will probably never be marked as static) and hopefully find a way to merge both materials into one 2pass shader. anyway – here is how it might look like (please note: ambient lighting is not supported at the moment). [edit: ambient lighting is supported now]
the outer tips of the hair strands still do not receive any shadows but this is less noticeable than i thought it would be (and might be improved by “blurring” the shadow texture).
real time shadows are supported for directional, spot and point lights. so keep your fingers crossed that i will find a way to bring back ambient diffuse and specular lighting. then this shader might be a good foundation for rendering hair or other things having a highly detailed alpha texture like e.g. wire mesh fences. however: it won’t help on semi transparent materials.
and one more
i have implemented my own ambient occlusion parameter and function so now ambient lighting is up and running, everything looks nice and should be correct as well:
i would be happy too
as right now it is glitching in unity 5 as well… i hope to get it stable, but that could take some time – if it is possible at all. so eventually i will publish the lux hair shader for unity 5 just using alpha testing.
after having moved forth and back for quite a while i hope i have a pretty stable version now – at least as far as opengl is concerned.
but as it is a rather expensive solution i wonder if it worth it…
I suspect I’m just being an idiot here, but how do you install your plugin? I’m using R3 and both 2.0 LuxHair shaders are throwing errors along the lines of
expression left of .“SpecShift” is not a struct or array .
I forced OpenGL but these errors are still d3d9, could that cause it? 1.0 hair shader throws (just the one)
declaration of “unity_FogColor” conflicts with previous declaration at /UnityShaderVariables.cginc(174)
Also, there is a Missing Prefab in your Hair Demo Scene. I think you might have to share the scene as a package like you do for the Lux Eye Shader Demo . Furthermore by disabling the main camera by default any Camera.main will return null which causes some editor scripts to fail.