phong_gl2.frag 604 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
//Pixel_Shader

varying vec3 normal, lightDir, eyeVec;
varying vec3 vcolor; 

void main (void)
{
	vec4 final_color = vec4(0.0,0.0,0.0,0.0);
							
	vec3 N = normalize(normal);
	vec3 L = normalize(lightDir);
	
	float lambertTerm = dot(N,L);
	
	if(lambertTerm > 0.0)
	{
		final_color += vec4(vcolor,1.0) * 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_FrontMaterial.specular * 
					   specular;	
	}

	gl_FragColor = final_color;

}