Holo.shader 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  3. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  4. // Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
  5. Shader "HOLO/Holo"
  6. {
  7. Properties
  8. {
  9. _originalDiffuse("Original Diffuse Map", 2D) = "white" {}
  10. _Diffuse("Diffuse Map", 2D) = "white" {}
  11. [HDR] _diff_Color ("Diffuse Color Mult", Color) = (1,1,1,1)
  12. _N_map("Noise", 2D) = "white" {}
  13. _M_map("Mask", 2D) = "white" {}
  14. _intensity("Intensity", float) = 0
  15. _deform("Deformation Intensity", float) = 1
  16. [HDR] _Color ("Outline Color Mult", Color) = (1,1,1,1)
  17. _Opacity("Base Opacity", range (0,1)) = 0
  18. _Bias("Bias", range (0,1)) = 0
  19. _Scale ("Scale ", range (0,10)) = 0
  20. _Power("Power", range (0,3)) = 0
  21. //_Opacity_gl("Glitch Opacity", range (0,1)) = 0
  22. _Speed("Speed", range (-1,1)) = 0
  23. _t("Extra Option", range (0,1)) = 0
  24. _noise_details("G/H Noise Details Amount ", range (1,16)) = 0
  25. [Toggle] _X("Active X Axe", Float) = 1
  26. [Toggle] _Y("Active X Axe", Float) = 1
  27. [Toggle] _glitchColor("Display G/H Color", Float) = 1
  28. [Toggle] _monochrom("Monochromatic", Float) = 1
  29. [Toggle] _OriginalUVSwitch("Switch to Orginal UVs on/off", Float) = 0
  30. _Distance("Distance", float) = 0
  31. _Amplitude("Amplitude", float) = 0
  32. _Speed_Up("_Speed_Up", float) = 0
  33. _Amount("Amount", Range(0, 1)) = 0
  34. }
  35. Subshader
  36. {
  37. //http://docs.unity3d.com/462/Documentation/Manual/SL-SubshaderTags.html
  38. // Background : 1000 - 0 - 1499 = Background
  39. // Geometry : 2000 - 1500 - 2399 = Geometry
  40. // AlphaTest : 2450 - 2400 - 2699 = AlphaTest
  41. // Transparent: 3000 - 2700 - 3599 = Transparent
  42. // Overlay : 4000 - 3600 - 5000 = Overlay
  43. Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
  44. Pass
  45. {
  46. Blend SrcAlpha OneMinusSrcAlpha
  47. Zwrite on
  48. ZTest on
  49. //cull off
  50. CGPROGRAM
  51. //http://docs.unity3d.com/Manual/SL-ShaderPrograms.html
  52. #pragma vertex vert
  53. #pragma fragment frag
  54. #include "UnityCG.cginc"
  55. //http://docs.unity3d.com/ru/current/Manual/SL-ShaderPerformance.html
  56. //http://docs.unity3d.com/Manual/SL-ShaderPerformance.html
  57. // VARIABLES ///////////////////////////////////////////////////////////////////////////////////////////
  58. uniform sampler2D _originalDiffuse;
  59. uniform half4 _Color;
  60. uniform half4 _diff_Color ;
  61. uniform sampler2D _Diffuse;
  62. uniform sampler2D _N_map;
  63. uniform sampler2D _M_map;
  64. uniform float4 _Diffuse_ST;
  65. uniform float4 _N_map_ST;
  66. uniform float4 _M_map_ST;
  67. uniform float _intensity;
  68. uniform float _deform ;
  69. uniform float _Bias ;
  70. uniform float _Scale ;
  71. uniform float _Power ;
  72. uniform float _Speed ;
  73. uniform float _t ;
  74. uniform float _X ;
  75. uniform float _Y ;
  76. uniform float _glitchColor ;
  77. uniform float _monochrom ;
  78. uniform float _Opacity ;
  79. uniform float _noise_details ;
  80. uniform float _Distance ;
  81. uniform float _Amplitude ;
  82. uniform float _Speed_Up ;
  83. uniform float _Amount ;
  84. uniform float _OriginalUVSwitch ;
  85. //uniform float _Opacity_gl ;
  86. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  87. //https://msdn.microsoft.com/en-us/library/windows/desktop/bb509647%28v=vs.85%29.aspx#VS
  88. // STRUCTURS //////////////////////////////////////////////////////////////////////////////////////////
  89. struct vertexInput
  90. {
  91. float4 vertex : POSITION;
  92. float4 texcoord : TEXCOORD0;
  93. float4 texcoord1 : TEXCOORD1;
  94. float4 normal : NORMAL;
  95. };
  96. struct vertexOutput
  97. {
  98. float4 pos : SV_POSITION;
  99. float4 uv : TEXCOORD0;
  100. float4 texcoord1 : TEXCOORD1;
  101. float3 uv_matcap : TEXCOORD2;
  102. float3 normalDir : TEXCOORD3;
  103. float4 R : TEXCOORD4;
  104. float4 normal : NORMAL;
  105. };
  106. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  107. // FUNCTIONS /////////////////////////////////////////////////////////////////////////////////////////////
  108. float4 glitch(float2 coord)
  109. {
  110. float4 c = float4(coord,0,1);
  111. float4 d;
  112. float4 e;
  113. for (int j=_noise_details;j>0;j--) {
  114. e=floor(c);
  115. d+=(sin(e*e.yxyx+e*(_Time/10)));
  116. c*=2.5;
  117. }
  118. float4 glitch_res = d;
  119. return glitch_res;
  120. }
  121. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  122. // VERTEX OPERATIONS ////////////////////////////////////////////////////////////////////////////////////
  123. vertexOutput vert(vertexInput v)
  124. {
  125. vertexOutput o;
  126. UNITY_INITIALIZE_OUTPUT(vertexOutput, o);
  127. fixed T = _Time * _Speed*30;
  128. fixed offset_sin =(sin(T*2)+1);
  129. fixed offset_cos = cos(T*2);
  130. float4 mask_map = tex2Dlod(_M_map, float4((v.texcoord.xy * ((((_M_map_ST.y),(_M_map_ST.y * offset_cos))) ) + (((_M_map_ST.z ),(_M_map_ST.w * offset_sin)))),0,0));
  131. float4 glitch_ver = glitch(v.texcoord.xy)*(0.001 * _deform) * (0.1*_intensity) * mask_map.x ;
  132. float3 axe = float3(_X,_Y,1);
  133. float Animation_Sinus = sin(_Time.y * _Speed_Up + (v.vertex.y*axe.y) +(v.vertex.x*axe.x)* _Amplitude) *_Distance * _Amount ;
  134. v.vertex.xyz += (glitch_ver.xyz * axe * v.normal.xyz * 10) ;
  135. //v.vertex.x += Animation_Sinus *axe.x *glitch_ver.x * v.normal.x ;
  136. //v.vertex.y += Animation_Sinus *axe.y *glitch_ver.y * v.normal.y;
  137. // PROJECTIONS
  138. o.pos = UnityObjectToClipPos( v.vertex);
  139. o.uv = v.texcoord;
  140. float3 posWorld = mul(unity_ObjectToWorld, v.vertex).xyz;
  141. //float3 normWorld = normalize(mul(float3x3(unity_ObjectToWorld), v.normal));
  142. float3 normalVS = mul(UNITY_MATRIX_MV,v.normal);
  143. normalVS = normalize(normalVS);
  144. o.normalDir = UnityObjectToWorldNormal(v.normal);
  145. o.uv_matcap.xy = normalVS.xy * 0.5 + float2(0.5,0.5);
  146. float3 I = normalize(posWorld - _WorldSpaceCameraPos.xyz);
  147. fixed temp1 = dot(I, o.normalDir) + _t;
  148. o.R.x = _Bias * _Scale * pow(temp1, _Power);
  149. return o;
  150. }
  151. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  152. // FRAGMENTS OPERATIONS ///////////////////////////////////////////////////////////////////////////////
  153. half4 frag(vertexOutput i , float facing : VFACE) : COLOR
  154. {
  155. /// TIME ANIMATION
  156. fixed T = _Time.x * _Speed*30 ;
  157. fixed offset_sin = (sin(T*2)+1);
  158. fixed offset_cos = cos(T*2);
  159. /// GET DIFF / MASK / NOISE FROM MAPS
  160. float4 temp_noise = tex2D(_N_map, float4((i.uv.xy * (_N_map_ST.xy ) + (_N_map_ST.zw * T)),0,0));
  161. float4 mask = tex2D(_M_map, float4((i.uv.xy * ((((_M_map_ST.y),(_M_map_ST.y * offset_cos))) ) + (((_M_map_ST.z ),(_M_map_ST.w * offset_sin)))),0,0));
  162. //float4 diff = tex2D(_Diffuse, i.uv);
  163. //float4 c_1 = tex2D(_Diffuse ,float4((i.uv_matcap.xy * ((_Diffuse_ST.x), _Diffuse_ST.y ) + ((_Diffuse_ST.z ),_Diffuse_ST.w )), 0,0)) ;
  164. float4 c_1 = float4(0,0,0,0);
  165. // Procedural Animation
  166. float Animation_Sinus_frag = sin(_Time.y * _Speed_Up + (i.uv.y) * _Amplitude) *_Distance * _Amount;
  167. ///////- Switch original UV
  168. if (_OriginalUVSwitch == 0)
  169. {
  170. float4 diff = tex2D(_Diffuse, i.uv);
  171. //i.uv.xy += (temp * sin(1)* i.uv.x)*(_intensity) ;
  172. c_1 = tex2D(_Diffuse ,float4((i.uv_matcap.xy * ((_Diffuse_ST.x), _Diffuse_ST.y ) + ((_Diffuse_ST.z ),_Diffuse_ST.w )), 0, 0 )) ;
  173. }
  174. if (_OriginalUVSwitch == 1)
  175. {
  176. float4 diff = tex2D(_originalDiffuse, i.uv);
  177. //i.uv.xy += (temp * sin(1)* i.uv.x)*(_intensity) ;
  178. c_1 = tex2D(_originalDiffuse ,i.uv) ;
  179. }
  180. //////////// Procedural noise glitch
  181. /// Distortion Uvs and Colors
  182. fixed temp = temp_noise.x * mask.x ;
  183. i.uv.xy += (temp * sin(T)* i.uv.x)*(_intensity) ;
  184. float4 glitch_res = glitch(i.uv.xy) * _glitchColor ;
  185. //// Color distortion
  186. float4 c_2 = _Color;
  187. c_2.r += (temp * sin(T*1) * glitch_res.x * (_intensity)*0.25) *0.75 ;
  188. c_2.g +=(temp * sin(T*2) * glitch_res.y * (_intensity)*0.5) *0.75;
  189. c_2.b += (temp * sin(T*4) * glitch_res.x * (_intensity)) *0.75;
  190. /// main color opacity and color override
  191. c_1.a *= _Opacity ;
  192. c_1 *= _diff_Color ;
  193. /// Switch to Monchromatic Mode
  194. if (_monochrom == 1)
  195. {
  196. fixed c_2_to_grey = (c_2.r +c_2.g + c_2.b) /3;
  197. fixed c_1_to_grey = (c_1.r +c_1.g + c_1.b) /3;
  198. c_2.rgb = float3(c_2_to_grey,c_2_to_grey,c_2_to_grey);
  199. c_1.rgb = float3(c_1_to_grey,c_1_to_grey,c_1_to_grey);
  200. }
  201. /// Results
  202. return lerp(c_1,c_2,i.R.x);
  203. }
  204. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  205. ENDCG
  206. }
  207. }
  208. CustomEditor "Glitch_Editor_lite"
  209. }