123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- Shader "ModelEffect/VerticsOutline_Normal"
- {
- Properties {
- _MainTex("Base (RGB)", 2D) = "white" {}
- _OutlineFactor("Outline Factor", Range(0, 1)) = 0.5
- _OutlineColor("Outline Color", Color) = (1,1,1,1)
- _OutlineWidth("Outline Width", Range(0, 10)) = 0.002
- _BodyAlpha("Body Alpha", Range(0, 1)) = 1
- _Stencil("Stencil ID", Int) = 16
- [HideInInspector] _StencilWriteMask("Stencil Write Mask", Float) = 255
- [HideInInspector] _StencilReadMask("Stencil Read Mask", Float) = 255
- }
- SubShader {
- Tags {
- "RenderType" = "Transparent"
- "Queue" = "Transparent"
- "IgnoreProjector" = "True"
- }
- LOD 200
- Pass {
- Name "VerticsOutline_Outline_Stencil"
- Cull Off
- ZWrite Off
- ZTest Always
- ColorMask 0
- Stencil {
- Ref [_Stencil]
- Comp Always
- Pass Replace
- ZFail Replace
- ReadMask [_StencilReadMask]
- WriteMask [_StencilWriteMask]
- }
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma target 2.0
- #pragma multi_compile_fog
- #include "UnityCG.cginc"
- struct appdata_t {
- float4 vertex : POSITION;
- float2 texcoord : TEXCOORD0;
- float3 normal : NORMAL;
- UNITY_VERTEX_INPUT_INSTANCE_ID
- };
- struct v2f {
- float4 vertex : SV_POSITION;
- float2 texcoord : TEXCOORD0;
- UNITY_FOG_COORDS(1)
- UNITY_VERTEX_OUTPUT_STEREO
- };
- sampler2D _MainTex;
- float4 _MainTex_ST;
- v2f vert(appdata_t v)
- {
- v2f o;
- UNITY_SETUP_INSTANCE_ID(v);
- UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
- UNITY_TRANSFER_FOG(o, o.vertex);
- return o;
- }
- fixed4 frag(v2f i) : SV_Target
- {
- fixed4 col = tex2D(_MainTex, i.texcoord);
- UNITY_APPLY_FOG(i.fogCoord, col);
- UNITY_OPAQUE_ALPHA(col.a);
- return col;
- }
- ENDCG
- }
- Pass {
- Name "VerticsOutline_Outline_Face1"
- Cull Off
- ZWrite On
- //ZTest Always
- ColorMask RGBA
-
- Stencil {
- Ref [_Stencil]
- Comp NotEqual
- Pass Keep
- ZFail Keep
- ReadMask[_StencilReadMask]
- WriteMask[_StencilWriteMask]
- }
-
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma target 2.0
- #pragma multi_compile_fog
- #include "UnityCG.cginc"
- struct appdata_t {
- float4 vertex : POSITION;
- float2 texcoord : TEXCOORD0;
- float3 normal : NORMAL;
- UNITY_VERTEX_INPUT_INSTANCE_ID
- };
- struct v2f {
- float4 vertex : SV_POSITION;
- float2 texcoord : TEXCOORD0;
- UNITY_FOG_COORDS(1)
- UNITY_VERTEX_OUTPUT_STEREO
- };
- sampler2D _MainTex;
- float4 _MainTex_ST;
- uniform fixed4 _OutlineColor;
- uniform float _OutlineWidth;
- uniform float _OutlineFactor;
- v2f vert(appdata_t v)
- {
- v2f o;
- UNITY_SETUP_INSTANCE_ID(v);
- UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
- float3 caculateVec = lerp(normalize(v.vertex.xyz), normalize(v.normal), _OutlineFactor);
- o.vertex = UnityObjectToClipPos(v.vertex);
- float3 norm = mul((float3x3)UNITY_MATRIX_IT_MV, caculateVec);
- float2 offset = TransformViewToProjection(norm.xy);
- o.vertex.xy += offset * o.vertex.z * _OutlineWidth;
- o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
- UNITY_TRANSFER_FOG(o,o.vertex);
- return o;
- }
- fixed4 frag(v2f i) : SV_Target
- {
- fixed4 col = _OutlineColor;
- UNITY_APPLY_FOG(i.fogCoord, col);
- UNITY_OPAQUE_ALPHA(col.a);
- return col;
- }
- ENDCG
- }
- Pass {
- Name "VerticsOutline_Outline_Face2"
- Cull Off
- ZWrite On
- //ZTest Always
- Blend SrcAlpha OneMinusSrcAlpha
- Stencil {
- Ref [_Stencil]
- Comp NotEqual
- Pass Keep
- ZFail Keep
- ReadMask[_StencilReadMask]
- WriteMask[_StencilWriteMask]
- }
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma target 2.0
- #pragma multi_compile_fog
- #include "UnityCG.cginc"
- struct appdata_t {
- float4 vertex : POSITION;
- float2 texcoord : TEXCOORD0;
- float3 normal : NORMAL;
- UNITY_VERTEX_INPUT_INSTANCE_ID
- };
- struct v2f {
- float4 vertex : SV_POSITION;
- float2 texcoord : TEXCOORD0;
- UNITY_FOG_COORDS(1)
- UNITY_VERTEX_OUTPUT_STEREO
- };
- sampler2D _MainTex;
- float4 _MainTex_ST;
- uniform fixed4 _OutlineColor;
- uniform float _OutlineWidth;
- uniform float _OutlineFactor;
- v2f vert(appdata_t v)
- {
- v2f o;
- UNITY_SETUP_INSTANCE_ID(v);
- UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
- float3 caculateVec = -lerp(normalize(v.vertex.xyz), normalize(v.normal), _OutlineFactor);
- o.vertex = UnityObjectToClipPos(v.vertex);
- float3 norm = mul((float3x3)UNITY_MATRIX_IT_MV, caculateVec);
- float2 offset = TransformViewToProjection(norm.xy);
- o.vertex.xy += offset * o.vertex.z * _OutlineWidth;
- o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
- UNITY_TRANSFER_FOG(o,o.vertex);
- return o;
- }
- fixed4 frag(v2f i) : SV_Target
- {
- fixed4 col = _OutlineColor;
- UNITY_APPLY_FOG(i.fogCoord, col);
- UNITY_OPAQUE_ALPHA(col.a);
- return col;
- }
- ENDCG
- }
- Pass {
- Name "VerticsOutline_Body"
- Cull Back
- ZWrite On
- Blend SrcAlpha OneMinusSrcAlpha
- ColorMask RGBA
- Stencil {
- Ref[_Stencil]
- Comp Always
- Pass Replace
- ZFail Replace
- ReadMask[_StencilReadMask]
- WriteMask[_StencilWriteMask]
- }
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma target 2.0
- #pragma multi_compile_fog
- #include "UnityCG.cginc"
- struct appdata_t {
- float4 vertex : POSITION;
- float2 texcoord : TEXCOORD0;
- UNITY_VERTEX_INPUT_INSTANCE_ID
- };
- struct v2f {
- float4 vertex : SV_POSITION;
- float2 texcoord : TEXCOORD0;
- UNITY_FOG_COORDS(1)
- UNITY_VERTEX_OUTPUT_STEREO
- };
- sampler2D _MainTex;
- float4 _MainTex_ST;
- uniform float _BodyAlpha;
- v2f vert(appdata_t v)
- {
- v2f o;
- UNITY_SETUP_INSTANCE_ID(v);
- UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
- UNITY_TRANSFER_FOG(o,o.vertex);
- return o;
- }
- fixed4 frag(v2f i) : SV_Target
- {
- fixed4 col = tex2D(_MainTex, i.texcoord);
- UNITY_APPLY_FOG(i.fogCoord, col);
- UNITY_OPAQUE_ALPHA(col.a);
- return fixed4(col.rgb, _BodyAlpha);
- }
- ENDCG
- }
- }
- }
|