Download
Softimage|XSI / mental ray lens shader.
Softimage|XSI 4.x UFO.
lmWarpDistort.v1.0.zip - shader : dll, so, spdl - UFO : dll, so.

Original Image (A)
Directly rendered with standard PAL camera

Distorted Image with Lens Shader (B)
Rendered with lmWarpDistort Lens Shader: distortion=0.08
Disclaimer
The software is released as is, without any written or implied warranty. The software cannot be redistributed without permission from LaMaison. The program will not be supported. LaMaison is not responsible for any damage or loss of data incurred by the use of this software. lmWeightMapTools was developed by Aloys Baillet for LaMaison.
Introduction
This document describe the lmWarpDistort shader and the lmWarpDistortUfo FXTree node wich are used to distort images according to the 3D Equalizer v3 lens distortion model. You will find a mathematical description of this model created by Uwe Sassenberg, Head of R&D, Science-D-Visions , in this paper. The distortion parameters can be computed in 3D Equalizer v3, or can be tweaked from a photographed grid, for exemple.
The main parameter of these tools are the distortion value. It can be positive (Pillow effect), or negative (Barrel effect).
The lmWarpDistort shader is a Mental Ray lens shader that changes the rays directions according to its distortion parameters.
This shader can only apply the distortion.
The main advantage of this shader is that it doesn't crop images when the distortion is applied: rays are just distorted (see Image B).
The lmWarpDistortUfo UFO is a custom FXTree node that applies or removes distortion in an image.
Be careful that if you apply positive distortion or remove negative distortion with this node, areas that
are not in the original image will be considered black and curved borders will appear in the computed image (see Image C).
The main use of this UFO is to remove distortion of an image sequence (to use them in camera mapping, for example).

Distortion applied on Image A with UFO (C)
Notice the black borders

Distortion removed from Image B with Ufo (D)
Installation
Add-On: Just Drag&Drop the addon in a XSI viewport.
Shader only: Click on File->Add-On->Plugins(SPDL)... and click on Install, select the lmWarpDistort.spdl file and click on install.
You can also run the following command in a XSI command prompt: xsi -i lmWarpDistort.spdl.
UFO only: Just copy the file lmWarpDistortUfo.dll in your %USER%\Application\fx\ufos directory.
lmWarpDistort Lens Shader Use
Connecting The Lens Shader
First, select the camera you want to apply the lmWarpDistort shader to. If one of your viewport is set to this camera, you can click on the little camera icon on top of the viewport, and choose "Properties" to view the Camera Property Page (PPG) and select the "Lens Shader" tab.
Click on the "Add" button, and select the lmWarpDistort shader in your file system.
There you go! The Lens Shader is applied to the camera, and you should see it in the Lens Shader list.
To edit it's properties, select it and click on the Inspect button.

You have to know that this lens shader will change the ray direction according to the distortion parameters. Thus it is not usable with the "Scanline Rapid Motion" Mental Ray optimization mode.
Lens Shader Parameters
- Enable
If this is not checked, the shader will do nothing. This parameter can be usefull to set up passes with only one camera. See the Tips Section at the end. - Distortion
Main distortion parameter. Default value is 0 : no distortion. The value can be positive (Pillow effect), or negative(Barrel effect). - Anamorphic Squeeze
The default value is 1 and represent an non anamorphic camera. - X Curvature and Y Curvature
Set the X and Y curvature. - Quartic Distortion
This parameter gives more precision to the distortion model, but has no simple explanation... play with it if you want!
lmWarpDistortUfo FXTree Node Use
Getting the Ufo
First, open the FXTree (Application->Layout->Compositing for example).
Click on Ops->Plugins[U]->lmWarpDistortUfo. NB: if you have installed the UFO in a workgroup, you will find it under Ops->workgroup[W]->lmWarpDistortUfo.

Click on the green (e) or double click on the node to show the lmWarpDistort Property Page.
FXTree Node Parameters

- Lens Distortion
Main distortion parameter. Default value is 0 : no distortion. The value can be positive (Pillow effect), or negative(Barrel effect). - Anamorphic Squeeze
The default value is 1 and represent an non anamorphic camera. - X Curvature and Y Curvature
Set the X and Y curvature. - Quartic Distortion
This parameter gives more precision to the distortion model, but has no simple explaination... play with it if you want! - Warp Operation
Allow the user to choose between "Apply deformation" and "Remove deformation". Usually this Ufo will be used to remove distortion from a image sequence shot with a real camera. - Filtering
This parameter sets the quality of the final image. Bicubic filtering is best but slower!

- Camera Aperture
The camera horizontal aperture, in degrees. - Camera Aspect
The camera aspect ratio. - X Curvature and Y Offsets
Set the X and Y offsets of the lens center.
Notes
When using the lens shader, be careful that the more you increase the distortion, the more you will put in your final image parts of your 3D scene that you don't see in the camera viewport.
If you look at the 3D Equalizer Lens Distortion Model, you will notice that applying the distortion to an image involve the numerical inversion of a 2D function. Thanks to a nice mathematical trick, the lens shader can apply the distortion function WITHOUT the numerical inversion (the function is geometrically inversed). As a result the image computed with the lens shader will be more accurate than if you apply the distortion with the UFO.
