//
// Atmospheric scattering fragment shader
//
// Author: Sean O'Neil
//
// Copyright (c) 2004 Sean O'Neil
//


uniform float3 v3LightPos;

struct PS_INPUT
{
   float3 FrontColor	: COLOR0; 
   float3 SecondaryColor: COLOR1;
   float3 Direction		: TEXCOORD0;
};

struct PS_OUTPUT
{
	float4 Color		: COLOR;
};

PS_OUTPUT main( PS_INPUT IN )
{   
	float g		= -0.95;
	float g2	= 0.9025;

	PS_OUTPUT OUT;

	float fCos = dot( v3LightPos, IN.Direction ) / length( IN.Direction );
	float fRayleighPhase = 0.75 * (1.0 + fCos * fCos);
	float fMiePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos * fCos) / pow( 1.0 + g2 - 2.0*g*fCos, 1.5 );
	   
	OUT.Color.rgb = (fRayleighPhase * IN.FrontColor + fMiePhase * IN.SecondaryColor);
	OUT.Color.a = 1.0;

	return( OUT );
}