SMAA – Subpixel Morphological Antialiasing integration

I’m having the same problem and can confirm this is occuring on version 4.14.

The thing is, even without using this new code, I notice that UE4’s TAA does the exact same thing on a much smaller scale. An easy way of looking at the issues is to open a project like Realistic Rendering and start with FXAA which is fine, TAA which has a slight shaking to it, then SMAA, and TFXAA both having pretty bad shaking.

As I said in the first post, I have no interest in providing support for this code. However, I’ve noticed that the way subpixel jitter is handled for temporal AA modes has changed over the engine versions and most probably the current version of the SMAA integration does not handle it correctly. It shouldn’t be that difficult, just look for code mentioning jitter and view matrices. The SMAA pass either needs to have jitter removed from view matrices before rendering, or it needs to keep it, I can’t exactly remember now, but there’s a very small number of combinations to try. :slight_smile:

If any of you fixes it, feel free to make a pull request, but I can’t afford to spend time debugging the.

Version of the engine? 4.14, code? latest i think

Any reason this code would be rejected as a pull request?

@RyanB @-Godlewski

hi @-Godlewski, thanks for your awesome work on this.
I know you offer no support but you didn’t seem contrary to the idea of sheding light to the so I’ll take a stab at it.

I tried integrating SMAA into 4.16 and got it to work except for the aforementioned screen shaking
I looked into what you said:

I searched for the code mentioning jitter and view matrices, and the only occurrence of “matrix”, “matrices” or “jitter” I found at line 783:


	//Remove the AA Projection Jitter
	View.ViewMatrices.HackRemoveTemporalAAProjectionJitter();

seems that the option of “have jitter removed” is already there (and seems to be the same thing done in PostProcessTemporalAA.cpp), and if I comment out this line (so in theory to keep the jitter) it still shakes.

would you happen to know where else I could look at?

(or anyone else, for that matter)

In file “SceneVisibility.cpp”, line 2221 change values 0.25 to 0.1, like this:
//static const FVector2D Samples[2] = { FVector2D(0.25, -0.25), FVector2D(-0.25, 0.25) };
static const FVector2D Samples[2] = { FVector2D(0.1, -0.1), FVector2D(-0.1, 0.1) };
It solved jittering for me.

Only that does not fix the problem, but effectively disables the temporal part of SMAA altogether due to jitter being small enough for floating point rounding errors to eradicate it.

yes that basically removes the offset sampling which is an integral part of Temporal AA

@-Godlewski I also tried commenting out the call to HackAddTemporalAAProjectionJitter, but I’m quite sure it’s the same effect as above
with this I actually see a difference with vs without the temporal part in the SMAA, but I’m almost sure this isn’t how it’s meant to look
kinda swamped still :frowning:

Hello, @Chosker! Can you help me to integrate SMAA to 4.16?
I get errors in PostProcessSMAA.cpp due to new engine API, maybe you can provide this file, or files, that you changed for 4.16 version?
Errors are all about FRHICommandList::"–FunctionName–" : Use GraphicsPipelineState Interface Please…
I tried to get into RHICommanList and found that many of function, that are used in 4.14 became structs and I have no idea how to reimplement this part of code. I will very appreciate if you help me with this hard part and it will be awesome if you provide changed file.
Oh, by the way, I inserted all of the smaa code carefuly from github by hands, so I think the only problem is changed engine API and the fact that I don’t know how to combine this stuff :slight_smile:
Thank you!

@ try the 4.14 branch on 's github, I never had any engine API errors

@ is right, there have been some API changes. They are quite trivial, though.

The key to fixing this in recent engine versions is simply to take a graphics debugger (such as RenderDoc), the instructions from the SMAA source code comments and just making sure the jitter in UE4 is set the way that SMAA expects it to.

Now that you can put shaders in plugins in 4.17, can this become a plugin?

I don’t know what the API for shaders in plugins is, but shaders are only half of the problem. The other half is whether you can swap in another compositing graph node in place of the engine’s AA.

I tried to migrate your code from 4.14 to 4.18, but failed. There are too many functions changed. Would you reboot your project for UE4 4.18?

Updated this for 4.18: https://github.com/0lento/UnrealEngine/tree/4.18-SMAA
Some of my changes are bit hacky, but it appears to work somewhat.

hey @0lento thanks for the 4.18 port, great effort
I tried your code but unfortunately it jitters the entire screen for me (I’m at 1080p). do you have any plans to continue working on it?

Can you try it without last commit? if you cloned the repo, just run

git reset --hard HEAD~1

I didn’t really see any difference with that commit, in the end there’s just one variable with different sign to the original code. For me, the original SMAA fork (tested it on 4.12 before) also had small jitter in it, I did check the code and there wasn’t really anything obviously wrong with it. You can try adjusting the cvars, there were few around for smaa which could help you minimize the jitter (or not). I personally didn’t see huge amount of jitter at 1080p on my test scene but it was noticeable when screenpercentage was set to 50. You can also see my earlier commit trying to “fix” the jitter but it actually just removed the temporal component so while it did remove the jitter, AA was also gone when things were not in motion.

I have no plans on working with this, I just wanted to see what this would look like in comparison to other AA tech in 4.18.

I didn’t clone the repo as I manually integrated it into my project. but I can roll back to the previous-to-last commit manually
I’ll try it and report back. thanks again!

ok so I tried without the “revert jitter fix” commit code and it got rid of the jitter.
SMAA ‘seems’ to work but either it naturally gives undesireable results or something might be wrong in the integration / 4.18-fix
I played with the cvars but r.SMAAIntegrateVelocities doesn’t seem to do anything, while r.SMAATemporal has a bit of impact but nothing significant

all in all this SMAA implementation makes the edges more aliased than the other techniques (though still not as much aliasing as no AA). at this point FXAA is arguably better (slightly more blurry but significantly less aliasing)

The commit you tried does get rid of the jitter but it also greatly reduces the AA effect when things are not moving. I think it basically removed the temporal effect, which would explain why your SMAATemporal=0 looks better (vs 1). I didn’t think that was a proper fix so I reverted it. I couldn’t figure out how to make it work any better (I tried bunch of things on my end). It’s also not just with my 4.18 branch, same thing happened on 4.14. Some people just lowered the temporal math values from 0.25 to 0.1 but it’s basically just reducing the effect, not really solving the core with the jitter.