!!ARBvp1.0 OPTION ARB_position_invariant ;

# VPROG_NV_SPECULAR_COLOR
# 
# input:
# 
# TEX0	texture coordinates
# TEX1	normal
# TEX2	tangent[0]
# TEX3	tangent[1]
# COL0	vertex color
# 
# output:
# 
# HPOS	homogeneous clip space position
# TEX0	is the normalization cube map for the half angle
# TEX1	will be the per-surface bump map
# TEX2	will be the per-surface specular map
# TEX3	will be the light projection texture

TEMP	R0, R1, R2;

# textures 1, and 2 use the same source texcoords
# textures 1 takes the base coordinates by the texture matrix
DP4	result.texcoord[1].x, vertex.texcoord[0], program.env[10];
DP4	result.texcoord[1].y, vertex.texcoord[0], program.env[11];

# textures 2 takes the base coordinates by the texture matrix
DP4	result.texcoord[2].x, vertex.texcoord[0], program.env[14];
DP4	result.texcoord[2].y, vertex.texcoord[0], program.env[15];

# texture 0's texcoords will be the halfangle in texture space

# calculate normalized vector to light in R0
ADD		R0, -vertex.position, program.env[4];
DP3		R1, R0, R0;
RSQ		R1, R1.x;
MUL		R0,	R0, R1.x;

# calculate normalized vector to viewer in R1
ADD		R1, -vertex.position, program.env[5];
DP3		R2, R1, R1;
RSQ		R2, R2.x;
MUL		R1,	R1, R2.x;

# add together to become the half angle vector in object space (non-normalized)
ADD		R0, R0, R1;

# put into texture space
DP3		result.texcoord[0].x, vertex.texcoord[1], R0;
DP3		result.texcoord[0].y, vertex.texcoord[2], R0;
DP3		result.texcoord[0].z, vertex.texcoord[3], R0;

# texture 3 has three texgens
DP4	result.texcoord[3].x, vertex.position, program.env[6];
DP4	result.texcoord[3].y, vertex.position, program.env[7];
DP4	result.texcoord[3].w, vertex.position, program.env[8];

# copy color
MOV	result.color.xyz, vertex.color;

END
