ARKitシーンでユニティちゃんトゥーンシェーダー2.0でアウトラインカラーを出す

Unity　ARKit　Pluginを使ったシーンでユニティちゃんトゥーンシェーダー2.0を使うと、アウトラインがSceneビューでは表示されるけどGameビューや実機で表示されませんでした。
シェーダー関数を少し書き換えて対応しました。

方法としてはユニティちゃんシェーダー(ユニティちゃんトゥーンシェーダー2.0ではなく)のアウトラインなら表示できるのでユニティちゃんトゥーンシェーダー2.0のアウトラインPassだけ上書きします

[・ユニティちゃんトゥーンシェーダー2.0](http://unity-chan.com/download/releaseNote.php?id=UTS2_0)

[・ユニティちゃんシェーダー](http://unity-chan.com/download/releaseNote.php?id=AdditionalUnityChanShader)

ライセンス表記：© Unity Technologies Japan/UCL

#ユニティちゃんシェーダーのアウトラインPass

```
Pass {
    Name "Outline"
    Tags {
    }
    Cull Front
    
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #define _GLOSSYENV 1
    #include "UnityCG.cginc"
    #include "UnityPBSLighting.cginc"
    #include "UnityStandardBRDF.cginc"
    #pragma fragmentoption ARB_precision_hint_fastest
    #pragma multi_compile_shadowcaster
    #pragma multi_compile_fog
    #pragma exclude_renderers d3d11_9x xbox360 xboxone ps3 psp2 
    #pragma target 3.0
    #pragma glsl
    uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
    uniform sampler2D _Outline_sampler; uniform float4 _Outline_sampler_ST;
    uniform float _Outline_Width;
    uniform float4 _Line_Color;
    struct VertexInput {
        float4 vertex : POSITION;
        float3 normal : NORMAL;
        float2 texcoord0 : TEXCOORD0;
    };
    struct VertexOutput {
        float4 pos : SV_POSITION;
        float2 uv0 : TEXCOORD0;
        UNITY_FOG_COORDS(1)
    };
    VertexOutput vert (VertexInput v) {
        VertexOutput o = (VertexOutput)0;
        o.uv0 = v.texcoord0;
        float4 _Outline_sampler_var = tex2Dlod(_Outline_sampler,float4(TRANSFORM_TEX(o.uv0, _Outline_sampler),0.0,0)); // Outlineの入り抜き調整Sampler
        o.pos = UnityObjectToClipPos(float4(v.vertex.xyz + v.normal*(_Outline_sampler_var.rgb*_Outline_Width*0.001).r,1) );
        UNITY_TRANSFER_FOG(o,o.pos);
        return o;
    }
    float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
        float isFrontFace = ( facing >= 0 ? 1 : 0 );
        float faceSign = ( facing >= 0 ? 1 : -1 );
        float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex)); // 通常Color用テクスチャ
        return fixed4(((_MainTex_var.rgb*_MainTex_var.rgb)*_Line_Color.rgb),0);
    }
    ENDCG
}
```

#ユニティちゃんトゥーンシェーダー2.0のUCTS_Outline.cginc

```
uniform float4 _LightColor0;
uniform float4 _BaseColor;
uniform sampler2D _BaseMap; uniform float4 _BaseMap_ST;
uniform float _Outline_Width;
uniform float _Farthest_Distance;
uniform float _Nearest_Distance;
uniform sampler2D _Outline_Sampler; uniform float4 _Outline_Sampler_ST;
uniform float4 _Outline_Color;
uniform fixed _Is_BlendBaseColor;
uniform fixed _Is_LightColor_Base;
uniform float _Offset_Z;
struct VertexInput {
    float4 vertex : POSITION;
    float3 normal : NORMAL;
    float2 texcoord0 : TEXCOORD0;
};
struct VertexOutput {
    float4 pos : SV_POSITION;
    float2 uv0 : TEXCOORD0;
};
VertexOutput vert (VertexInput v) {
    VertexOutput o = (VertexOutput)0;
    o.uv0 = v.texcoord0;
    float4 objPos = mul ( unity_ObjectToWorld, float4(0,0,0,1) );
    float3 lightColor = _LightColor0.rgb;
    float2 Set_UV0 = o.uv0;
    float2 node_6326 = Set_UV0;
    float4 _Outline_Sampler_var = tex2Dlod(_Outline_Sampler,float4(TRANSFORM_TEX(node_6326, _Outline_Sampler),0.0,0));
    float Set_Outline_Width = (_Outline_Width*0.001*smoothstep( _Farthest_Distance, _Nearest_Distance, distance(objPos.rgb,_WorldSpaceCameraPos) )*_Outline_Sampler_var.rgb).r;
    float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - o.pos.xyz);
    float4 viewDirectionVP = mul(UNITY_MATRIX_VP, float4(viewDirection.xyz, 1));
    _Offset_Z = _Offset_Z * -0.1;
    o.pos = UnityObjectToClipPos(float4(v.vertex.xyz + v.normal*Set_Outline_Width,1) );
    o.pos.z = o.pos.z + _Offset_Z*viewDirectionVP.z;
    return o;
}
float4 frag(VertexOutput i, float facing : VFACE) : SV_Target{
    float isFrontFace = ( facing >= 0 ? 1 : 0 );
    float faceSign = ( facing >= 0 ? 1 : -1 );
    float4 objPos = mul ( unity_ObjectToWorld, float4(0,0,0,1) );
    float3 lightColor = _LightColor0.rgb;
    float2 Set_UV0 = i.uv0;
    float2 node_6858 = Set_UV0;
    float4 _BaseMap_var = tex2D(_BaseMap,TRANSFORM_TEX(node_6858, _BaseMap));
    float3 node_9970 = (_BaseColor.rgb*_BaseMap_var.rgb);
    float3 Set_BaseColor = lerp( node_9970, (node_9970*_LightColor0.rgb), _Is_LightColor_Base );
    float3 node_2878 = Set_BaseColor;
    float3 Set_Outline_Color = lerp( _Outline_Color.rgb, (_Outline_Color.rgb*node_2878*node_2878), _Is_BlendBaseColor );
    return fixed4(Set_Outline_Color,0);
}
```

#アウトラインPassを書き換えたUCTS_Outline.cginc

```
uniform float4 _LightColor0;
uniform float4 _BaseColor;
uniform sampler2D _BaseMap; uniform float4 _BaseMap_ST;
uniform float _Outline_Width;
uniform float _Farthest_Distance;
uniform float _Nearest_Distance;
uniform sampler2D _Outline_Sampler; uniform float4 _Outline_Sampler_ST;
uniform float4 _Outline_Color;
uniform fixed _Is_BlendBaseColor;
uniform fixed _Is_LightColor_Base;
uniform float _Offset_Z;
struct VertexInput {
    float4 vertex : POSITION;
    float3 normal : NORMAL;
    float2 texcoord0 : TEXCOORD0;
};
struct VertexOutput {
    float4 pos : SV_POSITION;
    float2 uv0 : TEXCOORD0;
};
VertexOutput vert (VertexInput v) {
    VertexOutput o = (VertexOutput)0;
    o.uv0 = v.texcoord0;
    float4 _Outline_sampler_var = tex2Dlod(_Outline_Sampler,float4(TRANSFORM_TEX(o.uv0, _Outline_Sampler),0.0,0)); // Outlineの入り抜き調整Sampler
    o.pos = UnityObjectToClipPos(float4(v.vertex.xyz + v.normal*(_Outline_sampler_var.rgb*_Outline_Width*0.001).r,1) );
    return o;
}
float4 frag(VertexOutput i, float facing : VFACE) : SV_Target{
    float isFrontFace = ( facing >= 0 ? 1 : 0 );
    float faceSign = ( facing >= 0 ? 1 : -1 );
    float4 _MainTex_var = tex2D(_BaseMap,TRANSFORM_TEX(i.uv0, _BaseMap)); // 通常Color用テクスチャ
    return fixed4(((_MainTex_var.rgb*_MainTex_var.rgb)*_Outline_Color.rgb),0);
}
```