Jump to content
  • entries
    943
  • comments
    5,899
  • views
    924,382

Banding and Dithering


Josh

3,434 views

 Share

I came across a very interesting presentation that talks about how to avoid "banding" artifacts in game graphics. The author uses dithering to add noise to an image and break up the visible lines your eye can detect. This even works with audio. When noise is added to the mix, the original tune appears to become more high-fidelity than it actually is:

 

 

I was able to use this concept to improve the appearance of banding in shadow acne in a low-resolution spotlight with a large volume. Here is the original situation, purposely created to maximize the banding effect:

 

blogentry-1-0-69667800-1463502560_thumb.jpg

 

And here is the result when some slight dithering is added:

 

blogentry-1-0-64261500-1463502565_thumb.jpg

 

The trick to dithering is to know how much noise to add. If we add too much it starts becoming very apparent:

 

blogentry-1-0-32129400-1463502705_thumb.jpg

 

You want to calculate your noise amplitude as the difference between the two discrete levels you are trying to bridge. In the case of the spotlight shader, random noise is being added to the z coordinate of the shadow lookup, so I want the noise amplitude to be equal to the minimum depth difference the shadowmap can display. I calculated this as follows, but more experimentation is needed to make sure its right:

 

float noiselevel = 0.000001 * lightrange.y;
shadowcoord.z += rand(lightnormal.xy) * noiselevel - noiselevel * 0.5;

 

You also want to make sure your random seed is really random. Using the screen coordinate alone produces bad results because the same random seeds will stay in place as you look around and cause visible patterns. If you use the "currenttime" shader uniform the noise will constantly change as the camera stays still, resulting in a film grain effect. I find it is best to multiply the xy components of the fragment coordinate by some other vec2 value.

 

Here's another example with a directional light exhibiting a banding appearance due to a low angle on the ground:

 

blogentry-1-0-81908100-1463504586_thumb.jpg

 

And here is the improved image with dithering applied:

 

blogentry-1-0-90197200-1463504623_thumb.jpg

 

This code does not eliminate shadow acne, it just breaks it up with some random noise so that your eye can't as easily detect a continuous line.

 

The same technique can be used to improve the appearance of the new godrays shader I am working on. With only 16 samples for the rays, banding is very easily visible in this image.

 

blogentry-1-0-70392200-1463503120_thumb.jpg

 

When we add a random offset to the ray starting position, with an amplitude equal to the length of the distance between steps, banding disappears.

 

blogentry-1-0-88368500-1463503208_thumb.jpg

 

Of course more samples are always better, but even at higher sample counts, dithering makes a huge improvement in quality. Leadwerks Engine 2 actually used 64 samples, with worse results than what I got using just 16 samples above. The ease with which I can now modify shaders in Leadwerks Editor and see the results instantly really helped develop these techniques.

  • Upvote 14
 Share

4 Comments


Recommended Comments

If the world coordinate was calculated from the screen coordinate, I think that might make a good seed value for lighting because each pixel would maintain the same noise level as you move around.

Link to comment

When will we be receiving these improvements? I noticed the lighting shaders where updating, but the banding still exists. smile.png

 

EDIT: it seems that on the left wall of 02-FPS Controller, you can see the left wall, the banding isn't apparent, but the right wall, the banding is still noticeable. Weird part being is that the spotlight is centered, but only one side has the banding.

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...