// transformations
shared const float4x4 World          : WORLD;
shared const float4x4 View           : VIEW;
shared const float4x4 Projection     : PROJECTION;
shared const float4x4 WorldView      : WORLDVIEW;
shared const float4x4 ViewProjection : VIEWPROJECTION;

shared const float3 camerapos;

const float defaultpointsize = 1;
const float	squaresizefalloff = 1;

shared const float ParticleScale;

struct VSOUTPUT
{
	float4	pos		: POSITION;
	float	psize	: PSIZE;
	float4	color	: COLOR0;
};

VSOUTPUT	PointVShader(float3 pos : POSITION, float psize : PSIZE, DWORD diff : DIFFUSE0)
{
	VSOUTPUT	o = (VSOUTPUT)0;

	float3 p = mul(float4(pos,1),(float4x3)World);

	float3 d = p - camerapos;

	//inverse square falloff wrt. distance (times what ever it is already)
	o.psize = ParticleScale * psize * rsqrt(squaresizefalloff*dot(d,d));

	o.pos = mul(float4(pos,1),ViewProjection);
	o.color = diff;

	return o;
}

sampler Sampler : register(s0);

float4 PointPS(float4 c : COLOR0, float2 t : TEXCOORD0) : COLOR
{
	return tex2D(Sampler, t) * c;
}

/*technique VertexShaderPS
{
	pass p0
	{
		ZWriteEnable	= false;
		FogEnable		= false;
		Lighting		= false;

		AlphaBlendEnable= true;
		SrcBlend		= One;
		DestBlend		= One;
		
		AlphaTestEnable = true;
		AlphaFunc		= GreaterEqual;
		AlphaRef		= 0x0A;

		PointSpriteEnable = true;
		
		ColorVertex = true;
		DiffuseMaterialSource = COLOR1;

		VertexShader = compile vs_1_1 PointVShader();
		PixelShader = compile ps_1_1 PointPS();
	}
}*/

technique FixedFunctionPS
{
	pass p0
	{
		WorldTransform[0]	= (World);
		ViewTransform		= (View);
		ProjectionTransform	= (Projection);

		FogEnable		= false;
		ZWriteEnable	= false;

		AlphaBlendEnable= true;
		SrcBlend		= One;
		DestBlend		= One;
		
		AlphaTestEnable = true;
		AlphaFunc		= GreaterEqual;
		AlphaRef		= 0x0A;

		Lighting		= false;
		PointSpriteEnable = true;
		PointScaleEnable = true;

		ColorVertex = true;
		DiffuseMaterialSource = Color1;

		ColorOp[0]	= Modulate;
		ColorArg1[0]= Texture;
		ColorArg2[0]= Diffuse;

		AlphaOp[0]	= SelectArg1;
		AlphaArg1[0]= Diffuse;
		//AlphaArg2[0]= Diffuse;

		//PointSize = 90000;

		PointScaleEnable = true;
		PointScale_A = 0;
		PointScale_B = 0;
		PointScale_C = 1;
	}
}

technique empty
{
}