# Fluid Dynamics - Curl Noise

#22

Okay, I’ve finished remaking my fluid system to work as a grid instead of discreet entities. It’s a bit slower than I’d like, but I’m getting there. Here are some images:

And now for one with a lower grid resolution:

Edit:
So I did some profiling, and the diffusion function turns out to be incredibly slow (close to a tenth of a second). I’ll look into what I can fix, but it doesn’t look to bad without diffusion, so if worse comes to worse I can kick that out:

#23

I recorded a video of this in action:

Comments anyone? It would be nice if you didn’t wait until after I was finished to tell me that compound clouds aren’t supposed to be discrete entities like last time…

#24

It all looks amazing! Does the total amount of the “compound” stay constant as it diffuses?

#25

I’ve mentally added the compound concentrations at each grid square and found a similar number to the one I started with, but obviously I ignored the hundredth decimal places and smaller. I’ll write some code to make sure when I gave time.

Also, to prevent rounding errors, is it okay that you can absorb a fraction of a compound?

#26

That looks great.

In terms of conservation if all you are doing is moving the values around then the total amount of compound will be conserved. (Advection preserves the L2 norm).

#27

Compounds are measured in units (specifically, picomoles) large enough that they may as well be continuous – a single molecule would be on the order of 10^-10 compound units, well below any sort of rounding error we would have to worry about.

Ah yes, and I heartily agree with ignoring diffusion – you can make the clouds look diffuse simply by starting with a diffuse cloud, and what we lose in realism we gain in fun, I’d say.

#28

So I’m probably going to keep diffusion. It makes the clouds look a lot better. The advection wasn’t conserving the compounds, but I used another method, and it seems to all add up to now. I lose around .1% of the compounds, which I don’t think is a big deal (the excess will just go to the same place compound clouds disappear after the player moves away from them). Here is the code for advection if anyone wants to look at it:

``````for (int x=0; x<width-1; x++)
{
for (int y=0; y<height-1; y++)
{
float dx = x + dt*velocity[x][y].x/width;
float dy = y + dt*velocity[x][y].y/height;

int i0=(int)dx; int i1=i0+1;
int j0=(int)dy; int j1=j0+1;

float s1 = dx-i0; float s0 = 1-s1; float t1 = dy-j0; float t0 = 1-t1;

density[i0][j0] += oldDens[x][y]*s0*t0;
density[i0][j1] += oldDens[x][y]*s0*t1;
density[i1][j0] += oldDens[x][y]*s1*t0;
density[i1][j1] += oldDens[x][y]*s1*t1;
}
}
``````

density[][] is initialized to zero at the beginning of the loop and oldDens is equal to the density from the previous iteration.

#29

I should probably rename this thread as “What TheCreator has been up to”…

Anyway, I’ve created a library on top of OpenCL that makes it really easy to run programs on GPU. This is all you need to write:

``````GPUProgram program;
program.Open("./fluid_sim.cl"); // Name of .cl file where we have the function
program.Run("addSource", density, densitySource, &factor); // Runs the function specified in the first parameter with the following arguments.
``````

Tomorrow I’ll apply this code to my fluid sim to make sure everything works, and then I’ll begin porting it to Ogre.

Edit: Actually, if it isn’t too hard, could someone check it now? Here is the Dropbox link. Preferably people with an AMD, and NVidia video card and someone who is on Apple and Linux. It should just print out 700 100 times if it works (it’s actually doing some complicated math) or 0, 1, 2, 3, … 100 if it doesn’t.

#30

Ooh, ooh! I’ve got a better name for this thread! Clears throat “TheCreator talking to himself”.

Anyway, making everything run on GPU turned out to be a catastrophic failure, it was up to 6 times slower. On the bright side, when I went back to CPU, I must have changed something because now the fluid sim runs at 1000 fps.

#31

What you’re doing sounds really good, not sure I have much to input. As always I’m impressed.

#32

You young’uns don’t know anything 'bout talking to yourself.

This is amazing work, we just don’t have all that much contribute (me in particular, because what the hell do I know about fluid dynamics?). Have you managed to link in @tjwhale’s earlier microbe-induced turbulence or is that still quite a way down the line?

#33

Yes, sensei, I remember that The good ole’ days of the old forum…

Should I add tjwhale’s turbulence? I don’t think it would be too hard, seeing how he already wrote the code, but I got the impression that we didn’t want microbes to create currents (it might make it hard to absorb compounds).

Anyway, I was kind of hoping that someone would try out the GPU demo thing, but I guess I’m not doing that anymore.

#34

IMO there’s a gameplay decision in there about the relationship between the cell and the fluid. Are you free of it and able to move around wherever you want? Which is non-realistic but may feel more usual and gamey. Or are you buffeted around by the currents and forced sometimes to flow with them, providing terrain? I sense that most people have been leaning towards the former, which is fine.

Whether the cells produce a purely cosmetic wake is really not so important and is really a graphics issue.

How would I run the GPU program? Would I need a working build of Thrive?

#35

I think that currents should definitely affect cells, but I’m fine with leaving it as is if other people mind. I just think it might make gameplay funner for photosynthesizers and will persuade people to invest into flagella and cilia. The bigger you are, of course, the less an affect currents should play.

#36

I’m afraid I’m getting two errors, MSVCP140.dll and VCRUNTIME140.dll are missing from your computer.

#37

I agree with TheCreator on the topic of having the cells being pushed by the fluids (are we talking about just the player cell or the NPC cells too?). Even if its toned down a lot, I think it’s much better than having nothing. It would break the sense of fluidity if, when you stop moving, your cell remains perfectly motionless in the environment.

#38

We can just play with scaling how much the cells are pushed by the flow compared to the compound clouds themselves – there’ll probably be a factor somewhere which lets compounds and microbes both flow around as quickly as we like.

#39

So after a day at it, I got this:

Edit: Played a bit more with the parameters:

I’m not going to work on this right now, but it would be nice if you guys could come up with a final list of colors for the various compounds.

#40

Awesome!

Is there a way you could make the cloud look more wispy/cloudy?

It looks more like the cells were airbrushed at the moment. Not to be rude though, this is really cool! Compound emitters really bog down the gameplay. Great work!

#41

Awesome! It looks a bit bright right now, so I agree with Nick that you could play around with transparency and graininess to get a more natural looking cloud (something like this).

Could you get a video of this as well? It might look a bit more natural when we can see it moving.