PDA

View Full Version : How expensive are clipping planes?



Anders
12-09-2002, 07:23 AM
Hi

It seems to me that the use of clipping planes is rather expensive. Right now I'm doing a program using projected textures as shadows. The problem with this technique is back projection. In a paper by Cass Everitt he mentions that the problem can be solved by using a 1D texture and then testing for negative q coordinates. Since I have no idea how to implement that codewise, I thought of using a clipping plane instead, thus clipping everything behind the light source away when rendering shadow recievers. This seems to work reasonably well, but it also seems very slow. Can this be true, or is it me who is doing something wrong?

Also if anyone knows of a code example or has written one themselves using the 1D texture to eliminate the back projection problem I would be very interested in seeing it, since that would be my preferable method of solving the problem. Cass own projective texture demo doesn't seem to account for the problem.

Regards Anders

Humus
12-09-2002, 10:05 AM
The Per-pixel spotlights (http://esprit.campus.luth.se/~humus/?page=3D) demo on my site uses a 1d texture for this.

ehart
12-09-2002, 11:00 AM
One thing to keep in mind here is that non-positive q values can produce unpredictable results. The GL spec explicitly allows things to go off the rails in this case, so you need to be aware this code is not portable. I can't say it is a problem in practice, but you still need to be mindful of it.

-Evan

Humus
12-09-2002, 11:22 AM
Also, when the the q coord approaches zero you might get precision problems. I noticed that while coding that particular demo. I would get a grey flickering area around -0.008 < q < 0.008 (or something like that) on my old Radeon 8500. Had to finetune it to get good results such that it cuts at q = 0.008 instead of q = 0. This have the negative effect that when a polygon get close enough to the light it'll darken.

fritzlang
12-09-2002, 11:29 AM
Or you draw only the triangels that your projector can "see". There is really no need to draw the ones that "backproject".
At least this works in all cases for me.

fritzlang

[This message has been edited by fritzlang (edited 12-09-2002).]

Coriolis
12-09-2002, 01:33 PM
In answer to the clipping plane part of the original question, yes user-defined clipping planes are slow in general.

jwatte
12-09-2002, 02:28 PM
The DX9 specification requires that cards support 6 user defined clipping planes.

Note that with 2D textures and alpha testing, you can get 2 clipping planes for the cost of a texture unit on plain old hardware. With shader-y things, you can get four clip planes out of texgen (each dotproduct can be compared to > or < 0).

Anders
12-10-2002, 05:27 AM
Hi all

First of all, thanks for your answers. From what I can see, I am faced with three possibilities to fix my back projection problem:

1: Use a 1D texture. Since I am still not completely sure how this works and how it should be set up, implementing it will be a problem. Humus, thanks for the link, but the source you provided, does not seem to include spotlight.h and texture.h. Would it be possible to see those, or are they intentionally left out of the source package? If so, could you please post a code snippet, where you create and set up the 1D texture, with a little explanation?

2: Use a user defined clipping plane. This seems to work O.K., but it also seems computationally expensive and thus gives an undesireable frame rate hit.

3: Draw only the triangles recieving the shadow. This seems like a good solution, but it will require more CPU computations, but in the end less triangles will be sent to the GPU. I am not experienced enough to judge if this will be more or less effecient than using the 1D texture, but perhaps some of you can help. Besides this would also free up a texture unit.
I would do it in the following way:
First go through all object faces (consisting of triangles) and check wether they are in front of or at least partially in front of the light source.
If so, then test each individual triangle in the face against the lights field of view and store all triangles intersecting the lights view frustum in a list.
Finally send all those triangles to the GPU. Does this sound like a reasonable way of doing it?

Regards Anders

Gdo
12-10-2002, 03:27 PM
And what about stencil buffer ?