SHOW:
|
|
- or go back to the newest paste.
1 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) | |
2 | // Edited by MinionsArt for hologram effect | |
3 | ||
4 | Shader "FX/Hologram Effect" { | |
5 | Properties{ | |
6 | _TintColor("Tint Color", Color) = (0,0.5,1,1) | |
7 | _RimColor("Rim Color", Color) = (0,1,1,1) | |
8 | _MainTex("Main Texture", 2D) = "white" {} | |
9 | _GlitchTime("Glitches Over Time", Range(0.01,3.0)) = 1.0 | |
10 | _WorldScale("Line Amount", Range(1,200)) = 20 | |
11 | } | |
12 | ||
13 | Category{ | |
14 | Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Sphere" } | |
15 | Blend SrcAlpha OneMinusSrcAlpha | |
16 | ColorMask RGB | |
17 | Cull Back | |
18 | SubShader{ | |
19 | Pass{ | |
20 | ||
21 | CGPROGRAM | |
22 | #pragma vertex vert | |
23 | #pragma fragment frag | |
24 | #pragma target 2.0 | |
25 | ||
26 | ||
27 | #include "UnityCG.cginc" | |
28 | ||
29 | sampler2D _MainTex; | |
30 | fixed4 _TintColor; | |
31 | fixed4 _RimColor; | |
32 | ||
33 | ||
34 | struct appdata_t { | |
35 | float4 vertex : POSITION; | |
36 | fixed4 color : COLOR; | |
37 | ||
38 | float2 texcoord : TEXCOORD0; | |
39 | float3 normal : NORMAL; // vertex normal | |
40 | UNITY_VERTEX_INPUT_INSTANCE_ID | |
41 | }; | |
42 | ||
43 | struct v2f { | |
44 | float4 vertex : SV_POSITION; | |
45 | fixed4 color : COLOR; | |
46 | float2 texcoord : TEXCOORD0; | |
47 | float3 wpos : TEXCOORD1; // worldposition | |
48 | float3 normalDir : TEXCOORD2; // normal direction for rimlighting | |
49 | ||
50 | }; | |
51 | ||
52 | float4 _MainTex_ST; | |
53 | float _GlitchTime; | |
54 | float _WorldScale; | |
55 | float _OptTime = 0; | |
56 | ||
57 | v2f vert(appdata_t v) | |
58 | { | |
59 | v2f o; | |
60 | ||
61 | o.vertex = UnityObjectToClipPos(v.vertex); | |
62 | ||
63 | // Vertex glitching | |
64 | _OptTime = _OptTime == 0 ? sin(_Time.w * _GlitchTime) : _OptTime;// optimisation | |
65 | float glitchtime = step(0.99, _OptTime); // returns 1 when sine is near top, otherwise returns 0; | |
66 | float glitchPos = v.vertex.y + _SinTime.y;// position on model | |
67 | float glitchPosClamped = step(0, glitchPos) * step(glitchPos, 0.2);// clamped segment of model | |
68 | o.vertex.xz += glitchPosClamped * 0.1 * glitchtime * _SinTime.y;// moving the vertices when glitchtime returns 1; | |
69 | ||
70 | ||
71 | o.color = v.color; | |
72 | o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); | |
73 | ||
74 | // world position and normal direction | |
75 | o.wpos = mul(unity_ObjectToWorld, v.vertex).xyz; | |
76 | o.normalDir = normalize(mul(float4(v.normal, 0.0), unity_WorldToObject).xyz); | |
77 | ||
78 | return o; | |
79 | } | |
80 | ||
81 | fixed4 frag(v2f i) : SV_Target | |
82 | { | |
83 | float4 text = tex2D(_MainTex, i.texcoord) * _TintColor;// texture | |
84 | ||
85 | // rim lighting | |
86 | float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.wpos.xyz); | |
87 | half rim = 1.0 - saturate(dot(viewDirection, i.normalDir));// rimlight based on view and normal | |
88 | ||
89 | // small scanlines down | |
90 | float fraclines = frac((i.wpos.y * _WorldScale) + _Time.y);//small lines | |
91 | float scanlines = step(fraclines, 0.5);// cut off based on 0.5 | |
92 | // big scanline up | |
93 | float bigfracline = frac((i.wpos.y ) - _Time.x * 4);// big gradient line | |
94 | ||
95 | fixed4 col = text + (bigfracline * 0.4 * _TintColor) +(rim * _RimColor);// end result color | |
96 | ||
97 | col.a = 0.8 * (scanlines + rim + bigfracline);// alpha based on scanlines and rim | |
98 | ||
99 | return col; | |
100 | } | |
101 | ENDCG | |
102 | } | |
103 | } | |
104 | } | |
105 | } |