나는 지난 며칠 동안 처음으로 레이 트레이서를 해킹 해왔다. 그러나, 저를 괴롭히는 몇 가지 단점이 있으며 실제로 해결 방법을 모르겠습니다. 처음부터 거기에 있었던 것은 장면의 구체의 모양입니다. 렌더링 될 때 실제로는 타원처럼 보입니다. 물론 장면에는 원근법이 있지만 최종 모양은 여전히 이상하게 보입니다. 샘플 렌더링을 첨부했습니다. 문제는 이미지 왼쪽 하단의 반사 구체에서 특히 볼 수 있습니다.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