//Color
float4   MatColor   : MATCOLOR;
float4   DarkColor  : DARKCOLOR;
float4   White = float4(1.0f, 1.0f, 1.0f, 1.0f);

// transformations
float4x4 World      : WORLD;
float4x4 View       : VIEW;
float4x4 Projection : PROJECTION;

// light direction (view space)
float3 lightDir = {-0.2887, -0.5774, -0.2887};

struct VS_OUTPUT
{
    float4 Pos  : POSITION;
    float4 Diff : COLOR0;
    float2 Tex  : TEXCOORD0;
};

//The Sphere vertex shader
VS_OUTPUT SphereVertex(float3 Pos  : POSITION, float3 Norm : NORMAL, float2 Tex  : TEXCOORD0)
{
    //Create the output variable
    VS_OUTPUT Out = (VS_OUTPUT)0;

    //Put into view space
    float4x4 WorldView = mul(World, View);
    Out.Pos  = mul(float4(Pos, 1), WorldView);
    
    //Get the grayscale diffuse color
    float dot = (dot(Norm, lightDir) + 1.0) / 2.0;
    
    Out.Diff[0] = dot;
    Out.Diff[1] = dot;
    Out.Diff[2] = dot;
    Out.Diff[3] = 1.0;    
    
    //Put into projection space
    Out.Pos  = mul(Out.Pos, Projection);

    //No texture
    Out.Tex  = Tex;

    return Out;
}

float4 SpherePixel(
    float4 Diff : COLOR0) : COLOR
{
    //Get the brightness of the color
    if( Diff[0] < 0.16)
        return White;
    else if( Diff[0] < 0.5)
        return MatColor;        
    else
        return DarkColor;                       
}


technique SphereShader
{
    pass P0
    {
        VertexShader = compile vs_1_1 SphereVertex();
        PixelShader = compile ps_1_1 SpherePixel();
    }
}
