英文:
Draw full screen quad in vertex shader
问题
// 从Apple Metal文档中找到了这个示例代码。这个顶点着色器如何使用3个顶点绘制一个全屏四边形?
// 在设置管道状态后绘制命令
renderEncoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: 3)
typedef struct {
float4 position [[position]];
half3 worldNormal;
} ColorInOut;
/// 一个生成全屏四边形的顶点函数。
vertex ColorInOut quadPassVertex(uint vid[[vertex_id]])
{
ColorInOut out;
float4 position;
position.x = (vid == 2) ? 3.0 : -1.0;
position.y = (vid == 0) ? -3.0 : 1.0;
position.zw = 1.0;
out.position = position;
return out;
}
英文:
I came across this sample code from Apple Metal documentation. How does this vertex shader draw a full screen quad using 3 vertices ?
// Draw command after setting pipeline state
renderEncoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: 3)
typedef struct {
float4 position [[position]];
half3 worldNormal;
} ColorInOut;
/// A vertex function that generates full screen quad pass.
vertex ColorInOut quadPassVertex(uint vid[[vertex_id]])
{
ColorInOut out;
float4 position;
position.x = (vid == 2) ? 3.0 : -1.0;
position.y = (vid == 0) ? -3.0 : 1.0;
position.zw = 1.0;
out.position = position;
return out;
}
答案1
得分: 1
所绘制的三角形覆盖了归一化设备坐标的整个区间[-1, 1],无论是在x轴还是y轴方向。三角形超出[-1, 1]范围的额外部分会在管道的后续阶段进行裁剪。
英文:
The triangle that's drawn covers the whole normalized device coordinates [-1, 1] in both x and y directions. The extra area of the triangle that's outside the [-1, 1] bounds gets clipped in later stages of the pipeline.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论