PDA

View Full Version : Projective texture weirdness



Gorg
02-13-2003, 04:49 PM
Hi guys,

When do projective texturing, I get light on and close to the projection near plane.

Here is a picture of the problem http://members.rogers.com/deseric/problem.jpg

Here is a picture of the light and it's frustum touching the object http://members.rogers.com/deseric/projectlight.jpg (http://members.rogers.com/deseric/problemlight.jpg)

Here is the projection texture I use : http://members.rogers.com/deseric/light.jpg


Here is the code I use to setup the projection :




glActiveTextureARB(GL_TEXTURE0_ARB);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);

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

GLfloat splane[4] = {1,0,0,0};
GLfloat tplane[4] = {0,1,0,0};
GLfloat rplane[4] = {0,0,1,0};
GLfloat qplane[4] = {0,0,0,1};

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
glTexGenfv(GL_S, GL_OBJECT_PLANE, splane );
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
glTexGenfv(GL_T, GL_OBJECT_PLANE, tplane );
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
glTexGenfv(GL_R, GL_OBJECT_PLANE, rplane );
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
glTexGenfv(GL_Q, GL_OBJECT_PLANE, qplane );

glMatrixMode(GL_TEXTURE);
glLoadIdentity();



//scale and bias to bring texcoord in [-1,1] to [0,1]
glTranslatef(0.5f, 0.5f, 0.0f);
glScalef(0.5f, 0.5f, 1.0f);

const GraphicTools::ViewVolume& theVolume = light.GetViewVolume();

glFrustum( theVolume.Left, theVolume.Right, theVolume.Bottom, theVolume.Top, theVolume.Near, theVolume.Far );

MultMatrix( light.GetFrame().GetWorldToFrame() );
MultMatrix( objectSpaceToWorldSpace );


The light origin does not coincide with the light frustum which has it's near set to 3. I have tried moving back the near very close to 0, but nothing changed.

This gives me trouble because when I remove the back projection, I need to fudge the the bias to a bit less 0.5 to remove the band. But when I do that, if I am very close to an object and some of it's vertices are behind the far plane ,I get a sharp cut in the middle of the light projection . This is because I use a 1d texture with one side black and one side white and use NEAREST has my filtering mode. So obviously some of the fugded texcoords fall in the black even they should be in the white.


Anyone ever got that or have any clue why it is doing so?

EDIT : fixed a link


EDIT : BTW, the projection is correct when all the points are in front(or behind) the projector plane


[This message has been edited by Gorg (edited 02-14-2003).]

Gorg
02-15-2003, 08:54 AM
Ok. I found how to fix it but I don't understand why.

The band only appears when use a mipmaping filtering mode, I have been trying to picture what happens but I don't see how the band appears.

Anybody has a reason?

zed
02-15-2003, 11:20 AM
i couldnt actually see any problem in the screenshot.
perhaps use GL_NEAREST

edit - http://www.opengl.org/discussion_boards/ubb/smile.gif oh i see u do



[This message has been edited by zed (edited 02-15-2003).]

Gorg
02-15-2003, 01:24 PM
Zed, the problem is the band in the middle. Maybe I should have described the first picture a bit better.

The 2 half-elipses on each side are the projection and the back projection. The band in the middle should not be there, but I found it only appears with filtering mode of type GL_*_MIPMAP_*.

So I fixed my problem, but I still don't understand why it was a problem in the first place http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by Gorg (edited 02-15-2003).]

zed
02-15-2003, 09:52 PM
ok i see,
try using GL_REPEAT u it should give u an idea of whats happening
well u need to do is for each mipmap level create a border around the image + use clamp_to_edge.

glubuildmipmaps wont cut the ice

Gorg
02-16-2003, 08:47 AM
Oh I see now what was happenning! Thanks Zed.