gpt4 book ai didi

opengl - gl_PointSize 如何工作

转载 作者:行者123 更新时间:2023-12-04 22:48:41 24 4
gpt4 key购买 nike

来自 DX 背景,我试图理解 gl_PointSize 和 gl_PointCoord 究竟是什么/如何工作。我在网上和手册页上搜索过,但没有对它们做出很好的解释。假设我有一个 300x300 的输出缓冲区,我定义了一个具有 90,000 个点的顶点着色器,对应于 300x300 缓冲区中的每个位置(每个维度的增量为 1)。现在在顶点着色器中,如果我将 gl_PointSize 定义为 2,它会调用片段着色器 90,000 次还是 360,000 次?如果是 360,000 次,我可以理解 gl_PointCoord 代表什么。但如果它只是 90,000 次,那是否意味着每个片段输出就代表 4 个像素?在这种情况下,gl_PointCoord 代表什么?它不会总是 0.5,0.5 而不是真的有用吗??

谢谢

最佳答案

OpenGL 4.5 core profile specification的第14.4.1节“基本点光栅化”状态:

Point rasterization produces a fragment for each framebuffer pixel whose center lies inside a square centered at the point’s (xw; yw), with side length equal to the current point size.



因此,在点大小 > 1 的情况下,可能会生成多个片段。每个片段至少调用一次片段着色器。如果我们将多重采样排除在图片之外,它会在每个片段中调用一次,因此 360,000 次是正确答案。

请注意,这也忽略了早期深度测试,它可能会或可能不会在您描述的场景中发挥作用,因为它可能会在调用 FS 之前丢弃片段。

来自规范的同一部分:

All fragments produced in rasterizing a point sprite are assigned the same associated data, which are those of the vertex corresponding to the point. However, the fragment shader built-in gl_PointCoord contains point sprite texture coordinates. The s point sprite texture coordinate varies from zero to one across the point horizontally left-to-right. If POINT_SPRITE_COORD_ORIGIN is LOWER_LEFT, the t coordinate varies from zero to one vertically bottom-to-top. Otherwise if the point sprite texture coordinate origin is UPPER_LEFT, the t coordinate varies from zero to one vertically top-to-bottom. [...]



所以点坐标确实代表了你期望它代表的东西。请注意,此定义意味着即使点大小为 1 且未使用多重采样,点坐标也不一定总是以 0.5 结束。在这种情况下,会为像素中心调用片段着色器,但该点可能不完全位于像素中心,因此您将看到正在采样的 1x1 像素大点的确切位置。

关于opengl - gl_PointSize 如何工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32193019/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com