To view 3D objects, we often rely on the shading on the surface of the object. This is often how we perceive depth in 3D. The shading effect is generated based on the light reflected on the surface of the object. In the next few video lectures, we will look at lighting and illuminating objects. We start by looking at a simple example called point light source. In the virtual environments, you need a light source to illuminate a scene. The light will be cast onto the surface of the 3D object. The direction of the light can be represented as the light vector i. On the other hand, you should also have a viewing plane or camera, viewing the 3D scene. We can define a point on the surface as P and a camera views the point P in the direction of the viewing vector V. The light cast on the point P will be reflected in a direction of the reflect vector R. In addition, we can define n as a normal vector of the surface of the object. In a very simple case, with have a point light source. The light emits with equal intensity in all directions. The illumination of the object will depend on how far the surface of the object is from the light source. Let's look at how we can represent this mathematically. Given a point light source allocation P_0, the light intensity will be emitted from the point equally in all directions. The intensity decreases with the square of the distance from the light source. Hence, the illumination of the surface can be calculated by the light source intensity divided by the squared distance between the object's surface and the light source. If we have a point light source rotating around a sphere, the sphere will be illuminated like this. Lets see how to implement a point light source in OpenGL ES. We first need to modify the vertex shader. To set a point light source parameters, I define a uniform variable, uPointLightingLocation, for setting the location of the light source. Then, I define a varying variable, vPointLightWeighting, for passing the illumination intensity to the fragment shader. To find the illumination intensity on the surface of the object, we first need to calculate the distance between the point light source and the vertex of the object. I use that distance function to calculate the distance between the uPointLightingLocation, which is the location of the light source and the mvPosition, which is the vertex coordinates. The vPointLightWeighting is then set to 10 over the distance square, where 10 is light source intensity at it's location P_0. Then in the fragment shader, a multiplied the floating point variable, vPointLightWeighting, with the color of the object. This will adjust the illumination intensity of the fragment accordingly. In the application program, I then need to define a variable lightLocation to set the light source location and a handle to point to the uniform variable. I first set the light location to 8, 8, 0. Then set the handle to the uniform variable, uPointLightingLocation. Then in the draw function, the value of the light location is passed to the shader for drawing the object. Let's implement this in our example program. Feel free to pause the video and code along with me if you like. Let's add the point light source in our program. We first modify the vertex shader, add the variables and also calculate the distance between the light source and the vertex, and then use it to set the illumination factor. Which we'll pass to the fragment shader, and then intensity of the color would be modified based on this parameter, and then we add the variable for setting the light location and pass it to the uniform variable. When you run the program, you see that the point source will illuminate the object and when you move the object around, and certain parts of the object will have a high intensity of light where it's closer to the point light source. Let's modify the program to see the effect of the point light source by moving the light source around the object. So we modify the timer functions in myView object and add the variable Px, Py, Pz, which define the location of the light source. We then modify the MyRenderer object for setting the light source location, which will pass those Px, Py and Pz to the sphere object. So in the Sphere object, we added function, setLightLocation, to set the location of the lights. When you run the program, you see that the large source will be moving diagonally from the top-right corner to the bottom-left corner. In the next video lecture, we'll look at directional lighting, which is a more realistic way of illuminating a scene or object.