Custom nonlinear distortion lens Is it possible to create a custom nonlinear distortion lens in Blender?

I'm assuming that Blender superimposes a rectangular grid in front of the eye, and fires out a ray through the center of each cell on the grid, returning the colour for that pixel.



So my question reduces to: is it possible to replace this grid with my own warped grid?

EDIT: I'm most interested in a code-level solution -- this is for experimental project and as such I would like fine-grained control.

PS I can't find any tags, such as ray-tracing, eye-ray, lens, distortion
Why not use the compositor to achieve this affect? 

Doing this in the compositor is really easy. All you need to do is to add a lens distortion node.