So, I’ve been playing around with point sprites, but I can’t seem to get attenuation working right. It seems like no matter how I set the attenuation coefficients moving the camera around doesn’t change the size of the point sprite.

The formula I found for the result size was:

size = PointSize * sqrt( 1 / (constant + linear * d + quadratic * d * d))

I figured if I just took the position of the camera and found the distance to the point sprite then I could calculate the size of the point sprite, but it doesn’t seem to be working.

Here’s an example of how I’m doing it:

float constant = 0.0f;

float linear = 0.5f;

float quadratic = 0.0f;

float thresh = 5.0f;

float min = 1.0f;

float max = 60.0f;

float coefficients[] = {constant,linear,quadratic};

glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, coefficients);

glPointParameterfv(GL_POINT_SIZE_MIN, &min);

glPointParameterfv(GL_POINT_SIZE_MAX, &max);

glPointParameterfv(GL_POINT_FADE_THRESHOLD_SIZE, &thresh);

glEnable(GL_TEXTURE_2D);

glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);

glEnable(GL_POINT_SPRITE);

glPointSize(60.0f);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glBegin(GL_POINTS);

glVertex3f(0,0,20);

glEnd();

glDisable(GL_POINT_SPRITE);

So, changing the coefficients will make the point sprite a different size, but actually moving the camera doesn’t. Anyone have any ideas? I’m on an NVIDIA GeForce 8600, so I’d have to assume that attenuation works.

I suppose part of it is how does it actually determine the distance between the camera and the vertex? I figure it does some sort of inspection of the projection and modelview matrices and the vertex being transformed. Or if it’s just the modelview matrix then I could see the identity matrix being a problem. This seems rather counter-intuitive though.