开发者

Reverse perspective (Byzantine) projection, Vulkan

I am trying to render an object using inverse/revers/byzantine projection. To that effect I have tried both finding the formula or deriving it.

Scouting the web I found this: https://math.stackexchange.com/questions/3677516/what-is-the-projection-matrix-of-reverse-byzantine-perspective

That seemed correct although the mathematical proof seems to be obtuse so I didn't follow it to the end. That lead me to this hard coded function (orinagl, regular perspective code added as a comment):

fn perspective(fov : Float, aspect : Float, z_near : Float, z_far : Float) -> Mat4
{
    // debug_assert!(aspect > Float::MIN_POSITIVE, "");

    // let tan_half_fovy = Float::tan(fov / 2.0);

    // let mut result = Mat4::zeros();
    // result[(0, 0)] = 1.0 / (aspect * tan_half_fovy);
    // result[(1, 1)] = 1.0 / (tan_half_fovy);
    // result[(2, 2)] = -(z_far + z_near) / (z_far - z_near);
    // result[(2, 3)] = -(2.0 * z_far * z_near) / (z_far - z_near);
    // result[(3, 2)] = -1.0;

    // return result;

    let mut result = Mat4::zeros();
    result[(0, 0)] = 2.0 / 800.0;
    result[(1, 1)] = 2.0 / 800.0;
    result[(2, 2)] = 2.0 / (z_far - z_near);
    result[(2, 3)] = -(z_far + z_near) / (z_far - z_near);
    result[(3, 2)] = 2.0 / (z_near - z_far);
    result[(3, 3)] = (z_far + z_near) / (z_nea开发者_如何学Pythonr - z_far);

    return result;
}

This does not seem to work, when I try to render I get nothing, as if everything was clipped. I verified in renderdoc and no polygon is visible after the projection. So I tried re-deriving the matrix instead.

I got up to here:

Reverse perspective (Byzantine) projection, Vulkan

where n, f are the far and near distance planes, w and h are the width and height of the screen.

The above is an orthogonal projection matrix. It maps z to the range [0, 1]. The issue now is, the regular perspective matrix sets the w component of the final answer to -z, that way the implicit division of homogeneous coordinates multiplies the entire final vector by (1/z), making things smaller the further away they are from the screen. But I want the opposite effect so I would need to set the coordinate to 1/z so that things get multiplied instead. But this cannot be done with matrix operations alone, and yet it seems to me it should be possible to express the inverse camera as a matrix.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜