256 Shades of Grey

See those harsh grey lines?  That’s called quantizing or color banding.

Quantizing in a render.

Quantizing in a render.

Would more sampling remove this artifact?   Is it an error in the renderer or the light sampling?

While rendering, we’re generating a floating point result for each color (red, green, blue) that gets converted, losing some accuracy, to 8 bit integer red, 8 bit integer green and 8 bit integer blue.  8 bits per channel in 3 channels.

So we have 24 bits per pixel, but in a grey image like this, the red, green and blue are all the same, so we really only have 8 bits total for pure grey colors.  8 bits gives us 256 shades of grey.

Even though those colors are really close to each other, our eyes and brains are good at noticing the change between them when it’s a sharp line like these are.  With only 256 steps between pure deep black and bright clamped white, our eyes can pick out the line between each step.  Click on this 256 step grey ramp image to see for yourself:

A 256 shade grey ramp by Maximum PC

Click for full size – A 256 shade grey ramp by Maximum PC

The more accurate the render, the more accurate and clean these bands will become.  So more light samples would actually make the lines sharper, not softer.

Counter-intuitively, the answer is just a teeny bit of error added on purpose.  If the steps are in 1/256 increments, then we can randomize the transition a bit by adding a random number between half an increment down and half an increment up to the float before converting to an int.  In other words, add a random number between -1/512 and +1/512 to the float before converting to an int.  All this error does is affect the rounding, making the transition between levels actually represent the real transition the floating point numbers had a lot better when perceived by a human.

Contrast is cranked to emphasize the color banding. No dithering here.

Contrast is cranked to emphasize the color banding. No dithering here.

Contrast is cranked to emphasize the color banding. Dithering makes it all seem smoother.

Contrast is cranked to emphasize the color banding. Dithering makes it all seem smoother.

Contrast is cranked to emphasize the color banding. Closeup with no dithering.

Contrast is cranked to emphasize the color banding. Closeup with no dithering.

 

Contrast is cranked to emphasize the color banding. Closeup with dithering.

Contrast is cranked to emphasize the color banding. Closeup with dithering.

Leave a Reply

Your email address will not be published. Required fields are marked *