Search Unity

Will DOTS get us real time hair

Discussion in 'Entity Component System' started by RoughSpaghetti3211, Nov 28, 2019.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    A while backed Epic acquired Shave and Hair cut.
    https://www.unrealengine.com/blog/shave-and-a-haircut-v9-6-for-maya

    Probably because they wanted the patent rights for tech used by yeti and not get sued like everyone else.



    my question is will dots or any tech in the future get us real time hair in Unity. Currently the VXF/Animation industry are pouring millions into solving these issues and it seems like a good fit for DOTS.
     
    Gekigengar and NotaNaN like this.
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    What's your timeline? I have some algorithms that I am hoping to port to my framework with DOTS.

    However, I have quite a few prerequisite pieces that I need to implement first, many of which are pieces I had working in 0.1.1 but are broken in 0.2.0. Time is my biggest enemy. I only really have times to work on this on weekends and no amount of money thrown at me is going to change that.
     
  3. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    Do you have any examples of what your are able to achieve. I’m really trying for get a feel of what is currently possible.
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    Nope. Shaders don't compile anymore. Haven't taken time to investigate porting it to HDRP. It might be possible to feed the inputs into shader graph for the shading side (which is where the compile errors are at). However, that might not be possible with the anti-aliasing logic.

    It was pretty heavily based on TressFx 4. I was experimenting with some fake 2-way coupling with the environment and different friction models. I did this all on the GPU because CPU performance was abysmal, but I think of lot of that stuff will run a lot better on the CPU with Burst as the algorithms fit the CPUs processing model better.

    But again, this is not something I'm going to have time to investigate for a while. What's your timeline?
     
  5. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    I’m in no rush, this is more for getting information on what is possible/has been done in real time engines regarding hyper realistic characters. One constant barrier is hair, but it looks like epic is taking that problem on, heavily targeting film/tv. I believe Unity could achieve a feature ready character in DOTS but it doesn’t s appear to be a priority , form the blog I’ve seen they are targeting more the architectural side of things. Not sure how aware people are of the content war going on at the moment with all the online streaming services, but it is hot and a massive opportunity for real time engines since they could be used to keep up with the content creation demand. demand. Hair for a feature vfx char can take 40min-2h a frame. Simple can’t keep up
     
    Last edited: Nov 28, 2019
  6. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    1) Unity is focusing on the core tech first before trying to do everything at once.
    2) It is going to take a while before Unity can understand everyone's use cases regarding hair.

    Fortunately though, Unity has given us the ability to write low-level systems with low-level engine overhead using the Burst compiler. So especially with film/tv, if you have a specific simulation you need, write it yourself. Very rarely will Unity give you as good of a solution for you in a timely manner.

    As for my tech, it will very likely meet the needs for a lot of people in film/tv. But, it will require a full animation authoring solution inside of Unity. That's a big prereq for me I would love help with.
     
    Orimay likes this.
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    But lets say you want Tomb Raider's hair?

    It's done with compute shader and likely will remain that way for a while because it doesn't really affect a modern GPU that bad... DOTS is possible but it struggles with solving problems in order.
     
  8. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    What do you mean by this?

    Tomb Raider's hair is TressFX without a lot of environment interactions. The solution I was building added a lot of those environmental interactions. The gathering of the colliders and force vectors and baking them into SDFs and vector fields, along with mapping softbody joints to the guide hair vertices, those were all things that the CPU could do a much better job at. The actual simulation could be done on CPU or GPU depending on budget. I was already GPU-bound on a lot of my tech before DOTS. DOTS lets me perform extra preprocessing on the CPU efficiently so that the GPU can perform its tasks more easily. This lets me target weaker GPUs without having to invest in more art resources.
     
  9. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    Last edited: Dec 9, 2019
  10. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    @francois85 I don't know. It looks nice, but I am not particular impressed by the result atm.
    Isn't this something, that can be achieved with few meshes and maybe bones, or soft bodies?
    Maybe if I would see demo with longer softer hair instead, affected by different wind direction, or something in this context, then I would like it more.
     
  11. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    I agree this is not there yet but its a pretty impressive first step towards what is expected in VFX/Animation. In VFX animation there is not way of cheating this stuff especially on digital doubles, you need breakup and showing between strands. Trust me so much resources go into solving and rendering hair and Unreal knows it. If they can get this up to standard it will be a huge motivation for studios to jump on board.
     
  12. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    857
    @Antypodish While you could get similar results with an excellent mesh setup, having a realtime solution allows far faster iteration to your final result. There's a huge delta in the workflow from grooming a hair/fur description to going the hair mesh card workflow, and it reminds me a bit of the difference between sculpting a complex highres organic mesh vs the hell that is manual edgeloop modelling a complex organic mesh.

    I think its a little early to be talking about hair in dots when we dont even have a proper animation package yet, but I am all for realtime hair in the future.
     
  13. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    It looks like they are using an extremely low number of guide hairs in that video. And by extremely low, I mean one per each curl. This is a low enough resolution that I've seen people match this quality using bones and bone-based physics.
     
  14. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    For me this is more showing intent of what they are targeting witch is the start of trying to get cg production ready real time hair.

    Personally I’m interested in character fx and love working in Unity so my hope is that one day I can merge the two.
     
  15. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    Honestly I think they are missing the point. I have not seen any piece of software which allows for IK over FK animation tightly integrated with a scriptable game logic interface and physics guides for rapidly creating character interactions with an environment. Hair and cloth can be done in already existing tools as a final step after the main animation is done and re-integrated using alembic or similar.
     
  16. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Well, considering hairs and fur were possible even over 10 years ago

    Black & White 2 (2005)




     
  17. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    Yea I agree but hair and cloth can not be be done for vfx with current tools in real time engines. Rigging a vfx groom would be a mental task ( seen it done for shot specific reason but it was hell .. widow makers) for how heavy they are , we are talking for a human groom 10-4-million points and when get to apes it 10-20x that amount.

    Usual simulated strands are also needed for high detailed sims like wind, rain drops ect


    This was about 7-10 years ago
    upload_2019-12-10_10-4-2.png
     
    Gekigengar and MNNoxMortem like this.
  18. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Hi,

    here some fast tests with DOTs and HDRP (DX11 and DX12 + DXR) who worked out great so far.
    It´s based on VHair from kennux.
    https://github.com/kennux/VHair
    and comes with working wind and sphere colliders and is in an experimental stage.

    I added, on a naiv approach, 3 hair layers (simple offsets) and with HDRP Hair Master Node.
    2 opaque layers and one 1 transparent layer additive blended on the top to simulate sun bleeching.

    So far on HDRP 7.1.6 DX11,

    8x MSAA,
    TAA,
    IBL Lighting,
    Directional Light,
    Point Lights,
    Shadows,
    PPV3 DOF,
    and PPV3 AO (still some little artifacts on the hair)
    on a
    skinned mesh and the wind
    are working nicely.

    DX11.jpg

    Here some first movement and lighting tests with
    around 12 000 strands (96 000 vertices)


    The problem is the need of cranking up AO so much to get a dense behaviour towards the skin. However the scalp could be painted more dark by hand.

    I did an second test with
    HDRP 7.1.7 DX12 DXR
    and used the PPV3 Raytraced AO between the skin and the hair layers per layer mask.

    DXR_settings.jpg

    perfect!

    DXR.jpg

    Overall I think this is could be a way to go.

    At the moment i am rendering and bursting 3 times the hair meshes per head whats pretty stupid.

    With the new MeshAPI there should be further massive performance improvements possible
    https://github.com/Unity-Technologies/MeshApiExamples-2020.1

    I really like that the CPU is doing most all the work for interactivity.

    I am using 3 sphere colliders here for head, neck and body.
    There is a more modern approach here with sdf collision in the the new dev branch from TressFX,
    https://github.com/GPUOpen-Effects/TressFX/tree/4.1
    So i think HDRP with Visual Effect Graph in combination with SG could be an potential solution too to directly build up on the 4.1 approach.
     
    Last edited: Jan 3, 2020
  19. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    You have no idea how happy this made me. Do you have a YouTube link by any chance I would love a share this.
     
    AggressiveMastery likes this.
  20. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    I only have the video here. Do you have access?
    https://drive.google.com/file/d/10r3uHCg5MBTA--0E1XOpWF8NTeAvrUeM/view?usp=sharing

    some HQ interactive Grass and Hair are the last needed things to finally get over to HDRP.

    I think with a little community effort this is pretty fast done.
    I will forward this thread to kennux. Let s see.
     
    AggressiveMastery likes this.
  21. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    Yes I could watch it but it was very small for some reason.
     
    AggressiveMastery likes this.
  22. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    bigger is better
     
    Last edited: Jan 3, 2020
  23. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    It is kinda bizzare now when I look at an actual real world walking human and start appreciating how resource intensive it takes to make the hair move around
     
  24. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Yes. Nature only needs gravity, an atmosphere, some dead cells and and some light rays from a star to get it right.
    But we have Burst and HDRP debug rendering now. Here the channels for the Hair Master Node.

    Hair_Debug_Rendering.JPG

    -A full run for for the blonde hair.
    It s no fun to watch but was really helpful.



    Most missed is the knowledge from an hair stylist now.
     
    Last edited: Jan 3, 2020
  25. kennux

    kennux

    Joined:
    Aug 25, 2013
    Posts:
    43
    @keeponshading These results look amazing! Would you mind sharing your project here or via PN?
    I haven't yet had a look into HDRP, but this looks like I should probably have :p

    Regarding using DOTS for realtime hair, it is indeed possible to some degree. I think it can be used as long as you don't need very dense hair - while the performance is quite good it's still too much of cpu power to sacrifice when using it in an actual game.

    This can be somewhat solved by using guidance and follow hairs, but the simulation quality will suffer from that. It might just work well enough tho, I have started working on implementing guidance hair support for VHair, but it's not done yet. Another problem is the data upload, the mesh needs to be updated every frame which can be quite bad for dense hair (Example: Tomb raider hair is ~500k vertices iirc, vertex data is 32 bytes per vertex, 16mb need to be transferred per frame, which makes 960mb/s data transfer on 60 fps and 2,304gb/s on 144 fps).

    My favorite solution for VHair however would be access to the StreamOut / Transform Feedback shader stage, but it doesn't seem like unity will ever expose this in their API (I'm waiting for this since forever! And it seems like they have implemented it internally but it's not exposed for some reason - https://docs.unity3d.com/2020.1/Documentation/ScriptReference/ComputeBufferMode.StreamOut.html). If that would be implemented, it would be super easy to render the data since it would be a standard mesh that has it's vertices updated every frame from a compute shader without any data transfer from cpu to gpu needed.

    Another solution is Graphics.DrawProcedural, but you need to write a shader that can read vertex data from compute buffers (or does HDRP support this somehow magically? I don't know!). That's probably the best solution currently.
     
    sreinhold_mipumi likes this.
  26. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Hi. Sure i will send you the project and after a little cleanup i would like to add it to your git repo.
    After all the experiences with tressfx, hairworks and the Hair Tool Asset last years is see the biggest chance in a open source development by extending your repository.

    Here some questions (copy from the git issues):

    1. Is it possible to generate 16 or 12 vertices per strand to
      smooth out the highlights for longer hair.

    2. I have some issues with the render facing
      implementation.
      The hair disappears on very camera closeups and
      some large camera angles. I tried to correct your facing
      but without success.

    3. According to guidance.I use 3 times pony, cap and fringe meshes with and
      slight offset to generate the volume. 2 opaque layers
      and one
      transparent additive blended on the top to simulate the sun bleaching.
      I only would need the burst calculations for one pony, cap
      and fringe set and tranfer the calculations to the offset
      ones. Is that possible
    4. The new mesh api in 2020 could further improve your
      performance. Do you plan to integrate these?
    https://github.com/Unity-Technologies/MeshApiExamples-2020.1
    in special
    https://docs.google.com/document/d/1QC7NV7JQcvibeelORJvsaTReTyszllOlxdfEsaVL2oA/edit

    I tested the performance with these unoptimized layered setup on my fullik female driver in a moving car with window open.) and it s already stabil with 60fps (DX11) and stabil 55fps with raytraced AO (DX12 + DXR) on 3840x2160 with 5 colliders (head, neck, body, car seat, car door).
    All other pure gpu hair methods don t gave me these performance. I need the gpu for rendering car, driver and track.
    CPU only did sound and car physics up to know and was most time on idle.
     
    Last edited: Jan 3, 2020
    hopeful and Antypodish like this.
  27. kennux

    kennux

    Joined:
    Aug 25, 2013
    Posts:
    43
    I'll need to have a look at the mesh api stuff, I bookmarked it and will check it out if i have some spare time. Regarding your questions:

    1. If you mean subdividing the strands, that certainly is possible by implementing a custom hair asset processor (See https://github.com/kennux/VHair/tree/master/Assets/VHair/Code/EditorCode/Core/Processors) or by doing it at runtime with a geometry shader pass.
    2. I haven't encountered that yet, I'll test it and fix it when I have time.
    3. Yes, this is possible but not implemented currently. You could use multiple renderers that are offset and all use the same simulation data, but currently multiple renderers nor offsetted rendering is supported.
    4. I'll see if it makes sense to use :p
     
  28. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Nice.
    Thanks.

    Additional. A low hanging fruit for more visual volume.
    One of the opaque fringe, cap and pony layers could be rendered facing the directional light. (Hair Width 0.0002)
    The 2 layers above facing camera like in the video (Hair Width 0.0001).
    Would probably help to get more dense and better shadows and ao towards the skin.
    Probably not.

    For better understanding.
    Current naiv 3 times layering unfolded.
    Only one needs burst computation.
    The other 2 could be instanced.
    At the moment the 2 copys are bursted too.

    NaivLayering.JPG


    HDRP 7.1.6 DX11
    8xMSAA
    + TAA max sharpened

     
    Last edited: Jan 3, 2020
    RoughSpaghetti3211 likes this.
  29. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    Such good work , well done !!
     
  30. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    @keeponshading I think this is the best looking hair I've seen done with the TressFX 2.x solution. Nice job!
    Actually, there's a pretty good reason. It is suboptimal. Most graphics programmers I know have ditched geometry and tesselation shaders and instead do all of the tesselation and quad expansion using compute shaders instead. That means they skip the whole first geometry pass and don't require StreamOut. Geometry shaders can cause a pretty big performance hit on the GPU as they don't map well to the hardware, so replacing that step with compute shaders is almost always a win. Hardware tesselation isn't really that helpful for hair anyways.

    Mesh and Amplification shaders in DirectX12 and their equivalents in the other APIs seem promising in this area in that you can do the tesselation and quad expansion in a single step per strand in local cache memory.
     
    keeponshading likes this.
  31. kennux

    kennux

    Joined:
    Aug 25, 2013
    Posts:
    43
    I would also be cool with either accessing the mesh vertex buffer in the compute shader directly or being able to copy the compute butter contents into the vertex buffer. Afaik there's no support for both in unity at the moment (except via C++ plugin). But in terms of performance that should be a pretty quick operation, I think?
     
  32. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Last edited: Jan 9, 2020
  33. kennux

    kennux

    Joined:
    Aug 25, 2013
    Posts:
    43
    As far as I can tell, this still requires a copy from the cpu to the gpu to update the mesh data there (it should be faster than SetVertices / .vertices = tho). I'll have a look at how well these new mesh api calls perform - but I think the most efficient solution for hair is to run the simulation on the GPU and leave the CPU completely out of the equation. That's why I'd like to be able to write compute buffer data to a mesh vertex buffer.
     
    keeponshading likes this.
  34. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Sure. Purely GPU based is nice too.
    Here my modified Hair Tool (deprecated in Store) one in BuiltInRP.
    I am half way done to bring it to HDRP. Shadows are already working....


    However. I really like your approach.
    The GPU variants always break completly every 2 years.)
    Doing DOTS for interaction and HDRP SG for Shading could be more stable for longer use.
    Also for Android and IPhone they are some chances to get it run. (see mesh api post from https://twitter.com/_kzr/status/1214134928545239040).
    Simply use URP instead of HDRP SG shading.
     
    Last edited: Jan 9, 2020
  35. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    DrawProcedural and a custom vertex shader lets you read a compute buffer instead of a vertex buffer.
     
    keeponshading likes this.
  36. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
  37. r3ndesigner

    r3ndesigner

    Joined:
    Mar 21, 2013
    Posts:
    143
  38. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Hi. I don t plan to sell it. The base from the last long blonde hair video is from an deprecated asset.

    My main focus is to have an stabil solution for the next years.
    Meanwhile i think only an open source hosted solution can serve this need.

    The method from kennux i really like because it has potential to more ´divide an conquer´ hair rendering.

    Some platform independent dots base interactivity and some platform independent decoupled URP and HDRP rendering with full SRP support out of the box. (Full lighting, MSAA, TAA, motion vectors...) without custom stuff so that it is auto maintained.

    I cleaned up the extension (from first videos) from kennux s vhair and will sent it to him.
    I also will add it to the git repository from kennux for everyone.
    Need some more days for this.
    Then lets see what happens.

    Meanwhile i solved the volume problem. RealLive approach.)



    Some new questions raised. Probably someone has an answer?
    • could the DOTS method from Kennux take advantage from new DOTS Unity Phsyics switchable to Havok?
    • what i must do to get motion vectors for kennuxs hairs in HDRP Shadergraph Hair Lit Master Node?
     
    Last edited: Jan 10, 2020
    MNNoxMortem, r3ndesigner and hopeful like this.
  39. r3ndesigner

    r3ndesigner

    Joined:
    Mar 21, 2013
    Posts:
    143
    I am asking because i have bought hair tool and still have acess for it, as you said a stable solutin for long time its better, but as this product its not finished the hair tool "upgrade" can let me off the hook, can i send for you a private msg?
    Thanks ^^
     
  40. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
  41. TCROC

    TCROC

    Joined:
    Aug 15, 2015
    Posts:
    230
    When you get it working with HDRP, do u plan on going open source with it? And if not, could u send it to me as well?
     
  42. AggressiveMastery

    AggressiveMastery

    Joined:
    Nov 19, 2018
    Posts:
    206
    Keep up the awesome work here Keeponshading!!!
     
  43. Acatist

    Acatist

    Joined:
    Jun 7, 2016
    Posts:
    45
    VHair can also work on normal Unity projects?
     
  44. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Yes. Current burst port from kennux generates the mesh, normals and uv s and does the physics and collision calculation on CPU. So you have everything to shade it wherever you want.
    I added some HDRP Shadergraph to it but it also works with URP or BuiltIn Materials.
     
    Acatist and GilCat like this.
  45. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    I also had hair tool, and was so sad it deprecated, no updates, no working in HDRP, wanna hair too, please.
     
  46. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    First some upgrade on the blonde hair for
    Unity 2019.3.f1 HDRP 7.2.0



    tested with
    TAA
    FXAA
    SMAA
    MSAA
    Bloom
    Volumetric Fog
    slight Motion Blur
    Depth of Field
    Directional Light
    PointLights
    HDR Env
    Standard HDRP stuff is working without issues.
    Shadow casting from fine hairs still needs some trickery.


    Kennux did som great optimisations through proxys.
    This will greatly boost the performance and allow much more dense hairs.
    Will try this to integrate these next days.
     
  47. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    Have you seen HairStudio? This asset I'm working on allows to author the hair dressing, simulate physics and render tens of thousands of hair.

    Here 30k hair strands are rendered in 0.7ms on RTX 2070

    Available soon in early access on the asset store. You can follow me on Twitter to stay informed: https://twitter.com/dumas181


     
    Last edited: Feb 16, 2020
    wetcircuit and keeponshading like this.
  48. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Great.Like the demo vids.) Pretty dense.
    Which RP s you will support and do you plan to release an version with source?
     
    Last edited: Feb 16, 2020
  49. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    The shading of hair is very specific as there is no normal vector to work with, only tangents. The rendering I've created is physic based (Marschner), and quite basic so far (only single scattering). It's based on a surface shader for the Universal RP (LWRP), but I beleive it is not very far from being compatible with HDRP.

    Anyway, HDRP support will come in a future version and HairStudio will be released for URP at first.
     
    keeponshading likes this.
  50. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    wetcircuit and methusalah999 like this.