Search Unity

HairWorks Port For Unity

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

  1. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    437
    did everything in description for make it work, but something wrong with that. no errors in console, but i simply dont see any effect.
     

    Attached Files:

  2. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Do you have the .dll in the correct folder? Also is it the correct version of the dll?
     
  3. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Also guys, I'm really swamped with other projects right now. So I think I'm going to open source the code I've got and pass the torch on to someone else... for now. I'm not going stop working on this, I'll still answer any questions and help with trouble shooting, but this is going to take a backseat to some other stuff for a while. I don't want to do a pull request to the unity Japan branch because of how messy the code is, but I think @i_saint will want to pick and choose what to integrate. So please take a look at it once it's up in a few hours. Of particular interest to you will be my shader code and spherical harmonics code. You might also find my shadow code a little useful. I think I'm kinda on the right track there.
     
    i_saint and hopeful like this.
  4. norbykov

    norbykov

    Joined:
    Jul 27, 2010
    Posts:
    23
    Thanks @theprotonfactor, appreciate the work you put into it. If / when you post the code, we'll dig in, and will share whatever we may add to it.
     
    hopeful likes this.
  5. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    437
    did everything like it was sed on github
    no errors and no hairs. will do video later with screenshots. mabe im doing something wrong.
     
  6. MrWolf

    MrWolf

    Joined:
    Jun 9, 2013
    Posts:
    11
    Hi Proton and Saint,
    Thanks for the effort, looks great.

    Any chance of getting a proper tutorial of how to get hairWorks integration to work?
     
    mmilne likes this.
  7. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Hey guys, sorry I've been away for so long, but I'm working full time on other graphical features in Unity for my studio. Some of them might go on the asset store if our new game gets off of the ground. Anyway, that's well into the future.

    So, to the present...the source code is now live under a new repo here : https://github.com/theprotonfactor/HairWorksCode
    Just a word of caution, DO NOT download that repo if you do not intend to develop hairworks. It can't do anything my other repo can't and the code is highly unstable because of the incomplete shadow code. In fact it will probably crash quite a number of times when you try to open it.

    Again to @i_saint sorry to keep you waiting for so long. You'll mainly want to check out the .hlsl shader and my SH code in c#.

    To @MrWolf I'll see if I can maybe squeeze a video in of how to get everything up and running. To @zelmund, usually if you see nothing but there are no errors then you have the wrong .dll, the latest one doesn't work. You need one from around midway through last year.
     
    Last edited: Mar 21, 2016
    i_saint and ksam2 like this.
  8. songuke

    songuke

    Joined:
    May 7, 2016
    Posts:
    4
    Arkade likes this.
  9. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    After reading through the changes to the unity japan branch, I don't think they've have added a lot of functionality just yet. They still haven't integrated light probe or spot light support from what I've seen. They have added x86 support by the looks of it. In terms of stability the branch in my signature is very similar to their's. Minus the sdk update and x86 support... It's your pick really, they'll get around to adding everything eventually at which time I'll close my repo's.
     
    Last edited: Jun 12, 2016
    Arkade likes this.
  10. songuke

    songuke

    Joined:
    May 7, 2016
    Posts:
    4
    Thanks a lot @theprotonfactor. I have been using the plugin from their branch. It seems working quite well at the moment (at least for 64-bit platform). I haven't tried the x86 yet.
     
  11. jdods13

    jdods13

    Joined:
    Mar 18, 2014
    Posts:
    10
    How do you install this? I downloaded the files and dropped them into a fresh project. Then I copied the GFSDK_HairWorks.win64.dll from HairWorks-r1_1_1-62-distro.zip to Assets/HairWorksIntegration/Plugins/x86_64 and still I get nothing when I try to load a hair asset.

    Please help as I would like to use this in my project.
     
  12. songuke

    songuke

    Joined:
    May 7, 2016
    Posts:
    4
    @jdods13: What is the message in the console? Is the Hairworks DLL loaded successfully?
     
  13. jdods13

    jdods13

    Joined:
    Mar 18, 2014
    Posts:
    10
    Yes I was able to finally get the JP package to work successfully. I can see hairs loading in my scene only they are far to large for my character. A step by step tutorial would be so helpful. @songuke: What is your work flow when using Hair works? I am not using theprotonfactor's scripts. I am only using the ones found on the Japan github. dev page.
     
  14. jdods13

    jdods13

    Joined:
    Mar 18, 2014
    Posts:
    10
    It seems that no matter what I do, I cannot get the hair to be the correct scale. Even when I adjust the scale in maya before export the .apx file. This size of the hair is always massive compared to my character :(
     
  15. DamonJager

    DamonJager

    Joined:
    Jul 16, 2015
    Posts:
    56
    is this mac/linux/windows compatible? I don't know if it works with 5.4, can someone confirm me that?
     
  16. jdods13

    jdods13

    Joined:
    Mar 18, 2014
    Posts:
    10
    I'm pretty sure that this is for Windows only
     
  17. jdods13

    jdods13

    Joined:
    Mar 18, 2014
    Posts:
    10
    If anyone can please help... I'm unable to get the scale right within Unity. My hair works .apx loads fine in the hair viewer but when I load into Unity it's HUGE! lol :( not sure what i'm doing wrong...
     
  18. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    What are you using to make the hair with jdods13? It's been awhile since I've worked with the plugin, but I seem to remember having to make sure I scaled the hair correctly in my "authoring tool" (such as 3dsMax and the Nvidia FurViewer application that I was using).

    Check and make sure you are using the correct measurements. I think in the FurViewer, before I created the APX I had to switch some settings to use centimeters instead of inches or something like that.

    Also try to fiddle with some of the settings in the inspector when in Unity, or the import settings (such as when you load a 3D model). Other than that I forget exactly what could scale the hair properly. Just wanted to give you some options if you havn't tried all of that already. It's been awhile since I've worked with it.
     
  19. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Hey, the reason for that is probably because my version is using an older DLL, while Unity Japan recently updated theirs to the latest version. I could easily post a modified script from the Unity Japan branch that exposes a field to set the scale manually, if anyone is interested in that? I could add fields for scale, rotation and position. I believe that's something my branch has.

    Also, in case anyone wonders why my link to the Blender HairWorks exporter is down, its because I'm currently communicating with Nvidia regarding its licensing. I deleted my repository, but hopefully it will be back up in a new one eventually, we'll see how it goes :)
     
  20. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Does anyone know of any Nvidia devs on the forums? If I could talk to one of them directly it could really help me out. Also if any of you have a really pressing question or a really simple feature request like modifying scale then feel free to DM me. I'll receive a notification of it and I'll be able to get back to you and help much quicker as well. :)
     
  21. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Hey guys, quick question. I'm starting to work a little bit more with the hairworks plugin again, and I noticed that Unity's built-in anti-aliasing (the one in the graphics settings) seems to be the only anti-aliasing that works (i.e. that shows the hair correctly). I tried disabling Unity's built-in anti-aliasing, and using a post-process anti-aliasing image effect on my camera, and the hair was in a weird position that seemed to go up and down with the camera (but it wasn't in the correct location).

    Does anyone know why this is the case?

    My knowledge as to how the hairworks plugin actually works "behind-the-scenes" is pretty limited. That's why I'm glad Protonfactor is doing some work on it :)

    And also, no Protonfactor, I don't know of any Nvidia devs on the forums myself, sorry. My question above though is really all about trying to get performance out of this. I'd like to be able to have about 10 hairworks instances in my game at one time (not necessarily on screen all at once, but in the game). So, I'm trying to find out if that's even possible.
     
  22. johnartune

    johnartune

    Joined:
    Oct 18, 2016
    Posts:
    61
    Thank you for your Preject, It's seam like perfect. But I can't running it in unity 5.4.
    In Hair Instance(Script), can't Load Hair Asset. No metter whatever I chose **.apx, have nothing to appear.
    Waiting for your help.
     
  23. johnartune

    johnartune

    Joined:
    Oct 18, 2016
    Posts:
    61
  24. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Did you make a "Streaming Assets" folder. Then put the .apx and the .cso shader in the Streaming Assets folder. At least that's what I did for the old version. I don't know about any of the newer versions.

    Also, for some reason the hair works great when it's running in the editor -- but when I build my game I get a lot of "flickering". In a game build, the hair will appear for a short ways from where it should be for a frame or two, then go back to where it should be. Does anyone know why it works in the editor, but not when I compile and build the game?
     
  25. johnartune

    johnartune

    Joined:
    Oct 18, 2016
    Posts:
    61
    Hair appear for a short ways, I think it's becouse of the Animator culling Mode, if Culling Mode have no update, then it will considered the hair mesh still in there. So when old Culling Mode out of camera view, mesh disapear.
    Other reason is memory leak, you shud check the codes.
     
  26. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Thank you for your suggestion. I have tried all of the Animator component's "culling mode" options, but it still is not working. I still see "blinking forward" of the hair when my character is moving forward (backwards when moving backwards).

    I think it might have something to do with translation of my character, and perhaps it can't update fast enough?

    There are no memory leaks that I know of. Anyways thanks for the suggestion :)
     
  27. johnartune

    johnartune

    Joined:
    Oct 18, 2016
    Posts:
    61
    Good luck
     
  28. benjcooley

    benjcooley

    Joined:
    May 3, 2014
    Posts:
    45
    Velo222, were you able to get hairworks working for you?
     
  29. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    No unfortunately. I mean, it works (mostly). I have hair on my character, and it behaves correctly, except for that really annoying "blinking" of the hair -- where it seems to re-position itself for a frame or two before going back to normal.
     
  30. laugre

    laugre

    Joined:
    Mar 4, 2016
    Posts:
    13
    Hi guys !
    Thx for support :)
    I tried to render hairs using hairtool unity asset, it's a nice asset but I'd like to try nvidia one which seems to be more realistic.
    I'm using jap version and follow their procedure, imported the unity package in their example project.
    I have HairWorksIntegration.dll and GFSDK_HairWorks.win64.dll in the \Assets\UTJ\Plugins\x86_64 folder
    but I can't see any hairs on the sphere in their example scene
    and If I try to run I get a "failed to load hairworks dll".
    I'm using unity 5.5.0f3.
    Do I forgot something ? Any idea to solve it ?

    Capture.PNG
     
    Last edited: Jan 24, 2017
  31. Magpul

    Magpul

    Joined:
    Aug 27, 2014
    Posts:
    25
    Probably you didn't put library from Nvidia in your assets folder
     
  32. Vincent_Lo

    Vincent_Lo

    Joined:
    Sep 20, 2013
    Posts:
    3
    Hello,

    I'm doing some research to see if Nvidia Hairworks can suit our needs.

    I'm currently at a point where I got Japan's Hairworks package (from this link https://github.com/unity3d-jp/NVIDIAHairWorksIntegration/) to work inside of Unity. For those who are curious, I'm using Unity 5.2.0 and followed the steps provided in the link to get things working.

    I noticed a few assets were provided within the download on Nvidia's website such as the Mite and Manjaladon, which are preview-able within the Hairworks Viewer.

    1_manjaladon_hairViewer.PNG

    In the image above, I'm in HairWorks Viewer, and I just tweaked the root color and tip color to arbitrary colors.
    And then when I load up the asset in Unity, I get...

    2_manjaladon_unity.PNG
    It looks like the Root Color and Tip Color I put in the HairWorks Viewer did not transfer over into Unity. In Unity, I see white colors for those two properties, when I should be seeing orange and green. Not only that, but it looks like none of the other values or maps I set in HairWorks Viewer transferred over into Unity.

    My question is...

    Is there a way to transfer over all the maps and slider values from the Hairworks Viewer into Unity with Japan's version of the integration? Is there a step I'm missing or is it normal behavior to see nothing transfer over?
    I'd like to be able to make all my adjustments and fine-tuning within the Viewer, and then bring all those changes straight into Unity and have things look the same.

    @theprotonfactor I'm guessing your version of the Hairworks integration package was made to address this issue and to add additional features...?

    -Vincent
     
  33. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Not exactly no. What you're seeing is expected behavior. At the moment the apx parser just gets the hair data and nothing more. My version was essentially aimed at adding support for textured hair, support for spot lights, light probes etc.Graphical improvements really. Ideally it would've eventually replicated all the functionality of the viewer in the Unity Editor.

    I do intend on getting back to this project shortly. I now have a somewhat decent plan on how to add real-time shadows to the hair. However I am going to start with a clean fork of the original and then start from scratch. At the very least I'll make it compatible with 5.4 and up. And hopefully I'll do it properly this time.

    In the meantime I have updated Unity's Atmospheric Scattering from The Blacksmith to work with Unity 5.4 and 5.5 if anyone is interested in that. It features an extensive code refactor aimed at performance optimization. It'll have its own separate thread as well. It can be found here https://github.com/theprotonfactor/BlacksmithAtmosphericScattering
     
    norbykov likes this.
  34. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Update!

    Reflection Probe support coming soon.
    All previous features including texture support, spot light support and light probe have been added into a clean fork.
    No crashes or issues.
    Everything seems to run quite smoothly in 5.4
    Working on getting hair to receive shadows from Unity objects. Downside, shadows will only work in 5.5 and up.
    Working on getting hair to cast shadows. Downside, will probably require a modification to the standard shader or whatever shaders you need shadows to be casted onto.
    Working on TAA support.
    Attached is an image of the Manjaladon lit by nothing but a Reflection Probe with some okay-ish anti aliasing.
     

    Attached Files:

    Velo222 and hopeful like this.
  35. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Actually I done goofed in the shader. Proper Reflection Probe lighting attached.
     

    Attached Files:

  36. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
  37. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Thank You. Happy to be working on it again!

    Reflection Probe support is now up on the repository as well as spot light support. When reflection probes are enabled it now blends between the closest two probes or the two most important probes or a combination of closest and important. It also supports reflection probes with custom cubemap textures now.

    I also included a rendering foldout in the hair instance which allows you to enable and disable reflection probes and light probe usage on hair, set their intensities as well as a specular boost field for reflection probes.

    Quick note on Reflection probes: There is virtually no difference between reflection probes and light probes at low specular values. Using light probes is always much faster than using reflection probes. A scene with thousands of light probes will run much faster than a scene with thousands of reflection probes. It would be best to untick use reflection probes in the rendering tab of the hair instance if you don't really need them to affect hair or if your hair instance is not very shiny. That said, its still pretty damn fast with a low to medium number of active reflection probes in the scene.

    Working on getting hair to receive shadows now. It will unfortunately only work in Unity 5.5 and up. Why you ask? Because Unity exposed a key method we need in the Compute Buffer class in 5.5 and I could be wrong, but I don't think they backport api changes.

    I will talk about shadow casting, optimization stuff like batching and Anti Aliasing in a future post.
     
    Last edited: Feb 18, 2017
  38. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Yikes, it is quite broken in 5.5 isn't it? Special 5.5 branch will be up in a day or 2. Managed to fix compiler errors, but the new reversed z buffer will take a while to correct for.
     
  39. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Turns out a separate branch won't be necessary thanks to version macros. Repository now updated with 5.5 support. Should still work in 5.4 and 5.3 but feel free to let me know if it doesn't.
     
    Flurgle likes this.
  40. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    So the hair will be able to receive shadows now in 5.5? :D That is so cool. Glad to see you working on this again.
     
  41. norbykov

    norbykov

    Joined:
    Jul 27, 2010
    Posts:
    23
    Did anyone have any luck with scaling the model and the hair with it? Cheers!
     
  42. vuhiepck3

    vuhiepck3

    Joined:
    Aug 5, 2015
    Posts:
    4
    Somebody help me! i work in unity 5.3. It is OK. But when i update to Unity 5.5.1f1. i can't see hair. It is invisible. When i look it through a object. I can see hair. i don't understand. Help me, please!
     

    Attached Files:

  43. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    What you're seeing there is because of the reversed z buffer that was introduced in Unity 5.5. I fixed that issue in my fork of HairWorks, however, the Unity Japan version has not been updated to account for this. You either have to wait for them to update it or use my fork.

    Some of the code will have to be modified in order to do this, will add it to my to do list.

    Indeed! I had some issues figuring out what needed to be done, but I have some preliminary results to show.

    Attached is an image of preliminary shadow test results. I still need to add some fancy PCF or PCSS filtering, but I was able to successfully sample a Unity Shadow Map in a native c++ plugin. HOORAH!!! I haven't updated the repository yet, but it's coming soon.
     

    Attached Files:

  44. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Wow that is cool :) Nice! Shadows add a lot of depth to it.
     
  45. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Alright, I've added some very basic shadow support to the repository. Right now hair can receive shadow from objects using a single directional light. No self shadowing or soft shadows yet. No point or spotlight shadows yet either.

    However, there appears to be a problem. The shadows work fine in the editor but not in an actual build on my machine. I would be very grateful if someone could test weather the same happens to them. It might be a bug with Unity but I don't want call it that until some other people have tested it.
     
  46. vuhiepck3

    vuhiepck3

    Joined:
    Aug 5, 2015
    Posts:
    4
    Thank you for your help. i went back unity 5.3. i tried running your assets( https://github.com/theprotonfactor/BlacksmithAtmosphericScattering) but, it isn't not work. it have a lot of error about probe. I tried to correct it. But something, i don't understand. i always have problem with shade. Once more time, thank you!
     
  47. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Sent you a PM
     
  48. norbykov

    norbykov

    Joined:
    Jul 27, 2010
    Posts:
    23
    I tested it, the same happens for me. 5.5, shadow working in editor, not in build.
     
  49. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Looks like a bug. I think I've found the faulty code. Trying to reproduce the issue in an empty project now.
     
  50. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    So the issue appears to be with a Compute buffer. It gets populated with shadow matrices in a simple shader model 5 vertex + fragment shader. Works fine in the Editor but not in a build. Which means I thankfully only have about 5 or 6 lines of code to test :)