1.轮廓:
(1)直接 渲染两个物体:一个大 一个小,大的是轮廓,直接返回一个颜色;小的物体按照纹理采样返回颜色
两个Pass { }
第一个Pass 渲染大的物体边缘第二个Pass 渲染小的物品
Shader "Hidden/OutLine"
{Properties{_MainTex ("Texture", 2D) = "white" {}_OutLineWidth("OutLineWidth",float) = 1.2}SubShader{// No culling or depth//Cull Off ZWrite Off ZTest AlwaysPass{CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"struct appdata{float4 vertex : POSITION;float2 uv : TEXCOORD0;};struct v2f{float2 uv : TEXCOORD0;float4 vertex : SV_POSITION;};float _OutLineWidth;v2f vert (appdata v){v2f o;v.vertex.xy *=_OutLineWidth;o.vertex = UnityObjectToClipPos(v.vertex);o.uv = v.uv;return o;}sampler2D _MainTex;fixed4 frag (v2f i) : SV_Target{fixed4 col = tex2D(_MainTex, i.uv);// just invert the colors//col.rgb = 1 - col.rgb;//return col;return fixed4(1,0,0,1);}ENDCG}Pass{//通过深度测试ZTest AlwaysCGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"struct appdata{float4 vertex : POSITION;float2 uv : TEXCOORD0;};struct v2f{float2 uv : TEXCOORD0;float4 vertex : SV_POSITION;};v2f vert (appdata v){v2f o;o.vertex = UnityObjectToClipPos(v.vertex);o.uv = v.uv;return o;}sampler2D _MainTex;fixed4 frag (v2f i) : SV_Target{fixed4 col = tex2D(_MainTex, i.uv);// just invert the colors//col.rgb = 1 - col.rgb;return col;//return fixed4(0,1,0,1);}ENDCG}}
}
(2)渲染一个物体:
找到边缘--涉及到法线,越往边缘,法线和视线的夹角越大的给边缘着色非边缘地带正常纹理采样