!!ARBvp1.0
PARAM MVP[4] = { state.matrix.mvp };
PARAM MV[4] = { state.matrix.modelview };
PARAM v_scale = program.local[0];
PARAM skin_matrix[237] = { program.local[1..237] };

PARAM env_sun_color  = program.env[0];
PARAM env_sun_dir_v  = program.env[1];
PARAM env_ambient    = program.env[2];
PARAM env_hemi_color = program.env[3];

ATTRIB vPos_compressed       = vertex.attrib[0];
ATTRIB vNrm                  = vertex.attrib[1];
ATTRIB vSkinMatrix           = vertex.attrib[2];
ATTRIB vSkinWeight           = vertex.attrib[3];
if(USE_BUMP) ATTRIB vT       = vertex.attrib[4];
if(USE_BUMP) ATTRIB vB       = vertex.attrib[5];
if(USE_TEXTURES) ATTRIB vTc0 = vertex.attrib[6];

OUTPUT oT = result.texcoord[1];
OUTPUT oB = result.texcoord[2];
OUTPUT oN = result.texcoord[3];

TEMP Nm, Tm, Bm;
TEMP Nv;
TEMP vPos;
TEMP Ldir_v;
TEMP C; # color
TEMP Pv;
TEMP tmp;

TEMP skin_mat_0;
TEMP skin_mat_1;
TEMP skin_mat_2;
TEMP skin_mat_3;

ADDRESS addr;

# scale vertex
MUL vPos, vPos_compressed, v_scale;
MOV vPos.w, 1;

# unpack normal
MAD Nm, vNrm.zyxw, 2, -1;
MOV Nm.w, vNrm.w;

# skin vertex
#MUL tmp, vSkinMatrix, 0.33333333;
#MUL tmp, tmp, 4;
MOV tmp, vSkinMatrix;

ARL addr.x, tmp.x;
MUL skin_mat_0, skin_matrix[addr.x+0], vSkinWeight.x;
MUL skin_mat_1, skin_matrix[addr.x+1], vSkinWeight.x;
MUL skin_mat_2, skin_matrix[addr.x+2], vSkinWeight.x;
#MUL skin_mat_3, skin_matrix[addr.x+3], vSkinWeight.x;

ARL addr.x, tmp.y;
MAD skin_mat_0, skin_matrix[addr.x+0], vSkinWeight.y, skin_mat_0;
MAD skin_mat_1, skin_matrix[addr.x+1], vSkinWeight.y, skin_mat_1;
MAD skin_mat_2, skin_matrix[addr.x+2], vSkinWeight.y, skin_mat_2;
#MAD skin_mat_3, skin_matrix[addr.x+3], vSkinWeight.y, skin_mat_3;

ARL addr.x, tmp.z;
MAD skin_mat_0, skin_matrix[addr.x+0], vSkinWeight.z, skin_mat_0;
MAD skin_mat_1, skin_matrix[addr.x+1], vSkinWeight.z, skin_mat_1;
MAD skin_mat_2, skin_matrix[addr.x+2], vSkinWeight.z, skin_mat_2;
#MAD skin_mat_3, skin_matrix[addr.x+3], vSkinWeight.z, skin_mat_3;

ARL addr.x, tmp.w;
MAD skin_mat_0, skin_matrix[addr.x+0], vSkinWeight.w, skin_mat_0;
MAD skin_mat_1, skin_matrix[addr.x+1], vSkinWeight.w, skin_mat_1;
MAD skin_mat_2, skin_matrix[addr.x+2], vSkinWeight.w, skin_mat_2;
#MAD skin_mat_3, skin_matrix[addr.x+3], vSkinWeight.w, skin_mat_3;

MOV tmp, vPos;
DP4 vPos.x, skin_mat_0, tmp;
DP4 vPos.y, skin_mat_1, tmp;
DP4 vPos.z, skin_mat_2, tmp;
#DP4 vPos.w, skin_mat_3, tmp;
MOV vPos.w, 1;

MOV tmp, Nm;
DP3 Nm.x, skin_mat_0, tmp;
DP3 Nm.y, skin_mat_1, tmp;
DP3 Nm.z, skin_mat_2, tmp;

if(USE_BUMP) MAD tmp, vT.zyxw, 2, -1;
if(USE_BUMP) DP3 Tm.x, skin_mat_0, tmp;
if(USE_BUMP) DP3 Tm.y, skin_mat_1, tmp;
if(USE_BUMP) DP3 Tm.z, skin_mat_2, tmp;

if(USE_BUMP) MAD tmp, vB.zyxw, 2, -1;
if(USE_BUMP) DP3 Bm.x, skin_mat_0, tmp;
if(USE_BUMP) DP3 Bm.y, skin_mat_1, tmp;
if(USE_BUMP) DP3 Bm.z, skin_mat_2, tmp;

# transform vertex
DP4 result.position.x, MVP[0], vPos;
DP4 result.position.y, MVP[1], vPos;
DP4 result.position.z, MVP[2], vPos;
DP4 result.position.w, MVP[3], vPos;

# unpack texcoord (mul by 1/2048)
if(USE_TEXTURES) MUL result.texcoord, vTc0, { 0.00048828125, 0.00048828125, 0.00048828125, 1 };

# transform normal into view space
DP3 Nv.x, Nm, MV[0];
DP3 Nv.y, Nm, MV[1];
DP3 Nv.z, Nm, MV[2];

# transform point into view space
DP4 Pv.x, vPos, MV[0];
DP4 Pv.y, vPos, MV[1];
DP4 Pv.z, vPos, MV[2];

## calc ligthing

# camera light
# Ldir_v = normalize(Pv)
if(!WEATHER) DP3 tmp.x, Pv, Pv;
if(!WEATHER) RSQ tmp.y, tmp.x;
if(!WEATHER) MUL Ldir_v, Pv, tmp.y;

if(!WEATHER) DP3 C, Nv, -Ldir_v;
if(!WEATHER) MAX C, C, 0;

# sun light
if(WEATHER) DP3 C, Nv, -env_sun_dir_v;
if(WEATHER) MAX C, C, 0;
if(WEATHER) MUL C, C, env_sun_color;

if(WEATHER) MAD C, env_hemi_color, vNrm.wwww, C;
if(WEATHER) ADD C, C, env_ambient;

MOV result.color, C;
if(SHOW_AO) MOV result.color, vNrm.wwww;

MOV result.color.w, 1.0;

# pass TBN to fragment program
if(USE_BUMP) MOV oT, Tm;
if(USE_BUMP) MOV oB, Bm;
if(USE_BUMP) MOV oN, Nm; 

#MOV result.color, vNrm.wwww;
#MOV result.color, C;

if(USE_BUMP) MOV result.texcoord[4], Pv;

END