!!ARBfp1.0
OPTION ARB_precision_hint_fastest;

#-----------------------------------
OUTPUT oCol = result.color;

ATTRIB tc0 = fragment.texcoord[0];

PARAM p0 = program.env[0];
PARAM p1 = program.env[1];
PARAM p2 = program.env[2];

#PARAM c0 = { 1, 2, 3, 4 };
#PARAM c1 = { 5, 6, 7, 8 };
PARAM c0 = { 1, 3, 5, 7 };
PARAM c1 = { 9, 11, 13, 15 };
PARAM c2 = { 0.125, 0.5, 2, 0 };
PARAM c3 = { 0.25, 0.5, 0.25, 25.0 };

TEMP t0;
TEMP r0;
TEMP r1;
TEMP r2;
TEMP r3;
TEMP r4;
TEMP r5;
TEMP r6;
TEMP r7;

SUB r0, p2.xyzz, tc0;
MUL r0, r0, c0.y;
DP3 r1, r0, r0;
SUB r1, r1, p0.z;
MAX r1, c2.w, r1;
MUL r1, r1, c3.w;
MIN r1, r1, c0.x;

# Get direction
SUB t0, p0, tc0;
MUL t0, t0, c2.z;
MUL t0, t0, p1;
MUL t0, t0, r1;
MUL t0, t0, 2;

# Find sample positions
MAD r0, t0, c0.x, tc0;
MAD r1, t0, c0.y, tc0;
MAD r2, t0, c0.z, tc0;
MAD r3, t0, c0.w, tc0;
MAD r4, t0, c1.x, tc0;
MAD r5, t0, c1.y, tc0;
MAD r6, t0, c1.z, tc0;
MAD r7, t0, c1.w, tc0;

# Fetch
TEX r0, r0, texture[0], 2D;
TEX r1, r1, texture[0], 2D;
TEX r2, r2, texture[0], 2D;
TEX r3, r3, texture[0], 2D;
TEX r4, r4, texture[0], 2D;
TEX r5, r5, texture[0], 2D;
TEX r6, r6, texture[0], 2D;
TEX r7, r7, texture[0], 2D;

MUL r0.rgb, r0, r0;
MUL r1.rgb, r1, r1;
MUL r2.rgb, r2, r2;
MUL r3.rgb, r3, r3;
MUL r4.rgb, r4, r4;
MUL r5.rgb, r5, r5;
MUL r6.rgb, r6, r6;
MUL r7.rgb, r7, r7;

# Sum
MOV t0.rgb, r0;
ADD r0.rgb, r0, r1;
ADD r1.rgb, r2, r3;
ADD r2.rgb, r4, r5;
ADD r3.rgb, r6, r7;
ADD r0.rgb, r0, r1;
ADD r1.rgb, r2, r3;
ADD r0.rgb, r0, r1;

# Average
MUL r0.rgb, r0, c2.x;
#POW r0.r, r0.r, c2.y;
#POW r0.g, r0.g, c2.y;
#POW r0.b, r0.b, c2.y;
DP3 r0.rgb, r0, c3;
MUL r0.rgb, r0, 2;
MUL oCol, r0, p0.w;


END