Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Blue noise crossfade / dither / lod

Discussion in 'Graphics Experimental Previews' started by hippocoder, Jul 3, 2018.

  1. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Peter77, Reanimate_L and dadude123 like this.
  2. Giles-Coope

    Giles-Coope

    Joined:
    Jan 5, 2015
    Posts:
    50
    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.
     
  3. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    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!
     
    dadude123 likes this.
  4. DefiantDev_Chris

    DefiantDev_Chris

    Joined:
    May 9, 2018
    Posts:
    11
    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)
     
    Awarisu, StaffanEk and Peter77 like this.
  5. Giles-Coope

    Giles-Coope

    Joined:
    Jan 5, 2015
    Posts:
    50
    Fair enough, I didn't profile it, and assumed they were performing the dithering without a texture lookup. Thanks for the info.
     
  6. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    Hope this makes its way into HDRP. It would be an improvement.
     
  7. DefiantDev_Chris

    DefiantDev_Chris

    Joined:
    May 9, 2018
    Posts:
    11
    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/
     
    neoshaman and Reanimate_L like this.
  8. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Thanks a lot Chris! much appreciated.

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

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    934
    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 :)

    But if you want to customize it for your HDRP project, look at
    https://github.com/Unity-Technologi...nder-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.
     
    Zee-Play, fherbst, Lin-Dong and 3 others like this.
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Impressive, thanks for clarification.
     
  11. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    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
     
    hippocoder likes this.
  12. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    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!
     
  13. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    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?
     
  14. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    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"
    - No more popping! LOD crossfading with Unity 2022.2 URP - unity japan