Advertisement

Draw array of points with individual colors

Started by September 10, 2019 01:41 AM
17 comments, last by CommanderLake 4 years, 6 months ago

Scratch that I figured I can access the vertex buffer via CUDA which is what I'm using to simulate the points.

Contrary to what I just said, I do need to change the point size which I can do but now the points are square rather than round and PointSmooth has been deprecated, how do I make the points round?

GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.PointSize(zoom);
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
GL.UseProgram(_shaderprogram);
GL.BindVertexArray(_renderObject._vertexArray);
GL.DrawArrays(PrimitiveType.Points, 0, pCount);
SwapBuffers();

fleabay said:
glLineWidth and glPointSize have not been deprecated. It is possible that there are discrepancies between vendors though.

Thank you. I will know it. Yes, it does not work on my computer.

Advertisement

You are using deprecated code. The first thing is you do not create glbufferarray but instead use old gl vertex arrays, second thing you coupd use one array with all data you need problem is that you can outrun the attribute count (position, texcoord, point size, color etc you imagine), by point size you need to find information about gl_pointsize of glsl which you take into account hiwever you could create 4 times karger.buffer and update that….. ir use geometry shader.. still not convinient…

But how do I make the square points round?

How about adding a transparency float to your vertex layout, passing that on to the fragment shader or whatever it's called in OpenGL and output it as alpha component…

.:vinterberg:.

CommanderLake said:

Contrary to what I just said, I do need to change the point size which I can do but now the points are square rather than round and PointSmooth has been deprecated, how do I make the points round?

Add some sort of texture coordinate to your squares vertices. Depending on the range you chose, you can calculate if a fragment lies inside a circle or not. If not, just call “discard” in the fragment shader to drop a pixel. Alternatively, you can use an alpha channel as suggested by vinterberg, but that requires additional setup.

Greetings

Advertisement

This was so much easier with the old code where I could have nice fuzzy circles, all I needed was a colour parameter for each point and now the seemingly trivial task of making them round seems impossible from my perspective.

I feel like I'm translating the works of Shakespeare to Klingon.

Here is my vertex shader:

#version 450 core
layout(location = 0) in vec4 position;
layout(location = 1) in vec4 color;
out vec4 vs_color;
void main(void){
	gl_Position = position;
	vs_color = color;
}

and here is my fragment shader:

#version 450 core
in vec4 vs_color;
out vec4 color;
void main(void){
	color = vs_color;
}

What does the old code do to make the points round?

CommanderLake said:
but now the points are square rather than round and PointSmooth has been deprecated, how do I make the points round?

You could also generate a circular mesh, and then use instancing to render that mesh once for each point. I do this to render starfields - it's pretty efficient on modern hardware.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This works quite well for me but they don't shade very well when just 2 or 3 pixels in size:

#version 450
in vec4 vs_color;
out vec4 color;
void main(void){
	color = vs_color;
 	float len = length(gl_PointCoord - vec2(0.5))*2;
	color.a *= smoothstep(len, len*1.1, 1.0);
}

This topic is closed to new replies.

Advertisement