0
votes

I am writing a simple path tracer and I want to make a preview with OpenGL. But since OpenGL pipeline use the projection matrix, images rendered with OpenGL and Path tracing are a bit different.

For OpenGL rendering I use the basic pipeline, where the final transformation matrix is:

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

Parameters for perspective projection are: 45.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 0.01, 10000.0f.

And in my path tracer I generate rays from camera like this:

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());

Here are images rendered by OpenGL (1) and Path Tracer(2). enter image description here enter image description here

The problem is the distance between the scene and the camera. I mean, it's not constant. In some cases the path tracer image looks "closer" to the objects and in some cases vise versa.

I haven't found anything in google.

1

1 Answers

1
votes

Invert the view-projection matrix as used for OpenGL rendering and use that to transform screen pixel positions into rays for your ray tracer.