A heads-up on pixel near-neighbor algorithms + postprocess + TemporalAA

I figured out the cause of flickering pixels when using a variant of the Stylized demo outline shader, which might affect other post-process algorithms that inspect neighboring pixels if using Temporal AntiAliasing (the default AA).

Basically, the outline shader, which worked fine most of the time, could create flickering pixels in some cases when rendering the scene, even when nothing was moving. The flickering pixels would repeat the same pattern every 4 or 8 frames.

The outline shader looks at all 4 immediate neighbors of each pixel at (x,y) to decide whether to emit the original pixel or a black border pixel. But since the pixel at (x,y) is affected by the pixels at (x+1,y) and (x,y+1), which have not had their values affected by that same algorithm yet, a second pass can change what happens to (x,y), which in turn can affect (x+1,y) and (x,y+1), leading to a feedback loop.

At least that’s what seems to be happening. I was able to stop the flickering by changing the algorithm to only use 2 neighboring pixels at (x-1,y) and (x,y-1) instead of all four, to avoid the possible feedback effect.

This could happen to other PP algorithms that look at adjacent pixels, so I’m posting this as a general heads-up.

Addendum: This might be due to the x-1 and y-1 pixels being delayed slightly in the pipeline – after I changed it so all four coordinates take the same length path, it seemed to work much better.