PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Water effect

Hi all,

Maybe one of you demo scene guru might be able to point me in the right direction.

I'm trying to make a 2D water effect. Not a ripple effect, but rather what one sees when uderwater. Like what I would see while looking though an aquarium, the objects on the other side changing shape as the water moves.

The effect needs to be animated too, and I really have no clue where to start looking.

Any info/tip/link appreciated. Thanks!

--Eric
Quake does a similar effect, don't know if it's after everything has been renderred though.
All Quake does is slightly offset the position of vertices based on time and position, using a sinus rhythm. So it is only applicable to 3D geometry.

Dan East
Thanks Pam, this is pretty much what I wanted!

I'll start working on this right away.

--Eric
There's a nicer way... without all those verticles/stuff

1.Create a warp map (32bpp will do fine), warp map is the size of real image

Now the 32bits represent two 16bits numbers. The X movement and Y movement. Store them with some additional precision, 12:4 fixedpoint number will do fine.

2.Fill warp map with data,
So for each pixel on screen you fill the 32bit data with something like
x=16 y=-16 (means this pixel will be taken from one place right and one place above - remember we use 12:4 fixedpoint number)

3.modify image using warp map

you simple do a loop like

Code:

newimage[x,y]=oldimage[x+((warp[x,y].x)>>4),y+((warp[x,y].y)>>4)]

of course this is without using fixedpoint math, in reality you should do bilinear interpolation using the fraction bits for good quality

4.Tricks

of course you don't need to recalculate warp map every time.. you can calculate it once and use few times

another thing is that you can generate warp data on fly without a warp map (like if you want to use sin/cos or similar waves you can simply precalculate sin in range 0-2pi and then use this data to calculate warp data on the fly.
This should be possibly for your needs (something like a modified shape sin/cos wave should be perfect)

5.Results
This methods gives good quality and fine speed results (assuming bilinear is used). Without bilinear performace is better but quality suffers.

6.Propsed solution

I guess you would be fine with on the fly calculated data, sth like code above which uses sin waves and normal pixel copy (no bilinear)
sin is a 8:8 fixedpoint number so 256==1.0f etc.

variables used:
t-time
image - your image
newimage - your image after warp
x,y
Code:

for x
for y
newimage[x,y]=oldimage[x+(sin[((t+x)&0xff)]>>4),y+(cos[((t+y)&0xff)]>>4)]
end for
end for


this should give you a 16pixels wave over your image which changes with time... this is the simplest effect possible... you need to add some checks so you don't try to grab pixels from position -5,-5 etc.

if you have got some questions (probably you do, chaotic explanation at 1 o'clock in the night :) let me know