gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:08:44 25 4
gpt4 key购买 nike

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

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