<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="texture scale" destination="register 4" />
  <variablemap variable="texture lod distance" destination="register 6"/>
  <program>
  <![CDATA[
    !!ARBvp1.0
    #---------------------------------------------------
    # terrain texture splatting with constant light term
    #---------------------------------------------------
    # Incoming program constants
    PARAM mv[4]                 = { state.matrix.modelview };
    PARAM mvi[4]                = { state.matrix.modelview.inverse };
    PARAM mvp[4]                = { state.matrix.mvp };
    PARAM eyePos                = { 0, 0, 0, 1};
    PARAM lightPos              = program.local[0];
    PARAM lightDiffuse          = program.local[1];
    PARAM lightSpecular         = program.local[2];
    PARAM lightAttenuation      = program.local[3];
    PARAM texscale              = program.local[4];
    PARAM loddist               = program.local[6];

    # Incoming vertex data
    ATTRIB iPos                 = vertex.position;
    ATTRIB iCol0                = vertex.color;
    ATTRIB iNorm                = vertex.normal;
    ATTRIB iTex0                = vertex.texcoord[0];
    ATTRIB iTan                 = vertex.texcoord[1];
    ATTRIB iBinorm              = vertex.texcoord[2];

    # Outgoing data to FP
    # Position transformed to perspective space
    OUTPUT oPos                 = result.position;
    # Light color
    OUTPUT oCol0                = result.color;
    # Diffuse coordinates (scaled by material parameter)
    OUTPUT oTex                 = result.texcoord[0];
    # Splatting alpha map coords (scaled not to tile over terrain)
    OUTPUT oSplat               = result.texcoord[1];

    # Placeholder for light relative to vertex
    TEMP objLight;
    # placeholder for light in tangent space
    TEMP tangLight;
    # Placeholder for reciprocal scale on material scaling
    TEMP scale;

    TEMP objEye;
    TEMP lodblend;

    # transform positon to perspective space
    DP4 oPos.x, mvp[0], iPos;
    DP4 oPos.y, mvp[1], iPos;
    DP4 oPos.z, mvp[2], iPos;
    DP4 oPos.w, mvp[3], iPos;

    # Transform light relative to object
    #DP4 objLight.x, mvi[0], lightPos;
    #DP4 objLight.y, mvi[1], lightPos;
    #DP4 objLight.z, mvi[2], lightPos;
    #DP4 objLight.w, mvi[3], lightPos;
     
    # Light dir relative to vertex
    #ADD objLight, objLight, -iPos;

    # Transform to tangent space
    #DP4 tangLight.x, iTan, objLight;
    #DP4 tangLight.y, iBinorm, objLight;
    #DP4 tangLight.z, iNorm, objLight;
    #SGE tangLight.w, tangLight.x, tangLight.x;

    # Pass tangent light to FP
    # MOV oLightDir, tangLight;

    # Pass normal map and diffuse map scaled by parameter
    #MUL oNormal, texscale, iTex0;
    MUL oTex, texscale, iTex0;

    MOV oSplat, iTex0;

    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;
    MUL lodblend, objEye.w, loddist;
    RCP lodblend.x, lodblend.x;
    ADD lodblend.x, eyePos.w, -lodblend.x;

    # Pass along diffuse light
    # MUL oCol0, lightDiffuse, lodblend.x;
    MOV oCol0, lightDiffuse;

    END
  ]]>
  </program>
</arbvp>
