Blue noise crossfade / dither / lod

Shader - Shadertoy BETA (animated test). I believe Chris said it’s so good it’s basically cheating - and he is right.

Source: x.com

Very interesting - where do I poke to put this in (and: any reason Unity doesn’t upgrade to doing this by default, as it isn’t a perf issue, is it?)

3 Likes

Blue noise requires a blue noise texture and thus an extra texture lookup. There is no good way of calculating blue noise in real-time. Thus the Bayer-matrix dithering is more performant in general.

I prefer blue noise over the bayer even after accounting for the performance cost. It is just visually pleasing.

I’ve always hated bayer grids being noticable when close to camera. Some games use it for fading out view blocking models, and it is disgusting!

1 Like

Unity uses a lookup texture for its bayer matrix. My blue noise dither implementation is the exact same code (with a different number in the math for the differing dimensions), and a different texture. There is no performance difference (trust me, I’ve run it through many profilers)

3 Likes

Fair enough, I didn’t profile it, and assumed they were performing the dithering without a texture lookup. Thanks for the info.

Hope this makes its way into HDRP. It would be an improvement.

Hey so I uploaded everything you’ll need to do this yourself. All you need to do is bang the texture in resources (so that the script can load it always), and include that cginc in any of your surface shaders which use the “dithercrossfade” generation option. If you don’t use surface shaders, I’m sure you can figure it out. Let me know if it doesn’t work for you.

https://bitbucket.org/ChrisPeWebb/bluenoisedither/src/master/src/

2 Likes

Thanks a lot Chris! much appreciated.

Also @SebLagarde do you have throughts about this small change? Seems a large quality improvement.

Hi,

Also @SebLagarde do you have throughts about this small change? Seems a large quality improvement.
Have you try the lod fade provide in HDRP? it is not the bayer pattern of Unity.

We are always worrying about performance, and adding a texture fetch for cross fade purpose is not in our plan :slight_smile:

But if you want to customize it for your HDRP project, look at
https://github.com/Unity-Technologies/ScriptableRenderPipeline/blob/master/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl

And update this function:

void LODDitheringTransition(uint3 fadeMaskSeed, float ditherFactor)
{
// Generate a spatially varying pattern.
// Unfortunately, varying the pattern with time confuses the TAA, increasing the amount of noise.
float p = GenerateHashedRandomFloat(fadeMaskSeed);
// We want to have a symmetry between 0…0.5 ditherFactor and 0.5…1 so no pixels are transparent during the transition
// this is handled by this test which reverse the pattern
// TODO: replace the test (ditherFactor >= 0.5) with (isLod0) to avoid the distracting pattern flip around 0.5.
p = (ditherFactor >= 0.5) ? p : 1 - p;
clip(ditherFactor - p);
}

Would recommend that whatever you do, validate it work in Unity for mesh Lod transition (Getting the symmetry right when transitioning is not always straightforward) and that it is working correctly when TAA is enabled.

6 Likes

Impressive, thanks for clarification.

hi , any tip on applying this effect on shader graph as a custom function node?
the current dither node in shader graph is really bad and too obvious to the eye.

thanks

1 Like

I have no tips, not sure how myself. I do think it’s probably something to do with jitter or such though… please post if you find out!

Would like to bump that again @SebLagarde - just tried to improve the look of dithering (not for LODs, but in general) by running Forward + MSAA but seems that Alpha to Coverage isn’t possible at all right now - no matter what I do, I end up with full 0/1 pixels after alpha clipping. Am I missing something?

Can you reconsider adding it now:
URP itself has blue noise crossfading now, it noticeably improves LOD transitions. I was wondering why URP crossfade looks better then found out they have support for two modes, one being blue noise.

Unity Japan also recommends using blue noise method, relating to performance they said the following: “I personally think it’s a level you don’t have to worry about, the difference is about sampling a tiny noise texture at most once”