I'm trying to render some particles with OpenGL 3+ using point sprites. I've just realized that I have a major issue with the points. They increase in size automatically with respect to the camera distance. Resulting in the following:
Close to the particle emitter:
And when far away, everything looks blurry and bloated:
In older versions it seems one could adjust the point size scales with glPointParameter
. The function is still available in new 3+ OpenGL, but it only supports two parameters. GL_POINT_FADE_THRESHOLD_SIZE
seemed like what I need, but I've tried it with no results. I'm also using glEnable(GL_PROGRAM_POINT_SIZE);
Any other way I could avoid this automatic scaling of the points based on camera distance? I would rather not have to change to code to use standard billboards made of triangles.
Not sure if relevant at the moment, but this is vertex shader I'm using:
layout(location = 0) in vec4 a_position_size; // Point size in w coord
layout(location = 1) in vec4 a_color; // RGBA color modulated with texture
layout(location = 0) out vec4 v_color;
uniform mat4 u_MVPMatrix;
void main()
{
gl_Position = u_MVPMatrix * vec4(a_position_size.xyz, 1.0);
gl_PointSize = a_position_size.w;
v_color = a_color;
}
gl_PointSize
with the distance away from the camera. OpenGL doesn't (and can't reasonably) do it for you. – Colonel Thirty Twogl_PointSize
units on screen, regardless of theirz
coordinate. They only look like they're getting bigger when moving away because everything else is getting smaller. – Colonel Thirty Twogl_PointSize
is in window-space. In other words its unit of measure is 1 pixel. – Andon M. Coleman