Show only some parts of a point cloud. OpenGl4

I am developing an opengl 4.0 app which is showing a point cloud. In the other hand, I have an array "pos" where I have some x,y,z positions:

pos[number of pos] , where 3 refers to :x :y :z

I would like to show only the points of the point cloud which are inside of a sphere of radius R for any of the positions I have in the array pos. I was thinking in sending the array pos to the vertex shader that draws my cloud point and there, do a loop for each position and check if the distance between any of the positions and the vertex is less than a radius R. If so, I put an alpha colour of 1.0. If not, an alpha colour of 0. Something like:

Vertex:

#version 460

uniform mat4 viewMatrix, projMatrix;

in vec4 position;
in vec3 pos[N];

in vec3 color;

float d;

out float Color;
out float AlphaC;

void main()
{
Color = color;
AlphaC = 0.0;

for ( int i = 0; i < pos[i].length; i++ ) {
d = distance(vec4(pos[i],1),position);
AlphaC = 1.0;
break;
}
}

gl_Position = projMatrix * viewMatrix * position ;
}

Fragment:

#version 460

in float Color;
in float AlphaC;

out vec4 outColor;

void main()
{
outColor = vec4(Color, AlphaC);
}

But I am not sure how to send this pos array since this matrix is an Nx3 with N depending in the file of positions that I am using. Any idea? Does N has to be defined before compiling?

• You want to send the whole array to the shader and call it once per draw call? Then iteratively go through the points? That defeats the purpose of the gpu. The shader should only handle a single point. Checking its distance. Then it can be done in parallel. Feb 3 '18 at 21:33
• My cloud point have always same positions but colours are different each frame and I want to show less transparent the points of the cloud around some positions that also change in each frame. How would you do it? Feb 3 '18 at 22:02
• Make your vertex shader accept only a single vertex and check if it's valid. If the positions don't change though you may want to consider not validating them every time you draw them. IE: Before the program even starts get the points in the sphere out throw them in a vertex buffer and draw. Feb 3 '18 at 22:26