title: Specular Shading Phong Model not working
body: <p>I am trying to implement the Phong reflection model using GLSL 3.3. I have followed a tutorial for it, and although I have changed my code to match up what the tutorial has, I am still unable to create the effect. I have a weird spotlight effect coming from origin to wherever the light source is instead of any Phong reflection. Here is the vertex shader:</p>
  
  <pre><code>#version 330
  layout(location = 0) in vec3 position;
  layout(location = 1) in vec3 normal;
  out vec3 Color;
  out vec3 NormalCamSpace;
  out vec3 EyeDir;
  out vec3 PositionWorldSpace;
  out vec3 LightDirCamSpace;
  uniform mat4 MVP;
  uniform mat4 M;
  uniform mat4 V;
  uniform vec3 lightPos;
  
  void main() {
      NormalCamSpace =(V*M *vec4(normal,0.0)).xyz;
      PositionWorldSpace = (M * vec4(position,1.0)).xyz;
      vec3 PositionCamSpace = (V*M*vec4(position, 1.0)).xyz;
      EyeDir = -PositionCamSpace;
      LightDirCamSpace = (V*vec4(lightPos, 1.0)).xyz + EyeDir;
      Color = vec3(0.0, 1.0, 1.0);
      gl_Position = MVP * vec4(position, 1.0 );
  }
  </code></pre>
  
  <p>And here is the frag shader:</p>
  
  <pre><code>#version 330
  in vec3 Color;
  in vec3 NormalCamSpace;
  in vec3 PositionWorldSpace;
  in vec3 EyeDir;
  in vec3 LightDirCamSpace;
  uniform vec3 lightPos;
  uniform float ambientIntensity;
  
  out vec3 outColor;
  
  void main() {
      vec3 n = normalize(NormalCamSpace);
      vec3 l = normalize (LightDirCamSpace);
      float cosTheta = clamp(dot(n, l),0,1);
  
      vec3 E = normalize(EyeDir);
      vec3 R = reflect(-l, n);
      float cosAlpha = clamp(dot(E, R),0,1);
      cosAlpha = pow(cosAlpha, 5);
      float attenIntensity = 1.0 + 0.01*distance(lightPos, PositionWorldSpace)*distance(lightPos, PositionWorldSpace);
      outColor = Color*cosTheta /attenIntensity+
      Color* vec3(0.3, 0.3, 0.3) * cosAlpha/attenIntensity+
      vec3(0.8, 0.8, 0.8) * ambientIntensity;
  }
  </code></pre>
  
  <p>lightPos is in world space.</p>
  
  <p>This is the <a href="http://www.opengl-tutorial.org/beginners-tutorials/tutorial-8-basic-shading/" rel="nofollow">tutorial</a> if it's relevent. Everything works except specular lighting.</p>