We made some progress with our terrain, we multi-textured it!
According to the height of the terrain we apply different textures and blend them at their border. So far so good, but we ran into a problem: Overall it looked nice, but when we got near the ground we only saw a bunch of pixels
Much too less detail here! So the first thing to try is to shorten the textures so that they repeat more often. Now it looked nice near the ground but tiling got visible in the distant. (Picture two)
So what had to be done is to map the detailed texture on vertexes near the camera while mapping a low res texture on those far away. This can entirely be solved in the PixelShader were we can do this accordingly to the distance from the camera.
float blendDistance = 30; float blendWidth = 20; float blendFactor = clamp((PSIn.Depth-blendDistance)/blendWidth, 0, 1);
PSIn.Depth is a value between the near and the far clipping plane value, in our case a value between 0.3f and 1000.0f. (It is the disctance from the camera to the vertex/pixel) To map this value in a range between 0 and 1 you divide it by 1000, this results in a gradient all over the clipping plane if assigned as a color to the pixels. If you subtract a value from the Depth before dividing it, then the range is scrolled to the left. This results in for example a range between -30 to 970. If you assign this as a color, all pixels less then 30 units away from the camera will be black and then fade to a color. This is the detailed area!
To restrict the gradient on a fixed distance (not from 30 to 970) you devide not by 1000 but by let’s say 20. This way from 0 to 30 there is back, then from 30 to 50 there is a gradient and then a solid color again. According to these values you can map eigther a detailed or a low res texture on the terrain.
Using the same technique it is totally simple to create fog:


