title: DirectX11: Height based texture blending
body: <p>I currently have 3 textures being blended using a slope amount, in my terrain project.  I do this by sampling each texture, determining the slope amount and setting the texture colour based on a lerp between two textures.  This is the snippet of this from my pixel shader:</p>
  
  <pre><code>static const float TEX_LOW_BOUND    = 0.4f;
  static const float TEX_HIGH_BOUND   = 0.7f; 
  
  ...    
  
  float4 texColour;
  float4 lowColour = lowerTex.Sample(SWrap, pin.Tex);
  float4 midColour = middleTex.Sample(SWrap, pin.Tex);
  float4 hiColour  = upperTex.Sample(SWrap, pin.Tex);
  float slope      = 1.0f - pin.Normal.y;
  
  if (slope &lt; TEX_LOW_BOUND)
  {
      texColour = lerp(lowColour, midColour, slope / TEX_LOW_BOUND);
  }
  else if (slope &gt;= TEX_LOW_BOUND &amp;&amp; slope &lt; TEX_HIGH_BOUND)
  {
      texColour = lerp(midColour, hiColour, (slope - TEX_LOW_BOUND) * (1.0f / (TEX_HIGH_BOUND - TEX_LOW_BOUND)));
  }
  else if (slope &gt;= TEX_HIGH_BOUND)
  {
      texColour = hiColour;
  }
  </code></pre>
  
  <p>I want to add a final snow texture, to apply above a certain height.  I get the height value in my vertex shader by using:</p>
  
  <pre><code>vout.WHeight = mul(vin.Pos, worldMatrix).y;
  </code></pre>
  
  <p>I can then just set the texture colour to the snow above a certain height using this in my pixel shader:</p>
  
  <pre><code>if (pin.WHeight &gt; 35.0f)
  {
      texColour = snowTex.Sample(SWrap, pin.Tex);
  }
  </code></pre>
  
  <p>Which produces the following:</p>
  
  <p><a href="https://i.stack.imgur.com/Mcy1Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mcy1Y.png" alt="Snow above a certain height"></a></p>
  
  <p>How can I blend the edge of the snow with the other textures so that the edge isn't so harsh. Bearing in mind the other textures may have already been lerped, and i'd like to maintain the texture colour.</p>
  
  <p>Thank you for your time</p>