iOS Metal - 当发送到片段着色器时,带有 [[position]] 限定符的位置会发生什么?

标签 ios metal

我试图了解当附加 [[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 of MTLRenderCommandEncoder. 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/

相关文章:

ios - 以编程方式设置 UIButton 的中心 - SWIFT

将 Core Image Kernel Language 函数转换为 Metal Shading Language

opengl-es - 在 SCNShadable 入口点之间传递值

metal - 从内核检索结果

ios - 无法使用新数据更新单元格为 (cell!=nil)

objective-c - 如何在 iOS 中创建不使用图像的动画启动画面

ios - 使用 Metal/OpenGL ES 在 iOS 中渲染视频

ios - computeFunction 不能为 nil 报错

android - 为什么应用程序使用推送通知而不是 VPN(虚拟专用网络)?

iOS Autolayout 相同宽度约束