title: How to fix incorrect Blinn-Phong lighting
body: <p>I am trying to implement Blinn-Phong shading for a single light source within a Vulkan shader but I am getting a result which is not what I expect.</p>
  
  <p>The output is shown below:
  <a href="https://i.stack.imgur.com/zqcr5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zqcr5.png" alt="Incorrect lighting"></a></p>
  
  <p>The light position should be behind to the right of the camera, which is correctly represented on the touri but not on the circle. I do not expect to have the point of high intensity in the middle of the circle.</p>
  
  <p>The light position is at coordinates (10, 10, 10).</p>
  
  <p>The point of high intensity in the middle of the circle is (0,0,0).</p>
  
  <p>Vertex shader:</p>
  
  <pre><code>#version 450
  #extension GL_ARB_separate_shader_objects : enable
  
  layout(binding = 0) uniform MVP {
      mat4 model;
      mat4 view;
      mat4 proj;
  } mvp;
  
  layout(location = 0) in vec3 inPosition;
  layout(location = 1) in vec3 inColor;
  layout(location = 2) in vec2 inTexCoord;
  layout(location = 3) in vec3 inNormal;
  
  layout(location = 0) out vec3 fragColor;
  layout(location = 1) out vec2 fragTexCoord;
  layout(location = 2) out vec3 Normal;
  layout(location = 3) out vec3 FragPos;
  layout(location = 4) out vec3 viewPos;
  
  void main() {
      gl_Position = mvp.proj * mvp.view * mvp.model * vec4(inPosition, 1.0);
      fragColor = inColor;
      fragTexCoord = inTexCoord;
      Normal = inNormal;
      FragPos = inPosition;
      viewPos = vec3(mvp.view[3][0], mvp.view[3][1], mvp.view[3][2]);
  }
  </code></pre>
  
  <p>Fragment shader:</p>
  
  <pre><code>#version 450
  #extension GL_ARB_separate_shader_objects : enable
  
  layout(binding = 1) uniform sampler2D texSampler;
  layout(binding = 2) uniform LightUBO{
      vec3 position;
      vec3 color;
  } Light;
  
  layout(location = 0) in vec3 fragColor;
  layout(location = 1) in vec2 fragTexCoord;
  layout(location = 2) in vec3 Normal;
  layout(location = 3) in vec3 FragPos;
  layout(location = 4) in vec3 viewPos;
  
  layout(location = 0) out vec4 outColor;
  
  void main() {
      vec3 color = texture(texSampler, fragTexCoord).rgb;
      // ambient
      vec3 ambient = 0.2 * color;
  
      // diffuse
      vec3 lightDir = normalize(Light.lightPos - FragPos);
      vec3 normal = normalize(Normal);
      float diff = max(dot(lightDir, normal), 0.0);
      vec3 diffuse = diff * color;
  
      // specular
      vec3 viewDir = normalize(viewPos - FragPos);
      vec3 reflectDir = reflect(-lightDir, normal);
      float spec = 0.0;
      vec3 halfwayDir = normalize(lightDir + viewDir);  
      spec = pow(max(dot(normal, halfwayDir), 0.0), 32.0);
  
      vec3 specular = vec3(0.25) * spec;
      outColor = vec4(ambient + diffuse + specular, 1.0);
  }
  </code></pre>
  
  <p>Note:
  I am trying to implement shaders from <a href="https://learnopengl.com/Advanced-Lighting/Advanced-Lighting" rel="nofollow noreferrer">this</a> tutorial into Vulkan.</p>