SSAA and FXAA

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

SSAA and FXAA

chung
Hi experts,

I'm using vtk 8.1 and am having a little bit of a trouble getting
anti-aliasing working.

When using the FXAA approach, the graphic remains the same regardless of the
FXAA options I pass to the renderer.

vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkOpenGLRenderer>::New();
renderer->SetUseFXAA ( true );
auto options = renderer->GetFXAAOptions();
options->SetSubpixelBlendLimit ( 0.75 );
options->SetHardContrastThreshold ( 0.045 );
options->SetRelativeContrastThreshold ( 0.125 );
options->SetEndpointSearchIterations ( 12 );
options->SetSubpixelContrastThreshold ( 0.25 );
options->SetUseHighQualityEndpoints ( true );

<http://vtk.1045678.n5.nabble.com/file/t342714/fxaa.png>


When using the SSAA render pass approach I have depth buffer issue where the
surfaces of a primitive cube get rendered in an incorrect order. I came
across this depth peeling fix but it didn't work for me unfortunately.

http://vtk.1045678.n5.nabble.com/vtk-developers-QVTKOpenGLWidget-SSAA-pass-breaks-depth-peeling-td5746428.html


vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkOpenGLRenderer>::New();
renderer->SetBackground ( 0.615f, 0.639f, 0.666f );

vtkNew<vtkRenderStepsPass> basicPasses;
vtkNew<vtkSSAAPass> ssaa;

vtkSmartPointer<vtkDepthPeelingPass> depthPeel = vtkSmartPointer <
        vtkDepthPeelingPass > ::New();
vtkSmartPointer<vtkTranslucentPass> translucent = vtkSmartPointer <
        vtkTranslucentPass > ::New();
depthPeel->SetMaximumNumberOfPeels ( 0 );
depthPeel->SetTranslucentPass ( translucent );
basicPasses->SetTranslucentPass ( depthPeel );


ssaa->SetDelegatePass ( basicPasses );
renderer->SetPass ( ssaa );
renderer->SetUseDepthPeeling ( true );
renderer->SetMaximumNumberOfPeels ( 0 );

<http://vtk.1045678.n5.nabble.com/file/t342714/ssaa.png>


I'm not sure what I'm missing and I would greatly appreciate if anyone can
help me spot it.

Thanks,
Chuan




--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: SSAA and FXAA

VTK - Users mailing list
I'm not sure what's causing this, enabling FXAA should work out of the box for all data rendered in the opaque/translucent passes. Have you tried with the default options? They shouldn't need to be tweaked unless you're having serious performance / quality issues.

For SSAA, I'm curious why you're setting the maximum number of peels to 0? That effectively disables peeling and would result in the improper blending that you're seeing.

HTH,
-Allie

On Tue, Mar 5, 2019 at 3:43 PM chung <[hidden email]> wrote:
Hi experts,

I'm using vtk 8.1 and am having a little bit of a trouble getting
anti-aliasing working.

When using the FXAA approach, the graphic remains the same regardless of the
FXAA options I pass to the renderer.

vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkOpenGLRenderer>::New();
renderer->SetUseFXAA ( true );
auto options = renderer->GetFXAAOptions();
options->SetSubpixelBlendLimit ( 0.75 );
options->SetHardContrastThreshold ( 0.045 );
options->SetRelativeContrastThreshold ( 0.125 );
options->SetEndpointSearchIterations ( 12 );
options->SetSubpixelContrastThreshold ( 0.25 );
options->SetUseHighQualityEndpoints ( true );

<http://vtk.1045678.n5.nabble.com/file/t342714/fxaa.png>


When using the SSAA render pass approach I have depth buffer issue where the
surfaces of a primitive cube get rendered in an incorrect order. I came
across this depth peeling fix but it didn't work for me unfortunately.

http://vtk.1045678.n5.nabble.com/vtk-developers-QVTKOpenGLWidget-SSAA-pass-breaks-depth-peeling-td5746428.html


vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkOpenGLRenderer>::New();
renderer->SetBackground ( 0.615f, 0.639f, 0.666f );

vtkNew<vtkRenderStepsPass> basicPasses;
vtkNew<vtkSSAAPass> ssaa;

vtkSmartPointer<vtkDepthPeelingPass> depthPeel = vtkSmartPointer <
        vtkDepthPeelingPass > ::New();
vtkSmartPointer<vtkTranslucentPass> translucent = vtkSmartPointer <
        vtkTranslucentPass > ::New();
depthPeel->SetMaximumNumberOfPeels ( 0 );
depthPeel->SetTranslucentPass ( translucent );
basicPasses->SetTranslucentPass ( depthPeel );


ssaa->SetDelegatePass ( basicPasses );
renderer->SetPass ( ssaa );
renderer->SetUseDepthPeeling ( true );
renderer->SetMaximumNumberOfPeels ( 0 );

<http://vtk.1045678.n5.nabble.com/file/t342714/ssaa.png>


I'm not sure what I'm missing and I would greatly appreciate if anyone can
help me spot it.

Thanks,
Chuan




--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: SSAA and FXAA

chung
This post was updated on .
Thanks for the response Allie. I tried the default options prior to tweaking
the numbers and I also verified the code execution of FXAAFilter inside
vtkOpenGLRender::UpdateGeometry() by stepping through the VTK source code.

The documentation indicated that a max peel of 0 means no maximum number of
peeling layers. Again I only changed it to zero because the default setting
did not work for me.

//@{
  /**
   * In case of depth peeling, define the maximum number of peeling layers.
   * Initial value is 4. A special value of 0 means no maximum limit.
   * It has to be a positive value.
   */

Sincerely,
Chuan



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: SSAA and FXAA

VTK - Users mailing list
On Wed, Mar 6, 2019 at 2:24 PM chung <[hidden email]> wrote:
Thanks for the response Allie. I tried the default options prior to tweaking
the numbers

Ok, just wanted to make sure :)
 
The documentation indicated that a max peel of 0 means no maximum number of
peeling layers. Again I only changed it to zero because the default setting
did not work for me.

Ah, yes, you are correct -- I forgot about that.
 
I also verified the code execution of FXAAFilter inside
vtkOpenGLRender::UpdateGeometry() by stepping through code.

This is very strange. While stepping through the rendering code, was anything rendered during the opaque/translucent passes on the renderer that called FXAA? You can step through vtkOpenGLRenderer::UpdateGeometry() to check this. If your data is volumetric or rendered in the overlay pass, FXAA is applied before those passes and won't affect them. It doesn't look like your scene is set up that way in your attached image, but it's something to check.

If you're building your own VTK, you can also try running the FXAA test interactively and see if it's being applied there. Enable testing in CMake and run

bin/vtkRenderingOpenGL2CxxTests TestFXAAFilter -I

from the build directory. This renders the same scene twice, side-by-side. One side has FXAA applied, the other does not. Is there a noticeable difference?

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: SSAA and FXAA

chung
This post was updated on .
Yes I do see a noticeable difference in the FXAAFilter test as well as in my
own test widget.

<http://vtk.1045678.n5.nabble.com/file/t342714/vtkFXAA.png


<http://vtk.1045678.n5.nabble.com/file/t342714/myFXAA.png
<http://vtk.1045678.n5.nabble.com/file/t342714/myFXAA2.png
I can see that the FXAA algorithm is affecting the grid lines at certain
angles but they aren't as smooth as I'd like them to be and tweaking the numbers didn't help me get rid of the curvy lines. After a while I started experimenting with SSAA. It worked great except for the depth buffer issue.


I stepped through the code and the grid was rendered in the opaque pass as
vtkRenderer::UpdateOpaquePolygonalGeometry returns 1.


Thanks again Allie for looking into this.

Sincerely,
Chuan



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: SSAA and FXAA

VTK - Users mailing list
Ah, ok, so FXAA *is* working then, and not broken.

FXAA (Fast approXimate Anti-Aliasing) is an approximate anti-aliasing technique that is applied as a post-processing step. Since it is approximate and operates in screen space, there are some scenes that it works well on, and others that it doesn't. It sounds like you've found one that it doesn't handle -- those thin, clustered lines just look like random noise and not edges to a screen-space algorithm, so it doesn't know what to do with them.

If you want higher quality anti-aliasing, you'll want MSAA (vtkRenderer::SetMultiSamples) or SSAA. MSAA is generally preferred and better tested.

On Thu, Mar 7, 2019 at 5:07 PM chung <[hidden email]> wrote:
Yes I do see a noticeable difference in the FXAAFilter test as well as in my
own test widget.

<http://vtk.1045678.n5.nabble.com/file/t342714/vtkFXAA.png>


<http://vtk.1045678.n5.nabble.com/file/t342714/myFXAA.png>
<http://vtk.1045678.n5.nabble.com/file/t342714/myFXAA2.png>
I can see that the FXAA algorithm is affecting the grid lines at certain
angles but they aren't as smooth as I'd like them to be.


I stepped through the code and the grid was rendered in the opaque pass as
vtkRenderer::UpdateOpaquePolygonalGeometry returns 1.


Thanks again Allie for looking into this.

Sincerely,
Chuan



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: SSAA and FXAA

chung
This post was updated on .
Hi Allie,

Okay I will continue experimenting with MSAA and SSAA. I couldn't find vtkRenderer::SetMultiSamples in the doc. However I've tried
vtkOpenGLRenderWindow::SetMultiSamples and
vtkOpenGLRenderWindow::SetGlobalMaximumNumberOfMultiSamples without having
any luck. Are there other setup required besides setting the multi-sample
size?

Thanks,
Chuan



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: SSAA / FXAA / MSAA

chung
This post was updated on .
Ah I figured out why MSAA didn't work for me. I needed to call
SetGlobalMaximumNumberOfMultiSamples before setting the QSurfaceFormat since
QVTKOpenGLWidget::defaultFormat() is dependent on that global max multiple
sample value.


//-----------------------------------------------------------------------------
QSurfaceFormat QVTKOpenGLWidget::defaultFormat()
{
  QSurfaceFormat fmt;
  fmt.setRenderableType(QSurfaceFormat::OpenGL);
  fmt.setVersion(3, 2);
  fmt.setProfile(QSurfaceFormat::CoreProfile);
  fmt.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
  fmt.setRedBufferSize(1);
  fmt.setGreenBufferSize(1);
  fmt.setBlueBufferSize(1);
  fmt.setDepthBufferSize(1);
  fmt.setStencilBufferSize(0);
  fmt.setAlphaBufferSize(1);
  fmt.setStereo(false);
  fmt.setSamples(vtkOpenGLRenderWindow::GetGlobalMaximumNumberOfMultiSamples());
#ifdef DEBUG_QVTKOPENGL_WIDGET
  fmt.setOption(QSurfaceFormat::DebugContext);
#endif
  return fmt;
}




// MSAA is fixed by adding these two lines before creating any QVTKOpenGLWidget
vtkOpenGLRenderWindow::SetGlobalMaximumNumberOfMultiSamples ( 8 );
QSurfaceFormat::setDefaultFormat ( QVTKOpenGLWidget::defaultFormat() );


Thanks Allie,
Chuan



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers