Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (867)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Simple 2D fluid simulation  (Read 5204 times)
0 Members and 1 Guest are viewing this topic.
Offline J0
« Posted 2015-06-18 17:34:31 »

Hi lads!

I've just begun coding a new game, and I arrived at a point where I need to make a simple fluid simulation.
I don't want anything complicated for now (it's the first time I attempt fluid simulations). What I need is, I have a gui in which I'd like to place water. The water should not react to any external events, just gently wave back and forth at the bottom of my gui. I already made a reflexion effect, but now I need the wave, which will be added on top of the reflexion with alpha transparency. I also think it would be better to have it painted smoothly with different blue tones.

Any ideas about how to do that? Would you recommend particles or a vectorial grid? persecutioncomplex
I found a lot of resources on the net, but they were always about making fluid that reacts with the environment, which is not what I want, so I guess what it will look like will be simpler Wink

Thank you for any help Grin

J0

Excuse my English please Roll Eyes

Offline basil_

« JGO Bitwise Duke »


Medals: 418
Exp: 13 years



« Reply #1 - Posted 2015-06-18 20:47:04 »

if you think as a "2D side view" of a water surface .. like (random google search)


.. i would do it in a full-screen-quad like texture shader - using value-noise FBM. very simple. just a fragment shader, noise + XY tex-coords.

actually, if it doesn't need to react to anything but itself i would do a "2D top view" of water like that too.
Offline philfrei
« Reply #2 - Posted 2015-06-18 21:18:14 »

I was fooling around with some fluid simulations, and came up with the following a while back. I don't know if it will give you what you want. (I'm reacting to the graphic that basil_ posted.) The amount of activity in it is determined by the starting positions of the y values.

1) create float array, with a length = x pixels (width that you wish to fill) and pre-fill with y values that match the water height in pixels of your starting wave shape.
2) create a second array to hold the differences in levels between all the elements in the first array.

Algorithm:
(a) fill second array with differences.
(b) add 1/2 of those differences to each corresponding side.

Example:
water[0] = 7
water[1] = 8
water[2] = 9
water[3] = 9
water[4] = 8
water[5] = 7
water[6] = 6
water[7] = 5

populate:
delta[0] = 1 // between water[0] and water[1]
delta[1] = 1
delta[2] = 0
...
delta[6] = -1 // between water[6] and water[7]

then add back to original:
water[0] += 1/2 delta[0]    // note, each end only has one delta contributor
water[1] += 1/2 delta[0] + 1/2 delta[1]
water[2] += 1/2 delta[1] + 1/2 delta[2]
...

I hope I am remembering this correctly. The amount of fluid stays the same, and the turbulence continues indefinitely. There is no "friction" component.

music and music apps: http://adonax.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline J0
« Reply #3 - Posted 2015-06-19 12:51:18 »

Thanks to you two Cheesy
Would you like credit in my game for that help? Smiley

J0

Offline basil_

« JGO Bitwise Duke »


Medals: 418
Exp: 13 years



« Reply #4 - Posted 2015-06-19 13:26:26 »

hell no! Wink
Offline J0
« Reply #5 - Posted 2015-06-19 15:54:10 »

Ikr haha Wink

Offline philfrei
« Reply #6 - Posted 2015-06-19 19:17:28 »

Just let me know if the algorithm ends up being useful, and a link to the game when you have a working demo would be nice. It would be neat to see in action.

music and music apps: http://adonax.com
Offline J0
« Reply #7 - Posted 2015-06-19 20:43:44 »

It would be neat to see in action.
Sure! The game is far from being finished tho, and I prefer completely finishing it before posting it in showcase, but I will when I'm done and I'll add a reminder here (if I manage to find this post persecutioncomplex )

Pages: [1]
  ignore  |  Print  
 
 

 
Riven (397 views)
2019-09-04 15:33:17

hadezbladez (5280 views)
2018-11-16 13:46:03

hadezbladez (2204 views)
2018-11-16 13:41:33

hadezbladez (5544 views)
2018-11-16 13:35:35

hadezbladez (1150 views)
2018-11-16 13:32:03

EgonOlsen (4585 views)
2018-06-10 19:43:48

EgonOlsen (5462 views)
2018-06-10 19:43:44

EgonOlsen (3119 views)
2018-06-10 19:43:20

DesertCoockie (4016 views)
2018-05-13 18:23:11

nelsongames (4708 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!