# N64 Quality Water...

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

## Recommended Posts

Hi again all.

I'm trying to mimic some old Nintendo 64 quality water...
The key points would be to interact with the water and to be able to run it on a low end android device. I'd like the water to animate, and for objects to be able to interact; but it doesn't need to be super realistic (IE: no reflection)

The issue is i'm having a hard time finding resources on renderin water that aren't about particle systems needing the latest and greatest hardware

Can anyone please point me in the right direction?

##### Share on other sites
The surface looks like it's just a triangle mesh, rendered after the scene with a surface texture and the waves are done by shifting the verticies up and down, probably in the shader. It's probably just a simple set of sine waves of different frequencies added together. It's fast and also easily reproducible for when you want to do (say) collision detection.

The interactions with the objects can be done in two ways.

Firstly, for decorative objects (say things floating on the surface of the water) they can be drawn with a shader which just computes the same sort of offset as the waves based on their position and adds that to all coordinates.

For player objects you'd probably do the position calculation on the CPU and send them prepositioned. This allows them to do things like sink into the water upon landing.

Scatter water splash particle effects around at all the interaction points based on what interaction is happening and that'll help obscure some of the polygon edge artefacts (although many are still visible in that video).

The only complicated part is going to be doing the bouncey "floating" behaviour for your player objects but it'll end up being a fairly small lump of code run a few times a frame (so efficiency won't be too much of a stress) with a few constant factors which will need tuning by hand until you get a behaviour you're happy with -- it's that that tuning process which will give your game its character and feel.

##### Share on other sites
[font=arial, verdana, tahoma, sans-serif][size=2]Thanks Katie.

That's pretty much what i had in mind too, but after some searching i found all sorts of particle this and spring simulation that which made me second guess myself. I also found a cool video on [color="#000000"][font="arial, sans-serif"]Gerstner Waves which i might try to do. Having characters interact with water is going to be hard, but i think i'll be able to figure something out. Thanks again![/font]
[color="#000000"][font="arial, sans-serif"]
[/font][/font]
[color="#000000"][font="arial, sans-serif"]
[/font]
[color="#000000"][font="arial, sans-serif"][size="4"]EDIT:[/font]
[color="#000000"][font="arial, sans-serif"]Actually, i have one more question. I can make a pretty nice wave effect using sinf(x) / x, however i have no idea how to animate this... Or how to combine multiple waves so my water isn't just going left to right... Any suggestions?[/font]

##### Share on other sites

[color="#000000"][font="arial, sans-serif"]Actually, i have one more question. I can make a pretty nice wave effect using sinf(x) / x, however i have no idea how to animate this... Or how to combine multiple waves so my water isn't just going left to right... Any suggestions?[/font]

Just add a time coefficient in there - replace x with (x + ct) where t is time and c is some constant you can tweak to adjust the speed. To get waves moving in different directions, instead of x, use some combination of x and y. To combine waves in different directions, just add them together.

##### Share on other sites
BattleMetalChri,

Thanks for the reply. Works perfectly now!

##### Share on other sites
One last question:

So, right now in my update function i'm calculating sine twice for every vertex. I kind of want to change this to use a lookup table as my project will be run on an embedded device (Nindento dsi).
I think constructing a lookup table then % the argument of sin to keep it in the lookup range would do the trick, but i don't know how the floating point value of timeCoefficient would effect this.
Can anyone point me in the right direction to using a lookup table for this?

 void Update() { DWORD thisTime = GetTickCount(); float deltaTime = (float)(thisTime - lastTime) * 0.001f; lastTime = thisTime; timeCoefficient += deltaTime; for (int z = 0; z < WATER_WIDTH; ++z) { for (int x = 0; x < WATER_HEIGHT; ++x) { deformData[x][z] = sinf(x + timeCoefficient) / x; deformData[x][z] += sinf(z + timeCoefficient)/ z; water[x][z][1] = deformData[x][z]; } } }

##### Share on other sites

The surface looks like it's just a triangle mesh, rendered after the scene with a surface texture and the waves are done by shifting the verticies up and down, probably in the shader. It's probably just a simple set of sine waves of different frequencies added together. It's fast and also easily reproducible for when you want to do (say) collision detection.

In the shader? that was on N64!

Would be interested to see some screenshots of your results PrjM

##### Share on other sites
Here's a description of what we used to do back in the old days.
http://freespace.virgin.net/hugo.elias/graphics/x_water.htm
When you've got it working you can just write some values into the current buffer for each position where you want objects to interact with the water.
This method is still used for games today when you need to get the water to ripple around objects.

##### Share on other sites

Can anyone point me in the right direction to using a lookup table for this?

Take a look at Direct Digital Synthesis.

No need to even calculate sine values, just keep them in a lookup table.

If a function call at a fixed frequency is available to you, this is an efficient way to calculate sine values:

 #define INC_FREQ 10000 // hertz #define ACC_BITS 32 #define ACC_VALUES 4294967296 #define SAMPLE_BITS 8 // There are 2^(SAMPLE_BITS) samples #define FREQ_INCR(f) ((long)f * (long)ACC_VALUES) / INC_FREQ void UpdateSineWaves() { for( int i=0; i<numSineWaves; i++ ) { sineWaves.accumulator += sineWaves.frequencyIncrement; sineWaves.amplitude = sineWave[sineWaves.accumulator>>(ACC_BITS-SAMPLE_BITS)]; } } 

To adjust the frequency of a sine wave, just change the frequency increment. This doesn't affect the phase, so the result is very smooth, like what might be wanted for water waves. ;)

##### Share on other sites
Wow, just wow! Thanks sooo much @whitechaos35 i would have never found that on my own!

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 13
• 30
• 9
• 16
• 12