
// ------- UNIFORMS (SHADER CONSTS) -------
Texture2D		u_sTexture0; // ambient0
SamplerState	SampleType0;
Texture2D		u_sTexture1; // Earth lights
SamplerState	SampleType1;
Texture2D		u_sTexture2; // specular
SamplerState	SampleType2;

vec3			u_vNormalizedLightDir;
vec4			u_vSpecularColor;
float			u_fSpecularPower;
float			u_fSpecularStrength;
float			u_fEffectsInterpolation;
vec4			u_vColor;

vec3			hu_vNormalizedViewDir;

// ------- INTERPOLATORS (SHADER INPUTS) -------
struct PIn
{
	vec4	v_vPosition: SV_POSITION;
	vec2	v_vTexCoord: TEXCOORD;
	vec3	v_vNormal: NORMAL;
};

// ------- FUNCTIONS ------- 

vec4 main(PIn input): SV_TARGET
{
	vec4 colBase =			u_sTexture0.Sample(SampleType0, input.v_vTexCoord) * u_vColor;
	vec4 colEarthLights =	u_sTexture1.Sample(SampleType1, input.v_vTexCoord);
	vec4 maskSpecular =		u_sTexture2.Sample(SampleType2, input.v_vTexCoord);
	
	vec3 vNormal = normalize(input.v_vNormal);
	
	// N.L
	float nDotL = dot(vNormal, u_vNormalizedLightDir); // [0.0, 1.0] away from sun, [-1.0, 0.0] toward sun
	float f = saturate(-nDotL + 0.1); // 0.0 away from sun, [1.0, 0.0] toward sun

	// Earth lights
	float fLights = saturate(1.0 - f*12.0);
	colEarthLights *= fLights;
	
	// specular
	vec3 vReflection = (2.0 * vNormal * nDotL) - u_vNormalizedLightDir;
	float fDotV = max(0.0, dot(vReflection, hu_vNormalizedViewDir));
	vec4 vSpecular = u_vSpecularColor * maskSpecular * pow(fDotV, u_fSpecularPower);
	vec4 colWithSpecular = f*(colBase + u_fSpecularStrength*vSpecular);

	return lerp(colBase, colEarthLights + colWithSpecular, u_fEffectsInterpolation);
}
