<arbvp>
<variablemap variable="light ambient" destination="register 0" />
<variablemap variable="texture scale" destination="register 1" />
<variablemap variable="beta1 + beta2" destination="register 2" />
<variablemap variable="texture lod distance" destination="register 3" /> 
<program>
<![CDATA[
!!ARBvp1.0
#---------------------------------------------------
# terrain texture splatting with constant light term
#---------------------------------------------------
# Incoming constants from the program
PARAM mvi[4]	 	= { state.matrix.modelview.inverse };
PARAM mvp[4]		= { state.matrix.mvp };
PARAM lightAmbient  	= { 1, 1, 1, 1};
PARAM texscale  	= program.local[1];
PARAM cB1plusB2   = program.local[2];
PARAM loddist		= program.local[3];
PARAM eyePos	 	= { 0, 0, 0, 1};
PARAM log_2_e		= { 1.4427, 1.4427, 1.4427, 1.4427 };

# Per-Vertex data used
ATTRIB iPos		= vertex.position;
ATTRIB iTex0		= vertex.texcoord[0];

# Output to FP
# Position in perspective space
OUTPUT oPos		= result.position;
# Light color
OUTPUT oCol0		= result.color;
# Object diffuse texture coord (scaled via material parameter)
OUTPUT oTex 		= result.texcoord[1];
# Object splat alpha map coord (scaled by alpha scale not to tiled)
OUTPUT oSplat		= result.texcoord[0];

# place holder for reciprocal texture scale from material
TEMP scale;
TEMP lodblend;
TEMP theta;
TEMP extinction;
TEMP objEye;

# translate in position 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;

# scale diffuse texture by parameter
#RCP scale.x, texscale.x;
#RCP scale.y, texscale.y;
#ADD scale.z, scale.z, -scale.z;
#SGE scale.w, scale.x, scale.x;
MUL oTex, texscale, iTex0;

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

MUL extinction, extinction, lightAmbient;
MUL extinction, extinction, lodblend.x;

# pass through ambient light color
MOV oCol0, extinction;

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