/*
in the edges the dotNL will be zero
so 1-edge will be basic glowing factor
for better control edgeFactor = (1-edge)^glowExponent
glowRejection will be the minimum edgeFactor that will be rendered
*/


float4x4 gWorldViewProj 	: WorldViewProjection;
float4 	gCameraPosObj;
float4	gGlowColor		: COLOR;
float 	gGlowExponent;
float 	gGlowRejection;
 
struct vertexIn
{
	float4 pos      : POSITION;
	float3 normal	: NORMAL;
};
 
struct vertexOut
{
	float4 pos		: POSITION;
	float3 normal	: TEXCOORD0;
	float3 viewDir  : TEXCOORD1;
};
 
struct pixelIn
{
	float3 normal	: TEXCOORD0;
	float3 viewDir	: TEXCOORD1;
};
 
vertexOut mainVS( vertexIn input)
{
	vertexOut output = (vertexOut)0;
 
	output.pos = mul(gWorldViewProj, input.pos);
	output.normal 	= input.normal;
	output.viewDir 	= gCameraPosObj - input.pos;
 
	return output;
}
 
float4 mainPS(pixelIn input) : COLOR 
{
	input.normal = normalize(input.normal);
	input.viewDir= normalize(input.viewDir);
 
	float dotNV 	= dot ( input.normal, input.viewDir );
	float edge	= pow (1-dotNV, gGlowExponent);
 
	if( edge < gGlowRejection ) edge = 0;
	float4 color = gGlowColor*edge;
 
	return color;
}


