Dev Log: Toon-shader that dithers behind objects

How I made a dithering toon-shader!

I have spent my work-time this week upgrading my equipment, working on mechanical concepts, and making a cool toon-shader that dithers when it’s behind an object. I spent some time learning about Unity’s shaders, I was interested in making a toon-shader that would dither when an enemy was not visible.If you are wondering how I did this, well I didn’t write down my steps… However, I will give you a rough breakdown.

Feel free to drop me a line if you have questions so I can update this for others, please bare in mind this is more of an intermediate tutorial. If you don’t know how to make a render pipeline it might be hard to follow along; on the other hand google is your friend, and if you want to do it you can.

Making the dithering shader

CustomRenderer.png
  1. Make custom a render pipeline where the default layer mask excludes a layer (for your enemies).

  2. Add a render object that renders after rendering opaques, check the depth box, and set depth test to greater. Override the material with a new material for your enemy.

  3. Make a shader graph for the dither. I put mine below. I started by creating a fresnel effect that I liked. I multiplied that by a red color and fed it into the color on the unlit master. Then I blended two dithers with a negative X value and a positive X value. I fed that into the alpha on the unlit master. I made a vector 1 for the alpha threshold and set it to X=.5

  4. Now assign the shader to your new enemy material. Your dither will work but you will only see your enemy when it is behind objects. Create another render object the same as before; this time leave the depth box un-ticked.

  5. If you want the toon-shader go to the next section. If you don’t want a toon-shader you can assign the standard material for the enemy to the material override and you’re ready to go. You will need a layer for each enemy material type and remember to un-tick them on the default layer mask. You will also need a render object for each enemy material.

Screen Shot 2020-01-30 at 11.16.45 AM.png
 

Making the toon-shader

SkeleShaded.png

Making the toon-shader was a bit of a bumpy ride for me. I’ll be honest i just frankenstiened a toon-shader made by SnutiHQ it into my custom renderer (link below). If you follow his instructions it is quite a robust shader that works by tracking lights in your scene and mapping those variables on to a material in real time. You can put the material into your custom renderer.

Create another render object the same as before this time leave the depth box un-ticked. Then, pop your new toon-shader material into the material override. As I mentioned above you will need a layer for each enemy material type and remember to un-tick them on the default layer mask. You will also need a render object for each enemy material.

Toon Renderer plugin with documentation and video tutorial.

A special thanks to Gamedev HQ,. If you like the models I used in this tutorial I highly recommend checking-out their site GameDevHQ.com