phong_cpv_ps.txt 857 Bytes
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
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
//Pixel_Shader

varying vec3 normal, lightDir, eyeVec;
varying vec4 color;

void main (void)
{
	vec4 final_color = vec4(0.0,0.0,0.0,0.0);
	(gl_FrontLightModelProduct.sceneColor * gl_FrontMaterial.ambient) + 
	(gl_LightSource[0].ambient * gl_FrontMaterial.ambient);
							
	vec3 N = normalize(normal);
	vec3 L = normalize(lightDir);
	
	float lambertTerm = dot(N,L);
	
	if(lambertTerm < 0.0)
	{
		N = -1.0 *N;
		lambertTerm = - lambertTerm;
	}

	if(lambertTerm > 0.0)
	{
	final_color += gl_LightSource[0].diffuse * 
					gl_Color * 
					lambertTerm;	
	
	vec3 E = normalize(eyeVec);
	vec3 R = reflect(-L, N);
	float specular = pow( max(dot(R, E), 0.0), 
						gl_FrontMaterial.shininess );
	final_color += gl_LightSource[0].specular * 
					gl_FrontMaterial.specular * 
					specular;	

	gl_FragColor = final_color;
	}
}