I am currently using per-pixel attenuated lights in my engine. I am having fill rate problems, so am trying to use scissor to limit the geometry drawn for each light.
I need to find the screen-space bounding rectangle of the sphere of influence of the light.

I am doing this at the moment by finding the vectors which will become screen space left and up, dx and dy.

Then I mulitiply these by the modelview and projection matrices, and scale and bias so that [-1,1]->[0,window width] and the same for height.
However, using these projected values for the scissor box seems to make the box too small and at certain angles, it cuts off a lit part of the scene.

I think this method should work, does anyone have a reason why it shouldn't?
Is there an easier way, or have I simply made a silly error?

AdrianD

08-15-2002, 12:39 PM

this is because a sphere gets also distorted, when its verty close the the viewer and you use a wide perpective angle.

to get it correct running, you must compute the screenspace coordinates of the boundingbox for this light (6 points) and then use this 2d-coordinates to build a 2d-box for clipping(take min/max values of them)

bakery2k

08-15-2002, 02:17 PM

Sorry, I'm not sure what you mean when you say:
"you must compute the screenspace coordinates of the boundingbox for this light (6 points)"

Could you please
elaborate?

SirKnight

08-15-2002, 06:45 PM

Well I havn't tried this code out yet but I think this will work (it looks ok to me so far).

EDIT: I just wanted to add that this code, while doing all the math on paper and drawing it on some graph paper does compute the correct values to go into glScissor for clipping the shadow volume where needed. Now all I need to do to be doubly sure is pop it into a shadow program and see what happens. Maybe ill try to do that before my college classes start up again. http://www.opengl.org/discussion_boards/ubb/smile.gif

//
// compute 3D->2D projection here using
// current projection/modelview matrix.
// (using openGL or by yourself, there are
// many many threads about this topic in this
// forum... just look for gluProject)
//
// store your 2D-coordinates (you need only x and y.)
// in a new array: