Dithering Shader

From Unify Community Wiki
Jump to: navigation, search
Dithering Shader Samples

Description

Update: The shader package now includes image effects which streamlines their usage in Unity Pro.

These shaders replace the colors on the screen with dithering patterns of one or more indexed colors taken from a palette image (by converting the original color into a XY coordinate on the palette image). The theoretical maximum number of dithering patterns is 16^3.

The palette images are generated with the CreatePalette editor component in Unity3d. The dithering algorithms used in color selection for the palette images are based on code and algorithms by Joel Yliluoma. A dithering pattern with over 2 colors uses the gamma-corrected algorithm, while an alternative algorithm is used for dithering patterns with 2 colors.

The shaders work best at low resolutions and DOES NOT PIXELIZE the screen. However, they will work in Unity3d Free since it's not a traditional Image Effect.

Included shaders:

  • Normal/Diffuse
  • Normal/Diffuse Simple
  • Normal/Unlit
  • Normal/Unlit Simple
  • Cutout/Diffuse
  • Cutout/Diffuse Simple
  • Cutout/Unlit
  • Cutout/Unlit Simple
  • ImageFx/Diffuse
  • ImageFx/Diffuse Simple

(The Simple shaders have a fixed dithering pattern with max 4 colors, but uses one less texture Sampler)

4-color palette image

Usage

Download and extract in the assets directory: Media:DitheringShaders.zip

  1. Use the CreatePalette component to create a palette image, or use one of the retro computer palettes included in the archive
    • Mixed Color Count: The number of colors to mix in a dithering pattern
  2. Apply one of the Palette Shaders to your material
  3. Configure the shader
    • Base: The main texture
    • Mixed Color Count: The number of mixed colors in your palette (rows of 16x16 pixel squares)
    • Palette Height: The palette image height in pixels
    • Palette: The palette image
    • Dither Size: The size of the chosen dither image
    • Dither: The dither pattern image (With the red values 0 to 254)

The textures used for both dithering patterns and palettes should be configured like this:

  • Texture Type: Advanced
  • Generate Mip Maps: Unchecked
  • Filter Mode: Point
  • Format: RGB 24 bit
  • Size: Power of two

To use the shader as an image effect: Camera > Add Component > Image Effects > Other > Dithering or Dithering Simple.

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox