Outline 边缘描边
轮廓:
1, 直接 渲染两个物体 。
一个大 一个小 。 大是轮廓 直接返回一个 颜色。
Pass{}
2, 渲染一个物体
1, 找到边缘
2, 给边缘着色
3, 非边缘地带正常纹理采样。
//多个pass渲染多次 边缘
Shader "Hidden/OutLine"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_OutLineWidth("width",float) = 1.2//属性
}
SubShader
{
// No culling or depth
//Cull Off ZWrite Off ZTest Always
Pass
{
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 = mul(UNITY_MATRIX_MVP, 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 = 1 - col;
return fixed4(1,0,0,1) ;
//return col;
}
ENDCG
}
Pass
{
ZTest Always
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;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, 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 = 1 - col;
// return fixed4(0,1,0,1) ;
return col;
}
ENDCG
}
}
}