gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > 2D Water Effect (Mario DS Style)

#41526 - Celeryface - Fri Apr 29, 2005 2:32 pm

Hi,

I know this isn't directly related to GBA coding, but I wanted to get some of your opinions on the subject. I'm starting some research on the 2D water effect found on this site: http://freespace.virgin.net/hugo.elias/graphics/x_water.htm

I also noticed a similar technique is found in the Special Effects Game Programming in DX book. Does anyone know where the algorithm originated, or if there are any other resources on it?

My main goal is to get this algorithm working, and then be able to apply it to a plane in a 3D world, similar to the effect in Mario 64/DS.

Thanks in advance. :)

#41554 - rapso - Fri Apr 29, 2005 4:47 pm

Celeryface wrote:
Hi,

I know this isn't directly related to GBA coding, but I wanted to get some of your opinions on the subject. I'm starting some research on the 2D water effect found on this site: http://freespace.virgin.net/hugo.elias/graphics/x_water.htm

I also noticed a similar technique is found in the Special Effects Game Programming in DX book. Does anyone know where the algorithm originated, or if there are any other resources on it?

My main goal is to get this algorithm working, and then be able to apply it to a plane in a 3D world, similar to the effect in Mario 64/DS.


Code:

    void ProcessWater(short *source, short *dest)
    {
        int i;

        for (i=320; i<64000-320; i++)
        {
            dest[i] = (
                    ((source[i-1]+
                          source[i+1]+
                          source[i-320]+
                          source[i+320])  >>1) )-dest[i];

            dest[i] -= (dest[i] >> 5);
        }
    }

that's the source for it (it's on the page), do you need more to get it working? it's quite simple!

I used it several times and there are lot of games using it (e.g. patrician2, baldurs gate dark alliance (ps2)).
but even with lot of optimisation it's slow 'cause you allways have to prepare a complett 2d array and on an image of 240*120 on the gba it won't run smooth anymore (I did not prove it)

greets
rapso


greets
rapso

#41563 - Celeryface - Fri Apr 29, 2005 6:29 pm

To put the algorithm on a 3D object, would the y component of the vertices be the height values in the array? Or does games like Dark Alliance project a 2D flat plane to a 3D object as a texture?

#41589 - rapso - Sat Apr 30, 2005 12:20 am

Celeryface wrote:
To put the algorithm on a 3D object, would the y component of the vertices be the height values in the array? Or does games like Dark Alliance project a 2D flat plane to a 3D object as a texture?

afaik it's right, just the y-component of the position-vectors are modified the change the geometry itself, but if you want to get some lighting and even env-mapping effects, you'd have to recalculate the normal of the vertices or calculate the gradient (as shown on the page, the gradient can be used to fake lighting and envmapping).

greets
rapso

#42060 - astu - Thu May 05, 2005 7:53 am

nah
you could do a loop from 0 to maxY and 0 to maxX
calculate distance to center and do some sin(dist+kakka) and pick pixel there.
or use some grid with changing u/v values if you prefer hardware (you should)