`
wgcode
  • 浏览: 575696 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

unity3d实现描边shader

阅读更多
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. Shader "Custom/OutLine" {Properties {  
  2.         _Color ("Main Color", Color) = (.5,.5,.5,1)  
  3.         _OutlineColor ("Outline Color", Color) = (0,0,0,1)  
  4.         _Outline ("Outline width", Range (0.0, 0.03)) = .005  
  5.         _MainTex ("Base (RGB)", 2D) = "white" { }  
  6.     }  
  7.     CGINCLUDE  
  8.         #include "UnityCG.cginc"  
  9.         struct appdata {  
  10.             float4 vertex : POSITION;  
  11.             float3 normal : NORMAL;  
  12.         };  
  13.         struct v2f {  
  14.             float4 pos : POSITION;  
  15.             float4 color : COLOR;  
  16.         };  
  17.         uniform float _Outline;  
  18.         uniform float4 _OutlineColor;  
  19.         v2f vert(appdata v) {  
  20.             v2f o;  
  21.             o.pos = mul(UNITY_MATRIX_MVP, v.vertex);  
  22.             float3 norm   = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal);  
  23.             float2 offset = TransformViewToProjection(norm.xy);  
  24.             o.pos.xy += offset * o.pos.z * _Outline;  
  25.             o.color = _OutlineColor;  
  26.             return o;  
  27.         }  
  28.     ENDCG  
  29.     SubShader {  
  30.         Tags { "Queue" = "Transparent" }  
  31.         Pass {  
  32.             Tags { "LightMode" = "Always" }  
  33.             Cull Off  
  34.             ZWrite Off  
  35.             //ZTest Always//始终通过深度测试,即可以渲染  
  36.             //ColorMask RGB // alpha not used  
  37.             Blend SrcAlpha OneMinusSrcAlpha // Normal  
  38.   
  39.             CGPROGRAM  
  40.             #pragma vertex vert  
  41.             #pragma fragment frag  
  42.             half4 frag(v2f i) :COLOR {  
  43.                 return i.color;  
  44.             }  
  45.             ENDCG  
  46.         }  
  47.         Pass {  
  48.             Name "BASE"  
  49.             ZWrite On  
  50.             ZTest LEqual  
  51.             Blend SrcAlpha OneMinusSrcAlpha  
  52.             Material {  
  53.                 Diffuse [_Color]  
  54.                 Ambient [_Color]  
  55.             }  
  56.             Lighting On  
  57.             SetTexture [_MainTex] {  
  58.                 ConstantColor [_Color]  
  59.                 Combine texture * constant  
  60.             }  
  61.             SetTexture [_MainTex] {  
  62.                 Combine previous * primary DOUBLE  
  63.             }  
  64.         }  
  65.     }  
  66.     Fallback "Diffuse"  
  67. }  

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics