Alpha Cutout with Custom Lighting

Hey all!

Im sitting and trying to write a custom lighting (toonish shader)… Ran into a problem when I try to have alpha cutout combined with my own custom lighting model though:

#pragma surface surf ToonLighting alphatest:_Cutoff

vs

#pragma surface surf Lambert alphatest:_Cutoff

As you can see, the alpha cutout works just fine with Lambert lighting but not with my custom lighting. Here’s the custom ToonLighting.cginc that I’ve made:

#ifndef TOON_LIGHTING
#define TOON_LIGHTING

#include "UnityLightingCommon.cginc"
#include "UnityGlobalIllumination.cginc"
#include "Lighting.cginc"

sampler2D         _LightRamp;

inline fixed4 UnityToonRampLight (SurfaceOutput s, UnityLight light)
{
    fixed diff = max (0, dot (s.Normal, light.dir));   
    fixed4 c;
    c.rgb = s.Albedo * light.color * diff;
    c.a = s.Alpha;
    return c;
}

inline half4 LightingToonRamp(SurfaceOutput s, half3 lightDir, half atten)
{
    #ifndef USING_DIRECTIONAL_LIGHT
    lightDir = normalize(lightDir);
    #endif
   
    half d = dot (s.Normal, lightDir)*0.5 + 0.5;
    half3 ramp = tex2D (_LightRamp, float2(d,d)).rgb;
   
    half4 c;
    c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
    c.a = s.Alpha;
    return c;
}

inline fixed4 LightingToonRamp_PrePass(SurfaceOutput s, half4 light)
{
    fixed4 c;
    c.rgb = s.Albedo * light.rgb;
    c.a = s.Alpha;
    return c;
}

#endif

Any ideas how to fix this? :slight_smile:

Cheers

Seems this had to do with camera depth rendering etc. as described here: