• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ProjectinMatrix

N64 Quality Water...

14 posts in this topic

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?
0

Share this post


Link to post
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"][url="http://www.youtube.com/watch?v=2VNNva1Nu-4"]Gerstner Waves[/url] 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]
[color="#000000"][font="arial, sans-serif"]
[/font][/color][/size][/font]
[color="#000000"][font="arial, sans-serif"]
[/font][/color]
[color="#000000"][font="arial, sans-serif"][size="4"][b]EDIT:[/b][/size][/font][/color]
[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][/color]
0

Share this post


Link to post
Share on other sites
[quote name='projectionmatrix' timestamp='1318516236' post='4872204']
[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][/color]
[/quote]

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 [i]and[/i] y. To combine waves in different directions, just add them together.
0

Share this post


Link to post
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?


[code]
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];
}
}
}[/code]
0

Share this post


Link to post
Share on other sites
[quote name='Katie' timestamp='1318500499' post='4872155']
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.
[/quote]

In the shader? that was on N64! :)

Would be interested to see some screenshots of your results PrjM
0

Share this post


Link to post
Share on other sites
Here's a description of what we used to do back in the old days.
[url="http://freespace.virgin.net/hugo.elias/graphics/x_water.htm"]http://freespace.virgin.net/hugo.elias/graphics/x_water.htm[/url]
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.
0

Share this post


Link to post
Share on other sites
[quote name='projectionmatrix' timestamp='1318605018' post='4872528']
Can anyone point me in the right direction to using a lookup table for this?

[/quote]

Take a look at [url="http://www.analog.com/library/analogDialogue/archives/38-08/dds.html"]Direct Digital Synthesis[/url].



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:

[code]
#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)];
}
}
[/code]

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. ;)
0

Share this post


Link to post
Share on other sites
@mikiex
Screenshots don't demonstrate the water well, here are the files i have so far [url="http://pastebin.com/9VLiNmsM"]WinMain.cpp[/url] [url="http://pastebin.com/jus0q8vK"]GLWater.h[/url] [url="http://pastebin.com/p8mvg3n3"]GLWater.cpp[/url]

[color="#1C2837"][size="2"]@whitechaos35[/size][/color]
[size="2"][color="#1c2837"]I'm still looking into the method & code snippet you posted, it looks very promising but i haven't been able to implement it (I was trying all weekend)[/color][/size]

[size="2"][color="#1c2837"]@MortenB[/color][/size]
[size="2"][color="#1c2837"]I'm going to be looking into the link you posted; i will need ripples around objects eventually.[/color][/size]

[size="2"][color="#1c2837"]THANKS EVERYONE![/color][/size]
0

Share this post


Link to post
Share on other sites
[quote name='MortenB' timestamp='1318679138' post='4872800']
Here's a description of what we used to do back in the old days.
[url="http://freespace.virgin.net/hugo.elias/graphics/x_water.htm"]http://freespace.vir...ics/x_water.htm[/url]
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.
[/quote]

o daaaaaaaamn, i havent been to that site in hella long ;-) I used to live on that site and other similar sites back in 2003-2005'ish. Talk about a blast from the past ;-] I learned how to draw lines, polygons, and do perlin noise off of that site. And their star field tutorial is still the best on the internet.
0

Share this post


Link to post
Share on other sites
I found a solution (In some old nVidia paper), so far this is acceptable for what i'm doing.
Also: [url="http://pastebin.com/rtyNu4NB"]Updated GLWater.cpp[/url]

[code]
#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);
}
}[/code]
0

Share this post


Link to post
Share on other sites
So, i've moved on to implementing ripples. So far This bit code causes a circular ripple in the water as one would expect.

[code]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];
}
}
}[/code]

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!
0

Share this post


Link to post
Share on other sites
[quote name='projectionmatrix' timestamp='1318876917' post='4873576']
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!
[/quote]


Every point within some radius of the impact point is going to oscillate. Points at an equal distance from the impact are going to be at the same value, which is determined by the phase at that distance and the attenuation value for that distance. A nice looking attenuation wave would look Gaussian.

If you can get the DDS algorithm I provided to work for you, then you can get phase-continuous samples for a sine wave (meaning if you want the frequency to decrease over time it will look perfect). By taking each of these samples and multiplying it by the corresponding attenuation sample, you will construct a "ripple wave". You can then map the distance from impact into a phase-lookup in the ripple table.

This solution eliminates your sine computation *for every value*, so long as you can output a sine wave from the DDS algorithm, which itself doesn't even compute sine values.

You also mention that you were having trouble implementing the DDS algorithm. Are you calling the "UpdateSineWaves" equivalent function at an exact frequency? If so, what is that frequency (500Hz, 1KHz, 10KHz)? Is this value defined as INC_FREQ? Is the accumulator variable 32 bits? If not, you need to set ACC_BITS to the number of bits. Is it unsigned (This algorithm works because of wraparound)? Is ACC_VALUES 2^(ACC_BITS)? If SAMPLE_BITS is 8, do you have a sine wave with 2^8 (256) values?

If you still can't get it to work, post what you have and I'll be happy to take a look.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0