How to deal with refraction when the rays start inside of a nested object

后端 未结 2 1032
萌比男神i
萌比男神i 2021-01-19 00:46

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 intersect

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-19 01:05

    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!

提交回复
热议问题