Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 12 October 2011 - 01:20 PM
Posted 13 October 2011 - 04:08 AM
Posted 13 October 2011 - 08:30 AM
Posted 13 October 2011 - 10:14 AM
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?
Posted 13 October 2011 - 12:57 PM
Posted 14 October 2011 - 09:10 AM
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]; } } }
Posted 15 October 2011 - 02:33 AM
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.
Posted 15 October 2011 - 05:45 AM
Posted 15 October 2011 - 06:41 PM
Can anyone point me in the right direction to using a lookup table for this?
#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[i].accumulator += sineWaves[i].frequencyIncrement; sineWaves[i].amplitude = sineWave[sineWaves[i].accumulator>>(ACC_BITS-SAMPLE_BITS)]; } }
Posted 16 October 2011 - 11:28 AM
Posted 17 October 2011 - 08:10 AM
Posted 17 October 2011 - 08:35 AM
Here's a description of what we used to do back in the old days.
http://freespace.vir...ics/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.
Posted 17 October 2011 - 10:04 AM
#define MAX_CIRCLE_ANGLE 512 #define HALF_MAX_CIRCLE_ANGLE 256 #define RECIP_HALF_MAX_CIRCLE_ANGLE 0.00390625f #define QUARTER_MAX_CIRCLE_ANGLE 128 #define MASK_MAX_CIRCLE_ANGLE 511 #define PI 3.1415926535897932f #define PI_RECIPRICAL 0.3183098861837907f float fast_cossin_table[MAX_CIRCLE_ANGLE]; float FAST_SIN(float n) { float f = n * HALF_MAX_CIRCLE_ANGLE * PI_RECIPRICAL; int i = int(f); if (i < 0) return fast_cossin_table[(-((-i)&MASK_MAX_CIRCLE_ANGLE)) + MAX_CIRCLE_ANGLE]; return fast_cossin_table[i&MASK_MAX_CIRCLE_ANGLE]; } float FAST_COS(float n) { float f = n * HALF_MAX_CIRCLE_ANGLE * PI_RECIPRICAL; int i = int(f); if (i < 0) return fast_cossin_table[((-i) + QUARTER_MAX_CIRCLE_ANGLE)&MASK_MAX_CIRCLE_ANGLE]; return fast_cossin_table[(i + QUARTER_MAX_CIRCLE_ANGLE)&MASK_MAX_CIRCLE_ANGLE]; } inline void SetupSinCosLookupTable() { for (int i = 0 ; i < MAX_CIRCLE_ANGLE ; i++) { fast_cossin_table[i] = (float)sin((double)i * PI * RECIP_HALF_MAX_CIRCLE_ANGLE); } }
Posted 17 October 2011 - 12:41 PM
void UpdateRippleWater() { for (int z = 0; z < MAP_WIDTH; ++z) { for (int x = 0; x < MAP_HEIGHT; ++x) { float dist = distance(ripple_x, ripple_y, x, z); deformData[x][z] = FAST_SIN(dist - timeCoefficient * 10.0f) * WAVE_Y_SCALE; water[x][z][1] = deformData[x][z]; } } }
Posted 22 October 2011 - 04:45 PM
My question is i want to make the ripple temporary, like someone had dropped an object into the water.
That is have it only start in the center, move outward then calm back down.
Any ideas on how this effect could be achieved?
Thanks for all the help so far everyone!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.