Why these Blinn-Phong shader specular highlights follow the camera?

Hello everyone,

continuing my [adventures][1] with the OpenGL programmable pipeline (3.3+), I’m now trying to implement the basic Phong and Blinn-Phong shaders entirely in “modern” OpenGL, and that’s one of my problems.

While I succeeded to make a working BlinnPhong GLSL 1.20 shader with the deprecated functions (gl_LightSource, etc.), something’s wrong on my version using the new pipeline : the specular highlights follow the camera.

Currently, I only implement a blue directional light and a material with white specular color on a sphere. The specular highlight of the “new”, programmable pipeline version is much like a headlight. It gives e.g. this kind of weird glitch :

with the specular coming across the darkness, compared to the normal result of the old pipeline shader :

It doesn’t appear while not in the light, but it follows the eye and I don’t think that’s normal (the old pipeline shader version doesn’t do this).
This looks really like a stupid error made in the shader or when passing uniforms, yet I can’t pinpoint it !

I made a gist with both shaders, working (BlinnPhongOld.vert) and not working (BlinnPhongNew.vert) : [here][2]. These are only vertex shaders for now, fragment shaders do nothing (just gl_FragColor = outputColor; ). The sphere with ambiant white is the one rendered by the fixed pipeline, I test against it to verify my results are correct. The sphere rendered with the shader is the one above.

I’ve also made a zip of the files of the little app I use to test it. You can throw it in a test app to see for yourself what’s wrong. Maybe the problem comes from where I set the uniforms (in the draw function), but I would be surprised… :frowning:

Thank you for your help if you’re able to detect what’s wrong in this. There’s so few examples with the new OpenGL pipeline, I’m at a loss this time. Any advices about the shaders are also welcome.

myShaders.zip (754.6 KB)
[1]: Some questions about lights & World->Eye coords translation with matrices
[2]: https://gist.github.com/Scylardor/11202512

For the record : finally found the error myself !

It was indeed stupid : I was doing vec3 halfVector = normalize(eyeVector - lightDir); instead of vec3 halfVector = normalize(eyeVector + lightDir);.

Problem solved :smiley: