Vector to eye position

Can anyone tell me how to determine a vector from a vertex to the eye/camera in the vertex or geometry shader?


vec3 eyeVec = (gl_ModelviewMatrix * gl_Vertex).xyz;

Shouldn’t you put a “-” before?

Shouldn’t you put a “-” before?
Yeah, the question was about the opposite vector, so I guess “-” should be there.
I alsways calclate vector from eye to vertex because it’s better for reflect() and refract().

Thanks guys,

I’ll give it a try on monday.

I was trying this actually in the Geometry Shader. However it seems that this:

vec4 pos = gl_ModelViewMatrix * vertex;
gl_Position = pos;

is different from:

vec4 pos = vertex;
gl_Position = gl_ModelViewMatrix * pos;

Any idea why?

It is different. gl_Position is same but pos is different in case 1 and case 2.

Ok, but the actual result is different. And that is based on the gl_Position. I would expect no visual difference.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.