varying vec3 light_dir; varying vec3 eyepos; varying vec4 light; uniform int NumEnabledLights; uniform int show_Lights; void main() { vec4 tmp; tmp = gl_ModelViewMatrix * gl_Vertex; eyepos = vec3(tmp)/tmp.w; gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[1] = gl_MultiTexCoord1; gl_TexCoord[2] = gl_MultiTexCoord2; gl_TexCoord[3] = gl_MultiTexCoord3; gl_TexCoord[0] = gl_TextureMatrix[0]*gl_TexCoord[0]; gl_TexCoord[1] = gl_TextureMatrix[1]*gl_TexCoord[1]; gl_TexCoord[2] = gl_TextureMatrix[2]*gl_TexCoord[2]; gl_TexCoord[3] = gl_TextureMatrix[3]*gl_TexCoord[3]; gl_Position = ftransform(); vec3 eye; bool LocalViewer; LocalViewer = false; if (LocalViewer) eye = -normalize(eyepos); else eye = vec3(0.0, 0.0, 1.0); vec3 normal = vec3(0.0, 0.0, 1.0); normal = normalize(gl_NormalMatrix*normal); vec3 L0, L1, L2, L3, L4, L5, L6, L7, a0, a1, a2, a3, a4, a5, a6, a7; float d0, d1, d2, d3, d4, d5, d6; vec3 v; v = vec3(gl_ModelViewMatrix * gl_Vertex); a0 = gl_LightSource[0].position.xyz - v; a1 = gl_LightSource[1].position.xyz - v; a2 = gl_LightSource[2].position.xyz - v; a3 = gl_LightSource[3].position.xyz - v; a4 = gl_LightSource[4].position.xyz - v; a5 = gl_LightSource[5].position.xyz - v; a6 = gl_LightSource[6].position.xyz - v; a7 = gl_LightSource[7].position.xyz; L0 = normalize(a0); L1 = normalize(a1); L2 = normalize(a2); L3 = normalize(a3); L4 = normalize(a4); L5 = normalize(a5); L6 = normalize(a6); L7 = normalize(a7); d0 = length(a0); d1 = length(a1); d2 = length(a2); d3 = length(a3); d4 = length(a4); d5 = length(a5); d6 = length(a6); d0 = 1.0 / ( gl_LightSource[0].constantAttenuation + gl_LightSource[0].linearAttenuation * d0); d1 = 1.0 / ( gl_LightSource[1].constantAttenuation + gl_LightSource[1].linearAttenuation * d1); d2 = 1.0 / ( gl_LightSource[2].constantAttenuation + gl_LightSource[2].linearAttenuation * d2); d3 = 1.0 / ( gl_LightSource[3].constantAttenuation + gl_LightSource[3].linearAttenuation * d3); d4 = 1.0 / ( gl_LightSource[4].constantAttenuation + gl_LightSource[4].linearAttenuation * d4); d5 = 1.0 / ( gl_LightSource[5].constantAttenuation + gl_LightSource[5].linearAttenuation * d5); d6 = 1.0 / ( gl_LightSource[6].constantAttenuation + gl_LightSource[6].linearAttenuation * d6); light = vec4(0.0); if (NumEnabledLights >= 0) light += gl_FrontLightProduct[0].diffuse * max(dot(normal, L0), 0.0) * d0; if (NumEnabledLights >= 1) light += gl_FrontLightProduct[1].diffuse * max(dot(normal, L1), 0.0) * d1; if (NumEnabledLights >= 2) light += gl_FrontLightProduct[2].diffuse * max(dot(normal, L2), 0.0) * d2; if (NumEnabledLights >= 3) light += gl_FrontLightProduct[3].diffuse * max(dot(normal, L3), 0.0) * d3; if (NumEnabledLights >= 4) light += gl_FrontLightProduct[4].diffuse * max(dot(normal, L4), 0.0) * d4; if (NumEnabledLights >= 5) light += gl_FrontLightProduct[5].diffuse * max(dot(normal, L5), 0.0) * d5; if (NumEnabledLights >= 6) light += gl_FrontLightProduct[6].diffuse * max(dot(normal, L6), 0.0) * d6; if (all(equal(gl_FrontLightProduct[7].diffuse, vec4(0.0)))) light += gl_FrontLightProduct[7].diffuse * max(dot(normal, L7), 0.0); light += gl_FrontLightProduct[7].ambient*gl_FrontMaterial.ambient; light += gl_LightModel.ambient * gl_FrontMaterial.ambient; }