离屏渲染时像素到顶点的坐标

Pixel to Vertex coordinate during off-screen rendering

我正在绘制一组用纯色填充到屏幕外纹理的三角形。

我的问题是结果图像中的三角形太大,看起来像这样:

我的顶点坐标以像素为单位。 (我只是将它们生成为 (0, outTexture.width/height) 中的随机浮点数)。我没有将它们乘以我的顶点函数中的任何投影(也许这是我的错误?)

所以我的问题是顶点坐标如何与像素坐标相关联?

解决方案是制作正射投影并将其作为统一传递。

这是对我有用的代码:

func makeOrthographicMatrix(left: Float, right: Float, bottom: Float, top: Float, near: Float, far: Float) -> [Float] {
    let ral = right + left
    let rsl = right - left
    let tab = top + bottom
    let tsb = top - bottom
    let fan = far + near
    let fsn = far - near

    return [2.0 / rsl,  0.0,        0.0,        0.0,
            0.0,        2.0 / tsb,  0.0,        0.0,
            0.0,        0.0,        -2.0 / fsn, 0.0,
            -ral / rsl, -tab / tsb, -fan / fsn, 1.0]
}

我是这样称呼它的:

var projection = makeOrthographicMatrix(0.0, right: Float(inTexture.width), bottom: 0.0, top: Float(inTexture.height), near: -1.0, far: 1.0)