如何在顶点着色器中更改 gl_PointSize?

How to change gl_PointSize in the vertex shader?

我正在优化我的粒子渲染器以使用 GL_POINTS,现在我需要使用顶点着色器中的 gl_PointSize 来调整点的大小,以从顶点着色器。 这是我现在拥有的顶点着色器:

#version 330 core

layout (location = 0) in vec3 position;
layout (location = 1) in uint uv;

uniform mat4 projection;
uniform mat4 view;

void main(){
    gl_PointSize = 10; // No difference with gl_PointSize = 1000
    gl_Position = projection * view * vec4(position, 1.0);
}

在顶点着色器中更改 gl_PointSize 似乎没有什么不同。

您必须启用 GL_PROGRAM_POINT_SIZE(参见 glEnable and gl_PointSize):

glEnable(GL_PROGRAM_POINT_SIZE);

OpenGL Reference - gl_PointSize

Description:

In the vertex, tessellation evaluation and geometry languages, a single global instance of the gl_PerVertex named block is available and its gl_PointSize member is an output that receives the intended size of the point to be rasterized, in pixels. It may be written at any time during shader execution. If GL_PROGRAM_POINT_SIZE is enabled, gl_PointSize is used to determine the size of rasterized points, otherwise it is ignored by the rasterization stage.