shaderEnvMap.frag 797 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
//ShaderEnvMap::fragmentShaderText

PRECISON;
VARYING_FRAG vec3 EyeVector, Normal, LightDir,refl;
#ifdef WITH_COLOR
VARYING_FRAG vec3 Color;
#endif
uniform vec4 materialDiffuse;
uniform vec4 materialAmbient;
uniform samplerCube EnvMap;
uniform float blendCoef;

FRAG_OUT_DEF;
void main()
{
	vec3 N = normalize (Normal);
	vec3 L = normalize (LightDir);
	float lambertTerm = dot(N,L);

	vec4 finalColor = materialAmbient;
	
	#ifdef DOUBLE_SIDED
	if (lambertTerm < 0.0)
	{
		N = -1.0*N;
		lambertTerm = -1.0*lambertTerm;
	#else
	if (lambertTerm > 0.0)
	{
	#endif
		#ifndef WITH_COLOR
		vec4 col = materialDiffuse;
		#else
		vec4 col = vec4(Color,0.0) ;
		#endif
		
		vec3 R  = reflect(-EyeVector,N);
		finalColor += mix(col,texture(EnvMap,R),blendCoef) * lambertTerm;
	}	
	gl_FragColor=finalColor;
}