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][3] , where 3 refers to [0]:x [1]:y [2]: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;
uniform float Radius;
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);
if (d<Radius) {
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?