> For the complete documentation index, see [llms.txt](https://stage-precision.gitbook.io/grid/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stage-precision.gitbook.io/grid/touch-designer-integration/camera-tracking/distortion-top.md).

# Distortion TOP

Apply SPNet camera lens distortion to a rendered image using the native SPNet Distortion TOP.

The SPNet Distortion TOP applies radial lens distortion to an incoming image using the lens data provided by an SPNet Camera CHOP.

Processing runs on the NVIDIA GPU through CUDA. The distortion implementation is included in the plugin DLL.

In the generated camera rig, this operator is named `lens_top` and is already configured.

### Input and output

The operator has one image input and produces one processed image.

In the camera rig, the connection is:

```
render_raw → lens_top → out1
```

The input contains the rendered scene, including any additional area created by overscan. The output contains the distorted image cropped to the final output dimensions.

The input must be a 2D color texture. Supported formats include:

* 8-bit fixed RGBA or BGRA.
* 16-bit fixed RGBA.
* 16-bit floating-point RGBA.
* 32-bit floating-point RGBA.

### Lens page

| Parameter         | Default    | Description                                                                                             |
| ----------------- | ---------- | ------------------------------------------------------------------------------------------------------- |
| SPNet Camera CHOP | Unassigned | References the CHOP providing panel dimensions, lens coefficients, optical center, and overscan scales. |
| Use Lens          | `On`       | Enables radial distortion using K1, K2, and K3.                                                         |
| Use Center        | `On`       | Uses the received optical center as the center of the distortion.                                       |

Inside the generated rig, these parameters are connected automatically. Use the rig's Lens page to control Use Lens and Use Center.

#### SPNet Camera CHOP

Select the SPNet Camera CHOP associated with the camera used to render the input image.

The TOP reads the required channels directly from that CHOP, including small distortion coefficients.

#### Use Lens

Enable Use Lens to apply the incoming radial distortion.

When disabled, radial distortion is bypassed while overscan cropping remains active. This allows you to compare the final image with and without distortion.

#### Use Center

Enable Use Center to apply distortion around the received optical center.

When disabled, the distortion is calculated around the image center.

The camera projection also needs the corresponding center-shift setting. The generated rig coordinates both stages through its Use Center control.

### Lens model

The operator uses the standard SPNet camera's radial coefficients:

| Coefficient | Contribution              |
| ----------- | ------------------------- |
| K1          | Second-order radial term. |
| K2          | Fourth-order radial term. |
| K3          | Sixth-order radial term.  |

The calculation uses physical panel dimensions in millimeters. The SPNet Camera CHOP provides the panel width, panel height, and normalized optical center.

When all three coefficients are zero, the image has no radial distortion.

### Overscan

Distortion can require image content beyond the original camera frame.

The camera rig provides that content by rendering a larger scene area. The distortion TOP then samples this larger image and crops it back to the final output.

Configure overscan on the source SPNet Camera CHOP:

* Enable **Overscan Override** to use a local factor.
* Disable it to follow the overscan received through SPNet.
* Increase the factor if distortion still reaches beyond the available rendered area.

The original panel dimensions and distortion coefficients remain unchanged.

{% hint style="info" %}
The distortion TOP processes the image it receives. Additional scene coverage must be rendered by the camera setup. The generated camera rig handles this automatically.
{% endhint %}

### Output resolution

In the generated rig, the TOP's output resolution follows Output Width and Output Height on the SPNet Camera CHOP.

If you build your own setup, configure the TOP's output resolution for the required final image size and ensure the input render matches the source camera's overscan setup.

### Checking the result

View `out1` in the camera rig and toggle **Use Lens** on the rig's Lens page.

For a clear visual reference:

1. Enable **Debug Mode** on the rig's Scene page.
2. Position the camera so the floor grid is visible.
3. Change the distortion coefficients in Grid Studio.
4. Compare the curved grid with Use Lens enabled and disabled.

Lens distortion appears in the processed image. The Camera COMP's 3D viewer displays the scene before this stage.
