Realistic water simulation ! [NOT a game]

SadiQ

  • Posts: 1780
   I decided to try my luck with this tutorial http://gamedev.tutsplus.com/tutorials/implementation/make-a-splash-with-2d-water-effects/  and this is what came out of it:
http://www.stencyl.com/game/play/20617

If anyone knows how I can apply a gradient to my water I'd love to do it. (if I apply the gradient on it it goes from left to right and I can't change it from bottom to top).


EDIT: Gradient applied...behavior is on the forge (name: Realistic Water Surface).
   Here's a quick adaptation of the bundled baloons game with the water behavior applied to it:
http://www.stencyl.com/game/play/20699

« Last Edit: August 14, 2013, 05:48:44 am by SadiQ »
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.


spoogob

  • Posts: 1106
Nice.

Not sure about applying a gradient though. Good luck with it :)

captaincomic

  • *
  • Posts: 6109
Nice.

In the link you posted they say
Quote
To make it look a bit nicer, we’ll also make the water darker as it gets deeper by colouring the bottom vertices dark blue. The GPU will automatically interpolate colours between the vertices.

In the code this is done here:
Code: [Select]
    primitiveBatch.AddVertex(p1, lightBlue);
    primitiveBatch.AddVertex(p2, lightBlue);
    primitiveBatch.AddVertex(p3, midnightBlue);
 
    primitiveBatch.AddVertex(p1, lightBlue);
    primitiveBatch.AddVertex(p3, midnightBlue);
    primitiveBatch.AddVertex(p4, midnightBlue);
For the first triangle there is only one vertex at the bottom that needs to be darker, for the second triangle their are two vertices.

TDonnally

  • Posts: 235
This is really cool. I don't think I have seen a Stencyl game with any form of realistic liquid.

SadiQ

  • Posts: 1780
Nice.

In the link you posted they say
Quote
To make it look a bit nicer, we’ll also make the water darker as it gets deeper by colouring the bottom vertices dark blue. The GPU will automatically interpolate colours between the vertices.

In the code this is done here:
Code: [Select]
    primitiveBatch.AddVertex(p1, lightBlue);
    primitiveBatch.AddVertex(p2, lightBlue);
    primitiveBatch.AddVertex(p3, midnightBlue);
 
    primitiveBatch.AddVertex(p1, lightBlue);
    primitiveBatch.AddVertex(p3, midnightBlue);
    primitiveBatch.AddVertex(p4, midnightBlue);
For the first triangle there is only one vertex at the bottom that needs to be darker, for the second triangle their are two vertices.

  Unfortunately my coding skills are not that advanced, and from my understanding he needed to transform a polygon into 2 triangles in order for the GPU to do the rendering(I assume that code handles the splitting and assigns each point to a color).
  The problem is that I can't use the GPU to handle the drawing part, or can I ?
  For now I just use filled polygons and it works great even on a 640x480 game size if I lower the surface of the water, but I can't change the angle at which the gradient works(apparently    
g.setGradient only allows 2 colors as it's arguements in stencyl, yet in the Adobe docs it has more options available ).
  Here's how the water looks with a gradient on(random colors) and stroke thickness at 1 pixel:

http://i.imgur.com/uMECsEU.png
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

captaincomic

  • *
  • Posts: 6109
Okay, I assumed you used that same code.
Could you show a screenshot of your behavior or post code you used?

Jay123

  • *
  • Posts: 153
I feel like i'm stuck in groundhog day - same code, same pc, same shite... no retreat, no surrender yaa !!!

aroncruce

  • Posts: 214
Wasnt there water in a omre complete version of that mambo adventure game?

SadiQ

  • Posts: 1780
Could you show a screenshot of your behavior or post code you used?

   Unfortunately there's no code in my behavior..only blocks :P
I was hoping to find some code that would allow me to apply that gradient but I'm not that lucky :D
  Anyway..here's the entire behavior without comments. I tried to follow his code to the best of my abilities, but if you spot any mistake please let me know so I can correct it.
  I will be uploading the behavior to the forge once I get everything commented :)

Any other ideas about adding that gradient?

Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

spoogob

  • Posts: 1106

  Anyway..here's the entire behavior without comments. I tried to follow his code to the best of my abilities, but if you spot any mistake please let me know so I can correct it.


I did start and have a go at the tutorial and tried to bring it into stencyl, but I got completely lost after 10 minutes where to go. lol So you got much further than I did  :D

SadiQ

  • Posts: 1780
@spoogob: don't worry mate...this wasn't my first attempt at that one, I started it about 3 times and every time I over complicated it heheh. This time I just went with the easy way and it works nicely :)
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

spoogob

  • Posts: 1106
lol yeah it looks pretty good. I think my problem is trying to convert that over into blocks, and because there's the math side of it which i struggle with sometimes, I just got stuck lol

But be good to see this finished and maybe a little more configurable maybe, once you have your gradient sorted out hopefully.

aroncruce

  • Posts: 214
I cant find it now but it was a game featuring mambo it was title something like "mambos extended adventure" or something similar. It had a water effect in it. Anyone know what game I am talking about?

captaincomic

  • *
  • Posts: 6109
Any other ideas about adding that gradient?
Hm, sorry, I tried a bit, but it seems to be unimplemented and I don't see a way to do it without modifying the source.