<arbvp>
  <variablemap variable="light 0 position" destination="register 0"/>
  <program>
  <![CDATA[!!ARBvp1.0
    #---------------------------------------
    # Shadow Volume Extrusion Program
    #  expects degenerate quads between tris
    #---------------------------------------
    # Parameter definition
    PARAM mv[4]         = { state.matrix.modelview };
    PARAM mvi[4]        = { state.matrix.modelview.invtrans };
    PARAM mvp[4]        = { state.matrix.mvp };
    PARAM p[4]          = { state.matrix.projection };
    
    PARAM lightPos      = program.local[0];
    PARAM testDir       = { 0, 0, 0, 1 };
    
    # colors for visible shadow volume
    PARAM frontColor    = { 0.5, 0.3, 0.1, 0.3};
    PARAM backColorDiff = { -0.3, 0.2, 0.0, 0.0};
    
    # Per vertex inputs
    ATTRIB iPos         = vertex.position;
    ATTRIB iNorm        = vertex.normal;
    # Per vertex outputs
    OUTPUT oPos         = result.position;
    OUTPUT oCol0	= result.color;
    # Temporaries
    TEMP tempPos;
    TEMP tempNorm;
    TEMP lightDir;
    TEMP faceTest;
    TEMP extrudedPos;
    TEMP nonextrudedPos;

    # Transform vertex and normal into view
    DP4 tempPos.x, mv[0], iPos;
    DP4 tempPos.y, mv[1], iPos;
    DP4 tempPos.z, mv[2], iPos;
    DP4 tempPos.w, mv[3], iPos;

    DP4 tempNorm.x, mvi[0], iNorm;
    DP4 tempNorm.y, mvi[1], iNorm;
    DP4 tempNorm.z, mvi[2], iNorm;
    DP4 tempNorm.w, mvi[3], iNorm;

    # Determine light dir
    SUB lightDir, lightPos, tempPos;

    # Find face direction
    DP3 faceTest.x, lightDir, tempNorm;
    SGE faceTest.y, testDir.x, faceTest.x;

    # Find both extruded and non-extruded projections
    DP4 extrudedPos.x, p[0], -lightDir;
    DP4 extrudedPos.y, p[1], -lightDir;
    DP4 extrudedPos.z, p[2], -lightDir;
    DP4 extrudedPos.w, p[3], -lightDir;
    DP4 nonextrudedPos.x, mvp[0], iPos;
    DP4 nonextrudedPos.y, mvp[1], iPos;
    DP4 nonextrudedPos.z, mvp[2], iPos;
    DP4 nonextrudedPos.w, mvp[3], iPos;

    # Determine which to use for output
    SUB faceTest.z, testDir.w, faceTest.y;
    MUL extrudedPos, extrudedPos, faceTest.y;
    MAD oPos, nonextrudedPos, faceTest.z, extrudedPos;

    MAD oCol0, backColorDiff, faceTest.z, frontColor;

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