<shader compiler="xmlshader" name="light">
  <technique priority="200" lights="1">
    <pass>
      <writemask r="false" g="false" b="false" a="true" />
      <mixmode><copy /></mixmode>
      <vp plugin="glarb" file="/shader/flat_ppl_attenuation.avp" />
      <texture destination="unit 0" name="light 0 attenuationtex" />
      <texture destination="unit 1" name="light 0 attenuationtex" />
      <fp plugin="glfixed">
        <fixedfp>
          <layer>
            <alphasource num="0" source="texture" modifier="alpha" />
            <alphaoperation operation="replace" />
          </layer>
          <layer>
            <alphasource num="0" source="texture" modifier="alpha" />
            <alphasource num="1" source="previous layer" modifier="alpha" />
            <alphaoperation operation="modulate" scale="2" />
          </layer>
        </fixedfp>
      </fp>
    </pass>
    <pass>
      <mixmode>
        <destalphaadd />
      </mixmode>
      <buffer source="normal" destination="normal" />
      <buffer source="color" destination="color" />
      <buffer source="texture coordinate 0" destination="texture coordinate 0" />
      <vp plugin="glarb" file="/shader/flat_ppl_diffuse.avp" />
      <texture destination="unit 0" name="standardtex normalization map" />
      <texture destination="unit 1" name="standardtex normalization map" />
      <texture destination="unit 2" name="tex diffuse" />
      <texture destination="unit 3" name="tex diffuse" />
      <fp plugin="glfixed">
        <fixedfp>
          <layer>
            <colorsource num="0" source="texture" modifier="color" />
            <coloroperation operation="replace" />
          </layer>
          <layer>
            <colorsource num="0" source="previous layer" modifier="color" />
            <colorsource num="1" source="texture" modifier="color" />
            <coloroperation operation="dot3" />
          </layer>
          <layer>
            <colorsource num="0" source="previous layer" modifier="color" />
            <colorsource num="1" source="texture" modifier="color" />
            <coloroperation operation="modulate" />
          </layer>
          <layer>
            <colorsource num="0" source="previous layer" modifier="color" />
            <colorsource num="1" source="primary color" modifier="color" />
            <coloroperation operation="modulate" />
          </layer>
        </fixedfp>
      </fp>
    </pass>
  </technique>
  <technique priority="150" lights="1">
    <pass>
      <writemask r="false" g="false" b="false" a="true" />
      <mixmode>
        <copy />
      </mixmode>
      <buffer source="texture coordinate 0" destination="texture coordinate 0" />
      <vp plugin="glarb" file="/shader/flat_ppl_attenuation.avp" />
      <texture destination="unit 0" name="light 0 attenuationtex" />
      <texture destination="unit 1" name="light 0 attenuationtex" />
      <fp plugin="glfixed">
        <fixedfp>
          <layer>
            <alphasource num="0" source="texture" modifier="alpha" />
            <alphaoperation operation="replace" />
          </layer>
          <layer>
            <alphasource num="0" source="texture" modifier="alpha" />
            <alphasource num="1" source="previous layer" modifier="alpha" />
            <alphaoperation operation="modulate" scale="2" />
          </layer>
        </fixedfp>
      </fp>
    </pass>
    <pass>
      <mixmode>
        <multiply />
      </mixmode>
      <writemask r="false" g="false" b="false" a="true" />
      <buffer source="normal" destination="normal" />
      <buffer source="texture coordinate 0" destination="texture coordinate 0" />
      <vp plugin="glarb" file="/shader/flat_ppl_diffuse_a.avp" />
      <texture destination="unit 0" name="standardtex normalization map" />
      <texture destination="unit 1" name="standardtex normalization map" />
      <fp plugin="glfixed">
        <fixedfp>
          <layer>
            <colorsource num="0" source="texture" modifier="color" />
            <coloroperation operation="replace" />
          </layer>
          <layer>
            <colorsource num="0" source="previous layer" modifier="color" />
            <colorsource num="1" source="texture" modifier="color" />
            <coloroperation operation="dot3 alpha" />
          </layer>
        </fixedfp>
      </fp>
    </pass>
    <pass>
      <mixmode>
        <destalphaadd />
      </mixmode>
      <buffer source="texture coordinate 0" destination="texture coordinate 0" />
      <vp plugin="glarb" file="/shader/flat_ppl_diffuse_b.avp" />
      <texture destination="unit 0" name="tex diffuse" />
      <fp plugin="glfixed">
        <fixedfp>
          <layer>
            <colorsource num="0" source="primary color" modifier="color" />
            <colorsource num="1" source="texture" modifier="color" />
            <coloroperation operation="modulate" />
          </layer>
        </fixedfp>
      </fp>
    </pass>
  </technique>
  <technique priority="100" lights="1">
    <pass>
      <mixmode>
        <add />
      </mixmode>
      <buffer source="normal" destination="normal" />
      <buffer source="texture coordinate 0" destination="texture coordinate 0" />
      <vp plugin="glarb" file="/shader/vertexlight.avp" />
      <texture destination="unit 0" name="tex diffuse" />
      <fp plugin="glfixed">
        <fixedfp>
          <layer>
            <colorsource num="0" source="primary color" modifier="color" />
            <colorsource num="1" source="texture" modifier="color" />
            <coloroperation operation="modulate" />
          </layer>
        </fixedfp>
      </fp>
    </pass>
  </technique>
  <technique priority="50" lights="1">
    <pass>
      <mixmode>
        <add />
      </mixmode>
      <buffer source="normal" destination="normal" />
      <buffer source="texture coordinate 0" destination="texture coordinate 0" />
      <vp plugin="glfixed" file="/shader/vertexlight.fvp" />
      <texture destination="unit 0" name="tex diffuse" />
      <fp plugin="glfixed">
        <fixedfp>
          <layer>
            <colorsource num="0" source="primary color" modifier="color" />
            <colorsource num="1" source="texture" modifier="color" />
            <coloroperation operation="modulate" />
          </layer>
        </fixedfp>
      </fp>
    </pass>
  </technique>
  
  <!-- Compute all lights with vproc_std (ie software per-vertex) -->
  <technique priority="0" lights="2147483647">
    <pass>
      <mixmode><add/></mixmode>
      <texture name="tex diffuse" destination="unit 0" />
      <buffer source="texture coordinate 0" destination="texture coordinate 0" />
      <buffer source="color" destination="color" />
      <vp plugin="software" />
      <vproc plugin="vproc_std">
	<vproc_std>
	  <lightmixmode>add</lightmixmode>
	  <colormixmode>none</colormixmode>
	  <finalfactor type="float">0.5</finalfactor>
	  <lights>2147483647</lights>
	</vproc_std>
      </vproc>
      <fp plugin="software">
	<softfp>
	  <flatcolor type="shadervar">mat flatcolor</flatcolor>
	  <colorfactor type="float">2</colorfactor>
	</softfp>
      </fp>
    </pass>
  </technique>
  
  <fallbackshader name="std_lighting" />
</shader>
