首页 > 代码库 > Unity3D带自发光及边缘高光的shader

Unity3D带自发光及边缘高光的shader

 1 Shader "Custom/Ill_RimLight"  2 { 3     Properties { 4         _Color ("Main Color", Color) = (.5,.5,.5,1) 5         _OutlineColor ("Rim Color", Color) = (0,0,0,1) 6         _Outline ("Rim width", Range (.002, 0.03)) = .005 7         _MainTex ("Base (RGB)", 2D) = "white" { } 8         _Illum ("Illumin (A)", 2D) = "white" { } 9         _EmissionLM ("Emission (Lightmapper)", Float) = 010     }11     12     SubShader 13     {14 15         Tags { "RenderType"="Opaque" }16         LOD 20017     18         CGPROGRAM19         #pragma surface surf Lambert20 21         sampler2D _MainTex;22         sampler2D _Illum;23         fixed4 _Color;24 25         struct Input {26             float2 uv_MainTex;27             float2 uv_Illum;28         };29 30         void surf (Input IN, inout SurfaceOutput o) {31             fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);32             fixed4 c = tex * _Color;33             o.Albedo = c.rgb;34             o.Emission = c.rgb * tex2D(_Illum, IN.uv_Illum).a;35             o.Alpha = c.a;36         }37         ENDCG38 39         Pass 40         {41             CGINCLUDE42             #include "UnityCG.cginc"43     44             struct appdata {45                 float4 vertex : POSITION;46                 float3 normal : NORMAL;47             };48 49             struct v2f {50                 float4 pos : POSITION;51                 float4 color : COLOR;52             };53     54             uniform float _Outline;55             uniform float4 _OutlineColor;56     57             v2f vert(appdata v) {58                 v2f o;59                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);60 61                 float3 norm   = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal);62                 float2 offset = TransformViewToProjection(norm.xy);63 64                 o.pos.xy += offset * o.pos.z * _Outline;65                 o.color = _OutlineColor;66                 return o;67             }68             ENDCG69 70             Name "OUTLINE"71             Tags { "LightMode" = "Always" }72             Cull Front73             ZWrite On74             ColorMask RGB75             Blend SrcAlpha OneMinusSrcAlpha76 77             CGPROGRAM78             #pragma vertex vert79             #pragma fragment frag80             half4 frag(v2f i) :COLOR { return i.color; }81             ENDCG82         }83     } 84     85     Fallback "Self-Illumin/VertexLit"86 }

 

Unity3D带自发光及边缘高光的shader