Here we go, enjoy!
CODE
//TINCS Vertex Shader
varying vec3 lightDirection,normal;
varying float Power, lightDistance;
varying vec3 halfV;
//I get my eyeDIR (eye direction vector, for specular) and lightPOS (light position vector) from the APP
uniform vec3 eyeDIR;
uniform vec3 lightPOS;
void main()
{
//Strangly, passing the lightPOS from the APP as a uniform 3f shizzle won't work (the eye does...), so i have to set it here if i wanna change it
lightPOS = vec3(0,0,0);
//I need the world position of the vertex, so i can get a direction vector between it and the light
vec3 calculatedVertex = gl_ModelViewMatrix * gl_Vertex;
//I need the light-vertex vector, to grab direction and distance off
vec3 lightVertexVec = lightPOS - calculatedVertex;
//Now, I normalize the light-vertex vector to get the direction of the light to the vertex
lightDirection = normalize(lightVertexVec);
//Then I just get the length for distance
lightDistance = length(lightVertexVec);
//Make sure everything that needs to be applied to the normal is
normal = normalize(gl_NormalMatrix * gl_Normal);
//Calculate the halfVector, (for specular stuff) I think this code might be dodgey! Take a good look darkblu
halfV = normalize((lightDirection + (vec4(eyeDIR.x,eyeDIR.y,eyeDIR.z,0) * gl_ProjectionMatrix * gl_ModelViewMatrix)) / 2);
//We only need one set of vertex co-ordinates
gl_TexCoord[0] = gl_MultiTexCoord0;
//Optmized setting of position
gl_Position = ftransform();
}
CODE
//TINCS Fragment Shader
//sampler2D for diffuse map and specular map
uniform sampler2D tex, spec;
varying vec3 lightDirection,normal;
varying float Power, lightDistance;
varying vec3 halfV;
void main()
{
//I store the final specular value in a single float
float specPower;
vec4 specular;
float specFinal;
//Att = multiplyer for light distance stuff
float att;
//Quick ambient, I'm going to set ambient to uniform when i link it in with TINCS, so map makers can set it
vec4 ambient = vec4(0.02,0.02,0.02,0.02);
vec4 color = ambient;
//Cacluate the power of the light, by getting the dot product of the normal and light direction
Power = max(dot(normalize(normal), normalize(lightDirection)),0.0);
//Get the diffuse value off the texture and if there is no diffuse, we set it to white
vec4 diffuse = texture2D(tex,gl_TexCoord[0].st);
if(diffuse == 0)
{
diffuse = vec4(1,1,1,1);
}
//Get the specular value off the specular texture
specular = texture2D(spec,gl_TexCoord[0].st);
//We don't want to waste time calcuating somthing that's going to be multplied by zero
if(Power > 0.0)
{
//attenuation equals one over the linear and quadratic power of the light, lower you go, the more powerful the light is
att = 1 / (0.01 * lightDistance + 0.01 * lightDistance * lightDistance);
//add the diffuse values onto the final color
color += att * (diffuse * Power);
//I've taken out the spec stuff for now, so we can solve this
//specPower = max(dot(normal, halfV),0.0);
//specFinal = 1 * pow(specPower,64.0);
//color += specFinal;
}
//Get the final color!
gl_FragColor = att * color;
}