   HLSL MultiLayer Terrain
  Hello  I am implementing terrains that support rendering multi layer textures using HLSL.  In frank luna's book, he demonstrated how to do that but with only a maxinum of three texture layers.  In the effect he included three color textures samplers and one blendmap like souniform extern texture gTex0;uniform extern texture gTex1;uniform extern texture gTex2;uniform extern texture gBlendMap;Where the gBlendMap was an RGB image that was used to blend each of the three textures respectivly.Now my question is, what would be some of the ways perhaps one would go about adding support for more texture layers besides just three. I apprecaite any ideas. Thanks!   
  you could use two blend textures, or a different texture format for the splatting (the blending) possibly?  The first one will work for sure, I'm not well versed on direct3D's texture formats, but if you could find one with more channels, or split the 4 channels up or something.EDIT:  By the way, you can use the alpha channel for a 4th blending factor.   ;  You can extend the blend-map approach up to 5 layers with little modification.Currently, RGB give you weights for the first 3 layers. Alpha can give you a weight for the 4th layer, and you can imply a weight for the 5th by having it as a default layer that shows up if the other weights are zero.//get first 4 weightsw1 = rw2 = gw3 = bw4 = a//infer 5th weightw5 = saturate( 1-(r+g+b+a) )//normalise the weightssum = w1+w2+w3+w4+w5w1 /= sumw2 /= sumw3 /= sumw4 /= sumw5 /= sumOr a more vectorised approach:float4 weights1234 = tex2d(...);float sum = dot( float4(1,1,1,1), weights1234 );float weight5 = saturate( 1-sum );sum += weight5;weights1234 /= sum;weight5 /= sum;;  Thanks guys, looks like were getting our way up there in terms of layer count :).I originally thought that Id do a maximum of 12 layers, but perhaps this may not really be praticle?  Those are great ideas but perhaps would this work?  I am planning to allow the level editor to "paint" opasity for a given texture layer on the terrain.  Kind of like painting the texture on the terrain but what is accually happening underneith is that the user if minipulating the grayscale intensity for the given layers opasity map. So I was thinking that with effect passes in mind, how about a dedicated alpha blend (grayscale) map that only corresponds to a given texture layer.  Then for each pass, I plug in the layers respective texture and blendmap shader parameters and essentially add all the pixil values up into one final texture?   I would need to figure out some specifics about that but thats probably the method I'll play with first.  But feedback is welcome, and thanks for the ideas so far : )   ;  Provided your minimum hardware features are d3d10, and you wanted a ridiculous number of layers you could use texture arrays.  The above approach just needs to be extended to sample a point filtered texture which indicates which textures out of the array to apply to the weights.  So instead of 'supporting up to 4 layers' in a single terrain it could be 'up to 4 layers per tile, or per-weightmap texel'The logical progression beyond this is to use texture atlasing and stream the terrain's texture in on the fly as you walk around on the terrain.   