相关疑难解决方法(0)

为什么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 …
Run Code Online (Sandbox Code Playgroud)

c++ geometry raytracing intersection

8
推荐指数
1
解决办法
2180
查看次数

标签 统计

c++ ×1

geometry ×1

intersection ×1

raytracing ×1