!!ARBfp1.0
OPTION ARB_precision_hint_fastest;

#/*ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ*\
#	File:			Program for XREngine guassian blur
#					
#	Author:			Magnus Högdahl
#					
#	Copyright:		Starbreeze AB 2004
#					
#	History:
#
# 		Cycles/64 pixel vector: ALU 82.7, vertex 0, texture 136, sequencer 32, interpolator 4
# 		18 GPRs, 10 threads, Performance (if enough threads): ~136 cycles per vector
#\*____________________________________________________________________________________________*/


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

ATTRIB v0 = fragment.color;
ATTRIB texcoord = fragment.texcoord[0];

#-----------------------------------------
PARAM ColorBias = program.env[0];	# r,g,b
PARAM ColorScale = program.env[1];	# r,g,b
PARAM ColorGamma = program.env[2];	# r, the rest is for target pos

PARAM UVMin = program.env[3];
PARAM UVMax = program.env[4];

PARAM Weight0 = program.env[5];		# 0, 0, 0, w0
PARAM Weight1 = program.env[6];		# w1,w2,w3,w4
PARAM Weight5 = program.env[7];		# w5,w6,w7,w8

PARAM dUV12 = program.env[8];
PARAM dUV34 = program.env[9];
PARAM dUV56 = program.env[10];
PARAM dUV78 = program.env[11];

PARAM c0 = { 0.5, 25, 1, 0 };
PARAM c1 = { 0.25, 0.75, 3.0, 0.0 };

#-----------------------------------------
TEMP tcbase;
TEMP tc0;
TEMP tc1;
TEMP tc2;
TEMP tc3;
TEMP tc4;

TEMP t0;
TEMP t1;
TEMP t2;
TEMP t3;
TEMP t4;

TEMP r0;
TEMP r1;
TEMP t0org;
TEMP Result;

#-----------------------------------------

SUB r0, ColorGamma.yzww, texcoord;
#SUB r0, c1.xyww, texcoord;
MUL r0, r0, c1.z;
DP3 r1, r0, r0;
SUB r1, r1, ColorBias.w;
MAX r1, c0.w, r1;
MUL r1, r1, c0.y;
MIN r1, r1, c0.z;

#SUB r0, c2.yyww, tc0;
#DP3 r1, r0, r0;
#SUB r1, r1, p0.z;
#MAX r1, c2.w, r1;
#MUL r1, r1, c3.w;
#MIN r1, r1, c0.x;

TEX t0, texcoord, texture[0], 2D;
MOV t0org, t0;
#MOV Result, t0;
MUL Result, t0, Weight0.w;
SWZ tcbase, texcoord, x, y, x, y;

ADD tc0, tcbase, dUV12;
MIN tc0, tc0, UVMax;
MAX tc0, tc0, UVMin;
SWZ tc1, tc0, z,w,0,0;
ADD tc2, tcbase, dUV34;
MIN tc2, tc2, UVMax;
MAX tc2, tc2, UVMin;
SWZ tc3, tc2, z,w,0,0;
TEX t0, tc0, texture[0], 2D;
TEX t1, tc1, texture[0], 2D;
TEX t2, tc2, texture[0], 2D;
TEX t3, tc3, texture[0], 2D;
MAD Result.rgb, t0, Weight1.x, Result;
MAD Result.rgb, t1, Weight1.y, Result;
MAD Result.rgb, t2, Weight1.z, Result;
MAD Result.rgb, t3, Weight1.w, Result;

ADD tc0, tcbase, dUV56;
MIN tc0, tc0, UVMax;
MAX tc0, tc0, UVMin;
SWZ tc1, tc0, z,w,0,0;
ADD tc2, tcbase, dUV78;
MIN tc2, tc2, UVMax;
MAX tc2, tc2, UVMin;
SWZ tc3, tc2, z,w,0,0;
TEX t0, tc0, texture[0], 2D;
TEX t1, tc1, texture[0], 2D;
TEX t2, tc2, texture[0], 2D;
TEX t3, tc3, texture[0], 2D;
MAD Result.rgb, t0, Weight5.x, Result;
MAD Result.rgb, t1, Weight5.y, Result;
MAD Result.rgb, t2, Weight5.z, Result;
MAD Result.rgb, t3, Weight5.w, Result;

SUB tc0, tcbase, dUV12;
MIN tc0, tc0, UVMax;
MAX tc0, tc0, UVMin;
SWZ tc1, tc0, z,w,0,0;
SUB tc2, tcbase, dUV34;
MIN tc2, tc2, UVMax;
MAX tc2, tc2, UVMin;
SWZ tc3, tc2, z,w,0,0;
TEX t0, tc0, texture[0], 2D;
TEX t1, tc1, texture[0], 2D;
TEX t2, tc2, texture[0], 2D;
TEX t3, tc3, texture[0], 2D;
MAD Result.rgb, t0, Weight1.x, Result;
MAD Result.rgb, t1, Weight1.y, Result;
MAD Result.rgb, t2, Weight1.z, Result;
MAD Result.rgb, t3, Weight1.w, Result;

SUB tc0, tcbase, dUV56;
MIN tc0, tc0, UVMax;
MAX tc0, tc0, UVMin;
SWZ tc1, tc0, z,w,0,0;
SUB tc2, tcbase, dUV78;
MIN tc2, tc2, UVMax;
MAX tc2, tc2, UVMin;
SWZ tc3, tc2, z,w,0,0;
TEX t0, tc0, texture[0], 2D;
TEX t1, tc1, texture[0], 2D;
TEX t2, tc2, texture[0], 2D;
TEX t3, tc3, texture[0], 2D;
MAD Result.rgb, t0, Weight5.x, Result;
MAD Result.rgb, t1, Weight5.y, Result;
MAD Result.rgb, t2, Weight5.z, Result;
MAD Result.rgb, t3, Weight5.w, Result;

MUL Result.rgb, Result, ColorScale;
ADD_SAT Result.rgb, Result, ColorBias;
POW Result.r, Result.r, ColorGamma.r;
POW Result.g, Result.g, ColorGamma.r;
POW Result.b, Result.b, ColorGamma.r;

#TEX Result, texcoord, texture[0], 2D;
LRP Result, r1, Result, t0org;

MOV oCol, Result;

END
