PDA

View Full Version : Double projection



stephanh
04-24-2003, 10:41 PM
Hi,

i am using OpenGL's texgen functionality for projective texturing. The downside is that it produces a second projection in the projector's opposite direction. Any idea how to overcome this?

Thank you very much in advance.

regards,
Stephan

JustHanging
04-25-2003, 01:33 AM
Three options:

1. Use a clipping plane to clip out the geometry behind the projector. This one is easy to implement, the downsides are, that it causes a slowdown on nvidia cards, and the results are not z-invariant with geometry rendered without a clipping plane, so you'll need to use polygon offset+certain effects are not possible.

2. Don't send the geometry behind the light. This can even speed things up, but it usually requires some kind of hierachial scene representation (bsp/octree), so it's tricky. Depending on the geometry it might not be 100% foolproof either. Some big polygons can recieve both front and back projections, so they would have to be clipped.

3. Use an 1d-texture and alpha test. The texture contains two texels one with alpha 0 and one with alpha 1. Nearest filtering. Then you generate the texture coordinates so that every fragment behind the projector gets zero alpha, and use alpha test to cut them out. This is the best option, fast and clean, if you can afford one texture unit for it.

-Ilkka

stephanh
04-25-2003, 05:41 AM
Originally posted by JustHanging:
Three options:

1. Use a clipping plane to clip out the geometry behind the projector. This one is easy to implement, the downsides are, that it causes a slowdown on nvidia cards, and the results are not z-invariant with geometry rendered without a clipping plane, so you'll need to use polygon offset+certain effects are not possible.

2. Don't send the geometry behind the light. This can even speed things up, but it usually requires some kind of hierachial scene representation (bsp/octree), so it's tricky. Depending on the geometry it might not be 100% foolproof either. Some big polygons can recieve both front and back projections, so they would have to be clipped.

3. Use an 1d-texture and alpha test. The texture contains two texels one with alpha 0 and one with alpha 1. Nearest filtering. Then you generate the texture coordinates so that every fragment behind the projector gets zero alpha, and use alpha test to cut them out. This is the best option, fast and clean, if you can afford one texture unit for it.

-Ilkka


Thank you very much. I am now using the clipping plane approach and it works fine.
The second idea won't work since we don't have any suitable partition scheme (yet). And I don't use it for shadowmaps but for ordinary projections (which might be the same setup, i don't know)

The third approach sounds pretty interesting but we target gf2 level hardware so using one of the two tex units for the proj. cutoff is somewhat too expensive. And i am not sure if i completely understand it, the 2 pixel black white texture is assigned with ordinary tex. coords on the geometry, or projected?

[This message has been edited by stephanh (edited 04-25-2003).]

JustHanging
04-26-2003, 05:46 AM
Originally posted by stephanh:

And i am not sure if i completely understand it, the 2 pixel black white texture is assigned with ordinary tex. coords on the geometry, or projected?


Doesn't matter really, just as long as the texcoord is greater that 0.5 in front of the projector and less when it's behind. You can use the third row of the projector's projection matrix, and use the texture matrix to shift the texture coordinates, I think. I've actually never had to do it myself. Certain old cards, TNT and TNT2 at least, require both texture units to have same q-coordinates, so with them you'd better make the texture coordinates projective, but since you're targeting gf2-level cards, you should be safe either way.

-Ilkka