c – 为什么光线跟踪器将球体渲染为椭圆形?

c – 为什么光线跟踪器将球体渲染为椭圆形?,第1张

概述在过去的几天里,我第一次一直在攻击光线跟踪器.然而,有一些困扰我的怪癖,我真的不知道如何解决.从一开始就存在的是场景中球体的形状 – 渲染时,它们实际上看起来像椭圆形.当然,场景中有透视,但最终的形状看起来仍然很奇怪.我附上了一个样本渲染,我所遇到的问题在图像左下角的反射球上特别明显. 我真的不知道是什么原因引起的.它可能是光线球体交叉代码,如下所示: bool Sphere::intersect 在过去的几天里,我第一次一直在攻击光线跟踪器.然而,有一些困扰我的怪癖,我真的不知道如何解决.从一开始就存在的是场景中球体的形状 – 渲染时,它们实际上看起来像椭圆形.当然,场景中有透视,但最终的形状看起来仍然很奇怪.我附上了一个样本渲染,我所遇到的问题在图像左下角的反射球上特别明显.

我真的不知道是什么原因引起的.它可能是光线球体交叉代码,如下所示:

bool Sphere::intersect(Ray ray,glm::vec3& hitPoint) {//Compute A,B and C coefficIEntsfloat 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 discriminantfloat disc = b * b - 4 * a * c;// if discriminant is negative there are no real roots,so return// false as ray misses sphereif (disc < 0)    return false;// compute qfloat distSqrt = sqrt(disc);float q;if (b < 0)    q = (-b - distSqrt)/2.0;else    q = (-b + distSqrt)/2.0;// compute t0 and t1float t0 = q / a;float t1 = c / q;// make sure t0 is smaller than t1if (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 sphereif (t1 < 0)    return false;// if t0 is less than zero,the intersection point is at t1if (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;    }}

或者它可能是另一回事.有没有人有想法?非常感谢!

解决方法 看起来你正在使用非常宽的 field of view(FoV).这给出了鱼眼镜头的效果,扭曲了画面,特别是朝向边缘.通常,诸如90度(即,在任一方向上45度)的东西给出合理的图像.

折射实际上看起来很不错;它是倒置的,因为折射率很高.漂亮的照片在this question.

总结

以上是内存溢出为你收集整理的c – 为什么光线跟踪器将球体渲染为椭圆形?全部内容,希望文章能够帮你解决c – 为什么光线跟踪器将球体渲染为椭圆形?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1238857.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存