how to make lens distortion work?

Old question, but in case anyone pokes around this question again, the Eat3D video is a bit more complex than is what is needed if you want simple barrel distortion. Doing a little digging around because I wanted to do the same thing, I found this:

However, as I read the shader code, I noticed that it was being completely ridiculous, first it gets the angle of the UV vector, the figures out the “magnification” using the barrel distortion, then it calculates the new x and y positions using sine and cosine on the angle–which is completely redundant. In fact, you can throw away all those trig ops (well and you can’t do atan in a material anyways) and just scale the vector using the barrel power parameter. You end up with a cute little material that you can create barrel or pincushion effects with on a single parameter. Screenshots of two examples and the material to follow.

Just a couple of notes:

  1. If you make the material, create a material instance so you can change the parameter easier without recompiling the material constantly. You can also create a dynamic material instance in blueprints with it and then modify the parameter via blueprints if you want to mess around and figure out what the right “barrel power” should be for your application (e.g., Cardboard).
  2. The final material masks out the pixels beyond the distortion area with black. If you’re already using something like a mask to get rid of those pixels, it’s an unnecessary step (use the previous material). You could also simply move that code to pick between the normal texture coordinate (in place of black) or the calculated texture coordinate by the exact comparison and this would give you a non-distorted image in those areas (more like the image in the links above).

Finally, I noticed that my post processing didn’t work properly in the preview window, at least on my Mac. Instead, I had to build and run in a separate window and then everything looked right.