
As you can see, grains of sand start filling cracks between cobble-stones, gradually hiding them by itself. So we got more natural transition from sand to stones. Return texture1.a + a1 > texture2.a + a2 ? texture1.rgb : texture2.rgb Īt the expense of summation less transparent texture will be higher than usually. float3 blend(float4 texture1, float a1, float4 texture2, float a2) To use it we just sum depth map and opacity map. But we didn't consider opacity of layers yet. Return texture1.a > texture2.a ? texture1.rgb : texture2.rgb Įxcellent! Tops of cobble-stones remain pure whereas sand lies in cracks between them. Considering this fact, we will try to draw pixels of that texture which is above. Notice that tops of stones lies higher than sand level. The blue line on the plot symbolizes the depth map of sand and red is cobble-stones.

In Unit圓D it can be done in texture inspector by setting flag "Alpha From Grayscale".įirst of all we will consider the simplified model of depth map of sand and stones. In this example we consider depth map is generated from grayscaled image and stored in alpha channel of texture. As we want sand to be "fallen down" between cobble-stones, for each texture we need the depth map. Let's try to simulate this behavior in Excel plots. Sand doesn't stick to stones, instead it falls down and fills cracks between them, leaving tops of stones pure.

Stones look evenly soiled by sand, but in real world it doesn't happen. As you can see, the transition is smooth but unnatural. Such technics is used in Unit圓D in the standard terrain editor. Return texture1.rgb * a1 + texture2.rgb * a2 Simplest way of blending is to multiply texture color with opacity and then sum results. For simplicity and obviousness our terrain will consist of sand and large cobble-stones. Now we will pass to the most interesting part - algorithms of blending of textures. Instead of tile textures, the opacity map stretches entirely on all terrain and therefore has quite low level of details. Of course on each point of a terrain the sum of opacities of all layers makes hundred percent as the terrain can't be transparent. The method works by applying an opacity map to the higher levels, revealing the layers underneath where the opacity map is partially or completely transparent.

Each layer has an opacity map which defines extent of texture presence on the terrain. One of the most common ways of terrain texturing is blending multiple tiled layers.
