struct fragment {
	float4 position : POSITION;
	float2 texcoord0 : TEXCOORD0;
	float3 normal : TEXCOORD1;
	float3 fog : TEXCOORD3;
};

fragment main(float4 position : POSITION,
              float2 texcoord : TEXCOORD,
              float4 normal : NORMAL,
              float4 fog : FOGCOORD,
              uniform float4x4 modelViewProj,
              uniform float4x4 modelViewIT,
              uniform float2x2 textureMatrix,
              uniform float3 camera)
{
	fragment OUT;

	float4 pos = mul(modelViewProj, position);
	OUT.position = pos;
	OUT.texcoord0 = mul(textureMatrix, texcoord);
	OUT.normal = 0.5+0.5*mul(modelViewIT, normal);

/*	float fogi = -pos.z+23;
	fogi *= 1.0/22.0;
	OUT.fog = 0.5+0.5*clamp(fogi, -1, 1);*/

//	OUT.fog.r = 0.5+0.5*clamp((camera-(position.xyz*40.0)), 0, 1);
	OUT.fog = 0.5+0.5*clamp(camera-position, -1, 1);

/*
; z-based linear fog
; r0 is the vertex coordinate in camera space
; c0 is {0, 1, fog_end, 1/(fog_end-fog_start)}

add r1.x, -r0.z, c0.z
mul r1.x, r1.x, c0.w
max r1.x, r1.x, c0.x
min oFog.x, r1.x, c0.y
*/


	return OUT;
}