- Home /
My Deferred Cell Shading is not working
I've changed the deferred rendering shader in unity back in version 5.3 based on this tutorial: http://www.gamasutra.com/blogs/DavidLeon/20150702/247602/NextGen_Cel_Shading_in_Unity_5.php
It worked like a charm and my game had the look I was aiming for. But once I've updated to version 5.5 the shader simply stopped working. I've found out it has to do with Unity 5.5 ignoring any light.ndotl variables in the shaders :
"The ndotl variable value in UnityLight is now calculated on the fly and any value written into the variable is ignored."
My game should look like this : But now it Looks like this:
Is there anyway I can achieve this look again?
I've tried and can't find a way to change the Internal-DefferedShading to achieve the look I once had.
In this project I might. But this will probably be carried over to unity 6,7,8,9... At one point I'll have to update. The way it is, we can't manipulate light behaviour in Unity's PBS. I've been trying to make this in a shader rather than in the Internal-DeferredShading and can't make a non-forward rendering custom lighting effect.
Answer by Koropokuruh · Jan 29, 2017 at 01:03 PM
Fixed! Now the Light.NDotl is calculated in CGINC files...
Hi I'm having the exact same issue as you. Did you make a copy of UnityCG.cginc and add the change to the ndotl section of the file? I tried that and it crash unity every time it tries to render in the editor.
This is how I change my file but it just crash unity every time:
// NdotL
float4 ndotl = 0;
ndotl += toLightX * normal.x;
ndotl += toLightY * normal.y;
ndotl += toLightZ * normal.z;
// correct NdotL
float4 corr = rsqrt(lengthSq);
ndotl = max (float4(0,0,0,0), ndotl * corr);
// cel shading
if (ndotl <= 0.0F)
ndotl = 0F;
else
ndotl = 1F;
Can you please let me know exactly how you solve this. Thanks!
I've altered the UnityStandardBRDF.cginc file. created a new method (so I can have more than 1 lighting option in the engine):
//copied from BRDF2_Unity_PBS and added :
//if (nl <= 0.0f) nl = 0.0f;
//else if (nl <= 0.9f) nl = 0.8f;
//else nl = 1.0f;
//to create a toon lighting effect without the need of a ramp texture
The code is too big to put here... But I've called it BRDF_Unity_Toon This way you can have the option to normal unity pbr lighting or a toon cel shaded lighting.
After that I've made a shader and added this line: #define UNITY_BRDF_PBS BRDF_Unity_Toon so now it will use the toon lighting method I've created in UnityStandardBRDF.cginc
@koropokuruh Any chance you can post a link to your code? I've been trying to get this working again (was working perfectly in an older version with no toon ramp) with the standard deferred shader.
Well I'll tell what I did, there's no need to post my code here.
1)I've made a copy of [program files]\Unity\Editor\Data\CGIncludes\UnityStandardBRDF.cginc
2)I've opened UnityStandardBRDF.cginc and looked for BRDF2_Unity_PBS function
3)copied everything in the function and pasted as a new function below BRDF3_Unity_PBS function
4)I've renamed it as BRDF_Unity_Toon
5)Below the line "half nl = saturate(dot(normal, light.dir));" I've added
if (nl <= 0.0f) nl = 0.0f;
else if (nl <= 0.9f) nl = 0.8f;
else nl = 1.0f;
6)Saved and replaced the original unity CGINC file (make a backup!!!)
7)Opened unity default deferred shading shader and changed the #define line with below
#define UNITY_BRDF_PBS BRDF_Unity_Toon
8)Save the file as "Toon-DeferredShading" and put it in unity graphics option.
Thank you!!! This did the trick. Seriously thank you for taking the time to explain that. I've never really done anything with shaders before so it's confusing to me.
One thing that i had to play with was where to put that #define line. I ended up sticking it right below the first CGPROGRA$$anonymous$$ line and that got it working.
Thanks again.
Yeah I still haven't resolved the issue, even after trying the methods details here: The bottom answer
It still causes unity to crash anytime I try to use a modified .cginc file.
the problem with that answer is that all of you projects will have that lighting, the solution I gave above gives me the option to use toon shading or not.