Barrel Distortion

This Generator implements the Barrel Distortion algorithm, situable for use with an Oculus Rift or Google Cardboard.

I do not have an Oculus Rift but I did test this Camera3D and Processing using Google Cardboard on my Samsung S6 phone. Unfortunately it is ridiculously slow. Camera3D works by copying images back forth between the GPU and the CPU, and for whatever reason that is very slow on my phone. Your experience might be different. If you want a better approach for using Processing with Google Cardboard, look at Scott Little's blog.

Here's a great video on what barrel distortion is and why it is important.

Start with the same right and left images:

/images/camera3D/barrel_distortion/fourcubes-left-component.png/images/camera3D/barrel_distortion/fourcubes-right-component.png

Distort each image. Here is the left component:

/images/camera3D/barrel_distortion/fourcubes-left-component-modified.png

and the right component:

/images/camera3D/barrel_distortion/fourcubes-right-component-modified.png

Notice that it does not squish each image to make all of it fit in the frame. Only the middle section is visible. Typically you would want to make the size of your sketch a wide rectangle, not a square as we are doing here. Keep the part you want people to look at in the center because the left and right 25% will be gone.

Add the two images together, yielding:

/images/camera3D/barrel_distortion/fourcubes-composite.png

Adding a label to the result with the postDraw method doesn't make sense for this, so skip that part.

By default the Barrel Distortion Generator is configured to the distortion coefficients for an Oculus Rift. You can easily change this to something else if you like using the setBarrelDistortionCoefficients method, as demonstrated in the example code.