Jump to content
  • Advertisement
Sign in to follow this  
gabriele farina

OpenGL Rendering liquids

This topic is 3049 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I'm working on a simple 2D platform game (that uses OpenGL ES for rendering) that involves fluids management. So far, each particle of the fluid simulation is being rendered using a single texture sprite. However the effect is not that good so I was thinking to try to alternative way to render the fluids when particles are in contact. What I want to achieve is something like PixelJunk Shooter's water rendering. The only thing I've tried so far is using Delaunay trinagulation on the particles: this creates a decent mesh out of a group of connected particles, that is then rendered using OpenGL. However the effect is not as expected because Delaunay triangulation creates every possible triangle that could be generated by the given set of points. So, if you have a situation like this one:
|
|O
|OOO
|AOOOOOO
-------OO
         OO
          OO
          OO
          B
You end out having additional edges (for instance the one that connects A and B, that shouldn't be there. As long as I'm on a mobile device, I cannot execute too much code so what I was thinking about was to remove all the edges that are longer then a given threshold (lets say that 2 particles interact when the distance is less then N, I can remove all the edges longer then N safely), and then render the fluid mesh below the obstacles on the screen. The effect won't be extremely good, but probably it will remove connections that are not required. Do you have any other suggestion ? Maybe an alternative approaches that are able to generate a less complicated mesh in less time ?

Share this post


Link to post
Share on other sites
Advertisement
I'm sure a 2D iso-surface is what you need. Basically a marching cubes implementation in 2D only. I'm sure this would be much simpler than the 3D case it's known for, but it still won't be trivial. I've not seen a demo for it done in 2D but tbh I never looked either.

Some kind of 2D metaballs might work too. At least it's a good seach term for you

Share this post


Link to post
Share on other sites
Quote:
Original post by Rubicon...Basically a marching cubes implementation in 2D only...


If you want to try this then 'Marching Squares' is the term to search for.

Share this post


Link to post
Share on other sites
I have done this before, and I'm having trouble following the example on wikipedia.org, so perhaps that isn't the best example to go from.

Anyway, if you need some working source code for the 2D case, you can send me a private message, or pry it out of http://nd-disconnectedness.googlecode.com/files/nd-disconnectednessv1.zip -- this zip file contains code for the 1D and 2D cases. In the 2D case I convert a grayscale image to a mesh.

Share this post


Link to post
Share on other sites
Quote:
Original post by PolyVox
Quote:
Original post by Rubicon...Basically a marching cubes implementation in 2D only...


If you want to try this then 'Marching Squares' is the term to search for.
LOL, I guess I shoulda worked that one out for myself :)

Share this post


Link to post
Share on other sites
Great, thanks for the code.

I already did a 2D marching squares implementation but it wasn't working as expected. However I think that the problem might have been related to the fact that the grid was too small.
The other problem I was having was with the fact that the generated mesh was too complex (too many triangles).

I'll give a look at the code and let you know if I can achieve a good result.

Share this post


Link to post
Share on other sites
Quote:
Original post by gabriele farina
Great, thanks for the code.

I already did a 2D marching squares implementation but it wasn't working as expected. However I think that the problem might have been related to the fact that the grid was too small.
The other problem I was having was with the fact that the generated mesh was too complex (too many triangles).

I'll give a look at the code and let you know if I can achieve a good result.


You will find that this code also gives lots of triangles. It's the nature of the beast.

Some kind of naive mesh simplification/decimation algorithm might work for you, like combining all adjacent squares on each "line" into a single rectangle.

Share this post


Link to post
Share on other sites
Not sure why you're getting too many triangles, but if they're mainly internal then it should be fairly easy to navigate the complex mesh you get and find just the edges, then restitch them using ear clipping.

Share this post


Link to post
Share on other sites
Quote:
Original post by Rubicon
Not sure why you're getting too many triangles, but if they're mainly internal then it should be fairly easy to navigate the complex mesh you get and find just the edges, then restitch them using ear clipping.


I think you're probably right, that they're internal. Let's all remember though that the time taken to decimate the mesh on the CPU has to be roughly less than the time it takes to transfer the non-optimized mesh to GPU RAM and render it, otherwise decimation's not even worth it in the first place. I should have made this explicit beforehand.

Share this post


Link to post
Share on other sites
this is an extremely awesome idea! id love to see it once you got it working i bet its really cool :)

All I could think of is to grid up all the particles in a mesh, but then it wouldnt be able to spread apart so that idea doesnt work.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!