Why does raytracer render spheres as ovals?

三世轮回 提交于 2019-12-06 23:52:24

问题


I've been hacking up a raytracer for the first time over the past few days. However, there are a few quirks which bother me and I don't really know how to work out. One that has been there since the beginning is the shape of spheres in the scene - when rendered, they actually look like ovals. Of course, there is perspective in the scene, but the final shape still seems odd. I have attached a sample rendering, the problem I have is especially visible on the reflective sphere in the lower left part of the image.

I don't really know what could be causing this. It might be the ray-sphere intersection code which looks as follows:

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;
    }
}

Or it could be another thing. Does anyone have an idea? Thanks so much!


回答1:


It looks like you're using a really wide field of view (FoV). This gives the effect of a fish-eye lens, distorting the picture, especially towards the edges. Typically something like 90 degrees (i.e. 45 degrees in either direction) gives a reasonable picture.

The refraction actually looks quite good; it's inverted because the index of refraction is so high. Nice pictures are in this question.



来源:https://stackoverflow.com/questions/14074643/why-does-raytracer-render-spheres-as-ovals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!