# Temporal AA sharpening

**URL:** <https://forums.unrealengine.com/t/temporal-aa-sharpening/98676>\
**Category:** Rendering\
**Tags:** unreal-engine\
**Created:** [August 17, 2017, 10:06pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676 "2017-08-17T22:06:25Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![John\_Alcatraz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@John\_Alcatraz](https://forums.unrealengine.com/u/John_Alcatraz)\
**Post date:** [August 18, 2017, 8:10pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/44 "2017-08-18T20:10:46Z")

</div>

If you could offer this in a 4.16 version that would help quite a few people I think… 4.17 is still new and you can’t always update immediately.

---

<div class="post-metadata">

**Author:** ![Konflict](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/konflict/32/906588_2.png) [@Konflict](https://forums.unrealengine.com/u/Konflict)\
**Post date:** [August 18, 2017, 9:23pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/45 "2017-08-18T21:23:50Z")

</div>

> [@John Alcatraz;751568](#):
>
> I think the other one is also for making the scene appear more sharp.

Yes the scene will appear more responsive and sharp (compared to original TAA) because the solution in the article i posted is going to reduce the antialiasing effectiveness, as well as the accumulation of the blur on these areas. The only requirement is to have your camera to move in order to gather the required information from the scene which will drive the final blending of the pixels.

> [@hallatore;751570](#):
>
> The other changes make the scene more sharp when you move around. I don’t think it should change the sharpness when the camera is stationary?

Yes, exactly! Since it is bound to camera movement, the static scenes will unable to provide the required informations for the simple equation, and it would require more robust solution (eg, a depth difference approach with an additional temporal pass) to have them work. It’s something i am working on currently, and the end result will likely be possible to be combined with this sharpening pass as well.

> [@hallatore;751582](#):
>
> Haven’t written any C++ or shader code before, so most of the .cpp stuff is just guessing.

Looks good and very advanced so far. Nice work on that. I’m not entirely sure of the reason for some refactors but let’s just have the freedom of the author 🙂

> [@Tom Looman;751668](#):
>
> The bluriness of TXAA

Here, this technology is labeled as TAA afaik, and a very simple approach which can be extended further by anyone. If you wish to reduce the blurriness of the TAA, it might be better to prevent it to happen long beforehand. Post sharpening of the screen best helps with fine adjustments only to pronounce the content for the viewers pleasures.

@hallatore have done an amazing job on demonstrating the possibilites (with the actual implementation too, it is mature) and i’m having a feeling this only is just the beginning you guys have witnessed here 🙂 Well done!

---

<div class="post-metadata">

**Author:** ![hallatore](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hallatore/32/1109226_2.png) [@hallatore](https://forums.unrealengine.com/u/hallatore)\
**Post date:** [August 18, 2017, 11:04pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/46 "2017-08-18T23:04:13Z")

</div>

> [@Konflict;751855](#):
>
> If you wish to reduce the blurriness of the TAA, it might be better to prevent it to happen long beforehand. Post sharpening of the screen best helps with fine adjustments only to pronounce the content for the viewers pleasures.
> 
> @hallatore have done an amazing job on demonstrating the possibilites (with the actual implementation too, it is mature) and i’m having a feeling this only is just the beginning you guys have witnessed here 🙂 Well done!

Thanks! 🙂  
This little project actually started because I got an idea while playing around with the anti-ghosting stuff.  
Without AA we have sharp textures, but also sharp edges. With TAA we get (slightly) blurry textures, but also smooth edges.

My idea was that because we have two eyes we see real life details both sharp and blurry. Details on a flat plane (tv screen, paper, wall, etc) we see very sharp since both eyes can focus on the same point in space. But edges of object are never truly sharp because our eyes don’t have a perfect focus point. So in a sense real life edges are smooth and not perfectly sharp.  
That’s the concept I’m trying to emulate. TAA already got the smooth part down, it’s just the sharp part that is not 100%.

By using the depth to detect object edges I can avoid sharpening those. Right now I have it set to fade from 0 to 15 world units in depth. As in 15 means 0 sharpening.  
The second piece is that I calculate the max contrast between the neighboring pixels. The more contrast already there, the less sharpening is applied. Right now I’ve found a sweet spot of 0 to 4% difference in contrast where 4% means 0 sharpening.  
Combining these two gives the resulting image where object edges are unaffected by sharpen, while texture details are affected. And low contrast details gets a slightly more sharpen than already high contrast stuff.

My goal is not to create a new sharpen post process, but to make TAA come as close to the “truth” as possible. The “truth” in this case is TAA with screen percentage set to 200. 🙂  
That’s also why I’m doing minor tweaks to the code, it’s hard to find the right balance where smooth stuff is smooth and crisp stuff stay crisp.

The easy part is making it sharper than the default: [Imgsli](https://imgsli.com/MDYzMg) (Default TAA vs. 0.25)  
The hard part is matching the “truth”: [Imgsli](https://imgsli.com/MDYzMw) (TAA 200% vs. 0.25)

An unintended side effect is that extreme values hold up much better than r.Tonemapper.Sharpen: [Imgsli](https://imgsli.com/MDYzNA) (Sharpen 1 vs. Dynamic 1.0)  
They are both way to high, but I feel sharpen has more artifacts while they deliver about the same amount of texture sharpening.

---

<div class="post-metadata">

**Author:** ![hallatore](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hallatore/32/1109226_2.png) [@hallatore](https://forums.unrealengine.com/u/hallatore)\
**Post date:** [August 18, 2017, 11:36pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/47 "2017-08-18T23:36:08Z")

</div>

Just some screen percentage tests. Using this thread to log my work. 🙂

70%: [Imgsli](https://imgsli.com/MDYzNQ)  
50%: [Imgsli](https://imgsli.com/MDYzNg)  
And an interesting one. 100% default vs. 70% dynamic: [Imgsli](https://imgsli.com/MDYzNw)

---

<div class="post-metadata">

**Author:** ![hallatore](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hallatore/32/1109226_2.png) [@hallatore](https://forums.unrealengine.com/u/hallatore)\
**Post date:** [August 19, 2017, 12:47am UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/48 "2017-08-19T00:47:15Z")

</div>

I could use some feedback on the following code. Does it look correct, is there stuff I can drop?

[https://github.com/hallatore/UnrealEngine/blob/TAA\_Sharpen/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessTemporalAA.cpp#L1142-L1253](https://github.com/hallatore/UnrealEngine/blob/TAA_Sharpen/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessTemporalAA.cpp#L1142-L1253)

---

<div class="post-metadata">

**Author:** ![trentpolack](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/trentpolack/32/1173069_2.png) [@trentpolack](https://forums.unrealengine.com/u/trentpolack)\
**Post date:** [August 19, 2017, 1:33am UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/49 "2017-08-19T01:33:01Z")

</div>

> [@hallatore;751907](#):
>
> I could use some feedback on the following code. Does it look correct, is there stuff I can drop?
> 
> [https://github.com/hallatore/UnrealEngine/blob/TAA\_Sharpen/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessTemporalAA.cpp#L1142-L1253](https://github.com/hallatore/UnrealEngine/blob/TAA_Sharpen/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessTemporalAA.cpp#L1142-L1253)

I was giving it a look earlier and it seemed fine and is consistent with the rest of the source. The only thing I’d be concerned about is potentially unknown effects on the overall post stack given the presence (or lack thereof) of other effects. But, I don’t see any issues on my end in-game, so it seems solid.

(Though I’d recommend making your TAA\_Sharpen branch the promoted/default branch for your repo – it’s easy enough to do in the repo settings).

---

<div class="post-metadata">

**Author:** ![hallatore](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hallatore/32/1109226_2.png) [@hallatore](https://forums.unrealengine.com/u/hallatore)\
**Post date:** [August 19, 2017, 8:02am UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/50 "2017-08-19T08:02:21Z")

</div>

> [@mittense;751914](#):
>
> I was giving it a look earlier and it seemed fine and is consistent with the rest of the source. The only thing I’d be concerned about is potentially unknown effects on the overall post stack given the presence (or lack thereof) of other effects.

It only runs when Temporal AA is also running. [https://github.com/hallatore/UnrealEngine/blob/TAA\_Sharpen/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessing.cpp#L901-L912](https://github.com/hallatore/UnrealEngine/blob/TAA_Sharpen/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessing.cpp#L901-L912)  
@Chris.Bunner Is it required to add a Computer shader pass also?

---

<div class="post-metadata">

**Author:** ![hallatore](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hallatore/32/1109226_2.png) [@hallatore](https://forums.unrealengine.com/u/hallatore)\
**Post date:** [August 19, 2017, 10:02am UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/51 "2017-08-19T10:02:56Z")

</div>

**Moving frames!** 🙂  
These images are captures while the camera is moving. So it represent what you would see if you took a screenshot while moving.

By default TAA gets blurrier when the camera is moving because of how it reuses frames. It’s actually quite bad. ([https://imgsli.com/MDY0NA](https://imgsli.com/MDY0NA))  
Dynamic improves it a bit ([https://imgsli.com/MDY0NQ](https://imgsli.com/MDY0NQ)), but it’s not perfect since TAA blurs it so much.

I’ve looked at the TAA blend that @Konflict made and think it works quite well combined with my code. [Adaptive-Blended TAA, a tiny magic for your sharp and responsive scenes - Rendering - Unreal Engine Forums](https://forums.unrealengine.com/showthread.php?152521-Adaptive-Blended-TAA-a-tiny-magic-for-your-sharp-and-responsive-scenes)  
I reduced the blend amount just a tiny bit to reduce jitter on stuff with very high noise.

```auto

BlendFinal = clamp( BlendFinal + sqrt(sqrt(distance(BackN.xy, UV.xy))) * 0.5f , BlendFinal , 1.0f );

```

The end result is a much better moving frame! 🆒 (**[Imgsli](https://imgsli.com/MDY0Mg)**)  
It also matches No AA much better than the default AA does. [https://imgsli.com/MDY0NA](https://imgsli.com/MDY0NA) vs. [Imgsli](https://imgsli.com/MDY0Mw)

![fc5111116bd6834d7813df4b766ae60d7d4156b4.jpeg](https://d1ap1mz92jnks1.cloudfront.net/images/transparent.png)

---

<div class="post-metadata">

**Author:** ![John\_Alcatraz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@John\_Alcatraz](https://forums.unrealengine.com/u/John_Alcatraz)\
**Post date:** [August 19, 2017, 3:30pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/53 "2017-08-19T15:30:25Z")

</div>

Very nice to see the progress you’re making on it, really looks like your change and the one from Konflict work well together.

---

<div class="post-metadata">

**Author:** ![hallatore](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hallatore/32/1109226_2.png) [@hallatore](https://forums.unrealengine.com/u/hallatore)\
**Post date:** [August 19, 2017, 4:10pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/54 "2017-08-19T16:10:38Z")

</div>

> [@dvd.kh;751997](#):
>
> can you provide this Dynamic + Blend version as github branch please?

Will do later, it’s not quite there yet. 🙂  
I’ve tweaked the code @Konflict made to combat jitter-artifacts in noisy stuff. It’s more of a movement sharpening than a anti-ghost thing now.

Just a test with a very noisy cube. 🙂

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/9/1/0917390f216ba19cf7879af669b0b48d3cff99d1.jpeg "Unreal Engine - Anti blur while moving test") ](https://www.youtube.com/watch?v=lIlqljNSTok)

---

<div class="post-metadata">

**Author:** ![trentpolack](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/trentpolack/32/1173069_2.png) [@trentpolack](https://forums.unrealengine.com/u/trentpolack)\
**Post date:** [August 19, 2017, 5:29pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/55 "2017-08-19T17:29:34Z")

</div>

Out of curiosity, is this your sole source of sharpening for the full composition? I realized I had my tonemapper sharpening still at a (relatively low) value, and not sure if I should use small values for the combo or just go straight one way or the other. It’s possible that it’d be more efficient to reserve all sharpening to a single dedicated pass, but I can also see the value in potentially doing mild sharpening at separate stages.

(I’m currently debugging a bunch of engine-side changes I made, so I can’t just launch and test it, was just wondering in the interim).

---

<div class="post-metadata">

**Author:** ![alecmoody](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@alecmoody](https://forums.unrealengine.com/u/alecmoody)\
**Post date:** [August 19, 2017, 6:20pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/56 "2017-08-19T18:20:04Z")

</div>

This looks great. The only reason my VR project is on forward is for MSAA. I would love a sharper temporal AA so I could go back to deferred and ditch the early z pass.

---

<div class="post-metadata">

**Author:** ![Konflict](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/konflict/32/906588_2.png) [@Konflict](https://forums.unrealengine.com/u/Konflict)\
**Post date:** [August 19, 2017, 7:45pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/57 "2017-08-19T19:45:22Z")

</div>

> [@hallatore;751981](#):
>
> while the camera is moving. By default TAA gets blurrier when the camera is moving

Precisely. This is also the source of the problems with VR where the viewer can get sick of these. Me too, i hate this blurring, and the higher the coefficient for the equation the better the blur gets reduced.

> [@hallatore;751981](#):
>
> reduce jitter on stuff with very high noise.

Yes the side effects upon camera movement will result in aliased content showing up since the antialiasing get’s seriously reduced on high values. On a desktop monitor this can be witnessed.

> [@hallatore;752048](#):
>
> It’s more of a movement sharpening than a anti-ghost thing now

Then it finally serves it’s main purpose. Anti ghosting is only a side effect under given circumstances, but was not among it’s primary function 🙂

> [@mittense;752082](#):
>
> I had my tonemapper sharpening still at a (relatively low) value

No don’t use the tonemapper sharpen on scenes where high contrast can happen. It is best used on low contrast scenes only! You should use only this sharpening that excludes the high contrast areas, thus providing you the sharpening on the fine details only.

> [@alecmoody;752097](#):
>
> I would love a sharper temporal AA so I could go back to deferred

If you allow me to recommend this combined solution for your VR project, then please by all means try it! In VR you will find to be less annoying to have a little aliasing artifacts, so you can just go wild with these values and apply strong effect for any or both equations. The resulting deblurred screens expected to cause less sickness, but let us know what are your experiences!

---

<div class="post-metadata">

**Author:** ![John\_Alcatraz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@John\_Alcatraz](https://forums.unrealengine.com/u/John_Alcatraz)\
**Post date:** [August 19, 2017, 8:11pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/58 "2017-08-19T20:11:53Z")

</div>

> [@Konflict;752116](#):
>
> If you allow me to recommend this combined solution for your VR project, then please by all means try it! In VR you will find to be less annoying to have a little aliasing artifacts, so you can just go wild with these values and apply strong effect for any or both equations. The resulting deblurred screens expected to cause less sickness, but let us know what are your experiences!

I am currently using TAA in VR because MSAA doesn’t work with SSAO due to SSAO depending on TAA for good quality, so I would definitely try this out. I just can’t update my project to 4.18 at the moment, so I will have to wait until this is available for earlier engine versions, or I will try to port it back myself, but I guess that only makes sense to do after hallatore is done adding new things to this all the time 🙂 So it will be a while before I can give feedback on how this feels in VR.

---

<div class="post-metadata">

**Author:** ![ErnestoEASD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ErnestoEASD](https://forums.unrealengine.com/u/ErnestoEASD)\
**Post date:** [August 19, 2017, 10:50pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/59 "2017-08-19T22:50:57Z")

</div>

Seeing this hurts my eyes, this is curious to me thought why sharpen when its mostly ment to soften the edges?

Me personally I would never use Unreal Temporal AA, FXAA or even MSAA because its terrible and I prefer to just  
draw the image without any aliasing.

This looks interesting when I look at it I mostly would think if it will hit performance hard.

---

<div class="post-metadata">

**Author:** ![John\_Alcatraz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@John\_Alcatraz](https://forums.unrealengine.com/u/John_Alcatraz)\
**Post date:** [August 19, 2017, 10:55pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/60 "2017-08-19T22:55:56Z")

</div>

> [@ErnestoEFL;752156](#):
>
> Me personally I would never use Unreal Temporal AA, FXAA or even MSAA because its terrible and I prefer to just  
> draw the image without any aliasing.

Everyone prefers an image without aliasing, but you can only get an image without aliasing if you use any anti-aliasing technique like TAA, FXAA or MSAA.

---

<div class="post-metadata">

**Author:** ![hallatore](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hallatore/32/1109226_2.png) [@hallatore](https://forums.unrealengine.com/u/hallatore)\
**Post date:** [August 20, 2017, 10:20am UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/61 "2017-08-20T10:20:00Z")

</div>

> [@John Alcatraz;752124](#):
>
> I would definitely try this out. I just can’t update my project to 4.18 at the moment, so I will have to wait until this is available for earlier engine versions

What engine version are you on? It’s mostly research for now, but I might give it a go to port it if I got time.

> [@mittense;752082](#):
>
> Out of curiosity, is this your sole source of sharpening for the full composition? I realized I had my tonemapper sharpening still at a (relatively low) value, and not sure if I should use small values for the combo or just go straight one way or the other.

This isn’t meant as a replacement for the tonemapper sharpen. It’s meant as pure TAA anti blur. So it’s correct to use both, since they do slightly different things.

> [@John Alcatraz;752158](#):
>
> Everyone prefers an image without aliasing, but you can only get an image without aliasing if you use any anti-aliasing technique like TAA, FXAA or MSAA.

Especially with 4K I get that some prefer no AA over TAA, FXAA etc because of the slight blur they introduce. And it’s exactly what this code is trying to fix. 🙂  
The goal is smooth edges but same texture sharpens as with no AA.

---

<div class="post-metadata">

**Author:** ![hallatore](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hallatore/32/1109226_2.png) [@hallatore](https://forums.unrealengine.com/u/hallatore)\
**Post date:** [August 20, 2017, 12:10pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/62 "2017-08-20T12:10:11Z")

</div>

I have updated the github repo with the latest changes. It now works well both stationary and while moving. Give it a go! 🆒

Here is the current status/goals of the code.

1. Textures should have the same sharpness as with no AA. Not less or more.

2. Edges should have the same smoothness as with default TAA.

3. While moving textures should have the same sharpness as with no AA. Not less or more.

4. While moving noisy textures should have the same temporal stability as with default TAA.

5. and 2. are pretty much done. It looks great with the default value (0.25).

6. and 4. are working very well, but they are opposites. I can’t reduce the blur further while moving without reducing the temporal stability (jittering) in noisy textures. What I have now feels like a great middle road with unnoticeable difference on noisy textures while greatly increasing the sharpness while moving.

 ![comp.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/6/5/653bf88be7b0ae86ebd8c9a2c2071d42953bd463.png)

---

<div class="post-metadata">

**Author:** ![hallatore](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hallatore/32/1109226_2.png) [@hallatore](https://forums.unrealengine.com/u/hallatore)\
**Post date:** [August 20, 2017, 3:22pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/63 "2017-08-20T15:22:49Z")

</div>

Just another stationary test scene with the current code: [Imgsli](https://imgsli.com/MDY0OQ)

![7676039d3bbca8da0f32bd89fea6d56b3461e4c3.jpeg](https://d1ap1mz92jnks1.cloudfront.net/images/transparent.png)

---

<div class="post-metadata">

**Author:** ![John\_Alcatraz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@John\_Alcatraz](https://forums.unrealengine.com/u/John_Alcatraz)\
**Post date:** [August 20, 2017, 4:09pm UTC](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676/64 "2017-08-20T16:09:09Z")

</div>

> [@hallatore;752252](#):
>
> What engine version are you on? It’s mostly research for now, but I might give it a go to port it if I got time.

I am on 4.15, but if you would port this to 4.16 then it should be simple for me to port this to 4.15 I think. 4.16 is the version many people are currently still on since 4.17 is very new, so I think having a 4.16 version makes sense.

> [@hallatore;752266](#):
>
> I have updated the github repo with the latest changes. It now works well both stationary and while moving. Give it a go! 🆒
> 
> PS: A side effect is less ghosting while moving. (Notice the right side of the tree ghosting over the character)

Awesome!

[Previous page](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676.md?page=2)

[Next page](https://forums.unrealengine.com/t/temporal-aa-sharpening/98676.md?page=4)
