PDA

View Full Version : TexGen coords not clamped



kon
02-05-2002, 02:43 AM
Hi
For projective texture mapping I'm computing the projection matrix M = T*S*P*V-1 where T is the translation by 0.5 in x, y, z, S is scaling by 0.5 in x, y, z, P is the projection with fov = 45, aspect 1.0, near .1, far 1. and V-1 is the inverse of the projector's transformation. Then I enable GL_EYE_LINEAR and fill the four rows of M into the four texgen planes accordingly.
Now having texture parameters (of the texture to be projected) set to GL_REPEAT the projection is fine and of course repeated. Changing it to GL_CLAMP gives the projected texture but the four borders are then still repeated! The multiplication by P should transform the vector into the range [-1, 1] and the scaling/translating will map to the range [0, 1]. What can be the reason for this repeatness?

Thanks
kon

vincoof
02-05-2002, 04:49 AM
IMO, 3 possibilities :
- the clamp instruction fails, eg you call for GL_CLAMP at a bad moment or with a bad syntax,
- the drivers sux0rs,
- something else... http://www.opengl.org/discussion_boards/ubb/smile.gif

Bob
02-05-2002, 05:13 AM
+1 possibility

- You set wrap mode for wrong texture. Wrap mode is set per texture, and the default wrap mode is repeat.

cass
02-05-2002, 06:18 AM
Sounds like you're getting the correct behavior. What were you expecting GL_CLAMP to do? OpenGL only clamps the coordinates - but by the spec it still textures every fragment with a positive q. In every implementation I know of it textures fragments with negative q as well.

Thanks -
Cass

kon
02-05-2002, 06:42 AM
Bob, the texparams are set correctly.
Cass, then I can set a small (1 or 2 pixel) black boarder around the texture and the "repeated" part would be just black color and not something weird?

Thanks,
kon

vincoof
02-05-2002, 07:02 AM
cass: I think the correct behaviour would be to clamp texture coordinates in the range [0,1]. If this is the case, why is the texture repeated ? IMO, the fact that coordinates are automatically generated does not skip the clamp operation.

[This message has been edited by vincoof (edited 02-05-2002).]

cass
02-05-2002, 07:36 AM
Kon,

You could do that or use GL_CLAMP_TO_BORDER.

Vincoof,

Clamping is done per-fragment, so it comes after texgen. Kon said the "borders are then still repeated". This sounds to me like the filtered color half way between the border and edge texels is being smeared - which is the effect of GL_CLAMP.

Thanks -
Cass

vincoof
02-05-2002, 07:52 AM
Ok cass, I missed that detail ! o_O
Sorry. I didn't see he was talking about repeating the border.

anyhow, I agree with you on your analysis about the GL_CLAMP/border repetition thingy.
But I'd rather choose GL_CLAMP_TO_EDGE, wouldn't you ? http://www.opengl.org/discussion_boards/ubb/wink.gif

[This message has been edited by vincoof (edited 02-05-2002).]

kon
02-05-2002, 12:35 PM
Thanks Cass! Using GL_CLAMP_TO_BORDER_ARB gives the expected results. Unfortunately this extension is supported only on GeForce3 (and higher). Having a border of one texel the projected texture looks fine too.
And, CL_CLAMP_TO_EDGE doesn't solve this problem.

Thanks
kon

[This message has been edited by kon (edited 02-05-2002).]