1
\$\begingroup\$

So, for a game project I'm going to be working on I need to make a fully working 3D fluid simulator in Unity3D using C#, that can work in real time.

The only problem is, I've never done anything like fluid simulation. I've been doing tons of research on it, and I think a Eulerian based fluid simulator would fit my needs best (just like this).

Basically what I need is something that can react to changing terrain and move realistically.

The people that made that simulator have a research paper online, and I've read through it. I understand the basics, but I have no idea how I could get that in to C# or Unity3D. So I was wondering if any of you could help me, either by linking to other fluid-simulators where the code is open source, so I can pick it apart and change it to my needs, or by giving me tips on where to start/what I would need to do.

I've spent hours looking online for fluid simulators, but haven't found a single one programmed in C# as of yet, I have a program that can convert C++ to C#, but I don't understand C++ well enough to know where to put the scripts in Unity once they're converted.

Any help at all would be extremely appreciated, I'm really interested in teaching myself how to make this system, but I just have no clue where I should start, or what has already been done that I could build off of.

\$\endgroup\$

2 Answers 2

6
\$\begingroup\$

Disclaimer: I haven't heard of a paper describing how From Dust was done, so this is entirely guess-work.

A few things I noticed about From Dust:

  • Anything on the landscape is a fluid (notice what happens when you drop a lot of sand at once) - everything just has different viscosities.
  • You never get overhangs (at least on my computer) - this would be a cliff in terms of landscape.

This means that it isn't a proper 3D fluid simulation (I doubt you could do a 3D one in realtime at that scale) - I did some research into the topic myself a while back and pretty-much every post/article/paper I came across dealt with accurate 3D fluid dynamics: you just don't need this.

If was to actually implement this I would do the following:

  • A large amount of particles. These would have to be simulated on the GPU - in order and not simultaneously (so first landscape and then water). Each simulation would be aware of the result of the previous one, so in your first run landscape would be aware of nothing and water aware of landscape. During any subsequent run landscape would be aware of water and water would be aware of landscape. This means the landscape would erode one frame behind, but the user won't notice it anyway.
    • The simulation for each is quite simple: particles avoid each other and react to gravity. They can never fall below the particles of the previous simulation (e.g. water particles can't go under landscape). Their viscosity determines the springiness between particles of the same type.
  • Create a rough surface with marching cubes (these would be relatively big).
  • Use a geometry shader and NURBS to smooth out the geometry on the GPU.
  • In both physics and mesh generation skip processing particles that are under the current surface.
  • If two particles settle (stop moving) close to each other combine them into one bigger one.

You could also do a full 3D fluid dynamic simulation, but at a much lower resolution than the level and use marching cubes to generate the mesh; and then NURBS to smooth it out. Alternatively:

  • Possibly have a quad-tree-like structure of simulations.
  • If one system becomes to complex create a split in the structure. Essentially you want something like a gamut alarm; but for fluid dynamics.
  • If the user interacts with an area create a split in the structure.
  • If one of the systems stabilizes merge it into it's parent.
  • You could also tie the simulation accuracy to the camera position - but it might result in odd scenarios. Alternatively if you start running out of bandwidth you could start merging the simulation furthest from the camera.

This might get you close to what you want - but I never tackled it because I didn't have a concept to back the technology; and it's no small under-taking.

Finally, remember that once you get past the fluid simulation From Dust is a really simple game - I don't think they had much bandwidth left after implementing the technology.

\$\endgroup\$
1
  • \$\begingroup\$ +1! Great analysis of how From Dust probably does its magic! \$\endgroup\$ Commented May 10, 2012 at 4:30
0
\$\begingroup\$

How detailed of water are you looking for? Also what scale are we talking about?

If you need realtime water I suggest a much simpler approach which I'm going to dub the Minecraft approach. Basically partition your grid into very small blocks (this depends on the scale of the game). Every update check if the water is the same height as the surrounding 9 blocks. If it is not then talk to the other 9 blocks, divide them equally, and set the new water level from that new average.

This is iterative meaning that it doesn't work instantly but gradually over time - which as you may have seen from Minecraft actually makes it more realistic because it looks like it flows.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .