HLSL/GLSL View Matrix Question

toneburst's picture

I know I've asked this before, but I'd just like to finally get it sorted, so I know what to do when I come across this in the future.

I have an HLSL vertex shader that requires a variable to be passed to the pixel shader, and set like so:

float3 Vn = normalize(ViewIXf[3].xyz - Pw);

where

'Pw'

is the position of the current vertex, and

'ViewIXf[3].xyz'

is a 4x4 matrix defined as providing 'transform from "view" or "eye" coords back to world-space'

I'm kinda assuming that ViewIXf[3].xyz represents the XYZ position of some kind of camera in the 3D scene. OpenGL/GLSL has no concept of a camera, as such, though, and the view matrix is combined with the model matrix in the gl_ModelViewMatrix.

Soooo... how do I set Vn? I'd always thought that in OpenGL, the camera is assumed to be at vec3(0.0) (ie the Origin), but it also seems this isn't the case in QC- it applies an offset of 1 unit on the Z-axis, I think. I've tried simply using the vertex position in Eye Space (ie after gl_ModelViewMatrix transformation), but this doesn't seem to work.

Any OpenGL/GLSL gurus any ideas?

a|x