Here is the source code for a simple perspective camera node with custom distortion and vignetting :
In camera_create_ray you can also compute the direction and position derivatives. This is important for correct filtering. However, you can let Arnold compute the differentials automatically if you leave these fields set to the default 0.0 value.
The following example shows how to compute them in the camera node for a perspective camera. In this case the ray's origin is always the same, but the direction changes from pixel to pixel. Follows some sample code to compute the derivatives for a perspective camera (we do not take into account uv noise):
Example scene and render: