Gamasutra: The Art & Business of Making Gamesspacer
arrowPress Releases






If you enjoy reading this site, you might also want to check out these UBM Tech sites:


 

Next-Gen Cel Shading in Unity 5.6

by David Leon on 05/19/17 09:30:00 am   Featured Blogs

9 comments Share on Twitter    RSS

The following blog post, unless otherwise noted, was written by a member of Gamasutra’s community.
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.

 

Introduction

More than 2 years ago I wrote an article explaining the different methods available at the time to implement a Cel Shading art style in Unity 5. Since then, new Unity updates have made obsolete the use of the Custom Deferred Lighting method, and a new implementation is required to achieve the same results.

Until Unity makes available the new Scriptable RenderLoop feature, our best chance to get a PBR friendly Cel Shading art style is creating a new Deferred shader and a custom BRDF function.

Implementation

Working on a new update for Aragami, I finally decide to upgrade to Unity 5.6 and work on the new implementation. I hold developer time in high regard, so here’s the steps to get Deferred Cel Shading to work in Unity 5.6. All code is available here.

  1. Download the built-in shaders from the Download Archive
  2. Make a copy of /CGIncludes/UnityStandardBRDF.cginc . I just named it UnityStandardBRDFCustom.gcinc. Place it in a /Resources/ folder inside your project.
  3. Modify the file contents so that it only includes the 3 ‘#include’ lines and the BRDF2_Unity_PBS function. Rename BRDF2_Unity_PBS to BRDF_Unity_Toon.
  4. Modify the nl = saturate(dot(normal, light.dir)); line so that it has the desired cel shading cuts. In my case I replaced it for: 
  5. From the built-in shaders, grab and make a copy of /DefaultResourcesExtra/Internal-DeferredShading.shader. Rename it to your liking.
  6. Add #define UNITY_BRDF_PBS BRDF_Unity_Toon after the first CGPROGRAM, and comment the line with #include "UnityPBSLighting.cginc". Also include oour custom BRDF file with "#include "UnityStandardBRDFCustom.cginc"
  7. Place the file inside your /Resources/ folder.
  8. In Unity go to Editor->Project Settings->Graphics, and in the lower part of the inspector, in Built-in shader settings -> Deferred -> Custom Shader -> Select your new Deferred shader.
  9. Make sure that your scene camera is using Deferred rendering path, or that the Deferred rendering path is the default one in your project.

Conclusions

And voilà, now your whole project uses a Cel Shading style, which you can turn off anytime by just going back to the built-in Deferred shader in Project Settings. Bonus points as it works perfectly with Global Illumination, Lightmapping and the new Unity 5.6 Mixed Mode.

To summarize what we did, we just copied BRDF2_Unity_PBS, one of Unity's built-in Physically Based Lighting calculation methods, and modified it slightly to change how the light affects a 3D object. Then we created our custom Deferred shader and told it to use our modified PBS function instead of the original one. That's all.

Hope you liked this quick tutorial, and remember to contact me at david@linceworks.com or write a comment if you have any questions regarding this article.


Related Jobs

Firstborn
Firstborn — New York, New York, United States
[10.18.17]

Game Developer
Square Enix Co., Ltd.
Square Enix Co., Ltd. — Tokyo, Japan
[10.18.17]

Experienced Game Developer
2K
2K — Novato, California, United States
[10.17.17]

FULL-STACK WEB ENGINEER - TEMPORARY
2K
2K — Novato, California, United States
[10.17.17]

SITE RELIABILITY ENGINEER - TEMPORARY





Loading Comments

loader image