<?xml version="1.0" encoding="utf-8" ?> 
<shader compiler="xmlshader" name="ambientocclussion">
  <?if vars."tex glow".texture ?> 
    <?if vars."glow pulse speed" ?>
    <shadervars>
      <shadervar name="glow alpha" type="expression">
       <div>
         <add>
           <sin>
             <mul>
	         <atom type="var">standard time</atom>
	         <atom type="var">glow pulse speed</atom>
	       </mul>
	     </sin>
	     <atom type="num">1</atom>
	   </add>
	   <atom type="num">2</atom>
       </div>
      </shadervar>
     </shadervars>
    <?endif?>
  <?endif?>
  <technique priority="50">
	<pass>
	    <mixmode><copy/></mixmode>
	    <buffer source="texture coordinate 0" destination="texture coordinate 0" />
	    <buffer source="texture coordinate ao" destination="texture coordinate 1" />
	    <?if vars."tex glow".texture ?>
	    <buffer source="texture coordinate 0" destination="texture coordinate 1" />
	    <?endif?>
	    <vp plugin="glfixed">
	        <fixedvp>
		  <?Include /shader/ambient.fvp ?>
		</fixedvp>
	    </vp>
	    <texture name="tex diffuse" destination="unit 0" />
	    <texture name="tex ambient occlussion" destination="unit 1" />
	    <?if vars."tex glow".texture ?>
	    <texture name="tex glow" destination="unit 1" />
	    <?endif?>
	    <fp plugin="glfixed">
		<fixedfp>
		    <layer>
			<colorsource num="0" source="primary color" 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="texture" modifier="color"/>
			<coloroperation operation="modulate"/>
		    </layer>

		    <?if vars."tex glow".texture ?>
		    <?if vars."glow pulse speed" ?>
		    <layer>
			<colorsource num="0" source="previous layer" modifier="color"/>
			<colorsource num="1" source="texture" modifier="color"/>
			<colorsource num="2" source="constant color" modifier="one minus alpha"/>
			<coloroperation operation="interpolate"/>
		    </layer>
		    <?else?>
		    <layer>
			<colorsource num="0" source="previous layer" modifier="color"/>
			<colorsource num="1" source="texture" modifier="color"/>
			<coloroperation operation="add"/>
		    </layer>
		    <?endif?>
		    <?endif?>
		</fixedfp>
	    </fp>
	</pass>
  </technique>
  
  <technique priority="0">
    <pass>
      <mixmode><copy/></mixmode>
      <texture name="tex diffuse" destination="unit 0" />
      <buffer source="texture coordinate 0" destination="texture coordinate" />
      <vp plugin="software" />
      <fp plugin="software">
	<softfp>
	  <flatcolor type="shadervar">mat flatcolor</flatcolor>
	  <constcolor type="shadervar">light ambient</constcolor>
	</softfp>
      </fp>
    </pass>
  </technique>
    
</shader>
