Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Lux Hair shader for unity 5 beta20

Discussion in 'Unity 5 Pre-order Beta' started by larsbertram1, Dec 28, 2014.

  1. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi there,

    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]

    lux_alpha_blended_shadowreceiver_animgif.gif

    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.

    lars
     
    Last edited: Dec 30, 2014
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    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:

    Bildschirmfoto 2014-12-29 um 01.56.42.png
     
    ZiadJ, OneWayRoad and Reanimate_L like this.
  3. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    Very nice, are u releasing this publically?
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    if it stays stable while testing: yes.
     
    p87 likes this.
  5. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    This is kinda surprising actually, since this technique were glitching in unity4. if it's really stable in 5 i would be happy :)
     
  6. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,079
    Thanks
     
    p87 likes this.
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    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.

    lars
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    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...

    alpha blended shadow receiver01_animgif.gif
     
    ksam2 likes this.
  9. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Just curious, are you manage to make the anisotropic/Hair highlighting working?
     
  10. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    Yes, but lighting has never been the problem. Alpha blending and Real Time shadows are.
     
    ksam2 likes this.
  11. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,079
    old Lux shaders doesn't work anymore with unity5 can you convert them too?
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    KRGraphics, ArthurT, ksam2 and 2 others like this.
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    shader updated for beta 20.
    please note: alpha blending does not work correctly at the moment.
     
    Last edited: Feb 3, 2015
    ksam2 likes this.
  14. kiriri

    kiriri

    Joined:
    Jan 14, 2011
    Posts:
    107
    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.