PDA

View Full Version : projective texture matrix

supagu
09-15-2004, 04:41 AM
okay, i've been working on projective texturing trying to get it working, and think i finally figured out whats going on:

instead of rotating around origin of the world as i want, it looks as if its rotating around my camera!

demo showing the funk:

uses first person controls to steer camera, as you can see, as the camera moves, so does the projective texture

the 3 coloured lines show where the depth map is being rendered from, and where it should be being projected from.

heres how i calculate the projection matrix:

{
Matrix4 mBias(0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.5, 0.5, 0.0, 1.0);

glMatrixMode(GL_TEXTURE);

mBias.Set(); // set this matrix

gluPerspective(45.0f, 1.0f, 1.0f, 4.0f);

Matrix4 trans = light.GetTransform();
trans.SetM(); // multiply with existing matrix (lights model view matrix)

glMatrixMode(GL_MODELVIEW);
}
then to render:

glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_Q);

glMatrixMode(GL_MODELVIEW);
camera.LookAt(); // sets cameras model view matrix

//render my shapes here
im guessing i need some camera related matrix when producing the projective matrix? but what and in what order?

supagu
09-15-2004, 05:05 AM
light and camera transform are calculated as follows:

transform[ 0] = right[Vector3::X];
transform[ 4] = right[Vector3::Y];
transform[ 8] = right[Vector3::Z];

transform[ 1] = up[Vector3::X];
transform[ 5] = up[Vector3::Y];
transform[ 9] = up[Vector3::Z];

transform[ 2] = view[Vector3::X];
transform[ 6] = view[Vector3::Y];
transform[10] = view[Vector3::Z];

transform[12] = -( (position[Vector3::X] * right[Vector3::X]) + (position[Vector3::Y] * right[Vector3::Y]) + (position[Vector3::Z] * right[Vector3::Z]) );
transform[13] = -( (position[Vector3::X] * up[Vector3::X]) + (position[Vector3::Y] * up[Vector3::Y]) + (position[Vector3::Z] * up[Vector3::Z]) );
transform[14] = -( (position[Vector3::X] * view[Vector3::X]) + (position[Vector3::Y] * view[Vector3::Y]) + (position[Vector3::Z] * view[Vector3::Z]) );

supagu
09-16-2004, 02:48 AM
translating by the cameras position, makes the projective texture independent of cameras position, but not the rotation, so i tried multiplying by cameras world matrix, didnt work. then i tried using the cameras model view, and that didnt either :-/

the docs on the nvidia website say i need to multiply by camera view matrix

which makes my lights rotation independent of the camera, but the lights position is still affected by moving the camera :-/

rogerhe
09-22-2004, 11:36 PM
did you set eye plane with glTexGen?