Sprite point size attenuation using modern OpenGL

I am trying to display some particles using OpenGL 3+ using point sprites. I just realized that I have a serious problem with glasses. They automatically increase in size of the camera. As a result:

Close to particle emitter:

colse

And when far away, everything looks blurry and bloated:

far

In older versions, it seems that you can adjust the point size scales with glPointParameter. The function is still available in the new 3+ OpenGL, but it only supports two parameters. GL_POINT_FADE_THRESHOLD_SIZEseemed to me what I needed, but I tried it without any results. I also useglEnable(GL_PROGRAM_POINT_SIZE);

? , .

, , , :

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;
}
+4
2

, - gl_PointSize. , gl_PointSize . , , , , , , , 3D- .

, :

uniform mat4 u_MVPMatrix;
uniform vec3 u_cameraPos;

// Constants (tweakable):
const float minPointScale = 0.1;
const float maxPointScale = 0.7;
const float maxDistance   = 100.0;

void main()
{
    // Calculate point scale based on distance from the viewer
    // to compensate for the fact that gl_PointSize is the point
    // size in rasterized points / pixels.
    float cameraDist = distance(a_position_size.xyz, u_cameraPos);
    float pointScale = 1.0 - (cameraDist / maxDistance);
    pointScale = max(pointScale, minPointScale);
    pointScale = min(pointScale, maxPointScale);

    // Set GL globals and forward the color:
    gl_Position  = u_MVPMatrix * vec4(a_position_size.xyz, 1.0);
    gl_PointSize = a_position_size.w * pointScale;
    v_color      = a_color;
}
+11

GLSL .js. glampert, three.js :

uniform vec4 origin;

void main() {
    vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
    float cameraDist = distance( mvPosition, origin );
    gl_PointSize = 200.0 / cameraDist;
    gl_Position = projectionMatrix * mvPosition;
}

-, , modelViewMatrix , . , , , . ( ).

+3

All Articles