Search Unity

Cel Shading Issue: Strange Lines in Addition to Lighting Cuts

Discussion in 'Shaders' started by ThaBullfrog, Nov 29, 2016.

  1. ThaBullfrog

    ThaBullfrog

    Joined:
    Mar 14, 2013
    Posts:
    49
    I'm trying to make a cel shader, but it ends up looking like this:



    See those weird lines? It's like there's an extra form of shading that's bugging out and producing lines.

    I was following this tutorial:
    http://www.gamasutra.com/blogs/DavidLeon/20150702/247602/NextGen_Cel_Shading_in_Unity_5.php
    I am using forward rendering so I copied his shader and modified it to have three cuts and not be so bright.
    Relevant code:
    Code (csharp):
    1.  
    2.     half4 LightingCelShadingForward(SurfaceOutput s, half3 lightDir, half atten)
    3.     {
    4.         half NdotL = dot(s.Normal, lightDir);
    5.  
    6.         if (NdotL < -0.6) NdotL = 0;
    7.         else if (NdotL >= -0.6 && NdotL < 0.3) NdotL = 0.2;
    8.         else NdotL = 0.4;
    9.  
    10.         half4 c;
    11.         c.rgb = s.Albedo * _LightColor0.rgb * (NdotL * atten * 2);
    12.         c.a = s.Alpha;
    13.         return c;
    14.     }
    15.  
    Thank you.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    That's caused by shadows. That's a mild case of shadow acne, actually pretty common, but usually invisible because the ndotl hides the faces facing away from the light where this artifact is showing up. Because you've pushed the lit edge back to -0.6 you're seeing it. You can increase the shadow bias, or disable shadow receiving for the mesh, or try to use a custom shadowcaster pass for that object's shader with front face culling.
     
  3. ThaBullfrog

    ThaBullfrog

    Joined:
    Mar 14, 2013
    Posts:
    49
    Thank you, I decided to use
    "NdotL = smoothstep(0, 0.05f, NdotL);"
    and just lower the intensity of my light.