Search Unity

HairWorks Port For Unity

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

  1. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    What version of hairworks did you get that dll from? The latest version doesn't work, if possible could you maybe copy one out of a working project and paste it in before opening unity?
     
  2. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    For reference the dll and cpp code I'm using to build from is from a folder called HairWorks-r1-1-212-distro. Any other version's dll might not work at all.
     
  3. RyuMaster

    RyuMaster

    Joined:
    Sep 13, 2010
    Posts:
    468
    HairWorks-r1-1-212-distro - where did you get this one? The latets version is not working, and I can not find any link to HairWorks-r1-1-212-distro
     
  4. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    266
    Ok yeah I went back to an old binary and it's working. It does render in VR, but for some reason it appears to be rendering twice in the left eye. Very odd.
     
  5. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    266
    It's hard to see in the photo but it's definitely rendering the entire image twice if the left eye, both slightly offset from each other.
     
  6. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    It was the latest one at the time unity Japan originally released this, I think. Search on the nvidia developer website for a september/October release. I'll try to upgrade it to the latest release, but there's always I chance it will cause compiler errors and I'm not quite ready to break and repair it just yet.
     
  7. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    That's with the Hair VR script, correct? Do me a favour and go into your Hair instance script and navigate to the OnWillRenderObject () function. Remove the if statement and it's brackets, then disable the Hair VR script. See if it renders in VR. It's a very simple fix that occurred to me, just check it out before I take a look at why that could be.
     
  8. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Small Update. The spotlight falloff in my shader was very harsh. Now modified to match the soft falloff on other objects. Also, I managed to break additive lighting in the shader, that's now fixed. Attached are images showing the old hard falloff vs the new soft one as well as an example of additive lighting from a point light and a spot light. Links to my repo's are now in my signature.
     

    Attached Files:

    RyuMaster likes this.
  9. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Hey guys, quick status report. I'm hoping to have Global Illumination via Unity's builtin light probes done and on the repo within the next 24 hours and texture support within the week.
     
    hopeful likes this.
  10. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Ok, so spherical harmonics (light probes) took quite a bit longer than I thought...but it's about done. Still buggy though. Will be on the repo soon. See the attached image.
     

    Attached Files:

    • SHGI.png
      SHGI.png
      File size:
      304.9 KB
      Views:
      1,011
  11. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Light Probes up on the repo. The scene has a light probe group stationed around an emissive sphere. Change the color of the sphere to see the effect on the hair. It might not appear to be working in the editor when not in play mode. Also, I coded in a failsafe in case the light probe data doesn't make it to the shader correctly. Your hair will turn blue if this happens *Fingers crossed it doesn't*. On the roadmap right now is textures, I have high hopes it will go faster than light probes and then shadows then I'll upgrade HairWorks to the latest version. I'm still working on the annoying flickering too. Anyway, enjoy guys! Link to the repo in my signature.
     
    Last edited: Nov 30, 2015
  12. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Nice work Proton. You are the defacto Hairworks guru of the Unity forums :) I can't wait to see if you're able to get shadows working and/or able to fix the flickering problem. Thanks for your updates, and as always, good luck with it.
     
    hopeful and theprotonfactor like this.
  13. jleslie

    jleslie

    Joined:
    Mar 24, 2013
    Posts:
    12
    Has anyone gotten Collisions to work?
     
  14. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Hey, jleslie

    In what sense? It can't collide with any Unity colliders, but I think it can collide with colliders you set on the mesh during the .apx export, is that what you mean?
     
  15. Glader

    Glader

    Joined:
    Aug 19, 2013
    Posts:
    456
    Oooo this is exciting. I can't wait to give your work a shot to make a hairy Booma



    I think he'd look cool.
     
  16. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    I bet! Show me if you have something :). Just keep in mind that I'm still working on some bugs and features, so it might be a while before he's 100%
     
  17. jleslie

    jleslie

    Joined:
    Mar 24, 2013
    Posts:
    12
    I haven't tried creating my own apx file yet, I just started evaluating it last night to see if it would be a fit for a project I am working on, but when I enable collisions with the Sample apx hair files I found all the strands just sort of shoot upwards, like the roots are colliding with each other. Wasn't sure if that was a bug from the Unity implementation. I also get a weird bobbing effect with Gravity set to anything, like its constantly being stretched and bouncing back like a rubberband. So I ended up using a small downward wind force to cause the hair to fall naturally and come to a rest. But there's so many settings I could just have something configured wrong...
     
    Last edited: Dec 3, 2015
  18. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Yeah, it's hard to say what exactly could be wrong from your description, but I think that the samples make use of animations, backstop and capsule colliders to avoid hair going through the mesh and they can all have weird effects if not calibrated.

    Your best bet would be to just test the default hair strip in the project and see if you experience the same problems. I have no issues with it currently when collision is enabled.
     
  19. jleslie

    jleslie

    Joined:
    Mar 24, 2013
    Posts:
    12
    Turns out my problem was the stiffness curves in the samples I had. Once I set it all to 1 the bouncing stopped and making my own apx file removed the weird collision problem.

    So my only question now is, what's the purpose of the Probe Mesh? Should I be changing that in my own project or just leave it the same?
     
  20. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    It doesn't matter all that much because it won't get drawn. You just need a mesh renderer and filter of some sort so that a draw function gets called when it's in view and if you're using my version so that it can calculate light probe data.

    The probe mesh is just a single vertex that gets created procedurally, so it's probably more optimised to use it.
     
    Last edited: Dec 5, 2015
  21. jleslie

    jleslie

    Joined:
    Mar 24, 2013
    Posts:
    12
    Thanks for all the help.
     
  22. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Texture support is possibly only a few hours away!
    The new update will add support for the following features:
    Root color texture.
    Tip color texture.
    Specular color texture.
    See the attached image of an example using the stained glass texture in the project.
     

    Attached Files:

    hopeful likes this.
  23. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    266
    Hi Proton,

    Update on my project. I've done some tests in VR with the Vive and it is working! I still haven't been able to test with oculus yet.

    I am now trying to export my mesh and hair from Blender using your plugin, but I'm getting alot of issues. When the hair comes into Unity it is much much bigger than the actual mesh. Something is wrong with scale. Also, when the hair first comes in, the bones are not set on the Hair Instance, I set them manually, but it's difficult to know which goes where, should it be the same order as the Blender hierarchy?
     
  24. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    266
    Ok, I just realized that you have to have the root bone set on the hair instance before you load the asset, that ifxed the crazy looking mesh, but the hair mesh and real mesh are now rotated differently from each other in Unity.
     

    Attached Files:

  25. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Hmmmm...I've only tested importing from the blender addon in the HairWorks Viewer and in Unreal, so I'll have to test this myself. The incorrect rotation is likely to do with a difference in matrix calculation between the different applications. I'll give this my full attention once the texture support is on the repo, which should be 10 to 12 hours from now at the most. Just out of curiosity, are you importing directly out of Blender? My workflow would likely be to export from blender into the hairworks viewer and from there export again into unity. I don't know if that will actually change anything, but Nvidia might have a more complete apx exporter than I do. If that doesn't fix it then I'll probably have to make a change to the instance script. I'll be able to tell you better once I've run some tests myself after textures are done.
     
  26. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    266
    Yes I am exporting directly from Blender to Unity with the FBX and APX. I tried importing into Fur Viewer, but it often crashes. The few times it didn't crash though it had the same rotation problem.

    I'm also having scale problems as well. I have to set the FBX scale in Unity to 100 in import settings, to get it to match the hair scale.

    I'm not a Blender user (I'm usually Cinema 4D) so the export settings for FBX are confusing.

    Also, if you could condense some of your instructions from your videos into written tutorials or just instructiosn in the readme's on GitHub, it would be so helpful! The information is good, and your work is awesome! But the videos are very long, and I have to rewind a lot just to find the one tiny setting I need to know.
     
  27. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,684
    Have you tried exporting from Blender using FBX 6.1 ASCII mode? For some things that helps.
     
  28. kite3h

    kite3h

    Joined:
    Aug 27, 2012
    Posts:
    197




    I finished hairworks integration modification for unity3d.

    But I cannot make github branch. And That projects have some bugs still.

    But I cannot contact prject author. I contact Unity Korea( I lived in Korea ) But They ignore me. They block me their own forum. because I am agaist thier policy.

    Is it Unity3d company wants?
     
    Magpul likes this.
  29. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    UPDATE!

    Texture support now on my repo. Link in my signature.
    You can now set a root color texture, tip color texture and a specular color texture in the hair instance.
    I've also added a method to the instance called UpdateTextures(Texture2D root, Texture2D tip, Texture2D specular) so you can change it via code. There's also a tick box in the inspector that you can use to referesh textures. Enjoy guys!
     
  30. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Sorry it's a little hard to follow what you're saying, but if you are not the author of that project and they do not want you to modify it then there's nothing you can do about it. My version is complete except for shadows. If you'd like to contribute to it then I'd be more than welcome to share my source code, but I can't take another authors code without their permission, so I can't help you in that regard. Looks good though. I'm not seeing any shadows from hair in the videos either, which is what I'm working on now. So the integration we already have could replicate that scene to be perfectly honest.
     
    Last edited: Dec 7, 2015
  31. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Here's an image of the same sample with my version being lit by nothing but light probes. Shadows coming very soon. I'll add support for density and clump textures as well since it seems to be needed for a few of the samples to run correctly. Link in my signature, currently supports root, tip and specular textures. Take note that the color fields in the instance params will now act as a multiplier for the textures. So you'll have to set the colors to white if you want the texture color to remain unchanged.
     

    Attached Files:

    Last edited: Dec 7, 2015
  32. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Texture support, woohoo! Very nice Proton. You da man. :)

    Although I keep jumping around from project to project, I need to test this out sometime.
     
    theprotonfactor likes this.
  33. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Hey, guys.

    New update coming today.
    For some reason the textures get incorrectly vertically flipped when they are set, so this new update flips them back correctly. Also it now supports ALL texture types, which means :
    Density, root color, tip color, width, stiffness, root stiffness, clump scale, clump roundness, wave scale, wave frequency, strand, length, specular and weights can now all be driven by textures. But obviously it's not recommended for performance to use textures for all of them at once. I've also decided to throw Eve in the scene for you guys to play with as well. One thing I still have to do is code in the ability to 'unset' textures. And don't set Eve's density texture because it will give her a bald spot :) Finally I've added a color field to the instance that you can use for ambient light. If you for example have a day night cycle you can lerp the color from the instance to match the dominant color of your sky and it will appear as though the hair is being lit by the sky. Updates will be on the repo in a couple of hours. Attached is an image of Eve in the scene. Enjoy guys!
     

    Attached Files:

    • Eve.png
      Eve.png
      File size:
      417.8 KB
      Views:
      1,003
  34. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Updates on the repo.
     
  35. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Tested and working with 5.3
     
  36. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    How can I get some of that HairWorks for my real hair?
     
    Velo222 likes this.
  37. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    If only it were that easy :D
     
    goat likes this.
  38. kite3h

    kite3h

    Joined:
    Aug 27, 2012
    Posts:
    197
    I understand
    theprotonfactor's opnion.
    If you develope game, You did not to make that.
    It is only tech demo.
    Use Skycolor for ambient? Are you kidding?

    When my character enter the house, Check House trigger and change ambient to black?
    Most of Games could support hairworks are deferred rendering. Is it support?

    If You should make usefule solution. Support lightprobe and to receive shadow. and It has lack still. Cast shadow is not important. But If did not support receive shadow , Hair is too bright in indoor area.

    My demo's light is unity GI light. Hair light sync to unity light system. It is very important for game not demo. And use meter unit.

    Use centimeter unit? Are you kidding? I don't understand. It is not difficult. Why you make that bullshit code?

    I want to help to fix it. But You did not want it,now
    I stop this project. And Make My own Hair integration.
     
    Last edited: Dec 9, 2015
  39. jleslie

    jleslie

    Joined:
    Mar 24, 2013
    Posts:
    12
    I was wondering if collison spheres are supported? I haven't found any directions on how to set them up in 3ds Max and my few trials didn't seem to produce any collision results in Unity.
     
  40. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Yes, they should work. I don't know how to set them in Max, haven't used it in a while. But in the SDK under media\HumanSamples\Female there's one called Alice that has capsule colliders and there's a max file in there. If you figure it out please post it here so we all know :) I seem to remember there being a tab called dynamics somwhere and in it is a section called collision. Set that to polygon and set the mesh as a collider. Sorry if that's a little vague, again I haven't used it in ages. But check out that max file and report back if you find out how to set it up!
     
  41. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Hey guys.
    I was wondering if anyone would maybe be interested in helping me out to make a better demo scene? Preferably in 5.3, nothing too fancy, maybe just a first person controller with a couple of the hair samples with text meshes explaining what the sample illustrates and perhaps also a GUI with which to adjust some features. I've been meaning to do it, but I'm knee deep in shadow support right now, looks really promising by the way, so I was hoping someone could maybe contribute there. Also once shadows are done and I've updated it to the latest version of HairWorks I'm going to put the source code on GitHub and I'll naturally be accepting of pull requests, this should belong to the community.
     
  42. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Small update. Hair can now be rotated, translated and scaled using the following new parameters in the hair instance : Position Offset, Euler Rotation Offset and Scale Modifier. This was initially set to work around the mesh origin but it at the last minute I've got it to work in local space. Let's say you want to move the hair right by say 2 units, you would code something like : GetComponent<HairInstance>().positionOffset = new Vector3(200f, 0f, 0f); Same for the other 2 as they are all vector3's.
    Shadows coming in a day or 2.
     
    hopeful and goat like this.
  43. i_saint

    i_saint

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    5
    goat likes this.
  44. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Yes! I'd be more than happy to do so. I'm just going to add shadows, upgrade it to the latest version and clean up the code then it would be great to merge it, it will probably be in a few days from now. Great work by the way, full credit to you. I'm quite flattered that you like what I've done with it.
     
    goat likes this.
  45. i_saint

    i_saint

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    5
    I'm glad to hear that! Your pull request is always welcome.
     
    goat likes this.
  46. jleslie

    jleslie

    Joined:
    Mar 24, 2013
    Posts:
    12
    Any luck on getting shadows working?
     
  47. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    I'm wondering the same thing. Let us know how it's coming along Proton if you see this, and get some time to respond.
     
  48. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    I'm having some issues that aren't very easy to solve, unfortunately. A while back I was generating shadows in a very unorthodox method, but the shadows were incorrect and too slow for an actual game. So I'm going with the standard method of shadowing that most games use.


    The problem is that in order to do this I need to render the hair depth into a render texture via the plugin and unity doesn't like us hijacking the render target like that at all.


    If everyone is okay with it being only 5.3 and up I could have hair receive shadow quite soon? (Because 5.3 exposed shadow depth maps as textures) but yeah shadow casting is still a struggle at the moment.
     
  49. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Ya, I had a feeling it wasn't going to be so easy -- even though I know very little about what it actually involves. I just got the sense that it would be. Personally, I'd be perfectly fine if you made it only 5.3 and above. I'd have no problem with that at all.

    You've already done a lot with it, so getting shadows to work (in whatever way you go about it) would be icing on the cake :)
     
  50. theprotonfactor

    theprotonfactor

    Joined:
    Oct 10, 2014
    Posts:
    140
    Ok, so ignoring the fact that the lighting and shadow has flipped for some reason, I'm getting some pretty nice shadowing on the hair. Attached are images with shadowing turned on and off. I've deliberately disabled light probes on the shadowed areas as well to illustrate the effect. I'll put the update on the repo as soon as I can fix the flipping issue and support multiple lights with shadows. There's a directional light pointing at her face being blocked by a wall, to clarify, I think it might be a little hard to see.
     

    Attached Files:

    Last edited: Jan 18, 2016
    jdraper3 likes this.