码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-11-27 18:04:23      阅读:964      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   os   sp   for   on   div   

 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) = 0
10     }
11     
12     SubShader 
13     {
14 
15         Tags { "RenderType"="Opaque" }
16         LOD 200
17     
18         CGPROGRAM
19         #pragma surface surf Lambert
20 
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         ENDCG
38 
39         Pass 
40         {
41             CGINCLUDE
42             #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             ENDCG
69 
70             Name "OUTLINE"
71             Tags { "LightMode" = "Always" }
72             Cull Front
73             ZWrite On
74             ColorMask RGB
75             Blend SrcAlpha OneMinusSrcAlpha
76 
77             CGPROGRAM
78             #pragma vertex vert
79             #pragma fragment frag
80             half4 frag(v2f i) :COLOR { return i.color; }
81             ENDCG
82         }
83     } 
84     
85     Fallback "Self-Illumin/VertexLit"
86 }

 

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

标签:style   blog   io   color   os   sp   for   on   div   

原文地址:http://www.cnblogs.com/hrkblogs/p/4126794.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!