Terrain painting - How to?

You can fade out detail textures based on pixel depth,