//========================================
// Phong
//========================================
void Illuminate(const E3dFloat3 LightPosition, const E3dHalf4 LightColor,
	const E3dFloat3 PPosition,
	const LightingFloat3_t PNormal,
	const E3dHalf3 PPointToEye,
	const in E3dHalf3 Ambient, const in E3dHalf3 Diffuse, const in E3dHalf3 Specular, const in E3dHalf3 Emission,
	const float Shininess,

	inout E3dHalf4 PResultColor)
{
	E3dHalf3          LPointToLight = normalize(LightPosition - PPosition);
	LightingFloat3_t  LHalfAngleVector = normalize(LPointToLight + PPointToEye);
	E3dHalf4          LLighting = lit(dot(PNormal, LPointToLight), max(dot(PNormal, LHalfAngleVector), 0.0), Shininess);

	PResultColor.rgb += Ambient + Emission + (LLighting.y * Diffuse + LLighting.z * Specular * LLighting.y) * LightColor.rgb;
}


//========================================
// Phong with shadow-map
//========================================
void IlluminateWithShadow(const E3dHalf4 ShadowColor, const E3dFloat3 LightPosition, const E3dHalf4 LightColor,
	const E3dFloat3 PPosition,
	const LightingFloat3_t PNormal,
	const E3dHalf3 PPointToEye,
	const in E3dHalf3 Ambient, const in E3dHalf3 Diffuse, const in E3dHalf3 Specular, const in E3dHalf3 Emission,
	const float Shininess,

	inout E3dHalf4 PResultColor)
{
	E3dHalf3          LPointToLight = normalize(LightPosition - PPosition);
	LightingFloat3_t  LHalfAngleVector = normalize(LPointToLight + PPointToEye);
	E3dHalf           LDiffuseSh;
	E3dHalf4          LLighting = lit(dot(PNormal, LPointToLight), max(dot(PNormal, LHalfAngleVector), 0.0), Shininess);

// LightColor.a is "ShadowBrightness"
//
	LDiffuseSh = ShadowColor.r + LightColor.a;LDiffuseSh = LDiffuseSh <= 1.0 ? LDiffuseSh : 1.0;

	PResultColor.rgb += Ambient + Emission + (LLighting.y * LDiffuseSh * Diffuse + LLighting.z * ShadowColor.r * Specular * LLighting.y) * LightColor.rgb;
}
