Friday, 26 December 2008

Black water debunked on better beaches

When moving away from the terrain, I noticed that the water turned black. You can see what I mean if you look at the image in the previous post. This is a side effect of Riemers Skydome. In order to minimise the problem a bit, I did two things. The first was to change the background colour to something other than black (made it a blend between white smoke and sky blue). This small change made the problem much less apparent.

But, I was not yet convinced, so I took a closer look at the RiemersSkyDome class. In order to determine the place of the dome in the world, a matrix is calculated as follows:
wMatrix = Matrix.CreateTranslation(0, -0.30f, 0)
* Matrix.CreateScale(100)
* Matrix.CreateTranslation(camera.Position);

Our needs can be addressed by adjusting the value of the first translation's Y component (-0.30) and the scale value. A higher value of Y component lifts up the dome making the gradient effect more visible from the terrain surface. The scale adjusts the distance to the horizon of the dome. A scale factor of 300 produced the desired effect.

On a different note, I also refined the island terrain trimmer (the HeightMapIslandTrim class) produced more pleasing terrains. I added two options: the one is a shape and the other is a trim method. The shape is either a circle or a square.

The trim method is more interesting: it has two options: a fill option and a merge option. The fill option is the one described in the previous post. It simply fills in ground until the beach is perfect according to specification. The problem with this is that it creates an unnatural edge for the beach; except if that's what you were going for, you may not like it.

The merge option is much smarter. It takes the beach line (this is where the water hits the sand) and applies the fill method there. As it moves away from this line, the original form of the heightmap is gradually adopted with more vigor. Again this uses our old friend the lerp function.

The image shown here is a terrain built from a mirror of Riemer's original heightmap with the island modifier applied to it. Notice how the merge option created puddles on the beach.

No comments:

Post a Comment