I’m currently trying to learn how to add lights in LWJGL through shaders. Google search bought me these two but I don’t understand them. Can you explain them to me please?
[icode]shader.vert[/icode]
varying vec3 normal;
varying vec3 vertex;
void main(void)
{
vertex = vec3(gl_ModelViewMatrix * gl_Vertex);
normal = normalize(gl_NormalMatrix * gl_Normal);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
[icode]shader.frag[/icode]
varying vec3 normal;
varying vec3 vertex;
void main (void)
{
vec3 light = normalize(gl_LightSource[0].position.xyz - vertex);
vec3 eyeCoords = normalize(-vertex);
vec3 reflection = normalize(-reflect(light, normal));
//calculate Ambient Term:
vec4 ambientTerm = gl_FrontLightProduct[0].ambient;
//calculate Diffuse Term:
vec4 diffuseTerm = gl_FrontLightProduct[0].diffuse * max(dot(normal, light), 0.0);
diffuseTerm = clamp(diffuseTerm, 0.0, 1.0);
// calculate Specular Term:
vec4 specularTerm = gl_FrontLightProduct[0].specular * pow(max(dot(reflection, eyeCoords),0.0), 0.3 * gl_FrontMaterial.shininess);
specularTerm = clamp(specularTerm, 0.0, 1.0);
// write Total Color:
gl_FragColor = gl_FrontLightModelProduct.sceneColor + ambientTerm + diffuseTerm + specularTerm;
}
The main problem in them is the terms and how they works.