# Inverted perspective divide in VTK

**URL:** https://discourse.vtk.org/t/inverted-perspective-divide-in-vtk/13061
**Category:** Support
**Created:** [January 12, 2024, 1:43pm UTC](https://discourse.vtk.org/t/inverted-perspective-divide-in-vtk/13061 "2024-01-12T13:43:16Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [January 15, 2024, 4:36pm UTC](https://discourse.vtk.org/t/inverted-perspective-divide-in-vtk/13061/9 "2024-01-15T16:36:48Z")

</div>

I’ve tested this and you can get the correct reverse perspective by inverting the sign of the third column of the perspective projection matrix:

## Surface rendering

Normal perspective:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/9/9402ac2c1a552c518a1c9bcc17f89a7d00ac9ec2.jpeg)

Reverse perspective:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/3/3f5e2e2a318930a5d9559540127f4482e20dd99b.jpeg)

## Volume rendering

It also works for CPU volume rendering (unfortunately, ray computation seem to be implemented with some custom logic in the GPU volume renderer, so that would need some fixes).

Normal perspective:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/7/72287f9dfe9d11c62e7cacc223acdb4b4e21ccc0.jpeg)

Reverse perspective:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/1/1839435f2ff5f86aa1f3b01aedea6fc1e6bd28c6.jpeg)

## Implementation

This is the change that would be needed in vtkCamera:

> <https://github.com/lassoan/VTK/commit/1a555b3229beba2769e86bc91eb26451ac089636>

I used this change in 3D Slicer to create the screenshots above like this:

```python
threeDViewNode = slicer.app.layoutManager().threeDWidget(0).threeDView().mrmlViewNode()
cameraNode = slicer.modules.cameras.logic().GetViewActiveCameraNode(threeDViewNode)
cameraNode.GetCamera().SetReversePerspective(True)

```

You could clone the perspective matrix computation in your code, insert the column sign inversion there, and set the matrix explicitly, which would require more code to maintain but then you would not need to modify VTK.

---

_[View the full topic](https://discourse.vtk.org/t/inverted-perspective-divide-in-vtk/13061)._
