PDA

View Full Version : make point-sprites quad compatible

Inquisitor
09-05-2009, 10:50 AM
I have some problems getting my point-sprites behave like I want them to. Essentially I want to replace some quads by point-sprites.
The list of quads is defined by the mid-points and the edge-size (real quads, not rectangles), always facing the viewer. Now I'm trying to figure out a glPointParameter configuration so I can takes those two values for point-vertex and point-size, and get a "compatible" output using point-sprites. Of course taking perspective projection into account.
And that's the problem: I can't figure out what to feed into glPointParameter(GL_POINT_DISTANCE_ATTENUATION,... ) to get that working.
Any hints are welcome. Thanks!

aqnuep
09-06-2009, 09:50 AM
To get perfectly the same results you have with quads you'd better use vertex shader to change the point size.

Inquisitor
09-07-2009, 07:04 AM
yes, if I could. I'm on an iPod touch with OpenGL ES 1, so no shaders available.

Xmas
09-08-2009, 06:37 AM
For a proper projection, an object that is twice as far away appears half as big in each dimension, so what you want is the size in pixels being the quad size multiplied by some constant, divided by the view space distance:
size' = size * C / D

C is the size in pixels of an object of size 1 at distance 1 in view space, and usually equals the (0,0) component of the projection matrix multiplied by half the screen width.

The formula used for the attenuated point size is
size' = size / sqrt(a + b * D + c * Dē)
with (a, b, c) being the point distance attenuation parameters. With a = b = 0 you get this:
size' = size / (sqrt(c) * D)

So what's left to do is to figure out the value of c.
C = 1 / sqrt(c)
c = 1 / Cē

And, as mentioned above, C is the first component of the projection matrix multiplied by half the screen width.

Inquisitor
09-11-2009, 03:32 AM
Thanks a lot, Xmas! That's exactly the explanation I was looking for!