<shader compiler="xmlshader" name="terrain_fixed_splatting">
<?if vars."splat alpha map".texture ?>
  <technique priority="300"> 
    <tag>linear_fog</tag>
    <tag>terrain_splatting</tag>
    <pass>
      <mixmode><srcalphaadd /></mixmode>
      <alphamode><smooth /></alphamode>
      <buffer source="texture coordinate 0" destination="texture coordinate 0" />
      <buffer source="texture coordinate 0" destination="texture coordinate 1" />
      <buffer source="color" destination="color" />
      <vp plugin="glfixed">
	<fixedvp>
	  <texmatrix layer="0">
	    <scale type="shadervar">texture scale</scale>
	  </texmatrix>
	  <?Include snippets/fog-fvp.inc ?>
	</fixedvp>
      </vp>
      <texture name="tex diffuse" destination="unit 0"/>
      <texture name="splat alpha map" destination="unit 1"/>
      <?Include snippets/fog-mappings.inc ?>
      <fp plugin="glfixed">
        <fixedfp>
	  <fog>
	    <mode>linear</mode>
	    <start type="float">0</start>
	    <end type="shadervar">texture lod distance</end>
	    <fogcolor type="vector3">0,0,0</fogcolor>
	  </fog>
          <layer>
            <colorsource num="0" source="texture" modifier="color"/>
            <colorsource num="1" source="primary color" modifier="color"/>
            <coloroperation operation="modulate" scale="2" />
          </layer>
          <layer> 
            <colorsource num="0" source="previous layer" modifier="color"/>
            <coloroperation operation="replace"/>
	    <alphasource num="0" source="texture" modifier="alpha"/>
            <alphaoperation operation="replace"/>
          </layer>
	  <?if vars."fog density".float &gt; 0 ?>
	    <layer name="pea soup">
	      <colorsource num="0" source="constant color" modifier="color"/>
	      <colorsource num="1" source="previous layer" modifier="color"/>
	      <colorsource num="2" source="texture" modifier="alpha"/>
	      <coloroperation operation="interpolate" />
	      <alphasource num="0" source="previous layer" modifier="alpha"/>
	      <alphaoperation operation="replace"/>
	    </layer>
	  <?endif?>
        </fixedfp>
      </fp>
    </pass>
  </technique>
  
  <technique priority="250"> 
    <tag>linear_fog</tag>
    <tag>terrain_splatting</tag>
    <pass>
      <mixmode><srcalphaadd /></mixmode>
      <alphamode><smooth /></alphamode>
      <buffer source="texture coordinate 0" destination="texture coordinate 0" />
      <buffer source="texture coordinate 0" destination="texture coordinate 1" />
      <buffer source="color" destination="color" />
      <vp plugin="glfixed">
	<fixedvp>
	  <texmatrix layer="0">
	    <scale type="shadervar">texture scale</scale>
	  </texmatrix>
	</fixedvp>
      </vp>
      <texture name="tex diffuse" destination="unit 0"/>
      <texture name="splat alpha map" destination="unit 1"/>
      <fp plugin="glfixed">
        <fixedfp>
	  <fog>
	    <mode>linear</mode>
	    <start type="float">0</start>
	    <end type="shadervar">texture lod distance</end>
	    <fogcolor type="vector3">0,0,0</fogcolor>
	  </fog>
          <layer>
            <colorsource num="0" source="texture" modifier="color"/>
            <colorsource num="1" source="primary color" modifier="color"/>
            <coloroperation operation="modulate" scale="2" />
          </layer>
          <layer> 
            <colorsource num="0" source="previous layer" modifier="color"/>
            <colorsource num="1" source="texture" modifier="alpha"/>
            <coloroperation operation="replace"/>
	    <alphasource num="0" source="texture" modifier="replace"/>
            <alphaoperation operation="replace"/>
          </layer>
        </fixedfp>
      </fp>
    </pass>
    <!-- NOTE: technically, this is wrong in case the sector fog starts
       closer than splatting distance (the closer the sector fog starts the
       worse). But practically, "it looks okay", and I don't see how a 
       100% correct appearance could be achieved without a 3rdTU (which we 
       don't have if we use this tech). -->
  </technique>
  
  <!-- Some HW doesn't even handle the linear fog correctly at all. 
       SW doesn't support it.
       Effectively disable splatting there. (controlled through linear_fog
       tag.) -->
       
<?else?>
  <!-- @@@ FIXME: with SR that always seems to get used. Why? -->
  <!--fallbackshader name="std_lighting" /-->
<?endif?>
</shader>
