【问题标题】:How to make OpenGL camera and Ray-tracer camera show the same image?如何使 OpenGL 相机和 Ray-tracer 相机显示相同的图像?
【发布时间】:2016-10-07 12:29:43
【问题描述】:

我正在编写一个简单的路径跟踪器,我想使用 OpenGL 进行预览。 但由于 OpenGL 管道使用投影矩阵,因此使用 OpenGL 渲染的图像和路径跟踪有点不同。

对于 OpenGL 渲染,我使用基本管道,其中最终的转换矩阵是:

m_transformation = PersProjTrans * CameraRotateTrans * CameraTranslationTrans * TranslationTrans * RotateTrans * ScaleTrans

透视投影的参数为:45.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 0.01, 10000.0f

在我的路径追踪器中,我会像这样从相机生成光线:

m_width_recp = 1.0 /0m_width;
m_height_recp = 1.0 / m_height;
m_ratio = (double)m_width / m_height;

m_x_spacing = (2.0 * m_ratio) / (double)m_width;
m_y_spacing = (double)2.0 / (double)m_height;
m_x_spacing_half = m_x_spacing * 0.5;
m_y_spacing_half = m_y_spacing * 0.5;

x_jitter = (Xi1 * m_x_spacing) - m_x_spacing_half;
y_jitter = (Xi2 * m_y_spacing) - m_y_spacing_half;

Vec pixel = m_position + m_direction * 2.0;
pixel = pixel - m_x_direction * m_ratio + m_x_direction * (x * 2.0 * m_ratio * m_width_recp) + x_jitter;
pixel = pixel + m_y_direction - m_y_direction*(y * 2.0 * m_height_recp + y_jitter);

return Ray(m_position, (pixel-m_position).norm());

这里是由 OpenGL (1) 和 Path Tracer(2) 渲染的图像。

问题在于场景和相机之间的距离。我的意思是,它不是一成不变的。在某些情况下,路径跟踪器图像看起来“更接近”对象,在某些情况下反之亦然。

我在谷歌上没有找到任何东西。

【问题讨论】:

    标签: opengl 3d camera render raytracing


    【解决方案1】:

    反转用于 OpenGL 渲染的视图-投影矩阵,并使用它将屏幕像素位置转换为光线追踪器的光线。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-14
      • 2021-02-26
      • 1970-01-01
      • 1970-01-01
      • 2019-04-10
      • 2012-01-27
      • 1970-01-01
      相关资源
      最近更新 更多