

Detail maps
In UnrealEngine 3
Introduction
I remember when I first saw Unreal, I dropped my jaws several times. Once I got close to a metal door, and to my surprise, instead of big, smudged pixels, fine details appeared. In this tutorial we'll make a similar thing to add details to extensive surfaces (in this case to a cliff).
Required assets
Beyond the usual diffuse, specular, etc textures, we will need a detail map for the diffuse texture. In this case I used the map on the left, which was derived from the original diffuse texture. The dark parts of the image will darken, the light parts will brighten up the base image. In certain cases you can use the original diffuse texture as a detail map, it depends on the texture.
The normalmap sometimes also need a new texture for used as detail map, especially when it comes to artificial objects like machines or cloth. In this example I reuse the original normalmap, because many surfaces in nature are self-similar at different scales.
Setting up the shader
Click on the image on the left to see the whole shader.
Let's start from the top-right corner: The "texture coordinate" node defines how many times the detail textures are going to repeat. Then we shift the texture values down a bit so when we later add them to the original diffuse map, positive values will make that brighter, negative ones darker. Adjusting this value will tweak the detail texture to match the actual diffuse image. The reused detail map might need to be darker on one type of rock, but lighter on another. Try to find the value which keeps the overall brightness of the texture intact: the diffuse texture with and without the added detail map should feel the same. Also avoid pixels with negative values: they will be quite visible when they appear at dark areas. To fix them simply increase the constant a little bit. Since we have room on the positive side of the pixel values (>1 looks good, <0 looks bad) we add more details onto light texels by multiplying the detail texture with the amplified version of the diffuse image. It also colorizes the result.
(Sidenote: Why don't we use multiplication instead of addition to avoid negative pixel values? I found that with the multiply operation the results easily get over-saturated. But I'm sure in many cases it's a viable option.)
And finally we apply the detail texture to the diffuse one. At this point the surface looks nice and detailed up close, but very noisy from far away, because of the 10x tiling of the detail map. To fix this we have to make sure that the high frequency details are only visible when the camera is close to the surface. So we interpolate between the enhanced diffuse and the original one depending on the distance. Let's see the "Distance based mask" group at the bottom. The constant defines the distance where the details start to appear. Try to find a value where the surface is not too noisy, yet details don't appear late, and it looks okay in lower resolutions as well.
At the end weforce the result to the 0..1 range to make a proper alpha texture.
We also use this alpha in the "Normal group" to blend between the two versions of the normalmap. Before we add the high frequency detail normals to the original one, we set the Z axis to 0 so only the X and Y axis will have any affect.
If everything went well then we have a nicely detailed surface: