I’m using glReadPixels and gluUnProject to get the 3D coordinates of all the pixels of a picture (my purpose is to calculate a simulated sonar profile of the scene).
gluUnProject is time consuming, and returns absolute coordinates which I need to convert into new coords relative to the viewpoint.
I guess that this transformation is made twice (once, reversed, inside of the unproject subroutine and once by myself). I think that I would save time if I could directly unproject the winZ, winY, winZ into the viewpoint coordinates system.
The 2 ideas I have are:

do the unproj myself with a simplified algorithm

pass modified proj and/or model matrices to the gluUnProject routine

Why don’t you look at what gluUnProject() in the sample implementation source? It’s a pretty straightforward calculation, but the way that gluUnProject is specified, I expect they have to perform a matrix inversion each call.

If you’re going to unproject a lot of points by the same matrices, you can probably do much better.

Sounds like you just want to undo the projection matrix without the modelview. I’m too lazy to think how the inverse of the perspective projection will look, but with some luck it could result in a matrix with some zeroes, which would make it faster to multiply. You could probably get additional speed by calculating some differences beforehand. That’s because you’re using equally spaced X and Y values, so terms that use them should grow by a fixed amount every pixel.

Another thought - you may be able to get a similar result by drawing the scene again without the perspective projection. It might not get you the exact same result (certainly the view frustum will be different), but it may be a direction worth thinking about.

Sounds like you just want to undo the projection matrix without the modelview. I’m too lazy to think how the inverse of the perspective projection will look

<homer like voice> hmm. lazy. goOOod. <drools>

the inverse ot the projection matricies are given in the back of the red book! You can compute the inverse when you build your projection matrix, without doing some generic matrix reduction code. Is nice =)

cheers,
John

[This message has been edited by john (edited 05-14-2001).]