我试图了解当附加 [[position]] 限定符时 float4 在片段着色器中是如何改变的。我试图通过相同的位置,一次使用限定器,一次不使用,片段着色器中的结果完全不同。
最佳答案
顶点着色器的 [[position]]
输出是标准化的设备坐标。片段着色器的 [[position]]
输入在窗口坐标中。 (“窗口”坐标有点用词不当。它们是渲染目标附件边界内的坐标,以像素为单位。)它们之间的关系是已设置的视口(viewport)。 (如果没有显式设置视口(viewport),则使用附件的边界。)
Metal Programming Guide: Graphics Rendering: Render Command Encoder :
Working with Viewport and Pixel Coordinate Systems
Metal defines its Normalized Device Coordinate (NDC) system as a 2x2x1 cube with its center at (0, 0, 0.5). The left and bottom for x and y, respectively, of the NDC system are specified as -1. The right and top for x and y, respectively, of the NDC system are specified as +1.
The viewport specifies the transformation from NDC to the window coordinates. The Metal viewport is a 3D transformation specified by the
setViewport:
method ofMTLRenderCommandEncoder
. The origin of the window coordinates is in the upper-left corner.
对于其他顶点输出,到片段着色器输入的转换取决于采样和插值限定符。如果未指定限定符,则默认为 center_perspective
。以 _perspective
结尾的限定符使用透视校正插值。那些以 _no_perspective
结尾的使用线性插值。那些使用 flat
说明符的不被插值;来自图元的激发(即第一个)顶点的值被原封不动地传递给片段着色器。
关于iOS Metal - 当发送到片段着色器时,带有 [[position]] 限定符的位置会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43570917/