PDA

View Full Version : Help me with glTexGen



fuxiulian
12-12-2003, 05:04 AM
Hello !

I want to do a transparency effect to do a volumetric textured spotlight.

The effect should be similar to that found at

http://www.r3.nu/~cass/shadowsandstuff/

Let's say that the spotlight is treated like a camera: it has a projection transform matrix (projMat) and a modelview matrix (viewMat).

Let's say draw some textured quads from the
near plane of the spotlight's projection matrix to the far plane of the spotlight's projection matrix and use blending to achieve my effect.

My camera projection matrix is cameraProjectionMatrix and my camera modelview matrix is cameraViewMatrix.

To render the spotlight as viewed from the camera's point of view I use the following code:

glMatrixMode(GL_PROJECTION);
glLoadMatrixf(cameraProjectionMatrix);

glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(cameraViewMatrix);

glMultMatrixf(viewMat.GetInverse());
glMultMatrixf(projMat.GetInverse());

glutWireCube(2);

And to generate the texture coordinates I use

MATRIX4X4 biasMatrix(0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 0.5f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f); //bias from [-1, 1] to [0, 1]

MATRIX4X4 textureMatrix = biasMatrix;

//Set up texture coordinate generation.
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix.GetRow(0));
glEnable(GL_TEXTURE_GEN_S);

glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_T, GL_EYE_PLANE, textureMatrix.GetRow(1));
glEnable(GL_TEXTURE_GEN_T);


To my knowledge, using GL_EYE_LINEAR should
make the texture "stick" to the space and
apply the texture to any object found in
that space region.

However, if I do


glMatrixMode(GL_PROJECTION);
glLoadMatrixf(cameraProjectionMatrix);

glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(cameraViewMatrix);

z = 0.;

glBegin(GL_QUADS);

glVertex3f(-1, -1,z);
glVertex3f( 1, -1,z);
glVertex3f( 1, 1,z);
glVertex3f(-1, 1,z);

glEnd();

I will get garbage.

The quad intersects the spotlight with
my settings for the projection and modelview matrices.

So, the first question is:

- how do I set up the automatic texture generation so that the quad will have good textures coordinates ?

Another question will be how to draw quads that are perpendicular to the camera and fully enclose the spotlight's view frustum ?

Thank you for your time.
I tried to make figure this out on my own, I have made progresses, but still have a blurry image about what I should do...

Ffelagund
12-12-2003, 09:08 AM
well, this is the texture matrix transformation that i use for that effect:

float m1[4]={1,0,0,0};
float m2[4]={0,1,0,0};
float m3[4]={0,0,1,0};
float m4[4]={0,0,0,1};

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,m_texID); // projective texture
glTexGenfv(GL_S, GL_EYE_PLANE, m1);
glTexGenfv(GL_T, GL_EYE_PLANE, m2);
glTexGenfv(GL_R, GL_EYE_PLANE, m3);
glTexGenfv(GL_Q, GL_EYE_PLANE, m4);

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_Q);
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glTranslatef(0.5f, 0.5f, 0);
glScalef(0.5f, 0.5f, 1);
gluPerspective(m_fov, 1, 0.1f, 1);
gluLookAt(m_position.m_x,m_position.m_y,m_position .m_z,
m_view.m_x ,m_view.m_y ,m_view.m_z,
0 ,1 , 0 );
glMatrixMode(GL_MODELVIEW);
// Make geometry pass
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glDisable(GL_TEXTURE_GEN_Q);
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_TEXTURE);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

P.D: maybe gluLookAt can produce a gimbal, but is easiest that work with quaternions http://www.opengl.org/discussion_boards/ubb/wink.gif

[This message has been edited by Ffelagund (edited 12-12-2003).]