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

Particle Hair - WIP

Discussion in 'Made With Unity' started by cblarsen, Apr 2, 2007.

  1. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    In the "Wish List" forum, somebody said they wanted support for hair and cloth simulation.
    So I thought: "Hey, how hard could it be to do hair with the current particle system?"

    Well it turned out, that it is slightly difficult.

    The biggest problem was the particle collider, which was simply too forgiving. So I had to write my own collision system, which coexists to some degree with the builtin one.
    The hair can currently only collide against spheres and flat ground, since they were the easiest. As you may notice in the demo, it is still not perfect, but I thought that it was cool enough to show you.

    Web player here:
    http://proglet.com/software/Unity/Hair/HairBall.html

    Complete project here:
    http://proglet.com/software/Unity/Hair/Hair.zip
     

    Attached Files:

  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Wow, that's really neat! Also fun to play around with.

    --Eric
     
  3. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    very cool - thanks for sharing ; )
     
  4. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    What it needs is smaller strands and lots more of them. But it's good, a cool visual effect.
     
  5. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Too cool...Reminds me of the sentinels in the matrix....
    I tried using the grassonmesh generator to generate hair on a model, with interesting yet unsatisfying results. One day when I figure out how to code I might be able to get it to work. I look forward to trying your example in a scene. Well done and thanks
    AC
     
  6. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    That is pretty dang sweet! The hair doesn't quite have enough mass and gravity and has too much drag it seems. But that is quite impressive to do with a particle system.

    As well as world collisions it should have a certain way it wants to hang that it tries to go to. At least for a character. This could be useful in many ways! Does the hair add forces on the rigidbody? That would make it even sweeter.
     
  7. milkytreat

    milkytreat

    Joined:
    Jan 15, 2007
    Posts:
    267
    thats awesome, reminds me of squidee's in the matrix! :D
     
  8. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Glad you liked it :) Several answers:

    - If you want different gravity or drag, you can control it in the project by adjusting the paramters: "FixedForce" (gravity), "VelocityDamping" (drag)

    - The hair currently does not affect any other bodies (not) even the one it is attached to, but that should be relatively easy to add

    - About "a certain way to hang", I have considered adding starting directions to the first particle of each hair, and then "springiness", which causes the hair to try to straighten itself out. This could be simulated by having the direction vector of each particle try to approach the direction vector of its ancestor

    - About having more and thinner strands: I am running into performance problems on my 1Ghz PowerMac, when doubling the number of particles. I am thinking of solving it by going to a polygon mesh instead of particles, and then draw several hairs in one texture
    mapped onto every "fat" hair. It doesn't really look good when doing that with particles, because they do not blend smoothly into each other.

    But first I need to solve some of the lag, which exists between the movement of the ball, and the movement of the hair. I need to improve my collision check a bit, and probably move some code to OnCollisionStay, instead of FixedUpdate
     
  9. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    nice one! you have some cool ideas! l-sys trees, now this, very cool.
     
  10. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Wow, this is very impressive. :eek: Will you be able to add collisions with other types of meshes besides spheres and planes?

    I can already see that with a bit of tweaking and artistic wizardry something very cool could be made!
     
  11. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    If you want to get artistic you should really set up a more hand made rig with a mesh. but yeah this is the base for some awesome stuff.
     
  12. 3dtutorial

    3dtutorial

    Joined:
    Mar 9, 2007
    Posts:
    17
    Wow, that's awesome -- well done!

    Cheers,

    Joe
     
  13. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    About collisions: All the simple primitives such as boxes, cylinders, capsules are just a matter of doing it. I think ellipsoids could be done too. I would just have to figure out how the normals are modified when you squish a sphere.

    Arbitrary meshes would be possible, but expensive. If you want to avoid checking every particle against every triangle in the mesh, you have to set up a pre-calculated collsion data structure for every mesh. I'm thinking something like an octree.

    About using a hand-made mesh for the hair itself:
    I would have to think somewhat hard, about how to interpret a mesh into individual hairs.
    If I have to do that, I might as well do a full cloth simulation of the mesh. But first I learn something from the simple case.
     
  14. taumel

    taumel

    Joined:
    Jun 9, 2005
    Posts:
    5,292
    Cool! I just would add two eyes, a nose and a mouth... ;O)
     
  15. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Would using polygons improve or worsen performance for mesh collisions?
     
  16. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    It would have no effect with regard to collisions, since what I am doing the collision with is an internal data structure. It would only affect rendering performance, and I am not sure if it would get faster or slower with a mesh.
     
  17. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Very very interesting work, I likey. Oh, and I'm another one who's reminded of the sentinels from The Matrix.
     
  18. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    I had thought of doing hair with particles.
    I would love to use this, but I'm not sure whether I'd get the results I'm looking for.

    I am also looking at doing hair with ragdoll bones, or rigid body joint chains.

    Any thoughts on which would perform the best?
     
  19. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Speaking of hair..... where is Carston? I haven't seen him around these parts for a loooong time? Carsten, you still here?

    EDIT: Ok, just saw from his proglet website he is no longer doing games work.. not full time anyway... shame. I wish him luck in his new endeavors :)
     
  20. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Thank you. The wishes are reciprocated. But I have started lurking here lately, so no real reason to say goodbye yet :D

    About trying particles, you did notice that I included the complete project? So you should be able to do some tests with that.

    Using rigidbodies, hinge joints etc. would be very expensive performance-wise compared to using particles. You would in effect have several hundred individual GameObjects, each with their very own Transform, Rigidbody, Collider.etc. etc.
    And my experience with very long chains of rigidbodies suggests that they need help updating correctly anyway. So if you want to do very realistic animated hair, you need to do some of the physics simulation yourself.
    And yes, that complicates figuring out how to do collisions.

    I saw some cloth simulation around here too. Can't remember who did it. That could also be a good starting point for making hair. If you don't need to have that many individual strands, that is.
     
  21. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    Thanks Carston! I'm grateful for your prompt attention. And because You'll be around. I'm very impressed with this project.

    This helps me o appreciate that particles may be the least expensive of my options. I'll be working to implement this asap.

    Thanks again for your thoughts and advice!
     
  22. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    i was wondering where you were just the other day, nice to see you're still around - good luck with the new business ; )
     
  23. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Awesome, glad to see you are still around!
     
  24. aaron-parr

    aaron-parr

    Joined:
    Apr 22, 2007
    Posts:
    577
    Great work. I like the hair as it is. I don't think you need a reality simulation with one billion hairs for it to look good. It looks good as it is.