I have recently got my shader working, and since then have looked around for a vert+frag shader to work with my texture.
This shader has been the closest one i can find thats works close to perfect, except it cuts off nearly half of what it is lighting. I don't know why turns half of what it is lighting into black pixels. I'd kill for an answer.
![]()
Here are the shader files:
.vert
Code :varying vec3 normal, lightDir, eyeVec; varying float att; void main() { normal = gl_NormalMatrix * gl_Normal; vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex); lightDir = vec3(gl_LightSource[0].position.xyz - vVertex); eyeVec = vVertex; float d = length(lightDir); att = 1.0 / ( gl_LightSource[0].constantAttenuation + (gl_LightSource[0].linearAttenuation*d) + (gl_LightSource[0].quadraticAttenuation*d*d) ); gl_Position = ftransform(); gl_FrontColor = gl_Color; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; }
.frag
And if i change " eyeVec = vVertex; " to " eyeVec = -vVertex; " in .vert, i magically get the other half of my missing lighting.Code :varying vec3 normal, lightDir, eyeVec; varying float att; uniform sampler2D tex; void main (void) { vec4 final_color = (gl_FrontLightModelProduct.sceneColor * gl_FrontMaterial.ambient) + (gl_LightSource[0].ambient * gl_FrontMaterial.ambient) * att; vec3 N = normalize(normal); vec3 L = normalize(lightDir); float lambertTerm = dot(N,L); if(lambertTerm > 0.0) { final_color += gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * lambertTerm * att; 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 * att; } gl_FragColor = final_color; gl_FragColor *= texture2D(tex, gl_TexCoord[0].st); }
![]()



