Toon Shader problem

I have 2 problems with the standard toon-shader:

  1. The object on the left has outlines in the middle of the mesh. The mesh has no errors and consists of only 1 Element. The outline still gets displayed wrong and i don’t know why

  1. I want some details on my character. Is there any toon shader who supports normal or displacement maps, or even both?
    I know that a toon shader with a displacement map is kinda weird, but i have no idea how i can display small details on my meshes, without a retopologization of all my sculpted assets.

Thanky in advance…

Edit: I have no clue of shader coding and i don’t have the time to get into it at the moment, so i am searching for an alternative :frowning:

Here is a toon shader variant with normal-mapping.

It’s based on the lit toon shaders found in the Unity standard assets package (it contains a “Toon Shading” directory). The Toon Shading package is required to compile the following shaders.

Toony-LightedBump.shader

Shader "Toon/Lighted Bumped" {
    Properties {
        _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
        _BumpMap ("Normalmap", 2D) = "bump" {}
    }

    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 300
    
CGPROGRAM
#pragma surface surf ToonRamp

sampler2D _Ramp;
sampler2D _BumpMap;

// custom lighting function that uses a texture ramp based
// on angle between light direction and normal
#pragma lighting ToonRamp exclude_path:prepass
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 (_Ramp, float2(d,d)).rgb;

    half4 c;
    c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
    c.a = 0;
    return c;
}


sampler2D _MainTex;
float4 _Color;

struct Input {
    float2 uv_MainTex : TEXCOORD0;
    float2 uv_BumpMap : TEXCOORD1;
};

void surf (Input IN, inout SurfaceOutput o) {
    half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    o.Albedo = c.rgb;
    o.Alpha = c.a;
    o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG

    }

    Fallback "Toon/Lighted"
}

Toony-LightedOutlineBump.shader

Shader "Toon/Lighted Bumped Outline" {
    Properties {
        _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
        _OutlineColor ("Outline Color", Color) = (0,0,0,1)
        _Outline ("Outline width", Range (.002, 0.03)) = .005
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
        _BumpMap ("Normalmap", 2D) = "bump" {}
    }

    SubShader {
        Tags { "RenderType"="Opaque" }
        UsePass "Toon/Lighted Bumped/FORWARD"
        UsePass "Toon/Basic Outline/OUTLINE"
    }

    Fallback "Toon/Lighted Bumped"
}

Hope it helps!

1 Like

thx so much <3
any idea how to fix the broken outlines?
thx in advance the unity community is awesome :smile:

The toon shader renders outlines by rendering your model a second time, inside out and with its vertices moved outwards along their normal. There is probably some hidden complexity in your mesh that is exposed when it is pushed outwards.