uniform vec3 D_LightDir; uniform vec3 P_LightPos; uniform vec3 cameraPos; // vertex position: uniform vec4 gl_Vertex; // vertex normal: uniform vec3 gl_Normal; // vertex color: uniform vec4 gl_Color; void main() { vec4 vertex_light; // this shader is executed for each vertex // compute light at this vertex and update the front color below gl_FrontColor = gl_Color; vertex_light = vec4(dot(gl_Normal, P_LightPos)); // directional light: gl_FrontColor *= vec4(dot(gl_Normal, D_LightDir)); /* gl_FrontColor = gl_Frontcolor * vec4(dot(gl_Normal, P_LightPos)) the front color will be the color (blue) times the vertex light (white), the following division will make the object (blue) and the light (white) have a smoother transition. The higher the divider, the smoother the transition */ gl_FrontColor *= vertex_light / vec4(35, 35, 35, 35); gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }