// Phong shading with two lights // WARNING: squares the result color! varying vec3 n, l0, h0, l1, h1; #vertex void main() { // normal vector, light direction, half vector n = normalize(gl_NormalMatrix * gl_Normal); l0 = normalize(vec3(gl_LightSource[0].position) - vec3(gl_ModelViewMatrix * gl_Vertex)); h0 = normalize(gl_LightSource[0].halfVector.xyz); l1 = normalize(vec3(gl_LightSource[1].position) - vec3(gl_ModelViewMatrix * gl_Vertex)); h1 = normalize(gl_LightSource[1].halfVector.xyz); // the rest gl_FrontColor = gl_Color; gl_Position = ftransform(); } #fragment void main() { float d; vec3 nn; vec4 col = gl_Color * gl_LightModel.ambient; // lighting nn = normalize(n); d = dot(nn, normalize(l0)); if (d > 0.0) { col += gl_Color * d; col += gl_FrontMaterial.specular * pow(max(dot(nn, normalize(h0)), 0.000001), gl_FrontMaterial.shininess); } d = dot(nn, normalize(l1)); if (d > 0.0) { col += gl_Color * d; col += gl_FrontMaterial.specular * pow(max(dot(nn, normalize(h1)), 0.000001), gl_FrontMaterial.shininess); } gl_FragColor = col * col; }