
struct VS_OUTPUT
{
    float4 pos  : POSITION;
    float4 diff : COLOR0;
};


float4x4 World;
float4x4 WVP;
float4x4 World2;

float4 EyeLocation;

float4 DiffuseInner;
float4 DiffuseOuter;
float BlurStrength;
float CoreStrength;

VS_OUTPUT Render(float4 Pos  : POSITION, float3 Normal : NORMAL)
{
    VS_OUTPUT Out = (VS_OUTPUT)0;
    float4 posTemp = Pos;	
    posTemp.z += 50;
    Out.pos = mul(posTemp, WVP);
    
    float4 wCenter;
    wCenter.xyz = 0;
    wCenter.w = 1;
    
    wCenter = mul(wCenter, World);
    
    float3 wCenterToEyeDir = normalize(EyeLocation - wCenter);
    
    float4 wNormal = mul(Normal, World2); 
    
    wNormal = normalize(wNormal);
    
	////
    float4 vOZ;
    vOZ.xyw = 0;
    vOZ.z = 1;
    
    float4 wVOZ = mul(vOZ, World);
    wVOZ = normalize(wVOZ);
    float3 vTest = cross(wCenterToEyeDir, wVOZ);
    vTest = normalize(vTest);
    
    float3 vNormalTest;
    vNormalTest.xy = Normal.xy;
    vNormalTest.z = 0;
    vNormalTest = mul(vNormalTest, World);
    vNormalTest = normalize(vNormalTest);
     
    
    float fTemp2 = pow(1 - abs(dot(vTest, vNormalTest)), CoreStrength);
    
    ////
    float fTemp3 = pow(1 - abs(dot(wCenterToEyeDir, wVOZ)), 0.3f);  
    fTemp3 = sqrt(fTemp3);  
    
    //// 
    float fTemp;
    fTemp = -dot(Normal, vOZ); 
    
    //if(fTemp < 0)
	//	fTemp = 0;
		
	fTemp += 0.2f*fTemp*fTemp2*fTemp3 + 0.5f*(1 - fTemp3); 
	fTemp /= 1.2f;
	
	float fTempC = abs(fTemp);
	float fTempA = sign(fTemp)*pow(fTempC, BlurStrength);
	
     
    float4 ColorTemp;
    ColorTemp.a = (DiffuseInner.a*fTempA + (1 - fTempA)*DiffuseOuter.a)*fTempA;
    ColorTemp.r = DiffuseInner.r*fTempA + (1 - fTempA)*DiffuseOuter.r;
    ColorTemp.g = DiffuseInner.g*fTempA + (1 - fTempA)*DiffuseOuter.g;
    ColorTemp.b = DiffuseInner.b*fTempA + (1 - fTempA)*DiffuseOuter.b;    
    Out.diff = ColorTemp;

    // Return
    return Out;
}

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

