// Ads point lighting shader // vertex shader # version 330in vec4 vvertex; // The vertex position [world coordinates] In vec3 vnormal; // vertex normal [world coordinates] smooth out vec4 vvaryingcolor; Uniform vec4 ambientcolor; // ambient light uniform vec4 diffusecolor; // diffuse light uniform vec4 specularcolor; // mirror reflected light uniform vec3 lightposition; // The Position of the light source [world coordinates] uniform mat4 mvpmatrix; // Model-View-projection matrix uniform mat4 mvmatrix; // Model-View matrix uniform mat3 normalmatrix; // model without translation-view matrix void main (void) {// obtain the position of the vertex in the camera coordinate system. vec4 vec4temp = mvmatrix * vvertex; // offset the possible scaling of vec3 vvertexinview = vec4temp. XYZ/vec4temp. w; // calculate the unit vector vec3 vlightdirection = normalize (lightposition-vvertexinview) from the vertex to the light source; // obtain the position of the vertex normal in the camera coordinate vec3 vnormalinview = normalmatrix * vnormal; float fdiffusecolorweight = max (0, dot (vlightdirection, vnormalinview); // calculate the diffuse color vvaryingcolor = diffusecolor * fdiffusecolorweight; // overlay the ambient light, this cannot be placed after the calculation of the mirror reflection vvaryingcolor + = ambientcolor; // calculate the mirror reflection color if (fdiffusecolorweight> 0) {// calculate the reflected ray vector vec3 relectiondirection ction = normalize (reflect (-lightposition, vnormalinview); float ftemp = max (0, dot (relectiondirection ction, vnormalinview )); if (ftemp> 0) {float vspecularcolorweight = POW (ftemp, 128); // overlay the mirror highlight vvaryingcolor. RGB + = vec3 (vspecularcolorweight, vspecularcolorweight, vspecularcolorweight);} // projects the vertex from the world coordinate system to the cropped cube gl_position = mvpmatrix * vvertex ;}