  <arbvp>
  <variablemap variable="light 0 position" destination="register 0"/>
  <variablemap variable="light 0 diffuse" destination="register 1"/>
  <variablemap variable="light 0 specular" destination="register 2"/>
  <variablemap variable="light 0 attenuation" destination="register 3"/>
  <variablemap variable="beta1 + beta2" destination="register 4" />
  
  <variablemap variable="mat diffuse" destination="register 6"/>
  <variablemap variable="mat ambient" destination="register 7"/>
  <variablemap variable="mat reflection" destination="register 8"/>
  <variablemap variable="mat flatcolor" destination="register 9"/>
  
  <variablemap variable="mat specular" destination="register 10"/>
  <program>
    <![CDATA[
      !!ARBvp1.0
      #---------------------------------------
      # Simple Vertex Lighting Program
      #---------------------------------------
      #Parameter definition
      PARAM mv[4]	     	= { state.matrix.modelview };
      PARAM mvi[4]	 	= { state.matrix.modelview.inverse };
      PARAM mvp[4]	     	= { state.matrix.mvp };
      PARAM lightPos   		= program.local[0];
      PARAM lightDiffuse 	= program.local[1];
      PARAM lightSpecular 	= program.local[2];
      PARAM lightAttenuation 	= program.local[3];
      PARAM eyePos	 	= {0, 0, 0, 1};
      PARAM lightIntensity	= {100, 100, 100 };
      PARAM log_2_e		= { 1.4427, 1.4427, 1.4427, 0 };
      PARAM terrain_reflectance = { 0.0138, 0.0113, 0.008, 0 };

      PARAM cB1plusB2		= program.local[4];
      
      PARAM materialDiffuse	= program.local[6];
      PARAM materialAmbient	= program.local[7];
      PARAM materialReflection	= program.local[8];
      PARAM materialFlatColor 	= program.local[9];
      PARAM materialSpecular 	= program.local[10];
      # Per vertex inputs
      ATTRIB iPos		= vertex.position;
      ATTRIB iCol0		= vertex.attrib[1];
      ATTRIB iNorm		= vertex.attrib[2];
      ATTRIB iTex0		= vertex.attrib[3];
      # Outputs
      OUTPUT oPos		= result.position;
      OUTPUT oCol0		= result.color;
      OUTPUT oTex0		= result.texcoord[0];
      # Temporaries
      TEMP objEye;
      TEMP theta;
      TEMP extinction;
      
      #Transform vertex to viewspace
      DP4 oPos.x, mvp[0], iPos;
      DP4 oPos.y, mvp[1], iPos;
      DP4 oPos.z, mvp[2], iPos;
      DP4 oPos.w, mvp[3], iPos;
      
      #Just pass on texture-coordinate
      MOV oTex0, iTex0;
      
      ###
      # Find distance from eye to vertex (down the Y)
      DP4 objEye.x, mvi[0], eyePos;
      DP4 objEye.y, mvi[1], eyePos;
      DP4 objEye.z, mvi[2], eyePos;
      DP4 objEye.w, mvi[3], eyePos;

      ADD objEye, objEye, -iPos;
      DP3 objEye.w, objEye, objEye;
      RSQ objEye.w, objEye.w;
      RCP theta.z, objEye.w;

      ###
      # Find extinction term
      # extinction = -(beta_1+beta_2) * s
      MUL extinction, cB1plusB2, -theta.z;
      ###
      # extinction = -(beta_1+beta_2) * s * log_2(e)
      MUL extinction, extinction, log_2_e;
      ###
      # extinction = e^(-(beta1 +beta2) * s)
      EX2 extinction.x, extinction.x;
      EX2 extinction.y, extinction.y;
      EX2 extinction.z, extinction.z;

      ###
      # Apply reflectance to E to get the net effective E
      # MUL extinction, extinction, materialReflection;
      MUL extinction, extinction, terrain_reflectance;

      ###
      # Apply light color and intensity
      MUL extinction, extinction, lightDiffuse;
      MUL extinction, extinction, lightIntensity;
      #MUL extinction, extinction, lightDiffuse.w;

      # Pass along diffuse light modulated with extinction
      MOV oCol0, extinction;
      
      END
    ]]>
  </program>
</arbvp>
