# Refraction bending with planar surfaces in Cycles (2.78b)

I was always under the impression that straight lines should refract and reflect via planar surfaces into straight lines. Cycles seems not to do this in certain instances. In the video below you can see it best on the left face at the start and the right face at the end of the sequence. At first I thought it was a problem with my HDRi but it seems surrounding geometry creates the same effect. Am I wrong in my assumptions, do I have some settings or parameters incorrect in my materials or environment or is this a "feature" of Cycles?

Here's the Blend file (slightly edited since this video was made):

Here's a single face of the cube and no HDRi showing the effect.

• This render result is indeed physically incorrect. Can you share your scene and setup? I wasn't able to replicate this with a 35mm camera, a 1.3 IOR glass shader and HDRi. Note that refraction phenomena on HDRi are limited - here is an example: i.stack.imgur.com/egRBd.png Mar 2, 2017 at 13:44
• I think it is correct. For the refraction in the front plane the light is passing through two parallel planes and so ends up at the same angle as originally incident. As the HDR background is effectively out at infinity the parallel rays appear to be unaffected by the refraction. For the distorted "refraction" in the side, it's entering the side, reflecting off the back surface and passing out the opposite side. This means that the rays travel a different distance through the cube depending on where on the side face they hit, producing the 'bend'. Mar 2, 2017 at 15:21
• Well I'm about to concede that I'm wrong. Tests with POVRay and Blender Internal both show the same effect and if Cycles and LuxRender do as well then perhaps the maths is correct. I'm guessing that the flaw in my logic is that we are not used to seeing planar surfaces with materials that have an IOR as low as 1.3. Bumping up the IOR to 1.5 seems to straighten out all the distortion. @JerryNo thanks for the support but I think that for IOR values between 1 and 1.5 this distortion is normal. Mar 3, 2017 at 0:27
• @RichSedman so I tested couple more renderers and the same results. I did the math and draw the rays in Autocad and the projected refracted rays do not intersect in single point! I used the shnells formula n1/n2=sin(alpha)/sin(beta). All diagrams on web like this one: img.tfd.com/ElMill/thumb/F0R-07-S2958.jpg and others are lies. Also what they teach in schools is very simplified.. So the closer the camera is the bigger the distortion. IOR of 1.3 should be fine, water is 1.33. The distortion is always there for anyIOR, but if camera is further away it disappears fast. You were right! Mar 3, 2017 at 8:22
• @jerryno - thanks! I think the school point of view is typically that the incoming rays assumed to be parallel from infinity so I guess that normally avoids the problem. Impressed that you've managed to do the math - it was making my head hurt ;-) Do you feel able to put together an answer for this - I think you're probably better qualified for it and could probably do it a whole lot more justice (for the maths) than I could. Mar 3, 2017 at 9:35

On first look it might seem that refraction on planar surfaces will not distort the image, but just linearly bent it or zoom it:

In real world there are very few examples where the distortion is clearly visible, one of them being refraction on water level:

(Thanks to @RichSedman for pointing this out and patiently making me dig deeper to find the truth and how it works.)

Refraction follows the Snell's law. This means that for every IOR value there exist a critical angle after which the ray won't be refracted but reflected:

We can see this in the above pictures, where the refraction is surrounded by the reflection of pool or sea bed. We will return to this (in Cycles) later. What we also see is the distortion of those refracted rays, so lets tackle the distortion first:

It's best to start with reflection analogy. Reflection is much simpler - the angle of incidence is the same as angle of reflection - their relationship is linear (unlike with refraction). By tracing the reflected rays, we can construct a single(!) virtual viewing point B, from which we see the reflected image:

Doing this with refracted rays (and drawing them in CAD with Snell's formula) reveals, that the rays do not intersect into a single virtual viewing point, but into infinitely many of them (because the relationship between incidence angle and refracted angle is not linear). This means that every piece of the refraction we see from different perspective and that is the reason for the distortion (every 2 rays create a virtual viewing point in different location):

Now let's see how this behaves in Cycles - left how it changes with distance to camera (single refractive quad with IOR 1.3) and right how it changes with IOR (1.0 to 2.0):

This is physically correct behavior. By knowing this you are now able to create a panoramic fish-eye lens camera from simple perspective camera and a refractive quad (if the engine can do refractions but has no such camera option:)

But what Cycles doesn't do on it's own is to change the ray from refractive to reflective after the critical angle just with the Refractive shader (naturally) - it is just black. For this there is the Fresnel node that after the critical angle gives 1.0 mixing factor to mix in Glossy shader: