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…