I’ve started trying to implement shaders in my main project recently, and I’ve been coming across a problem. I’ve read plenty of examples, and I’m trying to go about implementing simple lighting before moving on to more difficult tasks.
All the example code I’ve seen uses a value for the eye position in the calculation of the specular lighting component, computing V as the eye position - the vertex/fragment position, normalized.
My problem is this: the sample code I’ve looked at used a constant viewport, and thus could send a simple value, like (0.0, 0.0, 1.0, 1.0), as the eye position as a constant. However, I already have a movable camera system, and no matter how I try to send the current camera position to the program, my specular highlights manifest themselves in incorrect positions on the model.
What’s the right way to calculate the eye position value so that my shader will produce the correct results?
And similarly, what version of the eye position should I use in calculating the incident vector to be reflected for looking up a fragment from an environment cube map?
Thanks in advance for your help.