

/*
Complete vertex program that does the necessary calculations for transforming the vertices and
calculating the values when they are lit by 3 lights.
*/
/*
!!ARBvp1.0
ATTRIB iPos              = vertex.position;
ATTRIB iNormal           = vertex.normal;
PARAM mvm[4]             = { state.matrix.modelview };
PARAM mvinv[4]           = { state.matrix.modelview.invtrans }; # The
             inversetransposed modelview matrix
PARAM proj[4]            = { state.matrix.projection }; # The projection                  matrix
PARAM lightPos0          = state.light[0].position; # Position of the
             lightsource
PARAM ambientCol0        = state.lightprod[0].ambient; # Product                          of ambient color of material and color of scene
PARAM diffuseCol0        = state.lightprod[0].diffuse; # Product                          of diffuse color of material and diffuse                intensity of           light
PARAM specularCol0 = state.lightprod[0].specular; # Product                               of specular color of material and specular intensity of                        light
PARAM halfDir0           = state.light[0].half; # Halfangle of              lightsource, for infinite eyecoordinates
PARAM lightPos1          = state.light[1].position; # Position of the              lightsource
PARAM ambientCol1        = state.lightprod[1].ambient; # Product                          of ambient color of material and color of scene
PARAM diffuseCol1        = state.lightprod[1].diffuse; # Product                          of diffuse color of material and diffuse                intensity of           light
PARAM specularCol1 = state.lightprod[1].specular; # Product                               of specular color of material and specular intensity of                        light
PARAM halfDir1           = state.light[1].half; # Halfangle of              lightsource, for infinite eyecoordinates
PARAM lightAttCoeff1                    = state.light[1].attenuation; #             Attenuation coefficients
PARAM lightPos2          = state.light[2].position; # Position of the             lightsource
PARAM ambientCol2        = state.lightprod[2].ambient; # Product                          of ambient color of material and color of scene
PARAM diffuseCol2        = state.lightprod[2].diffuse; # Product                          of diffuse color of material and diffuse                intensity of           light
PARAM specularCol2 = state.lightprod[2].specular; # Product                               of specular color of material and specular intensity of                        light
PARAM halfDir2           = state.light[2].half; # Halfangle of              lightsource, for infinite eyecoordinates
PARAM lightAttCoeff2                    = state.light[2].attenuation; #              Attenuation coefficients
PARAM lightSpotDir2 = state.light[2].spot.direction; #                      Direction of lightspot
PARAM specExp            = state.material.shininess; # Specular exponent
PARAM sceneLight         = state.lightmodel.scenecolor; # front scene color = a_cs * a_cm + e_cm
PARAM eyePositionConst                  = { 0.0, 0.0, 0.0, 1.0 }; # Position of              eye
TEMP normalEye, eyePosition, eyePositionNH, reflEyeLightVector, sphereEyeVector, halfVector, temp1, primFront, secFront, primBack, secBack, distVector;
OUTPUT oPos              = result.position;
OUTPUT oColorPrimFront                  = result.color.front.primary;

# -------- Modelview calculations ---------
# Transform the vertex to eye coordinates
DP4          eyePosition.x, mvm[0], iPos;
DP4          eyePosition.y, mvm[1], iPos;
DP4          eyePosition.z, mvm[2], iPos;
DP4          eyePosition.w, mvm[3], iPos;
# --------- /Modelview calculations --------

# ------------ Normal calculations ---------
# Transform the normal to eye coordinates.
DP3      normalEye.x, mvinv[0], iNormal;
DP3      normalEye.y, mvinv[1], iNormal;
DP3      normalEye.z, mvinv[2], iNormal;

# Non-homogeneous Eye position
RCP      temp1.w, eyePosition.w;
MUL      eyePositionNH, eyePosition, temp1.w;
# ------------ /Normal Calculations -----------

# ---------- Projection calculations ----------
# Transform the vertex to clip-coordinates
DP4      oPos.x, proj[0], eyePosition;
DP4      oPos.y, proj[1], eyePosition;
DP4      oPos.z, proj[2], eyePosition;
DP4      oPos.w, proj[3], eyePosition;
# ---------- /Projection Calculations ---------

# Compute the vector pointing from the vertex position to the eye
         position
SUB     temp1, eyePositionConst, eyePositionNH;

# Compute eye vector
# d = |eyePositionConst - eyePositionNH|
DP3     temp1.w, temp1, temp1;                   # temp1.w = d
RSQ     reflEyeLightVector.w, temp1.w;# reflEyeLightVector.w = 1/d
MUL     sphereEyeVector, temp1, reflEyeLightVector.w;     #    Normalized direction (VP_e unit vector)
#DST     reflEyeLightVector, temp1.w, reflEyeLightVector.w;        #      reflEyeLightVector = (1, d, d, 1/d)

#------- LIGHTSOURCE 0 --------

#Compute the light coefficients for diffuse and specular light for
Frontmaterial
DP3     temp1.x, normalEye, lightPos0;
DP3     temp1.y, normalEye, halfDir0;
MOV     temp1.w, specExp.x;  # now: temp1 = (n * VP_pli , n *      h_i , - , s_rm)
LIT     temp1, temp1;

# Adding up all the color components for Front Material
MAD     primFront.xyz, temp1.x, ambientCol0, primFront;
MAD     primFront.xyz, temp1.y, diffuseCol0, primFront;
MAD     primFront.xyz, temp1.z, specularCol0, primFront;

#------- LIGHTSOURCE 1 --------

# Compute the vector pointing from the vertex position to the      light
position
SUB     temp1, lightPos1, eyePositionNH; # temp1 = lightposition -          eyeposition (VP_pli)

# Compute light direction and distance vector
# d = |lightposition - eyeposition|
DP3     temp1.w, temp1, temp1;         # temp1.w = d
RSQ     distVector.w, temp1.w;         # distVector.w = 1/d
MUL     reflEyeLightVector, temp1, distVector.w;          # Normalized          direction (VP_pli unit vector)
DST     distVector, temp1.w, distVector.w;                # distVector =          (1, d, d, 1/d)

# Compute Distance attenuation
DP3      distVector.w, distVector, lightAttCoeff1;
RCP      distVector.w, distVector.w;

#Compute the light coefficients for diffuse and specular light for Frontmaterial
DP3     temp1.x, normalEye, reflEyeLightVector;
DP3     temp1.y, normalEye, halfDir1;
MOV     temp1.w, specExp.x;  # now: temp1 = (n * VP_pli , n *       h_i , - , s_rm)
LIT     temp1, temp1;
MUL     temp1, temp1, distVector.w;    # Light attenuation and spotlight is now multiplied with the ambient, diffuse and specular coefficients

# Adding up all the color components for Front Material
MAD     primFront.xyz, temp1.x, ambientCol1, primFront;
MAD     primFront.xyz, temp1.y, diffuseCol1, primFront;
MAD     primFront.xyz, temp1.z, specularCol1, primFront;

#------- LIGHTSOURCE 2 --------

# Compute the vector pointing from the vertex position to the       light
position
SUB     temp1, lightPos2, eyePositionNH; # temp1 = lightposition - eyeposition (VP_pli)

# Compute light direction and distance vector
# d = |lightposition - eyeposition|
DP3     temp1.w, temp1, temp1;         # temp1.w = d
RSQ     distVector.w, temp1.w;         # distVector.w = 1/d
MUL     reflEyeLightVector, temp1, distVector.w;          # Normalized
         direction (VP_pli unit vector)
DST     distVector, temp1.w, distVector.w;                # distVector =
         (1, d, d, 1/d)

# Compute Distance attenuation
DP3      distVector.w, distVector, lightAttCoeff2;
RCP      distVector.w, distVector.w;

# Compute spotlight cone attenuation
DP3     temp1.y, reflEyeLightVector, -lightSpotDir2;
ADD     temp1.x, temp1.y, -lightSpotDir2.w;
MOV     temp1.w, lightAttCoeff2.w;     # now: temp1 = ( P_pliV * S_dli  - cos(c_rli) , P_pliV * s_dli , - , s_rli)
LIT     temp1, temp1;        # temp1.z = 0.0, if P_pliV * S_dli - cos(c_rli) < 0
MUL     distVector.w, distVector.w, temp1.z;# Light attenuation     and spotlight attenaution is now  multiplied together

#Compute the light coefficients for diffuse and specular light for
Frontmaterial
DP3     temp1.x, normalEye, reflEyeLightVector;
DP3     temp1.y, normalEye, halfDir2;
MOV     temp1.w, specExp.x;  # now: temp1 = (n * VP_pli , n *       h_i , - , s_rm)
LIT     temp1, temp1;
MUL     temp1, temp1, distVector.w;    # Light attenuation and spotlight is now multiplied with the ambient, diffuse and specular coefficients

# Adding up all the color components for Front Material
MAD     primFront.xyz, temp1.x, ambientCol2, primFront;
MAD     primFront.xyz, temp1.y, diffuseCol2, primFront;
MAD     primFront.xyz, temp1.z, specularCol2, primFront;

# The final addition of scene color and moving it to the output     for Front Material
ADD     oColorPrimFront, primFront, sceneLight;
END
*/


/*
Complete vertex program that does that necessary transformations and moves input color to output
color because lighting is disabled.
*/
		
/*
!!ARBvp1.0
ATTRIB iPos          = vertex.position;
ATTRIB iNormal       = vertex.normal;
ATTRIB iColorPrim             = vertex.color.primary;
ATTRIB iColorSec             = vertex.color.secondary;
PARAM mvm[4]         = { state.matrix.modelview };
PARAM mvinv[4]       = { state.matrix.modelview.invtrans }; # The
inversetransposed m
odelview matrix
PARAM proj[4]             = { state.matrix.projection }; # The projection matrix
TEMP normalEye, eyePosition, eyePositionNH, reflEyeLightVector,
sphereEyeVector,
 halfVector, temp1, primFront, secFront, primBack, secBack, distVector;
OUTPUT oPos          = result.position;
OUTPUT oColorPrimFront          = result.color.front.primary;
OUTPUT oColorSecFront           = result.color.front.secondary;

# -------- Modelview calculations ---------
# Transform the vertex to eye coordinates
DP4       eyePosition.x, mvm[0], iPos;
DP4       eyePosition.y, mvm[1], iPos;
DP4       eyePosition.z, mvm[2], iPos;
DP4       eyePosition.w, mvm[3], iPos;
# --------- /Modelview calculations --------

# Normalize Eye Normal
DP3       normalEye.w, normalEye, normalEye;
RSQ       normalEye.w, normalEye.w;
MUL       normalEye, normalEye, normalEye.w;

# ---------- Projection calculations ----------
# Transform the vertex to clip-coordinates
DP4       oPos.x, proj[0], eyePosition;
DP4       oPos.y, proj[1], eyePosition;
DP4       oPos.z, proj[2], eyePosition;
DP4       oPos.w, proj[3], eyePosition;
# ---------- /Projection Calculations ---------
MOV oColorPrimFront, iColorPrim;
MOV oColorSecFront, iColorSec;
END
*/
