在過去的幾天裏,我一直在黑客中第一次使用光線跟蹤器。然而,有一些怪癖困擾着我,我真的不知道如何解決。從一開始就一直存在的是場景中的球體形狀 - 渲染時,它們看起來像橢圓形。當然,這個場景是有角度的,但最終的形狀仍然很古怪。我附加了一個示例渲染,我所遇到的問題在圖像左下角的反射球體上特別明顯。爲什麼raytracer渲染球體爲橢圓形?
我真的不知道這可能是導致此。它可能是射線球形十字路口代碼,如下所示:
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;
}
}
或者它可能是另一回事。有人有想法嗎?非常感謝!
此外,我也有感覺我的折射是關閉的(見右邊的球體,折射率是1.8)。你們同意嗎? – user1845810
當你只在屏幕中心渲染一個球時會發生什麼 – OopsUser