tunabrain / tungsten

High performance physically based renderer in C++11

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

the default far plane, near plane, and clip coordinates

IwakuraRein opened this issue · comments

commented

Hello! I'm still learning computer graphics. I want to try reprojection in the TAA algorithm:

where p is the pixel's homogeneous coordinate:

Therefore, I need to get the view matrix and projection matrix. The up, look at, and camera position can be found in JSON, but I still don't know the far plane and near plane to compute the projection matrix. I noticed that the far plane and near plane in the PreviewWindow.hpp are 100 and 0.01. Are the values the same inside the renderer?

Also, I'm not sure about the component z of the coordinate. I've made tungsten outputted depth buffers, but I don't know how to normalize them. Is the range of z (-1, 1), or (0, 1)? I guess z is somewhat like depth_buffer / (far - near). Am I correct?

Thanks.

Because Tungsten is a raytracer, it does not use a projection matrix internally and does not have a far/near plane per se. There is a de-facto near and far plane that are imposed by floating point precision, which are effectively 1e-4f for near and 1e30f for far, although those are not values you would want to use in a projection matrix :)
The values in PreviewWindow.hpp are only for the real-time preview inside the editor and are not used for actual rendering.

The depth buffers output by Tungsten are linear-depth (distance from the camera - not Z!), so there is no need to transform the values as you would in a hardware depth buffer.

commented

Because Tungsten is a raytracer, it does not use a projection matrix internally and does not have a far/near plane per se. There is a de-facto near and far plane that are imposed by floating point precision, which are effectively 1e-4f for near and 1e30f for far, although those are not values you would want to use in a projection matrix :)
The values in PreviewWindow.hpp are only for the real-time preview inside the editor and are not used for actual rendering.

The depth buffers output by Tungsten are linear-depth (distance from the camera - not Z!), so there is no need to transform the values as you would in a hardware depth buffer.

Thanks. I kind of mixed up rasterization and ray tracing.

I noticed that there is a transform matrix inside tungsten:

    float t = 1.0f/std::tan(Angle::degToRad(fov)*0.5f);
    float a = (far + near)/(far - near);
    float b = 2.0f*far*near/(far - near);
    float c = t/ratio;

    return Mat4f(
           c, 0.0f,  0.0f, 0.0f,
        0.0f,    t,  0.0f, 0.0f,
        0.0f, 0.0f,     a,   -b,
        0.0f, 0.0f,  1.0f, 0.0f

Tungsten uses it to multiply (u, v, cot(θ/2)) to decide a primitive ray's direction. So I reverse this process to get UV coordinates of world space coordinates. This time I successfully finished my 'reprojection' task.