Author Topic: weird fluid like behaviour  (Read 2806 times)

Offline Emil

  • Mr. Drawsprite
  • **
  • Posts: 64
    • View Profile
weird fluid like behaviour
« 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

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: weird fluid like behaviour
« Reply #1 on: 2014-Jan-21 »
Black screen only for me, can you give a little description what we should see there?
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
Re: weird fluid like behaviour
« Reply #2 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

"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4143
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: weird fluid like behaviour
« Reply #3 on: 2014-Jan-21 »
That's pretty cool. I like the way the particles are affected by the other particles around it. :)
I came. I saw. I played.

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: weird fluid like behaviour
« Reply #4 on: 2014-Jan-21 »
Haha right fuzzy, I did try different keys but not the mouse. :'(
Nice effect.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1631
  • Particle Hawk
    • View Profile
Re: weird fluid like behaviour
« Reply #5 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.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Emil

  • Mr. Drawsprite
  • **
  • Posts: 64
    • View Profile
Re: weird fluid like behaviour
« Reply #6 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).

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4177
    • View Profile
    • Portfolio
Re: weird fluid like behaviour
« Reply #7 on: 2014-Jan-24 »
looks like drips of water going by the carĀ“s window when rainning.
Really cool!

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1631
  • Particle Hawk
    • View Profile
Re: weird fluid like behaviour
« Reply #8 on: 2014-Jan-25 »
Very cool
That explains the high and low pressure distributions afte the forces stabilize
Like water in a balloon
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1631
  • Particle Hawk
    • View Profile
Re: weird fluid like behaviour
« Reply #9 on: 2014-Jan-26 »
food for thought:

convert the pressures to vertices in a 3d grid....dynamic 3d fluid.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Emil

  • Mr. Drawsprite
  • **
  • Posts: 64
    • View Profile
Re: weird fluid like behaviour
« Reply #10 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

Also on the other spectrum, We have used this program to do water simulations (particles and not grids)
http://www.realflow.com/

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1631
  • Particle Hawk
    • View Profile
Re: weird fluid like behaviour
« Reply #11 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 ;)
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: weird fluid like behaviour
« Reply #12 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.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1631
  • Particle Hawk
    • View Profile
Re: weird fluid like behaviour
« Reply #13 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?

Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: weird fluid like behaviour
« Reply #14 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.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64