How to change gl_PointSize in the vertex shader?

Viewed 244

I'm optimizing my particle renderer to work with GL_POINTS and now I need to adjust the size of the points using gl_PointSize in the vertex shader to scale the particles the right amount from the vertex shader. This is the vertex shader I have now:

#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);
}

Changing the gl_PointSize doesn't seem to make a difference when changed in the vertex shader.

2 Answers

You have to enable GL_PROGRAM_POINT_SIZE (see 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.

Related