!!ARBfp1.0
# OPTION ARB_precision_hint_fastest;

#/*ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ*\
#	File:			Program for OW grain
#					
#	Author:			Magnus Högdahl
#					
#	Copyright:		Starbreeze AB 2004
#					
#	History:
#
#\*____________________________________________________________________________________________*/


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

ATTRIB tc0 = fragment.texcoord[0];
ATTRIB tc1 = fragment.texcoord[1];
ATTRIB tc2 = fragment.texcoord[2];

PARAM OffsetScale = program.env[0];
PARAM Time = program.env[1];
PARAM VPParam = program.env[2]; # { F, B, 1/B, ... }
PARAM VPConst = program.env[3];	# { 2B, B+F, 2BF, 2(B-F) }
PARAM VPParam2 = program.env[4];# { 0, 0, bla, bla }
PARAM V2WRow0 = program.env[5];
PARAM V2WRow1 = program.env[6];
PARAM V2WRow2 = program.env[7];

TEMP t0;
TEMP t1a;
TEMP t1b;
TEMP tdepth;
TEMP ttemp;
TEMP t0_0;
TEMP t0_1;
TEMP t0_2;
TEMP t0_3;
TEMP r0;
TEMP r1;
TEMP r2;
TEMP PixelPosV, PixelPosW;

#-----------------------------------
TEX tdepth, tc0, texture[2], 2D;
@if xenon
SUB tdepth.a, 1.0, tdepth.r;

@else
MOV oCol, tdepth;
MUL tdepth.rgb, tdepth, 0.99609375;
MAD tdepth.a, tdepth.g, 0.00390625, tdepth.r;
MAD tdepth.a, tdepth.b, 0.0000152587890625, tdepth.a;
@endif

MAD r2.y, tdepth.a, VPConst.w, -VPConst.x;
RCP r2.y, r2.y;
MUL PixelPosV.z, r2.y, -VPConst.z;

MUL PixelPosV.z, PixelPosV, 0.5;
MUL PixelPosV.x, tc2.x, VPParam2.z;
MUL PixelPosV.y, tc2.y, VPParam2.w;
MUL PixelPosV.xy, PixelPosV, PixelPosV.z;
MOV PixelPosV.w, 1;

MOV PixelPosW, PixelPosV;

DP4 PixelPosW.x, PixelPosV, V2WRow0;
DP4 PixelPosW.y, PixelPosV, V2WRow1;
DP4 PixelPosW.z, PixelPosV, V2WRow2;

MUL PixelPosW, PixelPosW, 0.01;
#TEX r0, PixelPosW, texture[1], 2D;
#MOV oCol, r0;

#MUL oCol, tdepth.a, 0.001;
#MOV oCol, tdepth.a;

#ADD PixelPosW.y, PixelPosW.y, PixelPosW.z;
#-----------------------------------

TEX t0, tc0, texture[0], 2D;

#MUL r1, tc1, 0.1;
MUL r1, PixelPosW, 0.2;
MAD r1.yw, Time.x, 1, r1;
TEX t1a, r1, texture[1], 2D;
ADD r0.xy, r1, 0.5;
TEX t1b, r0, texture[1], 2D;
MOV r1.x, r1.z;
MOV r0.xy, r1;
TEX ttemp, r0, texture[1], 2D;
ADD t1b, t1b, ttemp;
ADD r0.xy, r1, -0.5;
TEX ttemp, r0, texture[1], 2D;
ADD t1a, t1a, ttemp;

MOV r2.xy, tc0;
MOV r2.z, tc0.x;
MOV r2.w, tc0.y;
MAD t1a, t1a, 1, { -1, -1, -1, -1 };
MAD t1b, t1b, 1, { -1, -1, -1, -1 };

MUL r0, t1a, OffsetScale;
MUL r0, r0, { 25, 52, 35, 52 };
ADD r0, r0, r2;
TEX t0_0, r0, texture[0], 2D;
MOV r1.x, r0.z;
MOV r1.y, r0.w;
TEX t0_1, r1, texture[0], 2D;

MUL r0, t1b, OffsetScale;
MUL r0, r0, { 25, 12, 15, 12 };
ADD r0, r0, r2;
TEX t0_2, r0, texture[0], 2D;
MOV r1.x, r0.z;
MOV r1.y, r0.w;
TEX t0_3, r1, texture[0], 2D;

MUL r0, t0, 1.5;
DP3 r1.r, t0_0, t0_0;
DP3 r1.g, t0_1, t0_1;
DP3 r1.b, t0_2, t0_2;
DP3 r1.a, t0_3, t0_3;
MUL r1, r1, 145.5;
SUB_SAT r1, 1, r1;
MUL r1, r1, r1;
MUL r1, r1, r1;
MUL r1, r1, r1;
#MUL r1, r1, r1;
#MUL r1, r1, r1;
#MUL r1, r1, r1;
#SUB_SAT r1, 1, r1;
DP4_SAT r1.a, r1, r1;
#MOV r0, r1.a;

#MOV r2, 0;
#MUL r1.a, r1.a, 0.7;
#LRP r0.rgb, r1.a, 0, r0;
#MOV r0.a, r1.a;
MUL r0.rgb, -r1.a, 0.1;

#MAD r0, t0, 0.5, r0;

MUL r1, t0_0, 0.25;
MAD r1, t0_1, 0.25, r1;
MAD r1, t0_2, 0.25, r1;
MAD r1, t0_3, 0.25, r1;
SUB_SAT r1, r1, 0.2;
MUL r1, r1, 3;
MUL r1, r1, r1;
MUL r1, r1, r1;
#MAD r0.rgb, r1, 0.5, r0;

#MUL r0, r0, 0.5;
#LRP r0, 0.7, t0, r0;

#MOV r0, t0_3;

#MUL r0, t1, 0.25;
#ADD r0, r0, t0;

MOV oCol, r0;

END

