/*=============================================================================
	SphericalHarmonicLightPixelShader.usf: Lights an object using a single SH environment.
	Copyright 1998-2010 Epic Games, Inc. All Rights Reserved.
=============================================================================*/

#undef WORLD_COORDS
#define WORLD_COORDS 1

#include "Common.usf"
#include "Material.usf"
#include "VertexFactory.usf"
#include "SphericalHarmonicCommon.usf"

void Main(
	in FVertexFactoryInterpolants FactoryInterpolants,
	in float4 CameraVectorOrVertexColor : TEXCOORD6,
	in float4 PixelPosition : TEXCOORD7,
	OPTIONAL_FacingSign
	OPTIONAL_PixelShaderScreenPosition
	out float4 OutColor : COLOR0
	)
{
	FMaterialPixelParameters MaterialParameters = GetMaterialPixelParameters(FactoryInterpolants);
	CalcMaterialParameters(MaterialParameters,FacingSign,CameraVectorOrVertexColor,PixelPosition,float3(0,0,1));

	// Allow the material to mask out pixels.
	GetMaterialClipping(MaterialParameters, PixelShaderScreenPosition.xy);

	// Transform the surface normal and the reflected camera vector into world-space.
	float3 WorldNormal = TransformTangentVectorToWorld(MaterialParameters, MaterialParameters.TangentNormal);

	OutColor.rgb = ComputeSHLighting(WorldNormal, MaterialParameters);
	half Opacity = GetMaterialOpacity(MaterialParameters);
	
#if MATERIALBLENDING_TRANSLUCENT
		OutColor.a = Opacity;
#elif MATERIALBLENDING_ADDITIVE || MATERIALBLENDING_SOFTMASKED
		OutColor.rgb = OutColor.rgb * Opacity;
		OutColor.a = 0.0f;
#else
		OutColor.a = 0.0f;
#endif

	OutColor = RETURN_COLOR(OutColor);
}
