PDA

View Full Version : Vector to eye position



ropel
05-15-2007, 08:05 AM
Can anyone tell me how to determine a vector from a vertex to the eye/camera in the vertex or geometry shader?

Thanks!

k_szczech
05-15-2007, 09:45 AM
vec3 eyeVec = (gl_ModelviewMatrix * gl_Vertex).xyz;

Zengar
05-15-2007, 11:07 AM
Shouldn't you put a "-" before?

k_szczech
05-16-2007, 12:38 AM
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().

ropel
05-20-2007, 04:17 AM
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?

yooyo
05-20-2007, 10:41 AM
It is different. gl_Position is same but pos is different in case 1 and case 2.

ropel
05-20-2007, 01:04 PM
Ok, but the actual result is different. And that is based on the gl_Position. I would expect no visual difference.