Overview
In previous examples, we saw that Position, Color, Texture data were sent to draw cubes. In this post we will discuss how to implement Phong lighting models and other lights such as Directional, Point and Spot Lights. For this surface normals needs to be sent as VBO data. They look as shown at the bottom. They look elongated because aspect ratio is not applied.
Details
| Name | Description |
|---|---|
| cameraPosition | Specifies the location of the light source for diffuse and specular illumination. |
| light | An instance of LightingUtil. It contains settings for illumination. |
Methods
| Name | Description |
|---|---|
| Init | This method overrides the base class Init method to load texture. Generates the vertices data consisting of surface normals in non indexed mode and later sets them up in VBO buffer. It also passes an input to use BlinnPhong or Phong illumination and also type of light source as defined by LightSource enum. |
| UpdateUniforms | This method overrides the base class UpdateUniforms method. Firs t it updates "cameraposition" uniform. Next it updates lighting related uniforms by calling Updateshader method on light. Finally it c alls base class UpdateUniforms method to send rest. |
| vertexShaderSource | This method overrides the base class vertexShaderSource method. It returns the vertex shader code to render the cube object. |
| fragmentShaderSource | This method overrides the base class fragmentShaderSource method. It returns the fragment shader code to render the cube object based on light source type. |
LightingUtil
| Name | Description |
|---|---|
| material | An instance of Material sub class. It contains settings of the material property for reflection. |
| light | An instance of Light sub class. It contains settings for illumination. |
Methods
| Name | Description |
|---|---|
| UpdateShader | Updates the uniforms that contains copies of the information stored in light and material members. |
Output
The output looks as shown below.
No comments:
Post a Comment