Hologram2.shader 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
  2. // Edited by MinionsArt for hologram effect
  3. Shader "Am/Hologram Effect" {
  4. Properties{
  5. _TintColor("Tint Color", Color) = (0,0.5,1,1)
  6. _RimColor("Rim Color", Color) = (0,1,1,1)
  7. _MainTex("Main Texture", 2D) = "white" {}
  8. _GlitchTime("Glitches Over Time", Range(0.01,3.0)) = 1.0
  9. _WorldScale("Line Amount", Range(1,200)) = 20
  10. //Dissolve Texture
  11. _DissolveTex("Dissolve Texture", 2D) = "white" { }
  12. _Height("Dissolve by Height in Local Space", float) = 1
  13. _DissolveUpDown("Dissolve Up to Down Or Down to Up", float) = 1
  14. _DissolveSpread("Dissolve Spread", float) = 3
  15. _DissolveTint("Dissolve Color Tint", Color) = (1.0, 1.0, 1.0, 1.0)
  16. _LineWidth("Dissolve Board Line Width", float) = 0.1442
  17. }
  18. Category{
  19. Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Sphere" }
  20. Blend SrcAlpha OneMinusSrcAlpha
  21. Cull Back
  22. SubShader
  23. {
  24. /*Pass{
  25. ColorMask 0
  26. }*/
  27. Pass{
  28. //ColorMask RGB
  29. CGPROGRAM
  30. #pragma vertex vert
  31. #pragma fragment frag
  32. #pragma target 2.0
  33. #include "UnityCG.cginc"
  34. sampler2D _MainTex;
  35. fixed4 _TintColor;
  36. fixed4 _RimColor;
  37. struct appdata_t {
  38. float4 vertex : POSITION;
  39. fixed4 color : COLOR;
  40. float2 texcoord : TEXCOORD0;
  41. float3 normal : NORMAL; // vertex normal
  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. //#if DissolveH
  50. float3 lightDir : TEXCOORD4;
  51. float3 viewDir : TEXCOORD5;
  52. fixed distance : TEXCOORD6;
  53. //#endif
  54. };
  55. float4 _MainTex_ST;
  56. float _GlitchTime;
  57. float _WorldScale;
  58. float _OptTime = 0;
  59. //#if DissolveH
  60. uniform sampler2D _DissolveTex;
  61. uniform fixed _Height;
  62. uniform fixed _DissolveSpread;
  63. uniform fixed3 _DissolveTint;
  64. uniform fixed _LineWidth;
  65. uniform fixed _DissolveUpDown;
  66. //#endif
  67. v2f vert(appdata_t v)
  68. {
  69. v2f o;
  70. o.vertex = UnityObjectToClipPos(v.vertex);
  71. // Vertex glitching
  72. //_OptTime = _OptTime == 0 ? sin(_Time.w * _GlitchTime) : _OptTime;// optimisation
  73. //float glitchtime = step(0.99, _OptTime); // returns 1 when sine is near top, otherwise returns 0;
  74. //float glitchPos = v.vertex.y + _SinTime.y;// position on model
  75. //float glitchPosClamped = step(0, glitchPos) * step(glitchPos, 0.2);// clamped segment of model
  76. //o.vertex.xz += glitchPosClamped * 0.1 * glitchtime * _SinTime.y;// moving the vertices when glitchtime returns 1;
  77. o.color = v.color;
  78. o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
  79. // world position and normal direction
  80. o.wpos = mul(unity_ObjectToWorld, v.vertex).xyz;
  81. o.normalDir = normalize(mul(float4(v.normal, 0.0), unity_WorldToObject).xyz);
  82. //#if DissolveH
  83. o.viewDir = normalize(_WorldSpaceCameraPos.xyz - o.wpos.xyz);
  84. o.lightDir = normalize(_WorldSpaceLightPos0.xyz);
  85. //Dissolve by height in local coordinate.
  86. fixed l = _Height - v.vertex.y;
  87. o.distance = l * _DissolveUpDown;
  88. //#endif
  89. return o;
  90. }
  91. fixed4 frag(v2f i) : SV_Target
  92. {
  93. float4 text = tex2D(_MainTex, i.texcoord) * _TintColor;// texture
  94. // rim lighting
  95. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.wpos.xyz);
  96. half rim = 1.0 - saturate(dot(viewDirection, i.normalDir));// rimlight based on view and normal
  97. // small scanlines down
  98. //float fraclines = frac((i.wpos.y * _WorldScale) + _Time.y);//small lines
  99. //float scanlines = step(fraclines, 0.5);// cut off based on 0.5
  100. // big scanline up
  101. float bigfracline = frac((i.wpos.y * 4 ) - _Time.x * 6);// big gradient line
  102. bigfracline = step(bigfracline, 0.05);
  103. fixed4 col = text + (bigfracline * 0.4 * _TintColor) + (rim * _RimColor);// end result color
  104. //col.a = 0.8 * (scanlines + rim);// alpha based on scanlines and rim
  105. //col.a = 0.8 * rim;
  106. //#if DissolveH
  107. //fixed NdotL = dot(i.normalDir, i.lightDir);
  108. //fixed NdotV = dot(i.normalDir, i.viewDir);
  109. //fixed3 dissColor = tex2D(_DissolveTex, fixed2(NdotL, NdotV));
  110. ////fixed l = _Height - i.posWorld.y;
  111. //fixed clipDiff = i.distance + dissColor * _DissolveSpread;
  112. //clip(clipDiff);
  113. //fixed t = 1 - smoothstep(0.0, _LineWidth, clipDiff);
  114. //
  115. //col.rgb = lerp(col.rgb, _DissolveTint.rgb, t);
  116. //#endif
  117. return col;
  118. }
  119. ENDCG
  120. }
  121. }
  122. }
  123. }