'orthographic projection in raytracing

i have a working perspective projection based ray tracing renderer in vulkan, i want to convert it into an orthographic projection, i tried replacing the perspective projection matrix by orthographic projection matrix and taking the ray origin as the pixel coordinates, but it seems to have not working, clearly something is wrong.

    uint randSeed = initRand(gl_LaunchIDEXT.x + gl_LaunchIDEXT.y * gl_LaunchSizeEXT.x, ubo.frameID, 16);

    //vec4 origin           = ubo.viewInverse * vec4(0.0, 0.0, 0.0, 1.0); //for perpective
    vec4 origin         = ubo.viewInverse * vec4(gl_LaunchIDEXT.x, gl_LaunchIDEXT.y, 0.0,  1.0); //for ortho

    // ---- [Apply jitter to anti alias] ---- 
    vec2 jitter         = vec2(nextRand(randSeed), nextRand(randSeed)) - 0.5;
    //vec4 target           = ubo.projInverse * vec4((gl_LaunchIDEXT.xy + jitter) / gl_LaunchSizeEXT.xy * 2.0 - 1.0, 0.0, 1.0); //for perpective
    vec4 target = ubo.orthoInverse * vec4((gl_LaunchIDEXT.xy + jitter) / gl_LaunchSizeEXT.xy * 2.0 - 1.0, 0.0, 1.0); //for ortho
    vec4 direction = ubo.viewInverse * vec4(normalize(target.xyz), 0.0);

i am calculating the orthographic matrix using glm::ortho function, i also tried calculating using the below code, but i am not getting the desired result -

// set the OpenGL orthographic projection matrix
void glOrtho(
    in float b, in float t, in float l, in float r,
    in float n, in float f,
    inout mat4 M)
{
    // set OpenGL perspective projection matrix
    M[0][0] = 2 / (r - l);
    M[0][1] = 0;
    M[0][2] = 0;
    M[0][3] = 0;

    M[1][0] = 0;
    M[1][1] = 2 / (t - b);
    M[1][2] = 0;
    M[1][3] = 0;

    M[2][0] = 0;
    M[2][1] = 0;
    M[2][2] = -2 / (f - n);
    M[2][3] = 0;

    M[3][0] = -(r + l) / (r - l);
    M[3][1] = -(t + b) / (t - b);
    M[3][2] = -(f + n) / (f - n);
    M[3][3] = 1;
}

How to solve this issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source