# Ported from !!VP1.0 to !!ARBvp1.0 
# by blueshogun96

!!ARBvp1.0

ATTRIB iPos = vertex.position;
ATTRIB iCol = vertex.color;
ATTRIB iTex = vertex.texcoord;
ATTRIB iNor = vertex.normal;

PARAM mvp[4] = {state.matrix.mvp};
PARAM mv[4] = {state.matrix.mv};

PARAM c8 = program.local[8];
PARAM c9 = program.local[9];
PARAM c10 = program.local[10];
PARAM c11 = program.local[11];
PARAM c12 = program.local[12];
PARAM c13 = program.local[13];
PARAM c14 = program.local[14];
PARAM c15 = program.local[15];
PARAM c16 = program.local[16];
PARAM c17 = program.local[17];

OUTPUT oPos = result.position;
OUTPUT oCol = result.color;
OUTPUT oTex = result.texcoord;
OUTPUT oNor = result.normal;

TEMP R0;
TEMP R1;
TEMP R2;
TEMP R3;
TEMP R4;
TEMP R5;
TEMP R6;

# R0 = (y coordinate of vertex * k) + (w * t)
MAD R0.x, iPos.y, c16.x, c16.z;

# R1 = cos(R0), R0 = any floating point number
MUL R0.x, c11.w, R0.x; 
EXP R0.y, R0.x; 
SLT R2.x, R0.y, c11; 
SGE R2.yz, R0.y, c11; 
DP3 R2.y, R2, c[14].zwzw;   
ADD R5.xyz, -R0.y, c10; 
MUL R5, R5, R5;
MAD R0, c12.xyxy, R5, c12.zwzw; 
MAD R0, R0, R5, c13.xyxy;      
MAD R0, R0, R5, c13.zwzw;      
MAD R0, R0, R5, c14.xyxy;      
MAD R0, R0, R5, c14.zwzw;      
DP3 R1.x, R0, -R2; 

# R2 = R1 * c[10] + 1.0
MAD R2.x, R1.x, c10.w, c10.z;

# R3 = perturbed vertex
# R4 = perturbed normal
MOV R2.yw, c16;
MUL R3, iPos, R2.xyxw;
MUL R4, iNor, R2.yxyw;

# Transform vertices into clip space via modelview-projection matrix
DP4 oPos.x, R3, mvp[0];
DP4 oPos.y, R3, mvp[1];
DP4 oPos.z, R3, mvp[2];
DP4 oPos.w, R3, mvp[3];

# Transform normals via inverse transpose modelview matrix & normalize
# R5 = transformed normal
DP3 R5.x, R4, mv[4];
DP3 R5.y, R4, mv[5];
DP3 R5.z, R4, mv[6];
DP3 R5.w, R5, R5;
RSQ R5.w, R5.w;
MUL R5, R5, R5.w;

# Get unit length eye vector to vertex....this is how we texture map
# R6 = vector
ADD R6, c8, iPos;
DP3 R6.w, R6, R6;
RSQ R6.w, R6.w;
MUL R6, R6, R6.w;

# Multiply by 0.5 for texture wrapping
MUL R6, R6, c10.y;
	    
# Texture coord is dot product of normal and vector from eye to vertex
DP3 oTex.x, R5, R6;

# Pass color through
MOV oCol, iCol;

END