Shader "Unlit/cartoon"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Diffuse("COLOR",Color)=(1,1,1,1)
_OutLine("OutLine",Range(0,2))=0.1
_OutLineColor("OutLineColor",Color)=(0,0,0,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
Name "Outline"
Cull Front
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCg.cginc"
float _OutLine;
fixed4 _OutLineColor;
struct v2f
{
float4 vertex:SV_POSITION;
};
v2f vert(appdata_base v)
{
v2f o;
v.vertex.xyz+=v.normal*_OutLine;
o.vertex=UnityObjectToClipPos(v.vertex);
return o;
}
float4 frag(v2f i):SV_Target
{
return _OutLineColor ;
}
ENDCG
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Lighting.cginc"
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
fixed3 worldNormal:TEXCOORD1;
float worldPos: TEXCOORD2;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Diffuse;
v2f vert (appdata_base v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
fixed3 worldNormal=UnityObjectToWorldNormal(v.normal);
o.worldNormal=worldNormal;
o.worldPos=mul(unity_ObjectToWorld,v.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed3 ambient=UNITY_LIGHTMODEL_AMBIENT.xyz;
fixed4 albedo=tex2D(_MainTex,i.uv);
fixed3 WorldLightDir=UnityWorldSpaceLightDir(i.worldPos);
float difLight=dot(WorldLightDir,i.worldNormal)*0.5+0.5;
fixed3 diffuse=_LightColor0.rgb*albedo*difLight*_Diffuse.rgb;
// sample the texture
fixed3 color=diffuse+ambient;
return fixed4(color,1);
}
ENDCG
}
}
}
05-11
09-08
97
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-07
07-10
4043
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)