我有一个用C ++实现的简单光线跟踪器。我正在做的是实现一个抗混叠滤波器,如第230页所述:
http://www.cs.utah.edu/~shirley/books/fcg2/rt.pdf
我正在使用带有16个常规样本的4x4网格,但结果有点奇怪:
普通光线追踪器
具有抗锯齿功能的光线跟踪器
我无法弄清楚为什么会遇到这种问题..你可以帮助我吗?提前谢谢!
编辑:这里有一些代码:
int RAY_DISTRIBUTION = 4;
Vec3<float> px_color;
for (int i = 0; i < WINDOW_WIDTH; i++)
{
for (int j = 0; j < WINDOW_HEIGHT; j++)
{
for (int k = 0; k < RAY_DISTRIBUTION; k++)
{
for (int l = 0; l < RAY_DISTRIBUTION; l++)
{
Vec3<float> rayDir = camera->pixelToWorld(i, j, (k + 0.5f) / RAY_DISTRIBUTION, (l + 0.5f) / RAY_DISTRIBUTION, 0, 0) - camera->position;
px_color = px_color + distributedRayTracer->trace(camera->position, rayDir, 0) * 255; //remap to [0,255]
}
}
px_color = px_color / pow(RAY_DISTRIBUTION, 2);
g_image->setPixel(i, j, qRgb(px_color.x, px_color.y, px_color.z));
}
}
Vec3<T> pixelToWorld(int i, int j, T offset_x, T offset_y, T jitter_dx, T jitter_dy)
{
float fov = 30;
float angle = tan(PI * 0.5 * fov / 180.);
T remapped_x = (2 * ((i + offset_x + jitter_dx) / WINDOW_WIDTH) - 1) * angle * (WINDOW_WIDTH / WINDOW_HEIGHT);
T remapped_y = (1 - 2 * ((j + offset_y + jitter_dy) / WINDOW_HEIGHT)) * angle;
Vec3<T> w = position - lookAt;
w.normalize();
Vec3<T> u = up.cross(w);
u.normalize();
Vec3<T> v = w.cross(u);
v.normalize();
Vec3<T> transf = -u*remapped_x + v*remapped_y - w;
transf.normalize();
return position + transf;
}