在过去的几天里,我第一次破解了光线追踪器。然而,有一些怪癖困扰着我,我真的不知道如何锻炼。从一开始就存在的一个是场景中球体的形状 - 渲染时,它们实际上看起来像椭圆形。当然,场景中有透视,但最终的形状仍然显得奇怪。我附上了渲染示例,我遇到的问题在图像左下部分的反射球体上尤其明显。
我真的不知道是什么原因造成的。它可能是射线球相交的代码,如下所示:
bool Sphere::intersect(Ray ray, glm::vec3& hitPoint) {
//Compute A, B and C coefficients
float a = glm::dot(ray.dir, ray.dir);
float b = 2.0 * glm::dot(ray.dir, ray.org-pos);
float c = glm::dot(ray.org-pos, ray.org-pos) - (rad * rad);
// Find discriminant
float disc = b * b - 4 * a * c;
// if discriminant is negative there are no real roots, so return
// false as ray misses sphere
if (disc < 0)
return false;
// compute q
float distSqrt = sqrt(disc);
float q;
if (b < 0)
q = (-b - distSqrt)/2.0;
else
q = (-b + distSqrt)/2.0;
// compute t0 and t1
float t0 = q / a;
float t1 = c / q;
// make sure t0 is smaller than t1
if (t0 > t1) {
// if t0 is bigger than t1 swap them around
float temp = t0;
t0 = t1;
t1 = temp;
}
// if t1 is less than zero, the object is in the ray's negative direction
// and consequently the ray misses the sphere
if (t1 < 0)
return false;
// if t0 is less than zero, the intersection point is at t1
if (t0 < 0) {
hitPoint = ray.org + t1 * ray.dir;
return true;
} else { // else the intersection point is at t0
hitPoint = ray.org + t0 * ray.dir;
return true;
}
}
或者也可能是另一回事。有人有想法吗?非常感谢!
看来您正在使用非常宽的视野 http://en.wikipedia.org/wiki/Field_of_view_in_video_games(视场)。这会产生鱼眼镜头的效果,使图像扭曲,尤其是边缘。通常,90 度(即任一方向 45 度)之类的角度可以提供合理的图像。
折射实际上看起来相当不错;它是倒置的,因为折射率非常高。好看的图片都在这个问题 https://stackoverflow.com/questions/13386003/glsl-refraction-getting-mapped-upside-down.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)