Let's now look at objects with shiny surfaces like a metallic surface. To draw a virtual shiny object, we have to use specular reflection where a high intensity of light are reflected by the shiny surfaces. Let's begin by modeling this. The highest intensity of light reflected on the surface should occur at a point where the angle between the incident light and the surface normal is equal to the angle between the reflected light and the surface normal. We can use this with the inverse view direction to calculate the angle Phi and Phi is used to set the intensity of the specular light reflection. The specular light reflection intensity is equal to K_s times L_s times cosine Phi. The variable K_s is a specular reflection coefficient. The variable L_s is a specular component of the light or the color of the light. Phi is the angle between the unit vector v and r, where v is the viewing vector and r is the reflection vector. Different types of surfaces have different shininess. A metallic surface should look more shiny than a wooden surface for example. A parameter, alpha, is defined it to set the shininess coefficient. The specular reflection intensity is then equal to K_s times L_s times the cosine Phi to the power of alpha. The value cosine Phi can be calculated by the dot product between the unit vector r and v. So the equation can be modified to K_s times L_s times the dot product of r and v to the power of alpha. To show the effect of light attenuation, we should multiply the intensity with the attenuation factor, and the equation then becomes 1 over a plus bq plus cq squared times K_s times L_s times the dot product of r and v to the power of alpha. Where q is the distance between the light source and a vertex of the object surface. Let's see how I introduce the specular reflection effect on a 3D object in the example program. The vertexShader, I added the uniform variables, uSpecularColor, uSpecularLightLocation, and uMaterialShininess to get the light color, light source location, and the shininess coefficient. The viewDirection vector, v, is then calculated by normalizing the negative of mvPosition, mvPosition is the vertex coordinate. The specular light direction is then calculated by subtracting the light location with the mvPosition. Then I use the reflect function to calculate the reflection direction unit vector r. The specular light weighting is then calculated by multiplying the attenuation factor with the dot product of the reflection direction and the view direction to the power of the material shininess. The specular light weighting is then passed to the fragmentShader. In the fragmentShader, the vSpecularLightWeighting is then multiplied with the vSpecularColor to calculate the specular effect. The specularColor is then added to the gl_FragColor to introduce the specular reflection effect on the fragments of the object. In the application program, I added the variables and handles for the specularColorLightLocation and the material shininess for passing the parameters to the uniform variables in the vertexShader. The specularColor is set to 1,1,1,1 which is the color white, the specularLightLocation is set to equal the diffuse light location. The values are then passed to the vertexShader in the draw function. Let's implement this in our program. We first add the uniform variables in a vertexShader, we then calculate the reflectionDirection and also the specularLightWweighting. We then pass that to the fragmentShader and then use it to calculate the specular color, which is added to the gl_FragColor. We then add the handles for passing the uniform variables, and also add the buffer to set the material shininess and also the color and location of the specular light. In the Sphere function, we set the handle to point to the uniform variables. Then we set a specularColor to all 1s, and set the specularLightLocation to be equal to the diffuse light location. Then we pass those values of the uniform variables to the shaders in the draw function. When you run the program, you will then see the effect of this specular reflection our 3D arbitrary object. In the next video, we'll look at how we can formulate ambient light, diffuse light, and specular light into one model called the phong reflection model.