# How to anti-alias in vtkRenderWindow

**URL:** https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556
**Category:** Support
**Created:** [November 3, 2020, 12:28pm UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556 "2020-11-03T12:28:37Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![carlusst](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/8797f3/32.png) [@carlusst](https://discourse.vtk.org/u/carlusst)
#### Post date: [November 3, 2020, 12:28pm UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/1 "2020-11-03T12:28:37Z")

</div>

```
     The vtkRenderWindow contains a collection of vtkRenderers, and parameters that control rendering features such as stereo, anti-aliasing, motion blur and focal depth.

```

I have an image followed.

 ![saw](https://discourse.vtk.org/uploads/default/original/2X/c/cdb86bbcad8853c94b3cb68c8b297d35ffd1b508.jpeg) . How could I do it with anti-aliasing operation in vtkRenderWindow? Demo code is better.

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [November 3, 2020, 12:39pm UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/2 "2020-11-03T12:39:52Z")

</div>

@carlusst  
You could try [this](https://vtk.org/doc/nightly/html/classvtkRenderWindow.html#aa50754fb4198abdc57edd7a7f31d09b0), but it depends on the hardware.

```
.... setup actors, mapper, renderer ...
vtkNew<vtkRenderWindow> renWin;
renWin->AddRenderer(yourRenderer);
renWin->SetMultiSamples(4); // add this to your code.
.... setup interaction and start event loop ....
```

---

<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: [November 3, 2020, 10:39pm UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/3 "2020-11-03T22:39:53Z")

</div>

You can enable [FXAA](https://blog.kitware.com/new-fxaa-anti-aliasing-option-in-paraviewvtk) by flipping a switch in the renderer: [UseFXAAOn()](https://vtk.org/doc/nightly/html/classvtkRenderer.html#aee61a7d27612ce75f3ad8b8f535a42cb). It is simple and fast but it just a 2D image post-processing operation, therefore it removes all kinds of details from your rendered image. There are many parameters that you can tune though, so there is a good chance that the image quality will be overall better than without using anti-aliasing at all.

---

<div class="post-metadata">

### Author: ![carlusst](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/8797f3/32.png) [@carlusst](https://discourse.vtk.org/u/carlusst)
#### Post date: [November 4, 2020, 1:24am UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/4 "2020-11-04T01:24:02Z")

</div>

Thank jaswantp. I will try it according to your step.

---

<div class="post-metadata">

### Author: ![carlusst](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/8797f3/32.png) [@carlusst](https://discourse.vtk.org/u/carlusst)
#### Post date: [November 4, 2020, 1:29am UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/5 "2020-11-04T01:29:19Z")

</div>

Thanks Andras for your advice.I am reading FXAA . It should be powerful. Could it be limited by hardware?

---

<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: [November 4, 2020, 2:32am UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/6 "2020-11-04T02:32:13Z")

</div>

It is all just 2D software post-processing, so it is quite limited in what it can do, but it is fully hardware-independent and does not interfere with 3D rendering passes.

---

<div class="post-metadata">

### Author: ![carlusst](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/8797f3/32.png) [@carlusst](https://discourse.vtk.org/u/carlusst)
#### Post date: [November 4, 2020, 6:56am UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/7 "2020-11-04T06:56:54Z")

</div>

UseFXAAOn() is a function in C code. But how to use it in Python ?

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [November 4, 2020, 8:12am UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/8 "2020-11-04T08:12:52Z")

</div>

Is it unavailable in python wrappings?

---

<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: [November 4, 2020, 2:18pm UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/9 "2020-11-04T14:18:26Z")

</div>

All VTK methods are Python-wrapped (maybe except a few cases that use special argument types).

```python
>>> ren = vtk.vtkRenderer()
>>> ren.UseFXAAOn()
>>> ren.GetUseFXAA()
True

```

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [November 4, 2020, 2:56pm UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/10 "2020-11-04T14:56:13Z")

</div>

FXAA is fast and does a decent job, but some people don’t like its visual results. Skyrim, a game from Bethesda, uses FXAA and is criticized for its blurry looks by some of its users. I let this up to the user (choose FXAA, MSAA or none). I personally find MSAA better. Just try each and choose the one that you feel right.

---

<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: [November 4, 2020, 6:14pm UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/11 "2020-11-04T18:14:34Z")

</div>

FXAA can be good for artistic visualization, where accurate colors and sizes are not crucial. I would consider risky to use FXAA for scientific visualization, as it alters the information: it blurs objects as if they had equal importance, while in correct anti-aliasing what is in front should never be altered by what is behind (unless it is semi-transparent).

For example, see discoloration in the purple line as it goes above green and blue background:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/b/bf3d3e26786e70c15f529626e8239c28d3291229.png)

Discourse scales down the image in the post, so you can only see the difference in the zoomed-in red circles, or if you click on the image, download the full resolution image, and view it on your screen 1:1 (without any rescaling).

---

<div class="post-metadata">

### Author: ![carlusst](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/8797f3/32.png) [@carlusst](https://discourse.vtk.org/u/carlusst)
#### Post date: [November 17, 2020, 4:29am UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/12 "2020-11-17T04:29:32Z")

</div>

If have any other functions in VTK beside FAXX?

---

<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: [November 17, 2020, 5:22am UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/13 "2020-11-17T05:22:50Z")

</div>

You can do true antialiasing, with multisampling (MSAA) - see [vtkRenderWindow::SetMultiSamples()](https://vtk.org/doc/nightly/html/classvtkRenderWindow.html#aa50754fb4198abdc57edd7a7f31d09b0). If you use a GUI toolkit then you may need to enable MSAA in the application and/or embedding rendering widget, too.

---

<div class="post-metadata">

### Author: ![carlusst](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/8797f3/32.png) [@carlusst](https://discourse.vtk.org/u/carlusst)
#### Post date: [November 17, 2020, 5:27am UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/14 "2020-11-17T05:27:57Z")

</div>

I did it with multisampling,but no effect is seen.

---

<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: [November 17, 2020, 5:30am UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/15 "2020-11-17T05:30:41Z")

</div>

This is exactly what is hard with hardware MSAA. It depends on the hardware, operating system, type of render window, etc. Do you embed the render window into a GUI toolkit (Qt, wxWidgets, …) or it is a plain vtkRenderWindow? How many samples did you set? You may get some hints about what goes wrong if you run your code step by step in a debugger.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [November 17, 2020, 1:30pm UTC](https://discourse.vtk.org/t/how-to-anti-alias-in-vtkrenderwindow/4556/16 "2020-11-17T13:30:37Z")

</div>

Hi, carlusst,

To use MSAA properly, you must call these BEFORE creating the viewer widget (assuming you’re using Qt):

```cpp
vtkOpenGLRenderWindow::SetGlobalMaximumNumberOfMultiSamples ( 8 );
QSurfaceFormat::setDefaultFormat ( QVTKOpenGLWidget::defaultFormat() );

```

Then you call:

```cpp
vtkwidget->GetRenderWindow()->SetMultiSamples( 4 );

```

I hope this casts some linght on MSAA usage.

regards,

Paulo
