Shader "Unlit/Cha" { Properties { _MainTex("Main", 2D) = "white" {} _Thred("Edge Thred" , Range(0.01,1)) = 0.25 _Range("Edge Range" , Range(1,10)) = 1 _Pow("Edge Intensity",Range(0,10)) = 1 } SubShader { Tags { "RenderType" = "Opaque" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag // make fog work #pragma multi_compile_fog #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; float3 normal : NORMAL; }; struct v2f { float2 uv : TEXCOORD0; //UNITY_FOG_COORDS(1) float4 vertex : SV_POSITION; float3 worldPos : TEXCOORD1; float3 vdotn : TEXCOORD2; }; sampler2D _MainTex; float4 _MainTex_ST; float _Thred; float _Range; float _Pow; v2f vert(appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); o.worldPos = UnityObjectToClipPos(v.vertex); float3 viewDir = normalize(mul(unity_WorldToObject, float4(_WorldSpaceCameraPos.xyz, 1)).xyz - v.vertex); o.vdotn = dot(viewDir, v.normal); return o; } fixed4 frag(v2f i) : SV_Target { fixed4 mainTex = tex2D(_MainTex, i.uv); fixed4 col = mainTex;// fixed4(blend, blend, blend, 1);//*mainTex; fixed edge = pow(i.vdotn, 1) / _Range; edge = edge > _Thred ? 1 : edge; edge = pow(edge, _Pow); fixed4 edgeColor = fixed4(edge, edge, edge, edge); col = edgeColor * (1 - edgeColor.a) + col * (edgeColor.a); // sample the texture //fixed4 col = tex2D(_MainTex, i.uv); // apply fog //UNITY_APPLY_FOG(i.fogCoord, col); return col; } ENDCG } } }