ray tracing view transform
October 22, 2020Less than 1 minute
ray tracing view transform
they will project any point on
a given pixel’s viewing ray back to that pixel’s position in image space
float ndcPixelx = (0.5f + i) / (scene.width * 1.f);
float ndcPixely = (0.5f + j) / (scene.height * 1.f);
// screen [-1,1],keep y > 0
// screen orgin is the center
// ndc、raster orgin is the left-top
float screenPixelx = 2 * ndcPixelx - 1;
float screenPixely = 1 - 2 * ndcPixely;
// world space
// camera-to-world matrix
float tanFov = (float)tan(scene.fov / 2 * M_PI / 180);
float cameraPixelx = screenPixelx * imageAspectRatio * tanFov;
float cameraPixely = screenPixely * tanFov;