Try / OpenGothic

Reimplementation of Gothic 2 Notr
MIT License
1.07k stars 78 forks source link

FXAA integration #572

Closed KirillAlekseeenko closed 3 months ago

KirillAlekseeenko commented 3 months ago

Integrated FXAA as a relatively simple spatial antialiasing algorithm at the end of the frame just before UI rendering

There are multiple presets: 0 -- no FXAA from 1 to 5 -- the higher this number the more expensive filtering is used

To set FXAA preset add "-fxaa preset_num" parameter to the command line arguments

Try commented 3 months ago

Hi, @KirillAlekseeenko and thanks for PR!

Currently busy with gpu-driven, - will look closely into PR afterward.

Some notes in a meantime:

And one more thing to note: there was a debate in last release comments about better AA technique, so it best next time to raise ticket and ask. On my end I was looking toward programmable-resolve based AA (can do on Apple, but not yet on Vulkan). It is OK with you, if after 6-12 months this FXAA will be replaced by else algorithm?

KirillAlekseeenko commented 3 months ago

Hi! Accroding to nvidia nsight frame capture FXAA takes from 0.06 to 0.08 ms (depends on quality preset) on nvidia 3070 card with full hd resolution. Source for Fxaa3_11.h can be found here: https://gist.github.com/jwoolston/c96c22473110c9924d831cebb5f2cdb4 Originally it's a part of NVIDIA samples: https://docs.nvidia.com/gameworks/content/gameworkslibrary/graphicssamples/opengl_samples/fxaa.htm https://docs.nvidia.com/gameworks/content/gameworkslibrary/graphicssamples/d3d_samples/fxaa311sample.htm

It's ok if FXAA will be removed in future releases, it's just a starting AA solution and not good comparing to alternatives, but it's cheap and simple though. What did you mean by programmable-resolve based AA?

There are shots before and after applying FXAA 4_beforeFXAA 4_afterFXAA 5_beforeFXAA 5_afterFXAA 3_beforeFXAA

3_afterFXAA

Try commented 3 months ago

What did you mean by programmable-resolve based AA?

This is though direction, rather a complete technique at this point. Basic idea here is to use (or abuse :D ) MSAA rendering with some extensions to get full-res gBuffer + 4x-coverage buffer. This method originally was intended only to deal with sky-to-object aliasing (trees/ship) - coverage buffer is perfect to compose sky on top of scene.

Naturally there are quite a few challenges to make it work, and one of then is to be able to resolve MSAA image into single-sampled image from shader, rather then from fixed-function hardware.

Try commented 3 months ago

There some code-style issues - I'll fix it afterward. Merged, thanks!