//========================================
// Lambert shader
//========================================
void Illuminate(const E3dFloat3 LightPosition, const half4 PLightColor,
	const E3dFloat3 PPosition,
	const LightingFloat3_t PNormal,
	const in half3 Ambient, const in half3 Diffuse, const in half3 Emission,

	inout half4 PResultColor)
{
	half3             LPointToLight = normalize(LightPosition - PPosition);
	LightingFloat3_t  LHalfAngleVector = normalize(LPointToLight + LPointToLight);  // This is just a dummy to work around a Cg compiler bug
	half4             LLighting;

	LLighting = lit(dot(LPointToLight, PNormal), dot(LHalfAngleVector, LPointToLight) , 16.0);

	PResultColor.rgb += Ambient + Emission + LLighting.y * PLightColor.rgb * Diffuse;
}


//========================================
// Lambert shader with shadow-map
//========================================
void IlluminateWithShadow(const half4 PShadowColor, const E3dFloat3 LightPosition, const half4 PLightColor,
	const E3dFloat3 PPosition,
	const LightingFloat3_t PNormal,
	const in half3 Ambient, const in half3 Diffuse, const in half3 Emission,

	inout half4 PResultColor)
{
	half3             LPointToLight = normalize(LightPosition - PPosition);
	LightingFloat3_t  LHalfAngleVector = normalize(LPointToLight + LPointToLight);  // This is just a dummy to work around a Cg compiler bug
	half4             LLighting;
	half              LDiffuseSh;


	LLighting = lit(dot(LPointToLight, PNormal), dot(LHalfAngleVector, LPointToLight) , 16.0);

// PLightColor.a is "ShadowBrightness"
//
	LDiffuseSh = PShadowColor.r + PLightColor.a;LDiffuseSh = LDiffuseSh <= 1.0 ? LDiffuseSh : 1.0;

	PResultColor.rgb += Ambient + Emission + LLighting.y * PLightColor.rgb * LDiffuseSh * Diffuse;
}
