GLBasic forum

Main forum => GLBasic - en => Topic started by: Emil on 2014-Jan-21

Title: weird fluid like behaviour
Post by: Emil on 2014-Jan-21
was experimenting with some fluid like simulation and then this happened. Tweaked it a bit to be more fun but nevertheless.

Enjoy :)

https://app.box.com/s/h1tnqdmfhqol6nbqqb3p (https://app.box.com/s/h1tnqdmfhqol6nbqqb3p)
Title: Re: weird fluid like behaviour
Post by: kanonet on 2014-Jan-21
Black screen only for me, can you give a little description what we should see there?
Title: Re: weird fluid like behaviour
Post by: fuzzy70 on 2014-Jan-21
Did.you press the left mouse button kanonet. I only discovered that by accident lol

Lee

Sent from my C6603 using Tapatalk

Title: Re: weird fluid like behaviour
Post by: Ian Price on 2014-Jan-21
That's pretty cool. I like the way the particles are affected by the other particles around it. :)
Title: Re: weird fluid like behaviour
Post by: kanonet on 2014-Jan-21
Haha right fuzzy, I did try different keys but not the mouse. :'(
Nice effect.
Title: Re: weird fluid like behaviour
Post by: Hemlos on 2014-Jan-24
Fluids sims are a beast, bravo on your success!

Correct me if im wrong please..
If im not mistaking, in a fluid simulator, i think its more like pixels affecting each other, as opposed to specified particles...physics simulation where every pixel in a specified field are all affected by each other.
The parts that look like particles moving away at diagonals are actually "disturbed" into certain directions...with specific forces applied in 4 (perhaps 8?) directions away from the mouse position.
Title: Re: weird fluid like behaviour
Post by: Emil on 2014-Jan-24
Quote from: Hemlos on 2014-Jan-24
Fluids sims are a beast, bravo on your success!

Correct me if im wrong please..
If im not mistaking, in a fluid simulator, i think its more like pixels affecting each other, as opposed to specified particles...physics simulation where every pixel in a specified field are all affected by each other.
The parts that look like particles moving away at diagonals are actually "disturbed" into certain directions...with specific forces applied in 4 (perhaps 8?) directions away from the mouse position.

Almost correct!
It's definitely different from "real" fluid simulations. But I guess there are two schools. One where you use particles and one where you use a grid (such as mine).
I'm trying to not look at how others do so.., If you want to do it "correctly" then don't listen too much to how I do it :)

I'm practicly doing 2 things:
First I'm diffusing the pressure, and this is what makes this simulation so interesting... Instead of spreading out high pressure to low pressure I'm doing the opposite. In practice this means that high pressure wants more pressure and low pressure does the same. This makes everything behave like it has lots of surface tension.

The second thing I do is to advect the field. I'm saving two buffers, one has the velocity of every pixel and the second has the density/pressure, the stuff being moved.
In the diffusion of pressure (that I just described) it doesn't just move the pressure but also changes the velocities of the grid. The idea is to fill a low pressure field and distribute out from the high pressure ones. Advection is done by adding whatever stuff you have in a cell to the cell that the original cells velocity is pointing towards. Since the velocity vector might be pointing to a position that's inbetween 4 cells then some math is needed to distribute that evenly. This means that stuff diffuses alot in strange ways.

I'm actually applying all directions from the mouse, I think it looks very much not like it but I guess that's because I'm adding it in a square shape with the mouseposition as center. This means that the distribution of force isn't circular but squareish.., hence the clover like pattern (my guess).
Title: Re: weird fluid like behaviour
Post by: erico on 2014-Jan-24
looks like drips of water going by the car´s window when rainning.
Really cool!
Title: Re: weird fluid like behaviour
Post by: Hemlos on 2014-Jan-25
Very cool
That explains the high and low pressure distributions afte the forces stabilize
Like water in a balloon
Title: Re: weird fluid like behaviour
Post by: Hemlos on 2014-Jan-26
food for thought:

convert the pressures to vertices in a 3d grid....dynamic 3d fluid.
Title: Re: weird fluid like behaviour
Post by: Emil on 2014-Jan-26
yeah for sure! people do that stuff.., without great optimization skills or ability to code directly to gpu it's kinda slow though...  :whistle:

Have used this neat plugin for 3dsmax at work from time to time (grid solution, also not realtime)
http://www.afterworks.com/FumeFX/Simulation.asp?ID=4 (http://www.afterworks.com/FumeFX/Simulation.asp?ID=4)

Also on the other spectrum, We have used this program to do water simulations (particles and not grids)
http://www.realflow.com/ (http://www.realflow.com/)
Title: Re: weird fluid like behaviour
Post by: Hemlos on 2014-Jan-26
Yes itll be slow on too many vertices.

Shader would be faster, but interaction with a GLBasic program would be extremely limited(cest la vie for glbasic and shaders).
You can only pass data as single chunks to a shader with glbasic...you can pass a vector, but in 3 separate vars...then you rebuild your triplets in shader code(this is a slowdown)

Food for thought is all this was meant to be ;)
Title: Re: weird fluid like behaviour
Post by: kanonet on 2014-Jan-26
You can use all OpenGL calls in GLBasic with INLINE. So if you want you can pass big arrays of data, if you need help with this write me a message and I help you with this. (all Desktop only, cant use shaders on mobile devces).
If there is a need I can write a lib to give you better and easier shader support in GLB, but would need some time to do so.

But using shader is not faster in every case, especially not when doing complex calculations per vertex and mixing it with GLBasics fixed pipline. Shader are more powerful, but not always faster. For fluid simulations it could be useful to use compute shaders, but this is very advanced stuff (which I have never done, only vertex and fragment/pixel shaders) and limited to really new hardware.
Title: Re: weird fluid like behaviour
Post by: Hemlos on 2014-Apr-22
Kanonet you can stream an array into a shader no problem...one dimension only, not 3 as 3d would require.
This is a x3 slowdown for passing vertice data into the shader via glbasic.

There is a way to use inlines to pass data such as Vector2 and Vector3?
How about passing a matrix into a shader?

Title: Re: weird fluid like behaviour
Post by: kanonet on 2014-Apr-23
With INLINE you can pass everything into the shader, e.g. I have done it with textures, matrices, vec3 and arrays of any of them. There are no limitations, as long as you accept that you can only do this on desktop platforms.
Title: Re: weird fluid like behaviour
Post by: nabz32 on 2014-Apr-24
I like grids, and I like this, it´s a very nice effect.