iOS Metal - 当发送到片段着色器时,带有 [[position]] 限定符的位置会发生什么?
iOS Metal - what happens to a position with [[position]] qualifier when sent to fragment shader?
我试图了解当 [[position]] 限定符附加到 float4 时片段着色器中的 float4 是如何改变的。我试图通过相同的位置,一次使用限定器,一次不使用,片段着色器中的结果完全不同。
顶点着色器的 [[position]]
输出是标准化的设备坐标。片段着色器的 [[position]]
输入在 window 坐标中。 ("Window" 坐标有点用词不当。它们是渲染目标附件边界内的坐标,以像素为单位。)它们之间的关系是已设置的视口。 (如果未明确设置视口,则使用附件的边界。)
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 of MTLRenderCommandEncoder
. The origin of
the window coordinates is in the upper-left corner.
对于其他顶点输出,到片段着色器输入的转换取决于采样和插值限定符。如果未指定限定符,则默认为 center_perspective
。以 _perspective
结尾的限定符使用透视校正插值。以 _no_perspective
结尾的使用线性插值。那些使用 flat
说明符的不被插值;图元的激发(即第一个)顶点的值不变地传递给片段着色器。
我试图了解当 [[position]] 限定符附加到 float4 时片段着色器中的 float4 是如何改变的。我试图通过相同的位置,一次使用限定器,一次不使用,片段着色器中的结果完全不同。
顶点着色器的 [[position]]
输出是标准化的设备坐标。片段着色器的 [[position]]
输入在 window 坐标中。 ("Window" 坐标有点用词不当。它们是渲染目标附件边界内的坐标,以像素为单位。)它们之间的关系是已设置的视口。 (如果未明确设置视口,则使用附件的边界。)
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
说明符的不被插值;图元的激发(即第一个)顶点的值不变地传递给片段着色器。