当射线从嵌套对象内部开始时如何处理折射 [英] How to deal with refraction when the rays start inside of a nested object

查看:110
本文介绍了当射线从嵌套对象内部开始时如何处理折射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为教育目的构建一个简单的光线跟踪器,并希望为对象添加折射。使用斯涅尔定律,我可以在交点处递归地创建新的射线。光线追踪器目前仅支持球体,而我使用的场景是多个球体以不同折射率嵌套在一起。



如果我从外面开始射线领域,一切都很简单。您从场景的折射率开始,一旦碰到第一个球体,就会使用之前的折射率和球体材料的折射率折射射线,直到您碰到下一个球体为止,依此类推。使用交叉点的法线我可以确定我是否进入或离开球体。然而,我不明白我应该如何处理球叶以及如何处理光线不会从场景的外部开始。




  • 我可以将一叠折射率指标和一层一旦我离开球体,就立即开始行动?

  • 如果我从球体内部开始,我该如何确定使用哪种折射率?

  • 例如

    您有三个球体,折射率分别为0.9,1.1和0.8从外到内。空气指数为1.0


    • 您的相机位于球体之外并指向球体的中心:




      • 开始索引是1.0,您首先用索引0.9命中外部球体并从1.0折射到0.9,并保存您的射线现在在0.9材质

      • 你点击中间球体并注意1.1的材质常量,因为你已经保存了0.9,你知道你必须从0.9折射到1.1并且除了0.9

      • 你击中了内部球体并从1.1折射到0.8,并且你保存到现在为止0.9,1.1和0.8
      • 你再次击中内球(this当你退出它时,所以你检查你保存的值,并知道你必须切换回1.1)

      • ...直到你在外面

      • ul>
      • 现在问题在于相机在球体内部。您不会知道您需要切换哪种折射率指数。

      • >从物理学的角度出发,而不是光线追踪实现的观点:P。



        Snell定律指出,入射角的正弦与折射角等于边界两侧的两种介质的折射率之比的倒数。因此,当光线接近新的光线时材料,并且您想要知道新材料中的角度,您需要知道光线照射新材料的角度,新材料的折射率以及光线当前材料的折射率。

        正如你所说,折射可以很好地进入球体,你必须知道每个球体和场景的折射指数。



        我想说创建一堆折射率是一个好方法处理进入一堆嵌套材料,因为当你移出嵌套的球体集合时,你将不得不触碰所有折叠指数。

        关于确定离开球体时必须开始的折射率,您总是会说sin(theta1)/ sin(theta2)= [折射率2] / [折射率1 ]。因此,您需要您当前所用材料的折射率以及您将要移动的材料的指数。

        如果我误解了你的问题,但我希望有帮助!


        I am building a simple raytracer for educational purposes and want to add refraction to objects. Using Snells Law, I am able to create a new ray recursively at the intersection points. The raytracer supports currently only spheres and I use a scene where I have multiple spheres nested inside of each other with different refraction indices.

        If I start a ray from outside of the spheres, everything seems simple. You start with the refraction index of the scene, and as soon as you hit the first sphere, refract the ray using the refraction index before and the refraction index of the material of the sphere until you hit the next sphere and so on. Using the normals of the intersection I can determine whether I enter or leave the sphere.

        However, I don't understand how I should handle sphere leaves and what to do if the ray doesn't start in the outer part of the scene.

        • Can I just take a stack of the refraction indices and go one layer up as soon as I leave a sphere?
        • How can I determine with what refraction index I have to start if I start inside of the spheres?

        Example

        You have three spheres, with refraction indices 0.9, 1.1 and 0.8 from outer to inner. Air index is 1.0

        • Your camera is outside of the sphere and points at the center of the sphere:

          • start index is 1.0, you first hit the outer sphere with index 0.9 and refract from 1.0 to 0.9 and save that your ray is now in 0.9 material
          • you hit the middle sphere and notice the material constant of 1.1, since you have saved the 0.9, you know that you have to refract from 0.9 to 1.1 and save the 1.1 in addition to the 0.9
          • you hit the inner sphere and refract from 1.1 to 0.8 and you have save until now 0.9, 1.1 and 0.8
          • you hit the inner sphere again (this time you exit it, so you check your saved values and know that you have to switch back to 1.1)
          • ... until you are outside
        • Problem now, when the camera is inside the sphere. You won't know to what refraction index you have to switch.

        解决方案

        Posting this from a physics point of view and not a raytracing implementation point of view :P.

        Snell's law states that the ratio of the sines of the incident angle and the refractive angle are equal to the inverse of the ratio of the refractive index of the two mediums on either side of the boundary.

        Thus, when you have a ray approaching a new material and you want to know the angle in the new material, you need to know the angle that the ray is hitting the new material, the index of refraction of the new material, and the index of refraction of the material the ray is currently in.

        As you say refraction works fine moving into the sphere, you must know the index of refraction of each sphere and your scene already.

        I'd say creating a stack of refractive indices would be a good way to deal with going into a bunch of nested materials, as you're going to have to touch all the refractive indexes that you push onto the stack again as you move out of the nested set of spheres.

        As to determining what refractive index you have to start with as you leave the spheres, you're always saying sin(theta1)/sin(theta2) = [refractive index of 2]/[refractive index of 1]. Thus, you need the refractive index of the material that you're currently in and the index of the material that you're going to be moving towards.

        Apologies if I misunderstood your question, but I hope that helps!

        这篇关于当射线从嵌套对象内部开始时如何处理折射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆