!!ARBfp1.0
OPTION ARB_precision_hint_fastest;

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

OUTPUT oCol = result.color;

# Texture coordinates
ATTRIB tc0 = fragment.texcoord[0];

# Predefines
PARAM c0 = program.env[0];
PARAM c1 = program.env[1];

# Program parameters
PARAM p0 = program.env[1];				# { c1, SpeedX, SpeedY, Frequency }

# Constants
PARAM const_val0 = { 0, 0.5, 1, 2 };	# Used (xyzw)

# Registers
TEMP t0;
TEMP t1;
TEMP t2;

TEMP r0;
TEMP r1;

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

# Scroll coords and load normal map texel and mask texel
MAD r1, p0.yzyz, c1.x, tc0;
TEX t1, r1, texture[2], 2D;
TEX t2, tc0, texture[1], 2D;

MAD r1.rgba, t1, const_val0.w, -const_val0.z;
SWZ r1.rgb, r1, 0, a, r, 0;
DP3 r1.r, r1, r1;
SUB r1.r, const_val0.z, r1.r;
RSQ r1.r, r1.r;
RCP r1.r, r1.r;

# Multiply with mask
MUL r1, r1, t2.xxxx;

# Offset
MAD_SAT r0, r1, p0.w, tc0;

# Clamp inside framebuffer coordinates
LRP r1.xy, r0.xyxy, c0.zwxy, c0.xyzw;

# Load texel
TEX t0, r1, texture[0], 2D;
MOV oCol, t0;

END

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