//$c5 FKP 01/31/07 flip texture if needed (pb with dds and opengl
//$c4 FKP 01/29/07 same lumiannce vector for the whole shader code now
//$c3 FKP 01/23/07 new ATI fix so that it is possible to use GetAmbiantAndDiffuseModifierEnv
//$c2 FKP 14/11/06 move stuff where it belongs
//$c1 FKP 10/09/06 created


// only very global stuff here

#define PI			3.141592
#define INVERSE_PI	0.318309

/////////////////////////////////////////
// saturate function
vec4 saturate(vec4 value)
{
	return clamp(value,0.0,1.0);
}
vec3 saturate(vec3 value)
{
	return clamp(value,0.0,1.0);
}
vec2 saturate(vec2 value)
{
	return clamp(value,0.0,1.0);
}
float saturate(float value)
{
	return clamp(value,0.0,1.0);
}
/////////////////////////////////////////


/////////////////////////////////////////
// from vec3 direction to spherical envmap coordinate
vec2 SphereMapCoord(vec3 envcoord)
{
	vec3 d = normalize(envcoord);
	return vec2(atan(d.z,d.x)*INVERSE_PI*0.5-0.25,asin(d.y)*INVERSE_PI+0.5);
}

/////////////////////////////////////////
// some texture need to be flipped because of conflicting windows/opengl convention
vec2 Flip(vec2 coord, const bool envmapFlip)
{
	if (envmapFlip) return vec2(coord.x,1.0-coord.y);
	else return coord;
}


////////////////////////////////////////////////////////////////////////
// homogenous to affine converter
vec3 Affine(vec4 v)
{
	return v.xyz*(1.0/v.w);
}


// trying to avoid warining (tmp)
#define EXP_ONE 2.71828182
float myExp(float x) {return pow(EXP_ONE,x);}
float myLog(float x) {return log(x);}

float myExpBase(float x,float base) {return pow(base,x);}
float myLogBase(float x,float base) {return log(x)/log(base);}

// get luminance
//const vec3 LUMINANCE_VECTOR  = vec3(0.2125, 0.7154, 0.0721);
const vec3 LUMINANCE_VECTOR  = vec3(0.3,0.59,0.11);
float GetLuminance(vec3 color)
{
	return max(dot(LUMINANCE_VECTOR,color),0.0);
}

