!!ARBvp1.0 OPTION ARB_position_invariant ;

# Parallax Mapping Engine 2.0
# by Junkguy
# junkguy@gmail.com
# www.junkguy.org
# Released on October 29, 2005

TEMP		R0, R1, R2;

PARAM		defaultTexCoord = { 0, 0.5, 0, 1 };

DP4		result.texcoord[1].x, vertex.attrib[8], program.env[10];
DP4		result.texcoord[1].y, vertex.attrib[8], program.env[11];

MOV		result.texcoord[2], defaultTexCoord;

DP4		result.texcoord[2].x, vertex.position, program.env[9];
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];
DP4		result.texcoord[4].x, vertex.attrib[8], program.env[12];
DP4		result.texcoord[4].y, vertex.attrib[8], program.env[13];
DP4		result.texcoord[5].x, vertex.attrib[8], program.env[14];
DP4		result.texcoord[5].y, vertex.attrib[8], program.env[15];

SUB		R0, program.env[4], vertex.position;

DP3		result.texcoord[0].x, vertex.attrib[9], R0;
DP3		result.texcoord[0].y, vertex.attrib[10], R0;
DP3		result.texcoord[0].z, vertex.attrib[11], R0;

DP3		R1, R0, R0;
RSQ		R1, R1.x;
MUL		R0, R0, R1.x;

SUB		R1, program.env[5], vertex.position;

DP3		result.texcoord[7].x, vertex.attrib[9], R1;
DP3		result.texcoord[7].y, vertex.attrib[10], R1;
DP3		result.texcoord[7].z, vertex.attrib[11], R1;

DP3		R2, R1, R1;
RSQ		R2, R2.x;

MAD 		R0, R1, R2.x, R0;
#MUL		R1, R1, R2.x;
#ADD		R0, R0, R1;

DP3		result.texcoord[6].x, vertex.attrib[9], R0;
DP3		result.texcoord[6].y, vertex.attrib[10], R0;
DP3		result.texcoord[6].z, vertex.attrib[11], R0;

SUB R1, program.env[5], vertex.position;

DP3 result.texcoord[7].x, vertex.attrib[9], R1;
DP3 result.texcoord[7].y, vertex.attrib[10], R1;
DP3 result.texcoord[7].z, vertex.attrib[11], R1;

MOV result.texcoord[7].w, 1.0;

MAD		result.color.xyz, vertex.color, program.env[16], program.env[17];
#MAD		result.color.xyz, vertex.color, program.env[16].x, program.env[16].y;

END


#======================================================================

!!ARBfp1.0 
#OPTION ARB_precision_hint_nicest;

TEMP	light, color, R1, R2, localNormal, specular, newtexcoord, newbumpcoord, newspeccoord, newspeclook;

#PARAM	subOne = { -1, -1, -1, -1 };	*ORIGINALE
#PARAM	scaleTwo = { 2, 2, 2, 2 };	*ORIGINALE
PARAM	subOne = { -2, -2, -3, -3 };
PARAM	scaleTwo = { 4, 4, 4, 4 };

DP3	R1.w, fragment.texcoord[7], fragment.texcoord[7];
RSQ	R1.w, R1.w;
MUL	R1.xyz, R1.w, fragment.texcoord[7];
TEX	R2, fragment.texcoord[1], texture[1], 2D;
MAD	R2.x, R2.z, -0.025, 0.025;
MAD	newbumpcoord.xyz, R2.x, R1, fragment.texcoord[1];
MAD	newtexcoord.xyz, R2.x, R1, fragment.texcoord[4];
MAD	newspeccoord.xyz, R2.x, R1, fragment.texcoord[5];
MAD	newspeclook.xyz, R2.x, R1, fragment.texcoord[6];
DP3	specular.w, newspeclook,newspeclook;
RSQ	specular.w, specular.w;
MUL	specular.xyz, specular.w, newspeclook;

TEX	light, fragment.texcoord[0], texture[0], CUBE;
MAD	light.xyz, light, scaleTwo, subOne;

# instead of using the normalization cube map, normalize with math
#DP3		light.w, fragment.texcoord[0], fragment.texcoord[0];
#RSQ		light.w, light.w;
#MUL		light.xyz, light.w, fragment.texcoord[0];

TEX	localNormal, newbumpcoord, texture[1], 2D;
MOV	localNormal.x, localNormal.a;
#MOV	localNormal.z, 0.85;
MAD	localNormal.xyz, localNormal, scaleTwo, subOne;
MOV	R1.xyz, localNormal;
MOV	R1.z, 0.0;
DP3	R1.w, R1, R1;
MAD	R1.z, R1.w, -1, 1;
RSQ	R1.w, R1.z;
RCP	localNormal.z, R1.w;
DP3	light.w, light, localNormal;
TXP	R1, fragment.texcoord[2], texture[2], 2D;
MUL	light.xyz, light.w, R1;
TXP	R1, fragment.texcoord[3], texture[3], 2D;
MUL	light.xyz, light, R1;
TEX	R1, newtexcoord, texture[4], 2D;
MUL	color.xyz, R1, program.env[0];
DP3	specular.w, specular, localNormal;
MAD_SAT	R1.w, specular.w, 4.0, -3.0;
MUL	R1.w, R1.w, R1.w;
MUL	R1.xyz, R1.w, program.env[1];
TEX	R2, newspeccoord, texture[5], 2D;
MAD	color.xyz, R1, R2, color;
MUL	color.xyz, light, color;

MUL	result.color.xyz, color, fragment.color;

END

