
// Shader output, position and diffuse color
struct VS_OUTPUT
{
    float4 pos  : POSITION;
    float4 diff : COLOR0;
};

// The world view and projection matrices
float4x4 World: WORLD;
float4x4 ViewProj: VIEWPROJECTION;
float4 Diffuse;
float GlowSize;

float ObjectRadius;
bool OrthographicView;
bool HasEffect;
float NearPlane;
float FarPlane;

VS_OUTPUT VertexShaderGlow(float4 Pos  : POSITION, float3 Normal : NORMAL0)
{
    // Declare our return variable
    VS_OUTPUT Out = (VS_OUTPUT)0;

    // Transform our position
    float3 p = mul(Pos, World);   
    float3 n = normalize(mul(Normal, World));
    p += n*GlowSize;
         
    Out.pos = mul(float4( p.xyz, 1.0f ), ViewProj);

	if(OrthographicView)
	{
		//float fTemp2 = 100.0f*ObjectRadius/(FarPlane - NearPlane)/100.0f;
		//Out.pos.z -= fTemp2;
	}
	else if(HasEffect)
	{
		float fTemp = (FarPlane - NearPlane - Out.pos.z)/(FarPlane - NearPlane);
		Out.pos.z -= 2.0f*fTemp*fTemp*ObjectRadius/(FarPlane - NearPlane);
    }

    		
	Out.diff = Diffuse;

    // Return
    return Out;
}


technique t
{
    pass P0
    {    
        // shaders
        VertexShader = compile vs_1_1 VertexShaderGlow();
        PixelShader  = NULL;
    }
}

