Cloov

08-24-2011, 06:47 AM

Hi all,

I'm having a problem with point sprites.

I'm working in GLES 2.0 on iOS. I can't seem to arrive at a good equation for scaling point primitives.

I've used an approach that most sites I've seen recommend, but what I don't quite understand is that my sprites get larger and larger as my camera approaches them, but then they get a bit smaller again before my camera passes by them.

'position' is my attribute for the point sprite's XYZ coords

vec4 newPosition = projection * modelview * position;

gl_Position = newPosition;

float distX = sqrt((newPosition.x-position.x)*(newPosition.x-position.x));

float distY = sqrt((newPosition.y-position.y)*(newPosition.y-position.y));

float distZ = sqrt((newPosition.z-position.z)*(newPosition.z-position.z));

totalDistance = distX + distY + distZ;

It may help to note that the totalDistance value works fine for distance fog, when I pass it through my fragment to shader, but I did think it was a little strange as it's not using the coords of the camera and the initial written coords of the vertex, it's using the calculated coords of the vertex and the initial written coords of the vertex.

Now onto gl_PointSize. The algorithm I used was from here: http://www.two-kings.de/tutorials/dxgraphics/dxgraphics17.html

But I thought I'd get this working, albeit not quite perfectly, without as much as a quadratic attenuation. So I've tried quadratic and linear attentuation too, but I always seem to get this issue with the sprites appearing smaller again when I get as close as I possibly can. It almost feels like the point sprites I'm seeing as smaller are actually behind the camera, but I can't work out why.

Below, I use 320 because that's my screen height at the moment.

float customPointSize = 0.5;

gl_PointSize = 320.0 * customPointSize * ( 1.0 / (2.0*distFromEye) );

I've also tried other equations, like:

gl_PointSize = 200.0 * (customPointSize / totalDistance);

Can anyone help with this?

Thanks

I'm having a problem with point sprites.

I'm working in GLES 2.0 on iOS. I can't seem to arrive at a good equation for scaling point primitives.

I've used an approach that most sites I've seen recommend, but what I don't quite understand is that my sprites get larger and larger as my camera approaches them, but then they get a bit smaller again before my camera passes by them.

'position' is my attribute for the point sprite's XYZ coords

vec4 newPosition = projection * modelview * position;

gl_Position = newPosition;

float distX = sqrt((newPosition.x-position.x)*(newPosition.x-position.x));

float distY = sqrt((newPosition.y-position.y)*(newPosition.y-position.y));

float distZ = sqrt((newPosition.z-position.z)*(newPosition.z-position.z));

totalDistance = distX + distY + distZ;

It may help to note that the totalDistance value works fine for distance fog, when I pass it through my fragment to shader, but I did think it was a little strange as it's not using the coords of the camera and the initial written coords of the vertex, it's using the calculated coords of the vertex and the initial written coords of the vertex.

Now onto gl_PointSize. The algorithm I used was from here: http://www.two-kings.de/tutorials/dxgraphics/dxgraphics17.html

But I thought I'd get this working, albeit not quite perfectly, without as much as a quadratic attenuation. So I've tried quadratic and linear attentuation too, but I always seem to get this issue with the sprites appearing smaller again when I get as close as I possibly can. It almost feels like the point sprites I'm seeing as smaller are actually behind the camera, but I can't work out why.

Below, I use 320 because that's my screen height at the moment.

float customPointSize = 0.5;

gl_PointSize = 320.0 * customPointSize * ( 1.0 / (2.0*distFromEye) );

I've also tried other equations, like:

gl_PointSize = 200.0 * (customPointSize / totalDistance);

Can anyone help with this?

Thanks