Fluid Dynamics - Curl Noise


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:

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:


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…


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


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?


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).


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.


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.


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.


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.


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


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?


Yes, sensei, I remember that :slight_smile: 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.


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?


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.

Just download the dropbox file and double-click on the .exe


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


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.


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.


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.



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!


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.