View Full Version : fragment program eye coord

11-10-2002, 02:59 AM
i currently try to map the existing opengl lighting engine to perpixellighting. so i use the state.light[0].position for my lightposition currently. this value is, even in the fragment program, in worldspace (i don't have anything in objectspace currently.. all the same)..

so, i send over the position in worldspace from the vp to the fp. and voilą, diffuse lighting, distance attentuation, all working in a short time..

now i tried specular, with simple halfangle math. and i got stuck. i need the eye position in worldspace. i could send it manually in, i think (well, currently i could send the same coords as i use in gluLookAt for example). but i want to get them automagically.

so i thought about it..
in screenspace, the eye coord is (0,0,0,1). and i need to backtransform that by the modelviewprojection matrix, so i take the inverse of it, and transform it with four dp4. now because only the last value is 1, the others are zero, only the .w component of the specific row in the dp4 actually is my vector.. so i thought of transposing the modelviewprojection, and just taking the last row out would be my eye position.

in code, its this:
PARAM eye = state.matrix.mvp.invtrans.row[3];

and then i try to use that..
but it's not what i thought, its a constant eye = (0,0,1,0) vector..

i hate matrix math, i'm so bad in it.. anyone has an idea, i played around with all sort of .invtrans, .inverse, .row[x]... it should work somehow that way, shouldn't it?

11-10-2002, 04:28 AM
The camera position is the .w components of row 0-2 of the inverse modelview matrix - or so I thought. You're thinking it's row 3?

11-10-2002, 08:36 AM
hehe, got it, its the third row of the transpose of the inverse.. i just had some typo http://www.opengl.org/discussion_boards/ubb/biggrin.gif