To create a shader program that can be used for implementing per-fragment (or Phong) shading using the Phong reflection model, use the following steps:
- The vertex shader simply converts the position and normal to camera coordinates and passes them to the fragment shader:
layout (location = 0) in vec3 VertexPosition;layout (location = 1) in vec3 VertexNormal;out vec3 Position;out vec3 Normal;uniform mat4 ModelViewMatrix, NormalMatrix, ProjectionMatrix, MVP;void main() { Normal = normalize( NormalMatrix * VertexNormal); Position = ( ModelViewMatrix * vec4(VertexPosition,1.0) ).xyz; gl_Position = MVP * vec4(VertexPosition,1.0);}
- The fragment shader evaluates the Phong reflection model using the values passed from the vertex ...