Saturday, July 16, 2022

Implementation: BlinnPhongLighted Cube

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  Blinn Phong lighting model. 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
System  class diagram
BlinnPhongLightedTexCube derives from TexturedCube class. It overrides mesh with an instance of CubeMesh to generate geometry. 


BlinnPhongLightedTexCube
BlinnPhongLightedTexCube is derived from TexturedCube class. It illuminates the textured cube as per settings done in the light parameter.

Members
NameDescription
cameraPositionSpecifies the location of the light source for diffuse and specular illumination. 
lightAn instance of PhongLightingUtil. It contains settings for illumination.

Methods
NameDescription
InitThis 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. 
UpdateUniformsThis 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.
vertexShaderSourceThis method overrides the base class vertexShaderSource method. It returns the vertex shader code to render the cube object.
fragmentShaderSourceThis method overrides the base class fragmentShaderSource method. It returns the fragment shader code to render the cube object.

BlinnPhongLightingUtil
It defines illumination properties of the light source and reflection properties of the material in the light and material members.
Members
NameDescription
materialAn instance of Material sub class. It contains settings of the material property for reflection.
lightAn instance of Light sub class. It contains settings for illumination.

Methods
NameDescription
UpdateShaderUpdates the uniforms that contains copies of the information stored in light and material members.

Output



No comments:

Post a Comment