!!ARBfp1.0
#OPTION ARB_precision_hint_fastest;

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

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

ATTRIB v0 = fragment.color;
ATTRIB tc0 = fragment.texcoord[0];
ATTRIB tc1 = fragment.texcoord[1];
ATTRIB tc2 = fragment.texcoord[2];
ATTRIB tc3 = fragment.texcoord[3];

PARAM dUV = program.env[0]; 	# { dU, dV, 0, DVIntensity }
PARAM const_val = { 1.0, 1.0, 1.0, 1.0 };
PARAM const_val2 = { 0.5, 0.0, 0.0, 0.0 };
PARAM const_bw = { 0.25, 0.5, 0.25, 0 };
PARAM const_edgeblur = { 0.25, 0.25, 0.25, 0 };
#PARAM const_edgeblur = { 1.2, 1.1, 0.8, 0 };
PARAM const_glowpow = { 1, 1.5, 2.5, 0 };


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


TEMP r0;
TEMP r1;
TEMP r2;
TEMP r3;
TEMP r4;
TEMP r5;
#-----------------------------------------

TEX t0, tc0, texture[0], 2D;
TEX t1, tc0, texture[1], 2D;
TEX t2, tc1, texture[2], 2D;
TEX t3, tc2, texture[3], 2D;
TEX t4, tc3, texture[4], 2D;

MOV r0, tc0;
ADD r0.x, r0.x, dUV.x;
MOV r1, tc0;
SUB r1.x, r1.x, dUV.x;
MOV r2, tc0;
ADD r2.y, r2.y, dUV.y;
MOV r3, tc0;
SUB r3.y, r3.y, dUV.y;

DP3_SAT t3.rgb, t3, const_bw;
SUB t3.rgb, const_val.x, t3;

TEX r0, r0, texture[0], 2D;
TEX r1, r1, texture[0], 2D;
TEX r2, r2, texture[0], 2D;
TEX r3, r3, texture[0], 2D;

ADD r0, r0, r1;
ADD r2, r3, r3;
ADD r0, r0, r2;
ADD r0, r0, t0;
MUL r0, r0, 0.0125;
POW r2.r, t2.r, const_glowpow.x;
POW r2.g, t2.g, const_glowpow.y;
POW r2.b, t2.b, const_glowpow.z;
MAD r0.rgb, r2, const_edgeblur, r0;
#MAD r0, r2, const_edgeblur, r0;
MUL r0, r0, dUV.w; # Mul DV with intensity
#MUL r2.gba, t2, t2;
#MOV r2.r, t2;

MUL r0, r0, t3;	# Mul DV with mask
ADD r0, r0, t1;	# Add screen
ADD r0, r0, t4;	# Add creeping dark

#MUL r0, t1, 2;
#MOV r0, t3;
#MOV r0, t4;

MOV oCol, r0;

END
