我有一个关于光线追踪中区域照明的问题。我正在学习Ray Tracing from the Ground Up,当没有抗锯齿时,我的区域光结果如下所示:
。你可以看到图像中有很多噪点。当我应用抗锯齿时,它看起来不错,当应用256x抗锯齿时,它看起来像这样:
![NO AA](https://istack.dev59.com/0LW3Q.webp)
[阴影颜色的变化微不足道,我改变了一些阴影属性]
我的问题是,这是区域光的行为方式还是我做错了什么?因为渲染第一个只需要4秒,但后一个却需要近20分钟。感觉有些不对劲。
我的点光源类和区域光源类之间唯一的区别是get_direction
函数。
点光源的get_direction
函数:
virtual Vec get_direction(ShadeRec& sr)
{
return Vec(position.x-sr.hit_point.x, position.y-sr.hit_point.y, position.z-sr.hit_point.z).norm();
}
Area Light的get_direction
函数:
virtual Vec get_direction(ShadeRec& sr)
{
Vec newLocation;
newLocation.x = position.x + radius * (2.0 * rand_float() - 1.0);
newLocation.y = position.y + radius * (2.0 * rand_float() - 1.0);
newLocation.z = position.z + radius * (2.0 * rand_float() - 1.0);
return ((newLocation - sr.hit_point).norm());
}