Search Unity

Water drops like the DriveClub's.

Discussion in 'Physics' started by imDanOush, Aug 12, 2015.

  1. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    UPDATE 2017: This thread is too old and obsolote, new visitors be aware!!
    ___________________________________________________________________________
    Hello.

    Have you seen the water drops on a car windshield of "DriveClub" video game for PS4? if no, please have a look at the GIF below:

    (http://media.giphy.com/media/3ohzdGteRdT4Gvhzby/giphy.gif)

    (C) GIF BY:Eric Chadwick

    So here is what I've made so far:

    (http://media.giphy.com/media/xUPGcvSuHjg9uV7Bzq/giphy.gif)


    ATTENTION: This is only a first try of making metaballs, And is simulating one water drop (metaball) in a bigger scale, because of performance issues. Otherwise it is possible to spawn a lot of them in a smaller scales but frame rate would be 4-5 FPS.

    but the problem is that when a car with that water drops goes a bit fast in my game, the water drops goes upward super fast, have a look at the GIF below:

    (http://media.giphy.com/media/xUPGctsq8p9v3lZqdG/giphy.gif)


    Simply it is a particle emitter that emits particles (the emitter is placed near the pointer in the last GIF image) and each particle has a collider, windshield has a collider,too. so when they collide they act as water, with a shader and a script those particles appear as water. As the car increases it's speed, the particle goes upward which is correct but the water drops act as if the car has a supersonic speed.

    Then to solve this problem, I increased frictions for both windshield and water drops, reduced and even increased wights of water drops and added force in (new vector3(0f,-100f,0f); ) to the water drops, still the problem is happening. Both windshield and the custom 2D Particles (with 3D colliders) have rigidbody.

    For more information about how did I create this effect, visit this address:
    http://www.polycount.com/forum/showthread.php?p=2337044#post2336924

    (C)Copyrights and notes:
    Shader: Rodrigo Fernández
    rest of the things and the new shader me.
    Images links are updated.
    If you the GIFs don't show up, try clicking on the hyperlinks.
    Thanks to Obscura and MrChadwick for their helps.
     
    Last edited: Mar 31, 2019
  2. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    Maybe it seems stupid but I just tried a 2D collider with a new script but obviously it wasn't working.
     
    Last edited: Jul 3, 2016
  3. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Physics for raindrops on a windshield?

    no.
     
    Freznosis likes this.
  4. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    Read the first post here it's a 2D particle. Still needs some more things to be done.
    However I think this thread became a bit complicated for visitors, Apologize for that.
     
    Last edited: Aug 13, 2015
  5. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    This :)
     
  6. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    Not trying to be a comedian, just trying to suggest that using colliders and all this stuff is probably not the way to go.
     
  7. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    I've solved the problem and finished creating this recently, still needs some tweaks but the problem is now fixed. Here's a GIF:

    However, since I've used big particles due to lower CPU usage, this effect became a bit less realistic, for more realistic effect smaller sphere mesh is recommended.
     
    Last edited: Aug 18, 2015
  8. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Hardly going off topic. Its clever, but pointless and a waste of resource for an effect that doesnt look real at all (yet)...

    The original link you posted will be completely faked. No-one would simulate individual rain drops in a car racing game.
     
    imDanOush likes this.
  9. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,664
    I found an interesting note on this Eurogamer website:
     
    imDanOush likes this.
  10. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    There you have it: Screen space effects. It's not going to be 3D rigidbody dynamics with mesh collisions for each individual droplet with impulses in 3D and all that. Physics simulations can be done at many levels, I've written a system that runs at 500,000 Hz on a compute shader to simulate gas dynamic flows for a real time internal combustion engine simulation, but it's not done the way you'd think.

    No doubt they did an incredible job, very clever, but it wasn't some "drag and drop a particle system and turn on the colliders and go PhysX, go" type of thing. When you're only getting 4 or 5 fps with very little rain, it's time to consider the possibility that they put a little more brilliance into their rain than we would be doing by just dropping some particles onto a windscreen and thinking it'll do the same thing.

    At some point it's like trying to do a car simulation by modelling every single molecule in the car as a separate rigid body and then wondering why the frame rate is 0.0000000000001 fps.
     
    Last edited: Aug 17, 2015
  11. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    Just to be clear, I'm not trying to discourage you from doing rain on a windscreen, I'm just saying that a system like that is not doing quite what you think it is. There's something fundamentally different about their system that isn't likely to be replicated with some PhysX particles and colliders. It's a custom physics model written solely for the purpose of producing that rain effect. This is why you're having performance problems.

    I'd love to see you make great rain effects like that, I'll root for you, but chances are that you're going to have to think of some other way to do it than using the built in physics.
     
    imDanOush likes this.
  12. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    If I had to take a wild guess at how they did it, or if I were to take a first stab at it, it would go something like this:

    The windscreen simulation would probably be a 2D grid of fluid flow. They model some outside rain somehow, and when a drop (which is not actually a rigid body with much if any physics per se) strikes the windshield, the value in the cell goes up, filling it partially. Do fluxes across the cell boundaries and pseudo forces up the windscreen depending on wind, and you can get water to flow from one cell to the next. The wipers would form a simple boundary (notice how straight they are) that can move stuff between the cells. Maybe not all of it, so you get a smear. It's all probably done in a compute shader. If it isn't, it should be.

    It's probably something along those lines, a flow simulation something like CFD (or my engine simulations) but in 2D, not a bunch of individual rain droplet particles. Do you see how the droplets collect on each other, pool up near the edges, smear out when wiped and all that nice stuff? You won't get that nice with particles. It's just not the way to even try to do it, quite frankly.

    Study up on water flow simulations done on grids, CFD type stuff. Then you'll be heading down the right track and one day might do something as good as they did.
     
  13. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    Before answering your posts, please note that I am not professional and I'm just learning, some professional artists helped achieving this effect in an other forum (mentioned in the first post), then one of them helped me to make this particle, so I am not emphasizing and I won't emphasize that this is the only way to recreate the effect, yet I'll be glad to show me other ways of creating this effect, of course this thread would be useful for other people if useful contents be here.

    Now this is an informative reply, comparing to your last reply. And yes, it is not that much realistic, but this isn't totally unrealistic! Thanks for your reply,though.

    great, thanks so much.

    Thanks for your informative reply, so you say that Grids and non-PhysiX physics are used? I will study them when possible,though.Also I get around -4 fps for each 180 particles, so there is no 0.00000001 fps.
     
    Last edited: Aug 18, 2015
  14. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    I don't know anybody at that company so don't really know how they did the rain effects. I was just guessing and suggesting how I would begin to go about solving the problem: Fluid simulations, not rigid bodies with collision meshes with very expensive collision detection/response computations. So I don't know for sure, but to me it seems very unlikely that they're using PhysX or anything like that. It's most likely an internally developed, proprietary, purpose built system just for the windshield rain effects. I could be wrong, but I'd put my money on it being a fluid simulation. To my eye, it looks too good not to be. :p

    0.0000001fps - I didn't mean to suggest that that's what you were getting. I was making a point about the relatively large amount of computations that need to be done by simulating systems like that with rigid bodies. Fluid simulations like those are usually something like finite volume techniques. You can't model every molecule or tiny, tiny little dot of water independently (how do you smear them, get them to stick together, etc?). CFD like that works in a fundamentally different way.

    Anyway, you might want to look to see how water and fluid simulations work instead of using particles. There are definitely physics going on in that windshield/rain simulation, it's just a different type of simulation than you might be aware of at this point. You might get there some day, but I'd suggest changing course on the whole approach.
     
    imDanOush likes this.
  15. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    It's probably something more along these lines:

    http://http.developer.nvidia.com/GPUGems/gpugems_ch38.html

    This is dated and written before compute shaders were around. So don't pay too much attention to the trickery they're doing with the fragment and vertex shaders. Back then you had to do it that way because that's all there was. It's a lot more straightforward today because of compute shaders.

    If you're not a shader guy at all yet, that's ok. What I'd do is try to write the simulation on the CPU like you're doing now. Don't worry too much if it's not super fast. When you pop it over into a compute shader it'll really fly.

    Here's an example from my engine simulation work:



    This is a real time engine simulation that produces audio in real time. It's not mixing sound files together, it's computing the wave form on the fly as the simulation runs and then running some of that information through the speaker. It's computing all of the exhaust cell states 500,000 times per second (imagine setting Unity's physics time step to only 0.000002).

    This would not be possible to do outside of a shader. One of the smaller engines I did, think it was a 4 or 8 cylinder, ran 43,000,000,000 (43 billion) calculations per second. This 11 cylinder is quite a bit higher than that. Your CPU can do a little better than 1 billion per core. So to do this on a CPU in real time like this you'd need a cluster of at least 10 or 11 quadcore machines. Even then I think the data transfer rate probably wouldn't allow it (not sure).

    So yeah, compute shaders are VERY fast for problems like fluid flow, anything that can be parallelized massively enough and if you can do some tricks to get rid of all the branching/if statements and that kind of thing. So just remember in the back of your mind that there are options to get massively more speed than you might even think is possible.
     
    Last edited: Aug 18, 2015
    imDanOush likes this.
  16. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    Great post @Todd Wasson, what you've said is completely new for me, Is it possible to use these "compute shading" stuff out side of making games, like for example data analyzing or something like that? are those engine sounds for a game or for a automotive manufacture?

    Since I don't know writing shaders (I make game for fun right now), I'll use this current particle system but when I get into the shaders, I will definitely use them instead of this.
     
    Last edited: Aug 18, 2015
  17. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    Yes, absolutely. It almost seems like that's what they were invented for. It's called GPU computing and is used for scientific purposes all the time.

    https://www.google.com/webhp?source...15US615&ion=1&espv=2&ie=UTF-8#q=gpu computing

    https://www.youtube.com/results?search_query=gpu+computing
    https://www.youtube.com/results?search_query=scientific+gpu+computing+


    My understanding is that supercomputers these days are all being built around GPU's with scientists using compute shaders (CUDA mainly, but DirectCompute like we have in Unity is good too).

    I had video games in mind for it, but it could have applications in the automotive industry as well. That industry does audio simulations too, but they operate differently and aren't usually (if ever) real time like this. It's the same goal in mind though.

    I did try the audio simulation in the boat sim about a year ago to see if it would work. Surprisingly it did:



    Unfortunately it's still too hungry for power to run a game on top of it, even with the GPU doing all the work. It starts hitting the frame rate pretty hard and in my opinion doesn't sound as good (yet) as some professionally mastered and recorded samples. Here's an example of recorded samples by a pro that does engine audio for a lot of today's racing games:



    It sounds better overall to me than my system, unfortunately. As much as I'd like my audio simulation to be able to replace good audio samples some day, it's just not there yet. I have some ideas on how to improve it, but that'll have to wait awhile. Maybe some day.

    Sure, good idea. This is just stuff to keep in the back of your mind while you're playing with your particles. That's how good ideas develop. You start with what you know how to do, and while you're playing around with it, other ideas come to mind, sometimes in the middle of the night. So if the idea excites you, just keep going with it. Who knows later what new, brilliant thing you may come up with? :)
     
    imDanOush likes this.
  18. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Heh, the abrasiveness/helpfulness of my posts depends on my mood at the time of post (was definitely not trying to discourage you from doing what you're doing). Im just very... up front about what I think (sometimes looking like a jerk in the process)
     
  19. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    I got a kick out of it and was thinking pretty much the same thing. ;)
     
    JamesLeeNZ likes this.
  20. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    No problem guys, People are different. We just should remember to respect each other and that's it, I've learned new things here, hopefully other people like me will learn those things here,too.

    Peace.
     
  21. cl9-2

    cl9-2

    Joined:
    May 31, 2013
    Posts:
    417
    This open sourced refraction shader by Keijiro Takahashi (who works for Unity) might interest you as well:

     
    imDanOush likes this.
  22. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,405
    Todd-Wasson and imDanOush like this.
  23. ADRIANO3D

    ADRIANO3D

    Joined:
    Oct 14, 2014
    Posts:
    13
  24. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    So summer comes again and I got a free time to continue this project. Although I thank the people here that suggested me shaders and assets, but I want to make one by myself. And I've made the shader recently, here is the result (the images below). I'm happy with the result so it's okay for me. NOTE: the rain drops intensity is exaggerated so that you can see them better in the images.


    Regards.
     
    TooManySugar, mgear and eses like this.
  25. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,405
    imDanOush likes this.
  26. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    Just a small update I gave the shader and its system to @kalagaan (an awesome shader-guru guy) so that he could make it compute shader Unfotunately things didn't go right. Then I decided to update the shader and its system by myself a bit. Here in the video below you may check it out.


    This shader will be shared in Polycount and here FOR FREE once the final of it version gets ready.
    Best.
     
    Last edited: Apr 20, 2017
    TooManySugar, Meceka and mgear like this.
  27. TheMightySeaSlug

    TheMightySeaSlug

    Joined:
    May 10, 2017
    Posts:
    2
    Jesus, I wish I hadn't gone through this thread. No need to get all butthurt when someone tells you your approach is all wrong. A simple google search would've steered you to shaders/compute shaders anyway and saved you lots of time.
     
  28. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    There are two notices that I should write about your post:

    1) Let me be clear for the new visitors to this thread, I've been testing several approaches for replicating the effect, those old comments were about those older approaches that I was testing. There is now much less CPU usage and more GPU usage.

    Therefore no one got "butthurt", This is a very old thread and the shader looked very bad at first. I was pissed - about two years ago - when people throw non-constructive comments here, But but they helped later.So I appreciate their comments and their efforts. However I find it "a good" option if I use the physics, but over time I've improved it and it became something that even some professional artist and tech art liked it.

    2) I didn't know about Compute shading and it is not the way this system could work with. I've learned that "compute shader" is "the best" option for it however I don't have enough time to use that technology (yet).
    Fortunately I've just edited the system and now it is very smooth and optimized (Only the dynamic water drops part needs a little CPU resource, Other parts are running via GPU). The exact approach is used in some released game. So this shader and its structure are not "all wrong".

    But that's okay I should've added more details instead of just posting GIFs and videos. In order to prevent these misunderstandings for future visitors, I'm going to delete this thread and make one new thread when the asset is ready to be shared for free.
     
    Last edited: Dec 31, 2017
    TooManySugar and Bartolomeus755 like this.
  29. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,664
    Please don't delete it, but let it get closed by a mod. Even though it's old and your previous approaches were wrong, it's still a good read.
     
    TooManySugar and imDanOush like this.
  30. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    Okay then. Glad you find it somehow useful.
     
  31. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    160
    Dear @D4N005H
    I'm following the thread on polycount and I'm trying to replicate your results. (I'm very noob comparing you but I'm trying to improve my skills).
    Following your original polycount thread it's difficult to understand what was the final workflow/setup to catch your goal. I mean. did you use metaballs? 3d particles? render to texture camera?

    Again, on polycount thread you posted a "final" solution and said that you'll release as free.
    If I'm not in trouble, are you planning to do it soon? Or did you throw away this option?

    Thanks in advance post, there are some interesting tips.
     
  32. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    160
    I have another question: if you used the particles, how did you manage the movement of secondary windshield (where real particles stay)?
     
  33. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    Hello. Glad you are interested in it. As a lot of people ask me these, I just wrote a post in my blog as a detailed answer to the question. Please check it out and read it. Here is the link: https://aroundtheground.tk/driveclub-water-drops-effect-unity3d-318/ .
    But I briefly answer your questions beased on the colors. Hope that helps.
    Don't worry about being an amateur - I am not a pro, either!!, Unity3D is easy to be learned. And I recommend you to use a baked solution instead of real-time for a serious game. But if you are a passionate software developer - like me - then that is a different story.
    I have used - temporarily - a set of 3D sphere objects acting like metaballs, I then catch the positions by a camera and send the details to the shader by using a render texture.

    I have not written "final" there, in fact, it is a "beta" hence why I still haven't released it.
    It is going to be shared for free. I explained why it is not shared yet in the blog post.
    Thanks, Always good things will happen to you if you share good things to people.
    I have used a trick for this, I've "added" external forces sourcing from the car to those metaballs (the 3D sphere objects) but I divided them by some number so that they are not excessive.
    Thanks!!
    Regards.
     
    Last edited: Oct 26, 2019
  34. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    160
    thank you for the reply.
    During my research about this topic, I've found this
    https://www.artstation.com/artwork/xO0XW

    Probably it's something similar you did... Anyway, I've read your reasons about the releasing of your asset and OK. I'll wait when we'll be available...but if you should feel that you'll never releasing due to other jobs...consider to leave the community the duty to solve the problems...or at least use as it is... :)

    Thanks again.
     
  35. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    No problem And the workflow of the shader you've shared is kinda similar to this.

    NEWER UPDATE: As this thread is too old and may cause misunderstandings for newcomers then leave the thread as is and don't "bump" it. You can download the shader, more info is here. Regards.
     
    Last edited: Oct 26, 2019