!!ARBfp1.0

ATTRIB Texture = fragment.texcoord[0];
ATTRIB TangentX = fragment.texcoord[3];
ATTRIB TangentY = fragment.texcoord[2];
ATTRIB TangentZ = fragment.texcoord[1];
ATTRIB tex_eye = fragment.texcoord[4];

OUTPUT Color=result.color;

PARAM Light= { 0, 0, 0, 1};
ATTRIB Ks = fragment.color.secondary;
ATTRIB Kd = fragment.color;
PARAM Ka=program.env[3];

PARAM mvinvtrans[4]={ $MODELVIEW_IT$ };
PARAM light_dir = state.light[0].position;
PARAM half_dir = state.light[0].half;

TEMP Base, N, L, R, V, temp, NewTex, Height,NdotL, RdotL, LDIR,HDIR, DISP;

DP3 temp.x, tex_eye, tex_eye;
RSQ temp.x, temp.x;
MUL temp, tex_eye, temp.x;
#MOV temp.w, temp.x;
#MUL temp.x, temp.y, -1;
#MUL temp.y, temp.w, -1;
#MUL temp.y , temp.y, -1.0;
 
TEX Height, Texture, texture[1], 2D;
MAD Height.w, Height.w, -0.01, 0.005;
MAD NewTex, Height.wwww, temp, Texture;
#MOV NewTex, Texture;

TEX Base, NewTex, texture[0], 2D;
TEX N, NewTex, texture[1], 2D;

MAD DISP, N, 2.0, -1.0;

#MOV DISP.z, 0.0;
#DP3 DISP.z, DISP, DISP;
#SUB DISP.z, 1.0, DISP.z;
#RSQ DISP.z, DISP.z;
#RCP DISP.z, DISP.z;

#MUL DISP.z, DISP.z, 0.2;
DP3 DISP.w, DISP, DISP;
RSQ DISP.w, DISP.w;
MUL DISP, DISP, DISP.w;

#MOV DISP , {0,0,0,0};

MUL V, TangentX, DISP.y;
ADD N, TangentZ, V;

MUL V, TangentY, DISP.x;
ADD N, N, V;

ABS DISP.z, DISP.z;
MUL V, TangentZ, DISP.z;
ADD N, N, V;

#MOV Base, TangentX;
#MOV N, TangentZ;

DP3 N.w, N.xyzz, N.xyzz;
RSQ N.w, N.w;
MUL N, N, N.w;



DP3 L.x, N, mvinvtrans[0];
DP3 L.y, N, mvinvtrans[1];
DP3 L.z, N, mvinvtrans[2];
#DP3 L.w, L, L;
#RSQ L.w, L.w;
#MUL L, L.w, L;
#MOV L,N;

DP3 V.w,light_dir, light_dir;
RSQ V.w, V.w;
MUL LDIR, light_dir, V.w;

#MOV V,Vertex;
#DP3 V.w, V, V;
#RSQ V.w, V.w;
#MUL V, V, V.w;

#DP3 R, L, V;
#MAX R, 0, R;
MOV R,L;


DP3 V.w, half_dir,half_dir;
RSQ V.w, V.w;
MUL HDIR, V.w, half_dir;

DP3 NdotL.x, L, LDIR;
DP3 NdotL.y, R, HDIR;
MOV NdotL.zw, Texture.w;
LIT NdotL, NdotL;

MUL RdotL , Ks, NdotL.z;
#MOV Base, {0.5, 0.6, 0.8, 1.0};
MAD Color, Base, NdotL.y , RdotL;
#ADD Color.rgb, TangentZ, RdotL;
#DP3 temp, TangentX, TangentX;
#RSQ temp.x, temp.x;
#MUL temp, TangentX, temp.x;
#MOV Color.rgb, temp;

#MOV Color.rgb, N;
#MOV Color.rgb, L;
#MOV Color, Base;
MOV Color.a , 1;

END
