光线追踪中的正交投影
我在 vulkan 有一个基于透视投影的光线追踪渲染器,我想将其转换为正交投影,我尝试用正交投影矩阵替换透视投影矩阵,并将光线原点作为像素坐标,但似乎没有工作,显然有些问题。
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);
我正在使用 glm::ortho 函数计算正交矩阵, 我也尝试使用下面的代码进行计算,但我没有得到所需的结果 -
// 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;
}
如何解决这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论