如何改变 OpenGL glBegin(GL_POINTS) 中的点大小?
绘制大量点时有什么方法可以改变点的大小吗?我知道有 glPointSize(float),但是有没有办法在“批量”或数组中做到这一点?
我希望这些点根据数据的属性具有不同的大小。比如每个点都有x、y、z和一个尺寸属性。我现在在java中使用帧缓冲区。
我可以为此使用顶点着色器吗?
Is there any way to vary the point size when drawing lots of points? I know there's the glPointSize(float), but is there a way to do it in a 'batch' or array?
I would like the points to have different sizes based on an attribute of the data. Such as each point having x, y, z, and a size attribute. I'm using frame buffers right now in java.
Could I possibly use vertex shaders for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用点精灵:使用
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
启用它,然后您可以在顶点程序中使用gl_PointSize
属性。顶点着色器示例取自 OpenGL 讨论线程:
You can use point sprite: enable it using
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
and then you can usegl_PointSize
attribute in your vertex program.Vertex shader example taken from an OpenGL discussion thread:
这就是我曾经做过的事
This was what I ever did,
我相信它与 glPointSize(GLfloat size)
来源:
I believe it's with glPointSize(GLfloat size)
Source:
使用 GL_POINT_DISTANCE_ATTENUATION (GL14?),您可以设置函数的系数(我认为它是二次函数),用于从 Z 距离计算点大小。
With
GL_POINT_DISTANCE_ATTENUATION
(GL14?) you can set the coefficients for a function (I think it's quadratic) for computing point size from Z distance.增加和减少点大小会影响多个像素,但着色器每个像素仅运行一次。它会失败,因为一旦对特定像素运行了着色器程序,更改是否只能影响后面的像素,而不影响前面的像素。
着色器程序同时在许多着色器单元上运行,并且对于许多像素并行运行,因此无法执行您想要执行的操作。限制是可以使用着色器程序设置像素大小,但它将保留着色器程序运行的所有像素的大小。
您可以尝试按大小对点数据进行排序,并将相同大小的点分组到一个数组中,并使用不同的点大小绘制每个数组。
或者,您可以尝试使用间接方式进行此操作,首先将不同的点大小渲染到纹理中,然后在第二遍中通过访问纹理数据并使用它来测试是否应该渲染像素来渲染像素。
Increasing and decreasing the point size affects more than one pixel, but shaders are meant to be run only once per pixel. It will fail, because once the shader program has been run for a particular pixel, can the change only affect the following pixels, but not the previous pixels.
Shader programs are run on many shader units simultaneously and for many pixels in parallel making it impossible to do what you are trying to do. The limitation will be that one can set the pixel size with a shader program, but it will keep its size for all pixels the shader program gets run.
You could try to sort your point data by size and group points of the same size into one array and draw each array with a different point size.
Or you could try doing it with an indirection where you first render the different point sizes into a texture and in a second pass render the pixels by accessing the texture data and using it to test if a pixel should be rendered (or not).