Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

HairWorks Port For Unity

Discussion in 'General Discussion' started by theprotonfactor, Nov 8, 2015.

  1. vuhiepck3

    vuhiepck3

    Joined:
    Aug 5, 2015
    Posts:
    4
    Somebody help me scale hair? When i scale all of project. I feel project is more heavy!
     
  2. norbykov

    norbykov

    Joined:
    Jul 27, 2010
    Posts:
    23
    Hah! That is good news. Let me know if and when I can help with test(s).
     
  3. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    I could honestly use some help because I'm going to be very busy this week. I'll PM you the details.
     
  4. norbykov

    norbykov

    Joined:
    Jul 27, 2010
    Posts:
    23
    Ok, shout when needed, and will see what I can do :)
     
  5. benjcooley

    benjcooley

    Joined:
    May 3, 2014
    Posts:
    45
    We've taken the Japanese port of Hairworks, and fixed it to work in Unity 5.6 as well as in VR - Mulitipass and Single pass mode.

    We haven't yet updated the shadowing and self shadowing, but we may do that as well. We'll post the source code to a git repository in a few days.

    Just to show you our results so far - here are some sample videos:







    These are still work in progress. For example, eyelashes are missing, and there are some pose based blend shapes missing in the red haired character's torso. But not bad so far.

    Our assets for these scenes:

    - Pre-integrated Skin Shader. Great skin results, with nice scattering and translucency. You can see this in the closeups in the videos.

    - Eye Advance for eyes (asset store).. This shader also takes some serious tweaking, and eye brightness has to be carefully animated in a scene to avoid cases where eyes are either "spooky" because they're too light or too dark.

    - NVidia Hairworks.. There's no self/model shadowing yet, but we have some other shots of this model from a bit later where the hair is perfect.

    - SE Soft Shadows - For any photoreal rendering in Unity, you've got to replace the nasty unity shadows with this shader. In fact there's no reason IMO to not just use this shader everywhere on everything as it's awesone.

    - Forward rendering with 8x MSAA and HDR (Unity 5.6) with the new postprocessing stack - in this case just a bit of color correction.

    - Mocap anim - Optitrack 8 camera 17W system.

    - Facial anim - Faceware analyzer, retargetter.

    Total time to produce this VR sequence was about 6 days. Obviously the assets took longer.. but production for the actual animation, audio, etc. did not take that long - one day of shooting mocap, then a few hours for the initial cleanup. Most of the time we spent tweaking lights and shaders to get the best look, and tuning the hair and hair shadows.
     
    Last edited: Mar 31, 2017
  6. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Wow, very nicely done. My fork should work in 5.6 as well but I would love to get my hands on your code for shadows and VR. I've managed to get it to receive shadows by passing Unity shadow maps to the native plugin, but I'd love to see some shadow casting and self shadowing.

    In terms of Anti-Aliasing I think the MSAA can be a bit of a performance killer. I would love it if we can get HairWorks to work with TAA in deferred. Once that hurdle has been crossed it should be a fairly complete integration.

    Please do feel free to post a link to the repository here in this thread when it's available. I'd love to help out with this and again great work :)
     
  7. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    I've fixed the shadow bug that prevented it from working in a build. There's a bug right now that Unity is aware of with Compute Buffers that made things overly complicated but I managed to find a workaround. HairWorks should now be able to receive shadows from a single directional light, both in editor and in build, feel free to try it out and let me know if everything is in order. No self shadowing or shadow casting yet, however I have implemented PCF shadow filtering. So you should see some nice soft shadows as well.

    On another note I've upgraded the project to work with 5.6. A known issue right now is that the hair only renders in the Game View and not in the Scene View. Annoying but harmless really.
     
  8. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    benjcooley that is super work
     
  9. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Very big fix just landed in my repository. Meshes now have correct scale and no longer need to be resized. Hair can also be scaled using a scale factor field in the hair instance in case it isn't automatically corrected. Starting to get close to being production ready now.

    I've also heard a lot of people complaining that they can't get the plugin up and running or that the instructions are too vague. So I'm in the process of translating the readme from Japanese and I might also make a video tutorial on how to set everything up.
     
    TerraUnity likes this.
  10. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    The readme has been translated to English and updated to reflect the current installation instructions. I realize now a lot of people were using the package to import the plugin dll instead of building the project. So I've updated the package as well to contain the latest dll. If you follow all of the instructions in the readme then everything should work now ;)
     
    Velo222 likes this.
  11. benjcooley

    benjcooley

    Joined:
    May 3, 2014
    Posts:
    45
    Hey, I'll see if we can't post our repo today. It looks like you've fixed quite a bit of stuff.. we've been mainly focused on getting everything to work in VR in both single pass and multi pass mode. Hopefully we can provide potentially some additional fixes that will help make your build work even better.
     
  12. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Heck yeah. I'm sure if we merge the useful sections of our codebases then we'll have a pretty powerful integration. :)
     
    thelebaron likes this.
  13. benjcooley

    benjcooley

    Joined:
    May 3, 2014
    Posts:
    45
    Here is where our repo is https://github.com/WayGate/unity_hairworks. Carlo Morgantini, the engineer that did our port fixed a few issues and set up the repo so that it can be easily built.

    Our main focus was on making the updating and base transforms work correctly. You still need to add both the hair and the hair manager components in the component order list in player settings to make sure that the hair manager component is updated after the hair components (or the animation is one frame behind).

    Other issues were making sure it worked correctly in VR, and in single pass render mode.
     
    MTDues, Velo222 and thelebaron like this.
  14. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    I had a quick look, there's some good stuff here :) I like that you guys added a rendering manager and some changes to the way skinning matrices and transforms are dealt with. Very useful for better performance. I think I might be able to improve it a little more as well.

    Most of the code will merge cleanly because you guys focused mainly on VR, but there are some conflicts here and there that need to be resolved. I'll try to leave the VR code as untouched as I possibly can.

    With regard to fixing issues we obviously have some overlap. In some cases my code has a more elegant fix and vice versa of course, so I'll selectively add those where useful or tweak them.

    By the end of it we'll have an integration that fully supports both our feature sets, but It'll take a week or two I reckon.
     
    Velo222 likes this.
  15. benjcooley

    benjcooley

    Joined:
    May 3, 2014
    Posts:
    45
    That's terrific. We'll switch over to your version whenever it's ready. If we do any additional fixes, we'll push them to our repo and I'll let you know.

    Thanks!
     
  16. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Just a quick update for you guys.

    Internally, I have an experimental version of the integration that's upgraded to HairWorks 1.2.1 (The public integration is currently running on the much older 1.1.1).

    The new version adds support for a shader cache and async methods, as well as general performance improvements and bug fixes. It does not, however, support DX12, but it definitely lays the foundation for it and from what I can tell DX12 support will probably be introduced in 1.3. So it's a good idea to upgrade before 1.3 lands.

    The issue right now is that the VR code will have to be modified for 1.2.1 and that's not really my forte. I'll have to consult with @benjcooley and his team.

    I'm thinking that I might just make separate branches for VR and 1.2.1 so people don't have to wait around for too long. I'll push 1.2.1 to the repository in a day or two. VR will still be a week plus.

    EDIT: 1.2.1 also appears to fix that nasty flickering in the basic example. Yay!
     
    Last edited: Apr 23, 2017
    norbykov likes this.
  17. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    HairWorks 1.2.1 update now up on the repository. Also features some bug fixes and I added some missing files to the unity package :)
     
    TerraUnity, goat and Velo222 like this.
  18. sccdhyt

    sccdhyt

    Joined:
    Apr 24, 2017
    Posts:
    9


    Hello,thanks for the tool,but why the hair which should be repainted in the sceneview is showing on the gameview just like this.
    How can I fix it?
     
  19. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Hi,
    I'm aware of this issue, it's due to a bug with 5.6 not firing a particular rendering event in the scene view. I have a workaround for this in forward, but there is no solution right now in deferred. It's something that Unity will have to fix. One of their employees said that the fix might land in Unity 2017.1. So unfortunately until then you'll have to close your scene view when in Game view.

    The good news is that the bug is obviously Editor only and won't affect an actual build of your game. :)
     
  20. sccdhyt

    sccdhyt

    Joined:
    Apr 24, 2017
    Posts:
    9
    Thank you very much!

    But I'm sorry that there is another problem and i can't deal with it.It seems that the texture of the hair tip color doesn't work well.Just like this.



    If don't use the hair color texture just change the root and tip color in param it works well.Is there something wrong with setting?
     
    Last edited: May 3, 2017
  21. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Yup! That's a bug. I've just pushed the fix to the repository. It should work for you now if you download it again. Thanks :)
     
    Last edited: May 3, 2017
  22. sccdhyt

    sccdhyt

    Joined:
    Apr 24, 2017
    Posts:
    9
    THX! It seems like work perfectly now! And I'm looking forward to the effect of hair shadow, Good luck!
     
  23. sccdhyt

    sccdhyt

    Joined:
    Apr 24, 2017
    Posts:
    9
    I'm so sorry there's another question. If I move the model a little out of view the hair will disappear. Like this.


    Is there something wrong with setting of hairwork or camera?
     
  24. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    The hair is probably being frustum culled. Could you change the camera's near clip plane and see if that has any effect?
     
  25. sccdhyt

    sccdhyt

    Joined:
    Apr 24, 2017
    Posts:
    9
    The error is like this.

    http://upload.ouliu.net/i/20170518172500jj6go.gif (Sorry, I dont know why I cant insert the gif. Please click the URL and you can see the picture)

    And this is the setting of camera.

    I had tried changing the near of clipping planes and field of view but it seems no work. Is something else wrong?
     
    Last edited: May 18, 2017
  26. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    After looking at the gif I'm 99% sure that it's culling. It's just happening incorrectly for some reason. I'll investigate and let you know when it's fixed. Thanks :)
     
  27. vuhiepck3

    vuhiepck3

    Joined:
    Aug 5, 2015
    Posts:
    4
    Sorry I can't control hair via script realtime. Help me! How to control hair by script. thanks so much !!!
     
  28. tweedie

    tweedie

    Joined:
    Apr 24, 2013
    Posts:
    311
    This is awesome work.

    Does this mean it currently works in deferred, just without TAA? Deferred support would be fantastic. Great job regardless, please keep going with it! :)
     
  29. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    You should be able to drive most things via script. Can you give me an example of what you want to do? Or an example of what isn't working exactly?
     
  30. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Thank you very much :)
    No, unfortunately not. It renders in forward, but works with a deferred camera because it renders from a native plugin to the active render target after Unity does all normal rendering.

    It definitely needs proper deferred support though, because it's breaking a lot of image effects that require depth or depth normal textures due to the fact that those are rendered before the hair renders. Properly supporting deferred requires a fairly big refactor on the c# side and that refactor is also necessary to enable the possibility of point and spot light shadows.

    I've started with the changes, but I still have some ways to go before I have anything meaningful to show.
    Thanks again. If there are people who make use of it then I'm happy to continue working on this. I'm a little busy with other features of a game i'm working on right now but I'll have some of the updates I mentioned above available in a week or two.
     
  31. tweedie

    tweedie

    Joined:
    Apr 24, 2013
    Posts:
    311
    I suspected as much, haven't come across a Hairworks / TressFX integration with proper deferred support yet. Thanks for the explanation, interesting to know the same changes will lead to point and spotlight shadows.

    I'm about to start a project which could potentially have a lot of hair / fur in it, just depends if we can find a solution that holds the visuals we're after - this looks to be the only thing that could, so I'm definitely interested, but we'll be working strictly in deferred. Completely understand your time constraints, so I'm doubly grateful you're even pursuing it in your spare time.
     
  32. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Hello is it possible to do hair like this?
     
  33. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Yes, this type of hair could be made by modeling simple straight hair strands and then that natural African look can be achieved by a combination of textures. You'd need clump, stiffness, density, strand and waviness to be authored in a very particular way.

    It's definitely very, very difficult to pull off in HairWorks, so at least in my opinion, a professional artist would be needed.
     
  34. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    It's due to the fact that you have to coordinate between Unity and the plugin to render different data into like 4 different textures at the right time. Made even more difficult due to the fact Unity doesn't expose a lot of rendering events.
    Any particular reason for that? Just curious. :)
     
  35. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    You mean that the strand can be larger in Hairworks? I'm half of an artist myself, I guess I need to try myself first. I'll prototype it when I'm at that task of the project.

    But I thought I could have the strand not straight with hairworks :(

    Thanks for the pointer!
     
  36. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    They won't be straight. :)

    I think I didn't explain properly. You'd start off with straight hair as a base and then morph them with textures. You could of course try to model them like your reference image from the outset but that's pretty difficult as well.

    The textures I mentioned aren't textures in the traditional sense. They're data textures like height maps or normal maps. Basically they allow you to physically morph hair strands individually. Think of how a height map morphs a terrain.

    For example the density texture will allow you to drive density per strand rather than having a global variable for all of the hair.

    So what I meant was you'd have to paint textures like clump and waviness and stiffness etc. in a way that would bend and twist hair strands according to your reference image.
     
  37. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Can you show a simple visual example without doing that hair style? I'm not sure where the texture apply, if it's the strand shape or the "influence map" on the scalp lol

    Tee thing is how twisted and varied can be one strand individually before composing the whole hairstyle, ie can it curl, can it have multiple curl going into many direction (due to mimicking tendril perversion), etc ...

     
  38. tweedie

    tweedie

    Joined:
    Apr 24, 2013
    Posts:
    311
    Performance isn't a concern for this project, so we plan to use SEGI, which unfortunately doesn't support forward rendered objects at present. Couple of other things like deferred decals but that's the big one.
     
  39. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    The textures are applied to the scalp, then during rendering the hair strands sample those textures based on their position on the scalp. I'll see if I can make an example at some point.
     
  40. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Sonic Ether's GI is definitely one the best dynamic solutions I've seen for Unity, but I don't know if I would limit myself to deferred only for it though. You're essentially going to impose a very limiting restriction on yourself in that you won't be able to render anything that your deferred renderer can't.

    That said, you might be out of luck for the time being. The best option for now might be to find the most promising hair solution that supports reflection probes (like this one) and see if SEGI can be rendered into reflection probes.

    For the future Unity are working on scriptable rendering pipelines and that's probably going to make deferred hairoworks a lot easier to implement, but I don't have any fixed ETA on when it'll be fully complete in this package.
     
  41. tweedie

    tweedie

    Joined:
    Apr 24, 2013
    Posts:
    311
    Deferred-only is definitely a limitation we'd ideally like to avoid, but besides the visual benefit of SEGI, not having to bake GI is tremendously liberating and iteration time for lighting goes through the roof; especially after considering Enlighten's bloated bake times. Getting SEGI into reflection probes sound like an idea worth investigating, really appreciate your input on it all, thanks.
     
  42. sccdhyt

    sccdhyt

    Joined:
    Apr 24, 2017
    Posts:
    9
    Hello,does the tool support the hair shadow now? It seems to support the shadow according to the introduction in the github. But when I use the single directional light and enable the shadow, I can't see shadow of the hair.Is something else wrong?
     
  43. saj

    saj

    Joined:
    Jul 6, 2012
    Posts:
    3
    @theprotonfactor
    I'm trying to get this to work in Unity 5.6.1f1. Is this version supported?

    I did the following:
    1. Got the HairWorks SDK from the nVidia website: HairWorks-r1_2_1-15-distro
    2. Created a fresh Unity project and imported your HairWorksIntegration.unitypackage in to it.
    3. Set the build architecture to x86_64
    4. Copied:
    ..\HairWorks-r1_2_1-15-distro\HairWorks\bin\win64\NvHairWorksDx11.win64.dll
    to:
    ..\Assets\UTJ\Plugins\x86_64

    When I add the HairInstance component to a sphere. I get the "Failed to load HairWorks (version 121) dll." dialog box.

    Can you please advise what I'm doing wrong? Based on the thread, I've downloaded the SDK multiple times from various machines to ensure I don't have a corrupt dll.

    Thanks
     
  44. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Crank up the shadow sigma under the Hair Instance properties to around 30. I'm working on a fix for it having to be so high
     
  45. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    The last Unity version I've tested it with is 5.6.0f3. With your reproduction steps it works fine for me on that version. Does the demo project bundled with the package work for you? And do you have a 64 bit machine? Only thing I can think of is if you have a 32 bit machine then you need to use the x32 dll
     
  46. sccdhyt

    sccdhyt

    Joined:
    Apr 24, 2017
    Posts:
    9
    I tried to set shadow sigma over 50, though there is still no hair shadow. I tested it both on 5.6.0f3 and 2017 b8. Maybe I should wait the new version after fixing it. Thanks for the tool and good luck!
     
  47. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    I forgot to mention that it only receives shadow from Unity objects and does not cast shadow at this time. If you can't see shadow on the hair then there's a problem. It says that it's receiver only on the github page but I should probably rewrite that section a little more clearly.
     
  48. r3ndesigner

    r3ndesigner

    Joined:
    Mar 21, 2013
    Posts:
    143
  49. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
  50. r3ndesigner

    r3ndesigner

    Joined:
    Mar 21, 2013
    Posts:
    143
    5.6.1 f1