Friday, July 3, 2015

Debugging refraction in a ray tracer

That picture I suspected had a refraction bug did.   It's always hard to tell-- that is one reason refraction hack can work so well.  I found a good debugging case so I will share.

Suppose you have a plate (closed box shape in my code) of glass of refractive index n.   What ray will go into it with easy to understand outcome?   Here is one:
Pink is the cross section of the solid glass pane which continues to the right.
Recall Snell's law that n sin(theta) = n' sin(theta').   That implies that for an incident ray from vacuum (my renderer will kill inhabitants immediately) at 45 degrees into a medium with refractive index sqrt(2), the refracted ray will have sin(theta') = 1/2.   There can't be any reflection on the next bounce because you would need sin(theta) = sqrt(6)/2, so you will get total internal reflection all the way until the other end of the glass plate.   I add some green exponential attenuation and voila (hopefully right):
Refraction looks plausible.  Maybe that quasi reflection of the sphere in the floor is a caustic?

No comments: