/*
struct fragment {
	float4 position  : POSITION;
	float2 texcoord0 : TEXCOORD0;
	float3 fog : FOGCOORD;
};
*/
float4 main(float3 position : POSITION,
			float2 texcoord : TEXCOORD0,
			float3 fog : TEXCOORD3,
//			float fog : FOG,
			uniform sampler2D texture,
			uniform sampler2D texture2,
			uniform float xmul,
			uniform float ymul,
			uniform float3 bgcol,
			uniform float falloff) : COLOR0
{
	float2 tex = float2(texcoord.x*2.0, texcoord.y);
	tex *= 8;

	float4 result = 0;
	float mu = 0.01;

	for (float i = 0; i < 4; i=i+1) {
		float2 texy = float2(0.00390625+fmod(tex.x, 1.0-0.00390625*2), 0.00390625+fmod(tex.y, 0.928));

		float4 col = tex2D(texture2, texy);
		float2 dir = -1.0+col.rg*2.0;

		dir = texcoord+dir;

		result += tex2D(texture, dir)*mu;

		tex *= 1.125;
		mu += 0.015;
	}


	if (falloff > 100) {
		result.rgb = result.rgb*result.rgb*0.25+0.75*result.rgb*result.rgb*result.rgb;
		result.rgb = result.rgb*50.0;
	}

	float fogi = abs(length(-1.0+2.0*fog));
	fogi = clamp((fogi*fogi)*falloff, 0, 1);

	result.rgb = lerp(result.rgb*1.75, bgcol, fogi);

	return result;
}