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

// The world view and projection matrices
float4x4 World;
float4x4 World2;
float4x4 WVP;

float4 EyeLocation;

float4 DiffuseInner;
float4 DiffuseOuter;
bool IsSmallCore;
float BlurStrength;
bool IsEyeFacing;
// Transform our coordinates into world space
VS_OUTPUT Render(float4 Pos  : POSITION, float3 Normal : NORMAL)
{
    // Declare our return variable
    VS_OUTPUT Out = (VS_OUTPUT)0;

    Out.pos = mul(Pos, WVP);
    
    float4 wCenter;
    wCenter.xyz = 0;
    wCenter.w = 1;
    
    wCenter = mul(wCenter, World);
    
    float3 wCenterToEyeDir = normalize(EyeLocation - wCenter);
    
    float4 wNormal;
	wNormal = mul(Normal, World);
		
    wNormal = normalize(wNormal);
    

    float fTemp;
    if(IsEyeFacing)
		 fTemp = dot(wNormal, wCenterToEyeDir); 
	else
	{
		float fTemp1 = dot(wNormal, wCenterToEyeDir); 
		float3 vTemp;
		vTemp.xy = 0;
		vTemp.z = 1;  
	    fTemp = dot(Normal, vTemp)*sqrt(fTemp1); 
    }
     
    if(fTemp < 0)
		fTemp = 0;
    
    if(IsSmallCore)
    {
		float fTemp2 = saturate(fTemp);
		float angle = acos(fTemp2);
		fTemp = 1 - 2*angle/3.1415927f;
    }
    
	fTemp = pow(fTemp, BlurStrength);
     
    float4 ColorTemp;
    ColorTemp.a = (DiffuseInner.a*fTemp + (1 - fTemp)*DiffuseOuter.a)*fTemp;
    ColorTemp.r = DiffuseInner.r*fTemp + (1 - fTemp)*DiffuseOuter.r;
    ColorTemp.g = DiffuseInner.g*fTemp + (1 - fTemp)*DiffuseOuter.g;
    ColorTemp.b = DiffuseInner.b*fTemp + (1 - fTemp)*DiffuseOuter.b;    
    Out.diff = ColorTemp;

    // Return
    return Out;
}

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

