为什么剪刀测试落后于片段操作?
Why is scissor test behind fragment operation?
如果我没理解错的话,剪刀测试是针对每个片段操作的,但我想知道是否可以将测试放在片段着色器之前,这样剪刀框外的片段就不需要着色,甚至可以放在光栅化器之前?
我能想到的不这样做的唯一原因是剪掉清晰的颜色。
剪刀测试几乎在任何现实世界场景中都会影响光栅化本身。 GPU 的光栅化器单元不会在剪刀矩形之外产生片段。首次创建 OpenGL 管道时,片段着色器并不存在。在 GL 规范的早期版本中,纹理映射之类的东西被认为是光栅化阶段的一部分。
但是,这个概念管道并不是实际的 HW 实现的。只要最终结果不会被偏离的实现改变,这就没有问题。
你通常会看到,比剪刀测试更重要的是,在调用片段着色器之前也会执行深度测试("early Z")。只要片段着色器不修改片段的深度值,这就会起作用。通常,只要片段着色器中没有对 gl_FragDepth
的赋值,该实现就会在您背后自动启用早期 Z。
现代版本的 GL 规范明确提到了 "early" 测试。 OpenGL 4.5 core profile specification 状态的第 14.9 "Early Per-Fragment Tests" 节(强调我的):
Once fragments are produced by rasterization, a number of per-fragment
operations may be performed prior to fragment shader execution (see
section 15). If a fragment is discarded during any of these
operations, it will not be processed by any subsequent stage,
including fragment shader execution. Up to five operations are
performed on each fragment, in the following order:
- the pixel ownership test (see section 17.3.1);
- the scissor test (see section 17.3.2);
- the stencil test (see section 17.3.5);
- the depth buffer test (see section 17.3.6); and
- occlusion query sample counting (see section 17.3.7).
The pixel ownership and scissor tests are always performed. The other operations are performed if and only if early fragment tests are enabled
in the active fragment shader (see section 15.2). [...]
所以实际上,"late" scissor 测试实际上不再存在于 GL 中,即使同一文档中的管道图仍然在片段着色器之后列出它。
如果我没理解错的话,剪刀测试是针对每个片段操作的,但我想知道是否可以将测试放在片段着色器之前,这样剪刀框外的片段就不需要着色,甚至可以放在光栅化器之前? 我能想到的不这样做的唯一原因是剪掉清晰的颜色。
剪刀测试几乎在任何现实世界场景中都会影响光栅化本身。 GPU 的光栅化器单元不会在剪刀矩形之外产生片段。首次创建 OpenGL 管道时,片段着色器并不存在。在 GL 规范的早期版本中,纹理映射之类的东西被认为是光栅化阶段的一部分。
但是,这个概念管道并不是实际的 HW 实现的。只要最终结果不会被偏离的实现改变,这就没有问题。
你通常会看到,比剪刀测试更重要的是,在调用片段着色器之前也会执行深度测试("early Z")。只要片段着色器不修改片段的深度值,这就会起作用。通常,只要片段着色器中没有对 gl_FragDepth
的赋值,该实现就会在您背后自动启用早期 Z。
现代版本的 GL 规范明确提到了 "early" 测试。 OpenGL 4.5 core profile specification 状态的第 14.9 "Early Per-Fragment Tests" 节(强调我的):
Once fragments are produced by rasterization, a number of per-fragment operations may be performed prior to fragment shader execution (see section 15). If a fragment is discarded during any of these operations, it will not be processed by any subsequent stage, including fragment shader execution. Up to five operations are performed on each fragment, in the following order:
- the pixel ownership test (see section 17.3.1);
- the scissor test (see section 17.3.2);
- the stencil test (see section 17.3.5);
- the depth buffer test (see section 17.3.6); and
- occlusion query sample counting (see section 17.3.7).
The pixel ownership and scissor tests are always performed. The other operations are performed if and only if early fragment tests are enabled in the active fragment shader (see section 15.2). [...]
所以实际上,"late" scissor 测试实际上不再存在于 GL 中,即使同一文档中的管道图仍然在片段着色器之后列出它。