In the 8th pack of slides of the Angel Shreiner book "Interactive Computer Graphics" (slides available here) the suggested code for calculating lighting starts like this:
vec3 pos = -(modelViewMatrix*vPosition).xyz;
vec3 L = normalize( lightPosition.xyz - pos );
vec3 E = normalize( -pos );
vec3 N = normalize(modelViewMatrix*vNormal.xyz);
vec3 H = normalize( L + E );
however, this way not only it looks wrong unless I remove the minus in the pos
declaration, but even if I do, lighting is too dependant on the viewer's position (some parts are dark and get completely light if the viewer moves there). If I switch the modelViewMatrix with only the model matrix in the declaration of N
it looks like it works like a charm. Is this an error in the book's code? And what's the mathematical reason of this? I'd like to really learn how the shading works but the book isn't always clear. I'd say the viewer should have an impact on how lighting is calculated, but not the unrealistic way it happens in the suggested code.