Adding water to a terrain map

I’ve been searching for a simple answer to adding water to my game for ages but I can’t seem to understand. I’ve tried using a flat blue egg model and then having it move with the character like the skybox does but I’m 100% certain this is completely the wrong way of doing it.

Also if it’s any help, I’m using perlin noise to make a heightfield map and then was planning to have the water fill in the lowpoints. Is this achievable?

Can anyone shed some light for me? Sorry if it’s a pretty dumb question :confused:

Cheers

A flat plane like you mentioned sounds like a good solution - I think its what most people would use if you don’t need something of variable height.

Depending on the size of your world, you could just scale the x and y so its REALLY big. That way you don’t need to worry about moving it.

A flat place is certainly a good way to start. If you are looking for some more detail, such as scrolling waves and reflection, then this post might be of help:

YARR:

Oh so it is the right way to do it. I thought there was something wrong because I seem to get this problem that where the water plane touches the terrain model, it starts flashing and flickering when I move the camera. It’s usually on areas where the water plane just overlaps the ‘sand’ part of my terrain. Is this meant to happen? :blush:

My terrain is generated when the player moves to the edge of the area so I thought it best to have the water move with him or else they will get to the end of it eventually.

Thanks for the help, I’m having a look at the Yarr source now :slight_smile:

It’s not meant to happen but it is one of the standard problems encountered in 3d programming usually called z-fighting. This is a depth buffer issue which you can read about in the manual here:

http://www.panda3d.org/manual/index.php/Transparency_and_Blending

One way you might be able to deal with it in your case is to manipulate the “near” and “far” attributes of the camera lens (about half way down the page):

http://www.panda3d.org/manual/index.php/Lenses_and_Field_of_View

Setting the “far” value to something smaller than the default might resolve some of the z-fighting in your case (but not too small as objects start disappearing once they are further “far” units from the camera). Changing cam len settings might help but this can be a tricky problem to deal with which might require a shader to totally fix.

Ah thanks cslos, that’s sorted that problem, the near attribute of my camera lens was 0.1 when the default is 1.0, there’s only a tiny bit of flickering when the player looks at the water in the distance but it’s ok for now. Plus the flickering kind of looks like waves or ripples or something.

Thanks for the help! :smiley:

I’m not sure if I should start a new topic for this, but I was having another problem with the seams between the terrain chunks. I have the texture generate from the perlin noise but where grass connects with sand, and sand with water etc, there is a line of sand in the middle of grass or a line of blue (water) in the middle of sand etc. I have borderStitching on and that’s made things look a lot better but there is still this problem. There’s a picture of it attached.

Is this a standard problem? :frowning:

That looks like it might be a texture seam problem. Maybe try clamping it?

Something like:

self.texColour.setWrapU(Texture.WMClamp)
self.texColour.setWrapV(Texture.WMClamp)

That did the trick perfectly, thanks! :smiley: